@bhsd/codemirror-mediawiki 3.0.3 → 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,173 +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 javascript from './javascript';
31
- import css from './css';
32
- import lua from './lua';
33
- import vue from './vue';
34
- const plain = () => EditorView.contentAttributes.of({ spellcheck: 'true' });
10
+ export const plain = () => EditorView.contentAttributes.of({ spellcheck: 'true' });
35
11
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
- const languages = { plain };
37
- function mediawikiOnly(ext) {
38
- return typeof ext === 'function'
39
- ? [(enable, cm) => enable ? ext(cm) : [], { mediawiki: true }]
40
- : [(e = []) => e, { mediawiki: ext }];
41
- }
12
+ export const languages = { plain };
42
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- const avail = {
44
- highlightSpecialChars: [highlightSpecialChars],
45
- highlightActiveLine: [highlightActiveLine],
46
- highlightWhitespace: [highlightWhitespace],
47
- highlightTrailingWhitespace: [highlightTrailingWhitespace],
48
- highlightSelectionMatches: [highlightSelectionMatches],
49
- bracketMatching: [
50
- ([config, e = []] = []) => [
51
- bracketMatching(config),
52
- e,
53
- ],
54
- ],
55
- closeBrackets: [(e = []) => [closeBrackets(), e]],
56
- scrollPastEnd: [scrollPastEnd],
57
- allowMultipleSelections: [
58
- () => [
59
- EditorState.allowMultipleSelections.of(true),
60
- drawSelection(),
61
- rectangularSelection(),
62
- crosshairCursor(),
63
- ],
64
- ],
65
- autocompletion: [
66
- () => [
67
- autocompletion({ defaultKeymap: false }),
68
- keymap.of([
69
- ...completionKeymap.filter(({ run }) => run !== startCompletion),
70
- { key: 'Shift-Enter', run: startCompletion },
71
- { key: 'Tab', run: acceptCompletion },
72
- ]),
73
- ],
74
- ],
75
- codeFolding,
76
- colorPicker,
77
- };
78
- const linterRegistry = {};
79
- const destroyListeners = [];
14
+ export const avail = {};
15
+ export const linterRegistry = {};
16
+ export const destroyListeners = [];
80
17
  const editExtensions = new Set(['closeBrackets', 'autocompletion', 'signatureHelp']);
81
18
  const linters = {};
82
19
  const phrases = {};
83
- /**
84
- * 注册特定语言的扩展
85
- * @param lang 语言
86
- * @param name 扩展名
87
- * @param ext 扩展
88
- */
89
- const registerLangExtension = (lang, name, ext) => {
90
- const addon = avail[name];
91
- addon[1] ??= {};
92
- addon[1][lang] = ext;
93
- };
94
- /** Register MediaWiki language support */
95
- export const registerMediaWiki = () => {
96
- languages['mediawiki'] = (config) => [
97
- mediawiki(config),
98
- plain(),
99
- bidiIsolation,
100
- toolKeymap,
101
- ];
102
- registerLangExtension('mediawiki', 'colorPicker', [
103
- [makeColorPicker({ discoverColors }), colorPickerTheme],
104
- { marginLeft: '0.6ch' },
105
- ]);
106
- registerLangExtension('mediawiki', 'bracketMatching', [
107
- { brackets: '()[]{}()【】[]{}' },
108
- tagMatchingState,
109
- ]);
110
- registerLangExtension('mediawiki', 'codeFolding', mediaWikiFold);
111
- Object.assign(avail, {
112
- openLinks: mediawikiOnly(openLinks),
113
- escape: mediawikiOnly(keymap.of(escapeKeymap)),
114
- refHover: mediawikiOnly(refHover),
115
- hover: mediawikiOnly(magicWordHover),
116
- signatureHelp: mediawikiOnly(signatureHelp),
117
- inlayHints: mediawikiOnly(inlayHints),
118
- });
119
- linterRegistry['mediawiki'] = getWikiLintSource;
120
- destroyListeners.push(view => getLSP(view)?.destroy());
121
- };
122
- /** Register mixed MediaWiki-HTML language support */
123
- export const registerHTML = () => {
124
- Object.assign(FullMediaWiki.prototype, {
125
- css() {
126
- return cssParser;
127
- },
128
- });
129
- languages['html'] = html;
130
- };
131
- /** Register JavaScript language support */
132
- export const registerJavaScript = () => {
133
- languages['javascript'] = javascript;
134
- linterRegistry['javascript'] = getJsLintSource;
135
- };
136
- /** Register CSS language support */
137
- export const registerCSS = () => {
138
- languages['css'] = css;
139
- registerLangExtension('css', 'colorPicker', [cssColorPicker]);
140
- linterRegistry['css'] = getCssLintSource;
141
- };
142
- /** Register JSON language support */
143
- export const registerJSON = () => {
144
- languages['json'] = json;
145
- linterRegistry['json'] = getJsonLintSource;
146
- };
147
- /** Register Lua language support */
148
- export const registerLua = () => {
149
- languages['lua'] = lua;
150
- linterRegistry['lua'] = getLuaLintSource;
151
- };
152
- /** Register Vue language support */
153
- export const registerVue = () => {
154
- languages['vue'] = vue;
155
- registerLangExtension('vue', 'closeBrackets', autoCloseTags);
156
- registerLangExtension('vue', 'colorPicker', [cssColorPicker]);
157
- linterRegistry['vue'] = getVueLintSource;
158
- };
159
- /**
160
- * Register a custom language support
161
- * @param name language name
162
- * @param lang language support
163
- * @param lintSource optional linter
164
- */
165
- export const registerLanguage = (name, lang, lintSource) => {
166
- languages[name] = lang;
167
- if (lintSource) {
168
- linterRegistry[name] = lintSource;
169
- }
170
- };
171
20
  /** CodeMirror 6 editor */
172
21
  export class CodeMirror6 {
173
22
  #textarea;
@@ -558,12 +407,4 @@ export class CodeMirror6 {
558
407
  };
559
408
  }));
560
409
  }
561
- /**
562
- * Convert a [WikiParser-Node](https://npmjs.com/package/wikiparser-node) configuration
563
- * to a CodeMirror-MediaWiki configuration
564
- * @param config WikiParser-Node configuration
565
- */
566
- static getMwConfig(config) {
567
- return getStaticMwConfig(config, tagModes);
568
- }
569
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
+ : []);