@bhsd/codemirror-mediawiki 2.31.0 → 3.0.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 CHANGED
@@ -10,8 +10,17 @@
10
10
  - [Browser Usage](#browser-usage)
11
11
  - [JavaScript](#javascript)
12
12
  - [CSS](#css)
13
+ - [Language modes](#language-modes)
14
+ - [css](#css)
15
+ - [html](#html)
16
+ - [javascript](#javascript)
17
+ - [json](#json)
18
+ - [lua](#lua)
19
+ - [mediawiki](#mediawiki)
20
+ - [vue](#vue)
13
21
  - [Constructor](#constructor)
14
22
  - [Accessors](#accessors)
23
+ - [dialect](#dialect)
15
24
  - [lang](#lang)
16
25
  - [textarea](#textarea)
17
26
  - [view](#view)
@@ -54,7 +63,6 @@
54
63
  - [refHover](#refhover)
55
64
  - [scrollPastEnd](#scrollpastend)
56
65
  - [signatureHelp](#signaturehelp)
57
- - [tagMatching](#tagmatching)
58
66
  - [Known issues](#known-issues)
59
67
  - [Syntax Highlighting](#syntax-highlighting)
60
68
 
@@ -77,7 +85,16 @@ npm install @bhsd/codemirror-mediawiki
77
85
  ```
78
86
 
79
87
  ```js
80
- import {CodeMirror6} from '@bhsd/codemirror-mediawiki';
88
+ import {
89
+ CodeMirror6,
90
+ registerMediaWiki,
91
+ registerHTML,
92
+ registerCSS,
93
+ registerJavaScript,
94
+ registerJSON,
95
+ registerLua,
96
+ registerVue,
97
+ } from '@bhsd/codemirror-mediawiki';
81
98
  ```
82
99
 
83
100
  # Browser Usage
@@ -88,26 +105,62 @@ You can download the code via CDN, for example:
88
105
 
89
106
  ```js
90
107
  // static import
91
- import {CodeMirror6} from 'https://cdn.jsdelivr.net/npm/@bhsd/codemirror-mediawiki';
108
+ import {
109
+ CodeMirror6,
110
+ registerMediaWiki,
111
+ registerHTML,
112
+ registerCSS,
113
+ registerJavaScript,
114
+ registerJSON,
115
+ registerLua,
116
+ registerVue,
117
+ } from 'https://cdn.jsdelivr.net/npm/@bhsd/codemirror-mediawiki';
92
118
  ```
93
119
 
94
120
  or
95
121
 
96
122
  ```js
97
- import {CodeMirror6} from 'https://unpkg.com/@bhsd/codemirror-mediawiki';
123
+ import {
124
+ CodeMirror6,
125
+ registerMediaWiki,
126
+ registerHTML,
127
+ registerCSS,
128
+ registerJavaScript,
129
+ registerJSON,
130
+ registerLua,
131
+ registerVue,
132
+ } from 'https://unpkg.com/@bhsd/codemirror-mediawiki';
98
133
  ```
99
134
 
100
135
  or
101
136
 
102
137
  ```js
103
138
  // dynamic import
104
- const {CodeMirror6} = await import('https://cdn.jsdelivr.net/npm/@bhsd/codemirror-mediawiki');
139
+ const {
140
+ CodeMirror6,
141
+ registerMediaWiki,
142
+ registerHTML,
143
+ registerCSS,
144
+ registerJavaScript,
145
+ registerJSON,
146
+ registerLua,
147
+ registerVue,
148
+ } = await import('https://cdn.jsdelivr.net/npm/@bhsd/codemirror-mediawiki');
105
149
  ```
106
150
 
107
151
  or
108
152
 
109
153
  ```js
110
- const {CodeMirror6} = await import('https://unpkg.com/@bhsd/codemirror-mediawiki');
154
+ const {
155
+ CodeMirror6,
156
+ registerMediaWiki,
157
+ registerHTML,
158
+ registerCSS,
159
+ registerJavaScript,
160
+ registerJSON,
161
+ registerLua,
162
+ registerVue,
163
+ } = await import('https://unpkg.com/@bhsd/codemirror-mediawiki');
111
164
  ```
112
165
 
113
166
  ## CSS
@@ -122,6 +175,81 @@ or
122
175
  <link rel="stylesheet" href="https://unpkg.com/@bhsd/codemirror-mediawiki/mediawiki.css">
123
176
  ```
124
177
 
178
+ # Language modes
179
+
180
+ ## css
181
+
182
+ The CSS mode contains a [dialect](#dialect) for [Extension:TemplateStyles](https://www.mediawiki.org/wiki/Extension:TemplateStyles). You can bundle the CSS mode by importing the `registerCSS` function:
183
+
184
+ ```js
185
+ import {registerCSS} from '@bhsd/codemirror-mediawiki';
186
+ registerCSS();
187
+ ```
188
+
189
+ ## html
190
+
191
+ This is a mixed MediaWiki-HTML mode, which is used for [Extension:Widgets](https://www.mediawiki.org/wiki/Extension:Widgets). You can bundle the HTML mode by importing the `registerHTML` function:
192
+
193
+ ```js
194
+ import {registerHTML} from '@bhsd/codemirror-mediawiki';
195
+ registerHTML();
196
+ ```
197
+
198
+ ## javascript
199
+
200
+ You can bundle the JavaScript mode by importing the `registerJavaScript` function:
201
+
202
+ ```js
203
+ import {registerJavaScript} from '@bhsd/codemirror-mediawiki';
204
+ registerJavaScript();
205
+ ```
206
+
207
+ ## json
208
+
209
+ You can bundle the JSON mode by importing the `registerJSON` function:
210
+
211
+ ```js
212
+ import {registerJSON} from '@bhsd/codemirror-mediawiki';
213
+ registerJSON();
214
+ ```
215
+
216
+ ## lua
217
+
218
+ You can bundle the Lua mode by importing the `registerLua` function:
219
+
220
+ ```js
221
+ import {registerLua} from '@bhsd/codemirror-mediawiki';
222
+ registerLua();
223
+ ```
224
+
225
+ ## mediawiki
226
+
227
+ You can bundle the MediaWiki mode by importing the `registerMediaWiki` function:
228
+
229
+ ```js
230
+ import {registerMediaWiki} from '@bhsd/codemirror-mediawiki';
231
+ registerMediaWiki();
232
+ ```
233
+
234
+ ## vue
235
+
236
+ You can bundle the Vue mode by importing the `registerVue` function:
237
+
238
+ ```js
239
+ import {registerVue} from '@bhsd/codemirror-mediawiki';
240
+ registerVue();
241
+ ```
242
+
243
+ ## Other languages
244
+
245
+ You can also register other languages by importing the `registerLanguage` function:
246
+
247
+ ```js
248
+ import {registerLanguage} from '@bhsd/codemirror-mediawiki';
249
+ import {python} from '@codemirror/lang-python';
250
+ registerLanguage('python', python);
251
+ ```
252
+
125
253
  # Constructor
126
254
 
127
255
  <details>
@@ -146,6 +274,18 @@ const cm = new CodeMirror6(textarea, 'lua');
146
274
 
147
275
  # Accessors
148
276
 
277
+ ## dialect
278
+
279
+ <details>
280
+ <summary>Expand</summary>
281
+
282
+ *version added: 2.28.0*
283
+
284
+ **type**: `'sanitized-css' | undefined`
285
+ Only used for [Extension:TemplateStyles](https://www.mediawiki.org/wiki/Extension:TemplateStyles) as a dialect of the CSS mode.
286
+
287
+ </details>
288
+
149
289
  ## lang
150
290
 
151
291
  <details>
@@ -233,7 +373,7 @@ cm.extraKeys([
233
373
  *version added: 2.1.3*
234
374
 
235
375
  **param**: `Record<string, any>` the optional linter configuration
236
- **returns**: `Promise<(doc: Text) => Diagnostic[] | Promise<Diagnostic[]>>`
376
+ **returns**: `Promise<(state: EditorState) => Diagnostic[] | Promise<Diagnostic[]>>`
237
377
  Get the default linting function, which can be used as the argument of [`lint`](#lint).
238
378
 
239
379
  ```js
@@ -283,11 +423,11 @@ cm.initialize();
283
423
  <details>
284
424
  <summary>Expand</summary>
285
425
 
286
- **param**: `(doc: Text) => Diagnostic[] | Promise<Diagnostic[]>` the linting function
426
+ **param**: `(state: EditorState) => Diagnostic[] | Promise<Diagnostic[]>` the linting function
287
427
  Set the linting function.
288
428
 
289
429
  ```js
290
- cm.lint(doc => [
430
+ cm.lint(({doc}) => [
291
431
  /**
292
432
  * @type {Diagnostic}
293
433
  * @see https://codemirror.net/docs/ref/#lint.Diagnostic
@@ -337,36 +477,48 @@ cm.prefer([
337
477
  'autocompletion',
338
478
  'bracketMatching',
339
479
  'closeBrackets',
480
+ 'codeFolding',
340
481
  'highlightActiveLine',
482
+ 'highlightSelectionMatches',
341
483
  'highlightSpecialChars',
342
- 'highlightWhitespace',
343
484
  'highlightTrailingWhitespace',
344
- 'highlightSelectionMatches',
345
- 'codeFolding',
485
+ 'highlightWhitespace',
346
486
  'scrollPastEnd',
347
487
 
488
+ // only available in CSS and MediaWiki modes
489
+ 'colorPicker',
490
+
348
491
  // only available in MediaWiki mode
349
492
  'escape',
350
- 'tagMatching',
493
+ 'hover',
494
+ 'inlayHints',
495
+ 'openLinks',
351
496
  'refHover',
497
+ 'signatureHelp',
352
498
  ]);
353
499
  cm.prefer({
354
500
  allowMultipleSelections: false,
355
501
  autocompletion: false,
356
502
  bracketMatching: false,
357
503
  closeBrackets: false,
504
+ codeFolding: false,
358
505
  highlightActiveLine: false,
506
+ highlightSelectionMatches: false,
359
507
  highlightSpecialChars: false,
360
- highlightWhitespace: false,
361
508
  highlightTrailingWhitespace: false,
362
- highlightSelectionMatches: false,
363
- codeFolding: false,
509
+ highlightWhitespace: false,
364
510
  scrollPastEnd: false,
365
511
 
512
+ // only available in CSS and MediaWiki modes
513
+ colorPicker: false,
514
+
366
515
  // only available in MediaWiki mode
367
516
  escape: false,
368
- tagMatching: false,
517
+ hover: false,
518
+ inlayHints: false,
519
+ openLinks: false,
369
520
  refHover: false,
521
+ signatureHelp: false,
370
522
  });
371
523
  ```
372
524
 
@@ -540,7 +692,7 @@ Provide autocompletion for MediaWiki, CSS and JavaScript modes.
540
692
 
541
693
  *version added: 2.0.9*
542
694
 
543
- Matched or unmatched brackets are highlighted in cyan or dark red when the cursor is next to them.
695
+ Matched or unmatched brackets or tags are highlighted in cyan or dark red when the cursor is next to them.
544
696
 
545
697
  ## closeBrackets
546
698
 
@@ -638,12 +790,6 @@ Allow the editor to be scrolled down past the end of the document.
638
790
 
639
791
  Show the parser function signature when typing.
640
792
 
641
- ## tagMatching
642
-
643
- *version added: 2.4.1*
644
-
645
- Matched or unmatched tags are highlighted in cyan or dark red when the cursor is inside.
646
-
647
793
  # Known issues
648
794
 
649
795
  ## Syntax Highlighting
@@ -1,118 +1,143 @@
1
1
  import { EditorView } from '@codemirror/view';
2
2
  import type { KeyBinding } from '@codemirror/view';
3
- import type { Extension, Text } from '@codemirror/state';
3
+ import type { Extension } from '@codemirror/state';
4
+ import type { LanguageSupport } from '@codemirror/language';
4
5
  import type { SyntaxNode } from '@lezer/common';
5
- import type { Diagnostic } from '@codemirror/lint';
6
6
  import type { ConfigData } from 'wikiparser-node';
7
7
  import type { MwConfig } from './token';
8
8
  import type { DocRange } from './fold';
9
9
  import type { Option, LiveOption } from './linter';
10
+ import type { LintSource, LintSourceGetter } from './lintsource';
10
11
  export type { MwConfig };
11
- export type LintSource = ((doc: Text) => Diagnostic[] | Promise<Diagnostic[]>) & {
12
- fixer?: (doc: Text, rule?: string) => string | Promise<string>;
13
- };
14
- export type Addon<T> = [(config?: T, cm?: CodeMirror6) => Extension, Record<string, T>];
12
+ export type Addon<T> = [(config?: T, cm?: CodeMirror6) => Extension, Record<string, T>?];
15
13
  export type Dialect = 'sanitized-css' | undefined;
16
- /** CodeMirror 6 编辑器 */
14
+ /** Register MediaWiki language support */
15
+ export declare const registerMediaWiki: () => void;
16
+ /** Register mixed MediaWiki-HTML language support */
17
+ export declare const registerHTML: () => void;
18
+ /** Register JavaScript language support */
19
+ export declare const registerJavaScript: () => void;
20
+ /** Register CSS language support */
21
+ export declare const registerCSS: () => void;
22
+ /** Register JSON language support */
23
+ export declare const registerJSON: () => void;
24
+ /** Register Lua language support */
25
+ export declare const registerLua: () => void;
26
+ /** Register Vue language support */
27
+ export declare const registerVue: () => void;
28
+ /**
29
+ * Register a custom language support
30
+ * @param name language name
31
+ * @param lang language support
32
+ * @param lintSource optional linter
33
+ */
34
+ export declare const registerLanguage: (name: string, lang: (config?: unknown) => LanguageSupport, lintSource?: LintSourceGetter) => void;
35
+ /** CodeMirror 6 editor */
17
36
  export declare class CodeMirror6 {
18
37
  #private;
38
+ /** only for sanitized-css */
39
+ dialect: Dialect;
19
40
  getWikiConfig?: () => Promise<ConfigData>;
20
41
  langConfig: MwConfig | undefined;
21
- dialect: Dialect;
42
+ /** textarea element */
22
43
  get textarea(): HTMLTextAreaElement;
44
+ /** EditorView instance */
23
45
  get view(): EditorView | undefined;
46
+ /** language */
24
47
  get lang(): string;
48
+ /** whether the editor view is visible */
25
49
  get visible(): boolean;
26
50
  /**
27
- * @param textarea 文本框
28
- * @param lang 语言
29
- * @param config 语言设置
30
- * @param init 是否初始化
51
+ * @param textarea textarea element
52
+ * @param lang language
53
+ * @param config language configuration
54
+ * @param init whether to initialize the editor immediately
31
55
  */
32
56
  constructor(textarea: HTMLTextAreaElement, lang?: string, config?: unknown, init?: boolean);
33
57
  /**
34
- * 初始化编辑器
35
- * @param config 语言设置
58
+ * Initialize the editor
59
+ * @param config language configuration
36
60
  */
37
61
  initialize(config?: unknown): void;
38
62
  /**
39
- * 设置语言
40
- * @param lang 语言
41
- * @param config 语言设置
63
+ * Set language
64
+ * @param lang language
65
+ * @param config language configuration
42
66
  */
43
67
  setLanguage(lang?: string, config?: unknown): Promise<void>;
44
68
  /**
45
- * 开始语法检查
46
- * @param lintSource 语法检查函数
69
+ * Start syntax checking
70
+ * @param lintSource function for syntax checking
47
71
  */
48
72
  lint(lintSource?: LintSource): void;
49
- /** 立即更新语法检查 */
73
+ /** Update syntax checking immediately */
50
74
  update(): void;
51
75
  /**
52
- * 添加扩展
53
- * @param names 扩展名
76
+ * Add extensions
77
+ * @param names extension names
54
78
  */
55
79
  prefer(names: string[] | Record<string, boolean>): void;
56
80
  /**
57
- * 设置缩进
58
- * @param indent 缩进字符串
81
+ * Set text indentation
82
+ * @param indent indentation string
59
83
  */
60
84
  setIndent(indent: string): void;
61
85
  /**
62
- * 设置文本换行
63
- * @param wrapping 是否换行
86
+ * Set line wrapping
87
+ * @param wrapping whether to enable line wrapping
64
88
  */
65
89
  setLineWrapping(wrapping: boolean): void;
66
90
  /**
67
- * 获取默认linter
68
- * @param opt 选项
91
+ * Get default linter
92
+ * @param opt linter options
69
93
  */
70
94
  getLinter(opt?: Option | LiveOption): Promise<LintSource | undefined>;
71
95
  /**
72
- * 重设编辑器内容
73
- * @param insert 新内容
74
- * @param force 是否强制
96
+ * Set content
97
+ * @param insert new content
98
+ * @param force whether to forcefully replace the content
75
99
  */
76
100
  setContent(insert: string, force?: boolean): void;
77
101
  /**
78
- * 在编辑器和文本框之间切换
79
- * @param show 是否显示编辑器
102
+ * Switch between textarea and editor view
103
+ * @param show whether to show the editor view
80
104
  */
81
105
  toggle(show?: boolean): void;
82
- /** 销毁实例 */
106
+ /** Destroy the editor */
83
107
  destroy(): void;
84
108
  /**
85
- * 添加额外快捷键
86
- * @param keys 快捷键
109
+ * Define extra key bindings
110
+ * @param keys key bindings
87
111
  */
88
112
  extraKeys(keys: KeyBinding[]): void;
89
113
  /**
90
- * 设置翻译信息
91
- * @param messages 翻译信息
114
+ * Set translation messages
115
+ * @param messages translation messages
92
116
  */
93
117
  localize(messages?: Record<string, string>): void;
94
118
  /**
95
- * 获取语法树节点
96
- * @param position 位置
119
+ * Get the syntax node at the specified position
120
+ * @param position position
97
121
  */
98
122
  getNodeAt(position: number): SyntaxNode | undefined;
99
123
  /**
100
- * 滚动至指定位置
101
- * @param position 位置
124
+ * Scroll to the specified position
125
+ * @param position position or selection range
102
126
  */
103
127
  scrollTo(position?: number | {
104
128
  anchor: number;
105
129
  head: number;
106
130
  }): void;
107
131
  /**
108
- * 替换选中内容
109
- * @param view
110
- * @param func 替换函数
132
+ * Replace the current selection with the result of a function
133
+ * @param view EditorView instance
134
+ * @param func function to produce the replacement text
111
135
  */
112
136
  static replaceSelections(view: EditorView, func: (str: string, range: DocRange) => string | [string, number, number?]): void;
113
137
  /**
114
- * wikiparser-node设置转换为codemirror-mediawiki设置
115
- * @param config
138
+ * Convert a [WikiParser-Node](https://npmjs.com/package/wikiparser-node) configuration
139
+ * to a CodeMirror-MediaWiki configuration
140
+ * @param config WikiParser-Node configuration
116
141
  */
117
142
  static getMwConfig(config: ConfigData): MwConfig;
118
143
  }