@bhsd/codemirror-mediawiki 2.27.2 → 2.28.2

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
@@ -8,13 +8,16 @@
8
8
 
9
9
  - [Description](#description)
10
10
  - [Usage](#usage)
11
+ - [JavaScript](#javascript)
12
+ - [CSS](#css)
11
13
  - [Constructor](#constructor)
12
14
  - [Accessors](#accessors)
13
- - [textarea](#textarea)
14
15
  - [lang](#lang)
16
+ - [textarea](#textarea)
15
17
  - [view](#view)
16
18
  - [visible](#visible)
17
19
  - [Methods](#methods)
20
+ - [destroy](#destroy)
18
21
  - [extraKeys](#extrakeys)
19
22
  - [getLinter](#getlinter)
20
23
  - [getNodeAt](#getnodeat)
@@ -26,6 +29,7 @@
26
29
  - [setContent](#setcontent)
27
30
  - [setIndent](#setindent)
28
31
  - [setLanguage](#setlanguage)
32
+ - [setLineWrapping](#setlinewrapping)
29
33
  - [toggle](#toggle)
30
34
  - [update](#update)
31
35
  - [Static methods](#static-methods)
@@ -36,19 +40,21 @@
36
40
  - [autocompletion](#autocompletion)
37
41
  - [bracketMatching](#bracketmatching)
38
42
  - [closeBrackets](#closebrackets)
39
- - [highlightActiveLine](#highlightactiveline)
40
- - [highlightSpecialChars](#highlightspecialchars)
41
- - [highlightWhitespace](#highlightwhitespace)
42
- - [highlightTrailingWhitespace](#highlighttrailingwhitespace)
43
- - [highlightSelectionMatches](#highlightselectionmatches)
44
43
  - [codeFolding](#codefolding)
45
- - [scrollPastEnd](#scrollpastend)
46
44
  - [colorPicker](#colorpicker)
47
45
  - [escape](#escape)
48
- - [tagMatching](#tagmatching)
49
- - [refHover](#refhover)
46
+ - [highlightActiveLine](#highlightactiveline)
47
+ - [highlightSelectionMatches](#highlightselectionmatches)
48
+ - [highlightSpecialChars](#highlightspecialchars)
49
+ - [highlightTrailingWhitespace](#highlighttrailingwhitespace)
50
+ - [highlightWhitespace](#highlightwhitespace)
50
51
  - [hover](#hover)
52
+ - [inlayHints](#inlayhints)
51
53
  - [openLinks](#openlinks)
54
+ - [refHover](#refhover)
55
+ - [scrollPastEnd](#scrollpastend)
56
+ - [signatureHelp](#signaturehelp)
57
+ - [tagMatching](#tagmatching)
52
58
  - [Known issues](#known-issues)
53
59
  - [Syntax Highlighting](#syntax-highlighting)
54
60
 
@@ -66,6 +72,8 @@ Nonetheless, this repository also provides a customized version with additional
66
72
 
67
73
  You can download the code via CDN, for example:
68
74
 
75
+ ## JavaScript
76
+
69
77
  ```js
70
78
  // static import
71
79
  import {CodeMirror6} from 'https://cdn.jsdelivr.net/npm/@bhsd/codemirror-mediawiki';
@@ -90,6 +98,18 @@ or
90
98
  const {CodeMirror6} = await import('https://unpkg.com/@bhsd/codemirror-mediawiki');
91
99
  ```
92
100
 
101
+ ## CSS
102
+
103
+ ```html
104
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@bhsd/codemirror-mediawiki/mediawiki.css">
105
+ ```
106
+
107
+ or
108
+
109
+ ```html
110
+ <link rel="stylesheet" href="https://unpkg.com/@bhsd/codemirror-mediawiki/mediawiki.css">
111
+ ```
112
+
93
113
  # Constructor
94
114
 
95
115
  <details>
@@ -114,25 +134,25 @@ const cm = new CodeMirror6(textarea, 'lua');
114
134
 
115
135
  # Accessors
116
136
 
117
- ## textarea
137
+ ## lang
118
138
 
119
139
  <details>
120
140
  <summary>Expand</summary>
121
141
 
122
- **type**: `HTMLTextAreaElement`
123
- The textarea element replaced by CodeMirror, read-only.
142
+ *version added: 2.0.14*
143
+
144
+ **type**: `string`
145
+ The current language mode, read-only.
124
146
 
125
147
  </details>
126
148
 
127
- ## lang
149
+ ## textarea
128
150
 
129
151
  <details>
130
152
  <summary>Expand</summary>
131
153
 
132
- *version added: 2.0.14*
133
-
134
- **type**: `string`
135
- The current language mode, read-only.
154
+ **type**: `HTMLTextAreaElement`
155
+ The textarea element replaced by CodeMirror, read-only.
136
156
 
137
157
  </details>
138
158
 
@@ -160,6 +180,21 @@ Whether the editor is visible, read-only.
160
180
 
161
181
  # Methods
162
182
 
183
+ ## destroy
184
+
185
+ <details>
186
+ <summary>Expand</summary>
187
+
188
+ *version added: 2.28.2*
189
+
190
+ Destroy the instance. This method is irrevocable and not recommended for general use. Instead, you should call the [`toggle`](#toggle) method to hide the editor.
191
+
192
+ ```js
193
+ cm.destroy();
194
+ ```
195
+
196
+ </details>
197
+
163
198
  ## extraKeys
164
199
 
165
200
  <details>
@@ -394,6 +429,23 @@ cm.setLanguage('lua');
394
429
 
395
430
  </details>
396
431
 
432
+ ## setLineWrapping
433
+
434
+ <details>
435
+ <summary>Expand</summary>
436
+
437
+ *version added: 2.28.0*
438
+
439
+ **param**: `boolean` whether to enable line wrapping
440
+ Switch between line wrapping and no line wrapping.
441
+
442
+ ```js
443
+ cm.setLineWrapping(false);
444
+ cm.setLineWrapping(true);
445
+ ```
446
+
447
+ </details>
448
+
397
449
  ## toggle
398
450
 
399
451
  <details>
@@ -483,32 +535,6 @@ Matched or unmatched brackets are highlighted in cyan or dark red when the curso
483
535
 
484
536
  Automatically close brackets (`{`, `[` and `(`) and quotes (`"`, and `'` except for the MediaWiki mode).
485
537
 
486
- ## highlightActiveLine
487
-
488
- Highlight the line the cursor is on in light cyan.
489
-
490
- ## highlightSpecialChars
491
-
492
- Show invisible characters as red dots.
493
-
494
- ## highlightWhitespace
495
-
496
- *version added: 2.0.12*
497
-
498
- Show spaces and tabs as dots and arrows.
499
-
500
- ## highlightTrailingWhitespace
501
-
502
- *version added: 2.0.9*
503
-
504
- Highlight trailing whitespace in a red-orange color.
505
-
506
- ## highlightSelectionMatches
507
-
508
- *version added: 2.15.3*
509
-
510
- Highlight texts that match the selection in light green.
511
-
512
538
  ## codeFolding
513
539
 
514
540
  *version added: 2.3.0*
@@ -522,12 +548,6 @@ Key bindings:
522
548
  - `Ctrl` + `Alt` + `[`: Fold all
523
549
  - `Ctrl` + `Alt` + `]`: Unfold all
524
550
 
525
- ## scrollPastEnd
526
-
527
- *version added: 2.15.3*
528
-
529
- Allow the editor to be scrolled down past the end of the document.
530
-
531
551
  ## colorPicker
532
552
 
533
553
  *version added: 2.18.0*
@@ -543,29 +563,37 @@ Key bindings:
543
563
  - `Ctrl`/`Cmd` + `[`: Escape the selected text with HTML entities
544
564
  - `Ctrl`/`Cmd` + `]`: Escape the selected text with URL encoding
545
565
 
546
- ## tagMatching
566
+ ## highlightActiveLine
547
567
 
548
- *version added: 2.4.1*
568
+ Highlight the line the cursor is on in light cyan.
549
569
 
550
- Matched or unmatched tags are highlighted in cyan or dark red when the cursor is inside.
570
+ ## highlightSelectionMatches
551
571
 
552
- ## refHover
572
+ *version added: 2.15.3*
553
573
 
554
- *version added: 2.17.1*
574
+ Highlight texts that match the selection in light green.
555
575
 
556
- Show the content of the `<ref>` tag defined elsewhere when hovering.
576
+ ## highlightSpecialChars
557
577
 
558
- ## hover
578
+ Show invisible characters as red dots.
559
579
 
560
- *version added: 2.21.1*
580
+ ## highlightTrailingWhitespace
561
581
 
562
- Show the help information of a magic word when hovering.
582
+ *version added: 2.0.9*
563
583
 
564
- ## signatureHelp
584
+ Highlight trailing whitespace in a red-orange color.
585
+
586
+ ## highlightWhitespace
587
+
588
+ *version added: 2.0.12*
589
+
590
+ Show spaces and tabs as dots and arrows.
591
+
592
+ ## hover
565
593
 
566
594
  *version added: 2.21.1*
567
595
 
568
- Show the parser function signature when typing.
596
+ Show the help information of a magic word when hovering.
569
597
 
570
598
  ## inlayHints
571
599
 
@@ -579,6 +607,30 @@ Show inlay hints for anonymous parameters.
579
607
 
580
608
  CTRL/CMD-click opens a link in a new tab.
581
609
 
610
+ ## refHover
611
+
612
+ *version added: 2.17.1*
613
+
614
+ Show the content of the `<ref>` tag defined elsewhere when hovering.
615
+
616
+ ## scrollPastEnd
617
+
618
+ *version added: 2.15.3*
619
+
620
+ Allow the editor to be scrolled down past the end of the document.
621
+
622
+ ## signatureHelp
623
+
624
+ *version added: 2.21.1*
625
+
626
+ Show the parser function signature when typing.
627
+
628
+ ## tagMatching
629
+
630
+ *version added: 2.4.1*
631
+
632
+ Matched or unmatched tags are highlighted in cyan or dark red when the cursor is inside.
633
+
582
634
  # Known issues
583
635
 
584
636
  ## Syntax Highlighting
@@ -12,11 +12,13 @@ export type LintSource = ((doc: Text) => Diagnostic[] | Promise<Diagnostic[]>) &
12
12
  fixer?: (doc: Text, rule?: string) => string | Promise<string>;
13
13
  };
14
14
  export type Addon<T> = [(config?: T, cm?: CodeMirror6) => Extension, Record<string, T>];
15
+ export type Dialect = 'sanitized-css' | undefined;
15
16
  /** CodeMirror 6 编辑器 */
16
17
  export declare class CodeMirror6 {
17
18
  #private;
18
19
  getWikiConfig?: () => Promise<ConfigData>;
19
20
  langConfig: MwConfig | undefined;
21
+ dialect: Dialect;
20
22
  get textarea(): HTMLTextAreaElement;
21
23
  get view(): EditorView | undefined;
22
24
  get lang(): string;
@@ -56,6 +58,11 @@ export declare class CodeMirror6 {
56
58
  * @param indent 缩进字符串
57
59
  */
58
60
  setIndent(indent: string): void;
61
+ /**
62
+ * 设置文本换行
63
+ * @param wrapping 是否换行
64
+ */
65
+ setLineWrapping(wrapping: boolean): void;
59
66
  /**
60
67
  * 获取默认linter
61
68
  * @param opt 选项
@@ -71,6 +78,8 @@ export declare class CodeMirror6 {
71
78
  * @param show 是否显示编辑器
72
79
  */
73
80
  toggle(show?: boolean): void;
81
+ /** 销毁实例 */
82
+ destroy(): void;
74
83
  /**
75
84
  * 添加额外快捷键
76
85
  * @param keys 快捷键
package/dist/css.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { LanguageSupport } from '@codemirror/language';
2
- declare const _default: () => LanguageSupport;
2
+ import type { Dialect } from './codemirror';
3
+ declare const _default: (dialect: Dialect) => LanguageSupport;
3
4
  export default _default;
package/dist/fold.d.ts CHANGED
@@ -21,7 +21,6 @@ export declare const braceStackUpdate: (state: EditorState, node: SyntaxNode) =>
21
21
  export declare const foldable: (state: EditorState, posOrNode: number | SyntaxNode, tree?: Tree | null) => DocRange | false;
22
22
  export declare const foldableLine: ({ state, viewport: { to: end }, viewportLineBlocks }: EditorView, { from: f, to: t }: DocRange) => DocRange | false;
23
23
  declare const _default: [(e?: Extension | undefined) => Extension, {
24
- lua: Extension[];
25
24
  mediawiki: (Extension | StateField<Tooltip | null>)[];
26
25
  }];
27
26
  export default _default;
@@ -0,0 +1,8 @@
1
+ export declare const noDetectionLangs: Set<string>;
2
+ /**
3
+ * 检测文本的缩进方式
4
+ * @param text 文本内容
5
+ * @param defaultIndent 默认缩进方式
6
+ * @param lang 语言
7
+ */
8
+ export declare const detectIndent: (text: string, defaultIndent: string, lang: string) => string;
@@ -24,7 +24,7 @@ const encapsulateLines = (text, pre, post) => {
24
24
  const lines = text.split("\n");
25
25
  return lines.map((line) => {
26
26
  var _a, _b;
27
- const str = ((_b = (_a = /^(={1,6})(.+)\1$/u.exec(line)) == null ? void 0 : _a[2]) != null ? _b : line).trim();
27
+ const str = ((_b = (_a = /^(={1,6})(.+)\1\s*$/u.exec(line)) == null ? void 0 : _a[2]) != null ? _b : line).trim();
28
28
  return pre === " " || lines.length === 1 || line.trim() ? pre + str + post : str;
29
29
  }).join("\n");
30
30
  };
package/dist/linter.d.mts CHANGED
@@ -3,7 +3,7 @@ import type { Linter } from 'eslint';
3
3
  import type { Warning } from 'stylelint';
4
4
  import type { Diagnostic } from 'luacheck-browserify';
5
5
  export type Option = Record<string, unknown> | null | undefined;
6
- export type LiveOption = (runtime?: true) => Option;
6
+ export type LiveOption = (runtime?: boolean) => Option;
7
7
  declare type getLinter<T> = () => (text: string) => T;
8
8
  declare type asyncLinter<T, S = Record<string, unknown>> = ((text: string, config?: Option) => T) & {
9
9
  config?: S;
@@ -19,6 +19,13 @@ declare interface MixedDiagnostic extends Omit<DiagnosticBase, 'range'> {
19
19
  from?: number;
20
20
  to?: number;
21
21
  }
22
+ declare interface JsonError {
23
+ message: string;
24
+ severity: 'error';
25
+ line: string | undefined;
26
+ column: string | undefined;
27
+ position: string | undefined;
28
+ }
22
29
  /**
23
30
  * 获取 Wikitext LSP
24
31
  * @param opt 选项
@@ -31,13 +38,6 @@ export declare const getJsLinter: getAsyncLinter<Linter.LintMessage[]>;
31
38
  export declare const getCssLinter: getAsyncLinter<Promise<Warning[]>>;
32
39
  /** 获取 Luacheck */
33
40
  export declare const getLuaLinter: getAsyncLinter<Promise<Diagnostic[]>>;
34
- declare interface JsonError {
35
- message: string;
36
- severity: 'error';
37
- line: string | undefined;
38
- column: string | undefined;
39
- position: string | undefined;
40
- }
41
41
  /** JSON.parse */
42
42
  export declare const getJsonLinter: getLinter<JsonError[]>;
43
43
  export {};
package/dist/linter.d.ts CHANGED
@@ -3,7 +3,7 @@ import type { Linter } from 'eslint';
3
3
  import type { Warning } from 'stylelint';
4
4
  import type { Diagnostic } from 'luacheck-browserify';
5
5
  export type Option = Record<string, unknown> | null | undefined;
6
- export type LiveOption = (runtime?: true) => Option;
6
+ export type LiveOption = (runtime?: boolean) => Option;
7
7
  declare type getLinter<T> = () => (text: string) => T;
8
8
  declare type asyncLinter<T, S = Record<string, unknown>> = ((text: string, config?: Option) => T) & {
9
9
  config?: S;
@@ -19,6 +19,13 @@ declare interface MixedDiagnostic extends Omit<DiagnosticBase, 'range'> {
19
19
  from?: number;
20
20
  to?: number;
21
21
  }
22
+ declare interface JsonError {
23
+ message: string;
24
+ severity: 'error';
25
+ line: string | undefined;
26
+ column: string | undefined;
27
+ position: string | undefined;
28
+ }
22
29
  /**
23
30
  * 获取 Wikitext LSP
24
31
  * @param opt 选项
@@ -31,13 +38,6 @@ export declare const getJsLinter: getAsyncLinter<Linter.LintMessage[]>;
31
38
  export declare const getCssLinter: getAsyncLinter<Promise<Warning[]>>;
32
39
  /** 获取 Luacheck */
33
40
  export declare const getLuaLinter: getAsyncLinter<Promise<Diagnostic[]>>;
34
- declare interface JsonError {
35
- message: string;
36
- severity: 'error';
37
- line: string | undefined;
38
- column: string | undefined;
39
- position: string | undefined;
40
- }
41
41
  /** JSON.parse */
42
42
  export declare const getJsonLinter: getLinter<JsonError[]>;
43
43
  export {};