@bhsd/codemirror-mediawiki 3.8.1 → 3.9.0
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 +45 -2
- package/dist/bidi.js +3 -3
- package/dist/codemirror.d.ts +9 -1
- package/dist/codemirror.js +51 -31
- package/dist/color.d.ts +1 -2
- package/dist/color.js +5 -16
- package/dist/config.d.ts +3 -2
- package/dist/config.js +4 -13
- package/dist/constants.d.ts +2 -1
- package/dist/constants.js +2 -1
- package/dist/escape.d.ts +1 -1
- package/dist/escape.js +11 -10
- package/dist/fold.d.ts +2 -1
- package/dist/fold.js +9 -8
- package/dist/hover.d.ts +1 -1
- package/dist/hover.js +9 -8
- package/dist/html.js +6 -5
- package/dist/indent.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +35 -38
- package/dist/inlay.d.ts +1 -1
- package/dist/inlay.js +11 -15
- package/dist/keymap.d.ts +2 -1
- package/dist/keymap.js +2 -3
- package/dist/linter.d.ts +2 -11
- package/dist/linter.js +17 -31
- package/dist/lintsource.d.ts +2 -2
- package/dist/lintsource.js +18 -33
- package/dist/lua.js +2 -1
- package/dist/main.min.js +27 -24
- package/dist/matchTag.js +2 -2
- package/dist/mediawiki.d.ts +2 -2
- package/dist/mediawiki.js +20 -17
- package/dist/mw.min.js +30 -27
- package/dist/mwConfig.js +3 -2
- package/dist/openLinks.js +9 -8
- package/dist/ref.d.ts +1 -1
- package/dist/ref.js +8 -6
- package/dist/signature.d.ts +1 -1
- package/dist/signature.js +3 -3
- package/dist/statusBar.js +8 -3
- package/dist/theme.js +1 -1
- package/dist/token.d.ts +2 -3
- package/dist/token.js +5 -3
- package/dist/util.d.ts +5 -0
- package/dist/util.js +7 -2
- package/dist/vue.js +2 -2
- package/dist/wiki.min.js +29 -26
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +12 -10
package/dist/mwConfig.js
CHANGED
|
@@ -158,7 +158,7 @@ var getMwConfig = async (modes) => {
|
|
|
158
158
|
...(config == null ? void 0 : config.variableIDs) ? [] : ["variables"],
|
|
159
159
|
...(config == null ? void 0 : config.functionHooks) ? [] : ["functionhooks"]
|
|
160
160
|
],
|
|
161
|
-
formatversion:
|
|
161
|
+
formatversion: 2
|
|
162
162
|
});
|
|
163
163
|
if (config && !isIPE) {
|
|
164
164
|
const { functionSynonyms: [insensitive] } = config;
|
|
@@ -209,7 +209,8 @@ var getParserConfig2 = (minConfig, mwConfig) => {
|
|
|
209
209
|
...getParserConfig(minConfig, mwConfig),
|
|
210
210
|
namespaces: mw.config.get("wgFormattedNamespaces"),
|
|
211
211
|
nsid,
|
|
212
|
-
variants
|
|
212
|
+
variants,
|
|
213
|
+
articlePath: mw.config.get("wgArticlePath")
|
|
213
214
|
};
|
|
214
215
|
const noCM = mw.loader.getState("ext.CodeMirror") === null;
|
|
215
216
|
for (const [key, val] of Object.entries(insensitive)) {
|
package/dist/openLinks.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EditorView } from '@codemirror/view';
|
|
2
2
|
import { ensureSyntaxTree } from '@codemirror/language';
|
|
3
|
-
import { tokens } from './config';
|
|
4
|
-
import { isMac } from './constants';
|
|
5
|
-
import { hasTag } from './util';
|
|
3
|
+
import { tokens } from './config.js';
|
|
4
|
+
import { isMac } from './constants.js';
|
|
5
|
+
import { hasTag } from './util.js';
|
|
6
6
|
const modKey = isMac ? 'metaKey' : 'ctrlKey', key = isMac ? 'Meta' : 'Control', tags = ['extLinkProtocol', 'extLink', 'freeExtLinkProtocol', 'freeExtLink', 'magicLink', 'pageName'], links = ['extlink-protocol', 'extlink', 'free-extlink-protocol', 'free-extlink', 'magic-link'], pagename = '.cm-mw-pagename', wikiLinks = [
|
|
7
7
|
'template-name',
|
|
8
8
|
'link-pagename',
|
|
@@ -59,12 +59,12 @@ export const mouseEventListener = (e, view, langConfig) => {
|
|
|
59
59
|
node = tree.resolve(position, 1);
|
|
60
60
|
}
|
|
61
61
|
const { name, from, to } = node;
|
|
62
|
-
if (name.includes(
|
|
63
|
-
return langConfig.titleParser(state, node);
|
|
64
|
-
}
|
|
65
|
-
else if (name.includes('-extlink-protocol')) {
|
|
62
|
+
if (name.includes('-extlink-protocol')) {
|
|
66
63
|
return wrapURL(state.sliceDoc(from, node.nextSibling.to));
|
|
67
64
|
}
|
|
65
|
+
else if (name.includes(tokens.pageName) && typeof langConfig?.titleParser === 'function') {
|
|
66
|
+
return langConfig.titleParser(state, node);
|
|
67
|
+
}
|
|
68
68
|
else if (/-extlink(?:_|$)/u.test(name)) {
|
|
69
69
|
return wrapURL(state.sliceDoc(node.prevSibling.from, to));
|
|
70
70
|
}
|
|
@@ -97,7 +97,8 @@ export default ({ langConfig }) => [
|
|
|
97
97
|
},
|
|
98
98
|
}),
|
|
99
99
|
EditorView.theme({
|
|
100
|
-
[[...links, ...langConfig?.titleParser ? wikiLinks : []]
|
|
100
|
+
[[...links, ...langConfig?.titleParser ? wikiLinks : []]
|
|
101
|
+
.map(type => `.cm-mw-${type}`).join()]: {
|
|
101
102
|
cursor: 'var(--codemirror-cursor)',
|
|
102
103
|
},
|
|
103
104
|
}),
|
package/dist/ref.d.ts
CHANGED
package/dist/ref.js
CHANGED
|
@@ -3,10 +3,10 @@ import { ensureSyntaxTree, language, highlightingFor } from '@codemirror/languag
|
|
|
3
3
|
import { highlightCode } from '@lezer/highlight';
|
|
4
4
|
import { getLSP } from '@bhsd/browser';
|
|
5
5
|
import elt from 'crelt';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { indexToPos, posToIndex, escHTML } from './util';
|
|
6
|
+
import { base } from './constants.js';
|
|
7
|
+
import { tokens } from './config.js';
|
|
8
|
+
import { getTag } from './matchTag.js';
|
|
9
|
+
import { indexToPos, posToIndex, escHTML, } from './util.js';
|
|
10
10
|
const trees = new WeakMap(), selector = '.cm-tooltip-ref', noDef = '.cm-tooltip-no-def';
|
|
11
11
|
/**
|
|
12
12
|
* 获取节点内容
|
|
@@ -45,7 +45,7 @@ export default (cm) => [
|
|
|
45
45
|
target = target.slice(1, target.slice(-1) === quote ? -1 : undefined).trim();
|
|
46
46
|
}
|
|
47
47
|
if (target) {
|
|
48
|
-
const { doc } = state, ref = await getLSP(view, false, cm.getWikiConfig,
|
|
48
|
+
const { doc } = state, ref = await getLSP(view, false, cm.getWikiConfig, base.CDN)
|
|
49
49
|
?.provideDefinition(doc.toString(), indexToPos(doc, first.to));
|
|
50
50
|
return {
|
|
51
51
|
pos,
|
|
@@ -63,7 +63,9 @@ export default (cm) => [
|
|
|
63
63
|
},
|
|
64
64
|
}, (code, classes) => {
|
|
65
65
|
const escaped = escHTML(code);
|
|
66
|
-
result += classes
|
|
66
|
+
result += classes
|
|
67
|
+
? `<span class="${classes}">${escaped}</span>`
|
|
68
|
+
: escaped;
|
|
67
69
|
}, () => {
|
|
68
70
|
result += '<br>';
|
|
69
71
|
});
|
package/dist/signature.d.ts
CHANGED
package/dist/signature.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EditorView, showTooltip } from '@codemirror/view';
|
|
2
2
|
import { StateField, StateEffect } from '@codemirror/state';
|
|
3
3
|
import { getLSP } from '@bhsd/browser';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { base } from './constants.js';
|
|
5
|
+
import { createTooltipView, indexToPos, escHTML, } from './util.js';
|
|
6
6
|
const stateEffect = StateEffect.define(), field = StateField.define({
|
|
7
7
|
create() {
|
|
8
8
|
return undefined;
|
|
@@ -36,7 +36,7 @@ export default (cm) => [
|
|
|
36
36
|
effects: stateEffect.of({
|
|
37
37
|
text,
|
|
38
38
|
cursor,
|
|
39
|
-
signatureHelp: await getLSP(view, false, cm.getWikiConfig,
|
|
39
|
+
signatureHelp: await getLSP(view, false, cm.getWikiConfig, base.CDN)
|
|
40
40
|
?.provideSignatureHelp(text, indexToPos(doc, cursor)),
|
|
41
41
|
}),
|
|
42
42
|
});
|
package/dist/statusBar.js
CHANGED
|
@@ -2,8 +2,8 @@ import { showPanel, EditorView } from '@codemirror/view';
|
|
|
2
2
|
import { nextDiagnostic, setDiagnosticsEffect } from '@codemirror/lint';
|
|
3
3
|
import { gotoLine } from '@codemirror/search';
|
|
4
4
|
import elt from 'crelt';
|
|
5
|
-
import { menuRegistry } from './codemirror';
|
|
6
|
-
import { panelSelector, diagnosticSelector, menuSelector, messageSelector, actionSelector } from './constants';
|
|
5
|
+
import { menuRegistry } from './codemirror.js';
|
|
6
|
+
import { panelSelector, diagnosticSelector, menuSelector, messageSelector, actionSelector } from './constants.js';
|
|
7
7
|
const statusSelector = '.cm-panel-status', workerSelector = '.cm-status-worker', errorSelector = '.cm-status-error', warningSelector = '.cm-status-warning', enabledSelector = '.cm-status-fix-enabled', disabledSelector = '.cm-status-fix-disabled', workerCls = 'cm-status-worker-enabled', lineCls = 'cm-status-line';
|
|
8
8
|
function getLintMarker(view, severity, menu) {
|
|
9
9
|
const marker = elt('div', { class: `cm-status-${severity}` }), icon = elt('div');
|
|
@@ -50,7 +50,12 @@ const updateDiagnosticMessage = (cm, allDiagnostics, main, msg) => {
|
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
52
52
|
const diagnostic = diagnostics.find(({ from, to }) => from <= main.head && to >= main.head) ?? diagnostics[0], view = cm.view;
|
|
53
|
-
|
|
53
|
+
if (diagnostic.renderMessage) {
|
|
54
|
+
msg.replaceChildren(diagnostic.renderMessage(view));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
msg.textContent = diagnostic.message;
|
|
58
|
+
}
|
|
54
59
|
if (diagnostic.actions) {
|
|
55
60
|
msg.append(...diagnostic.actions.map(({ name, tooltip, apply }) => {
|
|
56
61
|
const button = elt('button', { type: 'button', class: actionSelector.slice(1) }, name);
|
package/dist/theme.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EditorView } from '@codemirror/view';
|
|
2
2
|
import { nord as nordBase } from 'cm6-theme-nord';
|
|
3
|
-
import { foldSelector, hoverSelector, matchingCls, nonmatchingCls, menuSelector, messageSelector, actionSelector, panelsSelector, } from './constants';
|
|
3
|
+
import { foldSelector, hoverSelector, matchingCls, nonmatchingCls, menuSelector, messageSelector, actionSelector, panelsSelector, } from './constants.js';
|
|
4
4
|
const focused = '&.cm-focused', matching = `${focused} .${matchingCls}`, nonmatching = `${focused} .${nonmatchingCls}`, code = `${hoverSelector} code`, menuHover = `${menuSelector}>div:hover`;
|
|
5
5
|
export const light = /* @__PURE__ */ EditorView.theme({
|
|
6
6
|
'&': {
|
package/dist/token.d.ts
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* @see https://gerrit.wikimedia.org/g/mediawiki/extensions/CodeMirror
|
|
5
5
|
*/
|
|
6
6
|
import { Tag } from '@lezer/highlight';
|
|
7
|
-
import { tokens } from './config';
|
|
8
7
|
import type { MwConfig as MwConfigBase } from '@bhsd/cm-util';
|
|
9
8
|
import type { EditorState } from '@codemirror/state';
|
|
10
9
|
import type { StreamParser, StringStream as StringStreamBase } from '@codemirror/language';
|
|
11
10
|
import type { SyntaxNode } from '@lezer/common';
|
|
11
|
+
import type { TagName } from './config';
|
|
12
12
|
declare type Style = string | [string];
|
|
13
13
|
declare type Tokenizer<T = Style> = ((stream: StringStream, state: State) => T) & {
|
|
14
14
|
args?: unknown[];
|
|
@@ -48,7 +48,6 @@ declare interface StringStream extends StringStreamBase {
|
|
|
48
48
|
match(pattern: string, consume?: boolean, caseInsensitive?: boolean): true | null;
|
|
49
49
|
match(pattern: RegExp, consume?: boolean): RegExpMatchArray | null;
|
|
50
50
|
}
|
|
51
|
-
export type TagName = keyof typeof tokens;
|
|
52
51
|
export type ApiSuggestions = [string, string?][] & {
|
|
53
52
|
description?: string;
|
|
54
53
|
};
|
|
@@ -134,7 +133,7 @@ export declare class MediaWiki {
|
|
|
134
133
|
inStr(str: string, tag: TagName | false, errorTag?: TagName): Tokenizer<string>;
|
|
135
134
|
eatWikiText(style: string): Tokenizer;
|
|
136
135
|
eatApostrophes(obj: Pick<State, 'bold' | 'italic'>): Tokenizer<string | false>;
|
|
137
|
-
eatExternalLinkProtocol({ length }: string, free?: boolean): Tokenizer
|
|
136
|
+
eatExternalLinkProtocol({ length }: string, free?: boolean): Tokenizer;
|
|
138
137
|
inExternalLink(text?: boolean): Tokenizer;
|
|
139
138
|
eatFreeExternalLink(this: void, stream: StringStream, state: State): Style;
|
|
140
139
|
inLink(file: boolean, section?: boolean): Tokenizer;
|
package/dist/token.js
CHANGED
|
@@ -42,7 +42,7 @@ import { Tag } from '@lezer/highlight';
|
|
|
42
42
|
import { getRegex } from '@bhsd/common';
|
|
43
43
|
import { decodeHTML } from '@bhsd/browser';
|
|
44
44
|
import { otherParserFunctions } from '@bhsd/cm-util';
|
|
45
|
-
import { htmlTags, voidHtmlTags, selfClosingTags, tokenTable, tokens } from './config';
|
|
45
|
+
import { htmlTags, voidHtmlTags, selfClosingTags, tokenTable, tokens } from './config.js';
|
|
46
46
|
class MediaWikiData {
|
|
47
47
|
constructor(tags, urlProtocols) {
|
|
48
48
|
this.tags = tags.includes('translate') ? tags.filter(tag => tag !== 'tvar') : tags;
|
|
@@ -386,7 +386,7 @@ let MediaWiki = (() => {
|
|
|
386
386
|
_inStr_decorators = [(getTokenizer)];
|
|
387
387
|
_eatWikiText_decorators = [getTokenizer];
|
|
388
388
|
_eatApostrophes_decorators = [getTokenizer];
|
|
389
|
-
_eatExternalLinkProtocol_decorators = [
|
|
389
|
+
_eatExternalLinkProtocol_decorators = [getTokenizer];
|
|
390
390
|
_inExternalLink_decorators = [getTokenizer];
|
|
391
391
|
_inLink_decorators = [getTokenizer];
|
|
392
392
|
_inLinkText_decorators = [getTokenizer];
|
|
@@ -822,7 +822,9 @@ let MediaWiki = (() => {
|
|
|
822
822
|
return (stream, state) => {
|
|
823
823
|
stream.pos += length;
|
|
824
824
|
state.tokenize = free ? this.eatFreeExternalLink : this.inExternalLink();
|
|
825
|
-
return
|
|
825
|
+
return free
|
|
826
|
+
? makeTagStyle('freeExtLinkProtocol', state)
|
|
827
|
+
: makeLocalTagStyle('extLinkProtocol', state);
|
|
826
828
|
};
|
|
827
829
|
}
|
|
828
830
|
inExternalLink(text) {
|
package/dist/util.d.ts
CHANGED
|
@@ -37,3 +37,8 @@ export declare const braceStackUpdate: (state: EditorState, node: SyntaxNode) =>
|
|
|
37
37
|
* @param names 指定类型
|
|
38
38
|
*/
|
|
39
39
|
export declare const hasTag: (types: Set<string>, names: string | string[]) => boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 获取字符串开头的空白字符
|
|
42
|
+
* @param str 字符串
|
|
43
|
+
*/
|
|
44
|
+
export declare const leadingSpaces: (str: string) => string;
|
package/dist/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import elt from 'crelt';
|
|
2
|
-
import { tokens } from './config';
|
|
3
|
-
import { hoverSelector } from './constants';
|
|
2
|
+
import { tokens } from './config.js';
|
|
3
|
+
import { hoverSelector, } from './constants.js';
|
|
4
4
|
const dict = { '\n': '<br>', '&': '&', '<': '<' };
|
|
5
5
|
/**
|
|
6
6
|
* 转义HTML字符串
|
|
@@ -51,3 +51,8 @@ export const braceStackUpdate = (state, node) => {
|
|
|
51
51
|
* @param names 指定类型
|
|
52
52
|
*/
|
|
53
53
|
export const hasTag = (types, names) => (Array.isArray(names) ? names : [names]).some(name => types.has(name in tokens ? tokens[name] : name));
|
|
54
|
+
/**
|
|
55
|
+
* 获取字符串开头的空白字符
|
|
56
|
+
* @param str 字符串
|
|
57
|
+
*/
|
|
58
|
+
export const leadingSpaces = (str) => /^\s*/u.exec(str)[0];
|
package/dist/vue.js
CHANGED
|
@@ -2,8 +2,8 @@ import { vue } from '@codemirror/lang-vue';
|
|
|
2
2
|
import { htmlLanguage, htmlCompletionSource } from '@codemirror/lang-html';
|
|
3
3
|
import { javascript } from '@codemirror/lang-javascript';
|
|
4
4
|
import { LanguageSupport } from '@codemirror/language';
|
|
5
|
-
import { cssCompletion } from './css';
|
|
6
|
-
import { jsCompletion } from './javascript';
|
|
5
|
+
import { cssCompletion } from './css.js';
|
|
6
|
+
import { jsCompletion } from './javascript.js';
|
|
7
7
|
export default () => vue({
|
|
8
8
|
base: new LanguageSupport(htmlLanguage, [
|
|
9
9
|
htmlLanguage.data.of({ autocomplete: htmlCompletionSource }),
|