@bhsd/codemirror-mediawiki 3.0.2 → 3.1.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.
@@ -1,174 +1,22 @@
1
- import { EditorView, lineNumbers, keymap, highlightSpecialChars, highlightActiveLine, highlightActiveLineGutter, highlightWhitespace, highlightTrailingWhitespace, drawSelection, scrollPastEnd, rectangularSelection, crosshairCursor, } from '@codemirror/view';
1
+ import { EditorView, lineNumbers, keymap, highlightActiveLineGutter, } from '@codemirror/view';
2
2
  import { Compartment, EditorState, EditorSelection, SelectionRange } from '@codemirror/state';
3
3
  import { syntaxHighlighting, defaultHighlightStyle, indentOnInput, indentUnit, ensureSyntaxTree, } from '@codemirror/language';
4
4
  import { defaultKeymap, historyKeymap, history, redo, indentWithTab } from '@codemirror/commands';
5
- import { searchKeymap, highlightSelectionMatches } from '@codemirror/search';
5
+ import { searchKeymap } from '@codemirror/search';
6
6
  import { linter, lintGutter, lintKeymap } from '@codemirror/lint';
7
- import { closeBrackets, autocompletion, acceptCompletion, completionKeymap, startCompletion, } from '@codemirror/autocomplete';
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';
11
- import { getLSP } from '@bhsd/browser';
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';
15
- import escapeKeymap from './escape';
16
- import codeFolding, { foldHandler, mediaWikiFold } from './fold';
17
- import tagMatchingState from './matchTag';
18
- import refHover from './ref';
19
- import magicWordHover from './hover';
20
- import signatureHelp from './signature';
21
- import inlayHints from './inlay';
22
- import { getWikiLintSource, getJsLintSource, getCssLintSource, getJsonLintSource, getLuaLintSource, getVueLintSource, } from './lintsource';
23
- import openLinks from './openLinks';
24
- import { tagModes, getStaticMwConfig } from './static';
25
- import bidiIsolation from './bidi';
26
- import toolKeymap from './keymap';
7
+ import { foldHandler } from './fold';
27
8
  import statusBar from './statusBar';
28
9
  import { detectIndent } from './indent';
29
- import bracketMatching from './matchBrackets';
30
- import wikitextLSP from './lsp';
31
- import javascript from './javascript';
32
- import css from './css';
33
- import lua from './lua';
34
- import vue from './vue';
35
- const plain = () => EditorView.contentAttributes.of({ spellcheck: 'true' });
10
+ export const plain = () => EditorView.contentAttributes.of({ spellcheck: 'true' });
36
11
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
- const languages = { plain };
38
- function mediawikiOnly(ext) {
39
- return typeof ext === 'function'
40
- ? [(enable, cm) => enable ? ext(cm) : [], { mediawiki: true }]
41
- : [(e = []) => e, { mediawiki: ext }];
42
- }
12
+ export const languages = { plain };
43
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- const avail = {
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],
58
- allowMultipleSelections: [
59
- () => [
60
- EditorState.allowMultipleSelections.of(true),
61
- drawSelection(),
62
- rectangularSelection(),
63
- crosshairCursor(),
64
- ],
65
- ],
66
- autocompletion: [
67
- () => [
68
- autocompletion({ defaultKeymap: false }),
69
- keymap.of([
70
- ...completionKeymap.filter(({ run }) => run !== startCompletion),
71
- { key: 'Shift-Enter', run: startCompletion },
72
- { key: 'Tab', run: acceptCompletion },
73
- ]),
74
- ],
75
- ],
76
- codeFolding,
77
- colorPicker,
78
- };
79
- const linterRegistry = {};
80
- const destroyListeners = [];
14
+ export const avail = {};
15
+ export const linterRegistry = {};
16
+ export const destroyListeners = [];
81
17
  const editExtensions = new Set(['closeBrackets', 'autocompletion', 'signatureHelp']);
82
18
  const linters = {};
83
19
  const phrases = {};
84
- /**
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
165
- */
166
- export const registerLanguage = (name, lang, lintSource) => {
167
- languages[name] = lang;
168
- if (lintSource) {
169
- linterRegistry[name] = lintSource;
170
- }
171
- };
172
20
  /** CodeMirror 6 editor */
173
21
  export class CodeMirror6 {
174
22
  #textarea;
@@ -323,15 +171,11 @@ export class CodeMirror6 {
323
171
  * @param lang language
324
172
  * @param config language configuration
325
173
  */
174
+ // eslint-disable-next-line @typescript-eslint/require-await
326
175
  async setLanguage(lang = 'plain', config) {
327
176
  this.#lang = lang;
328
177
  if (this.#view) {
329
- let ext = (languages[lang] ?? plain)(config);
330
- ws: { // eslint-disable-line no-unused-labels
331
- if (lang === 'mediawiki') {
332
- ext = [ext, await wikitextLSP()];
333
- }
334
- }
178
+ const ext = (languages[lang] ?? plain)(config);
335
179
  this.#effects([
336
180
  this.#language.reconfigure(ext),
337
181
  this.#linter.reconfigure(linters[lang] ?? []),
@@ -563,12 +407,4 @@ export class CodeMirror6 {
563
407
  };
564
408
  }));
565
409
  }
566
- /**
567
- * Convert a [WikiParser-Node](https://npmjs.com/package/wikiparser-node) configuration
568
- * to a CodeMirror-MediaWiki configuration
569
- * @param config WikiParser-Node configuration
570
- */
571
- static getMwConfig(config) {
572
- return getStaticMwConfig(config, tagModes);
573
- }
574
410
  }
package/dist/color.d.ts CHANGED
@@ -3,5 +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];
6
+ declare const _default: ([e, style]?: [Extension?, StyleSpec?]) => Extension;
7
7
  export default _default;
package/dist/color.js CHANGED
@@ -27,19 +27,17 @@ export const discoverColors = (_, from, to, type, doc) => {
27
27
  };
28
28
  }).filter(Boolean);
29
29
  };
30
- export default [
31
- ([e, style] = []) => e
32
- ? [
33
- e,
34
- EditorView.theme({
35
- [`.${wrapperClassName}`]: {
36
- outline: 'none',
37
- ...style,
38
- },
39
- [`.${wrapperClassName} input[type="color"]`]: {
40
- outline: '1px solid #eee',
41
- },
42
- }),
43
- ]
44
- : [],
45
- ];
30
+ export default (([e, style] = []) => e
31
+ ? [
32
+ e,
33
+ EditorView.theme({
34
+ [`.${wrapperClassName}`]: {
35
+ outline: 'none',
36
+ ...style,
37
+ },
38
+ [`.${wrapperClassName} input[type="color"]`]: {
39
+ outline: '1px solid #eee',
40
+ },
41
+ }),
42
+ ]
43
+ : []);