@bhsd/codemirror-mediawiki 2.28.0 → 2.29.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
@@ -7,7 +7,10 @@
7
7
  <summary>Expand</summary>
8
8
 
9
9
  - [Description](#description)
10
- - [Usage](#usage)
10
+ - [Installation](#installation)
11
+ - [Browser Usage](#browser-usage)
12
+ - [JavaScript](#javascript)
13
+ - [CSS](#css)
11
14
  - [Constructor](#constructor)
12
15
  - [Accessors](#accessors)
13
16
  - [lang](#lang)
@@ -15,6 +18,7 @@
15
18
  - [view](#view)
16
19
  - [visible](#visible)
17
20
  - [Methods](#methods)
21
+ - [destroy](#destroy)
18
22
  - [extraKeys](#extrakeys)
19
23
  - [getLinter](#getlinter)
20
24
  - [getNodeAt](#getnodeat)
@@ -46,9 +50,11 @@
46
50
  - [highlightTrailingWhitespace](#highlighttrailingwhitespace)
47
51
  - [highlightWhitespace](#highlightwhitespace)
48
52
  - [hover](#hover)
53
+ - [inlayHints](#inlayhints)
49
54
  - [openLinks](#openlinks)
50
55
  - [refHover](#refhover)
51
56
  - [scrollPastEnd](#scrollpastend)
57
+ - [signatureHelp](#signaturehelp)
52
58
  - [tagMatching](#tagmatching)
53
59
  - [Known issues](#known-issues)
54
60
  - [Syntax Highlighting](#syntax-highlighting)
@@ -63,10 +69,24 @@ Here is a [demo](https://bhsd-harry.github.io/codemirror-mediawiki). To experime
63
69
 
64
70
  Nonetheless, this repository also provides a customized version with additional functionality for use on a MediaWiki site. Browser editing tools such as [Wikiplus-highlight](https://github.com/bhsd-harry/Wikiplus-highlight) and an [InPageEdit plugin](https://github.com/inpageedit/Plugins) are built upon it. Please refer to a separate [README](./mw/README.md) file for the information.
65
71
 
66
- # Usage
72
+ # Installation
73
+
74
+ You can install the package via npm and import it as a module:
75
+
76
+ ```bash
77
+ npm install @bhsd/codemirror-mediawiki
78
+ ```
79
+
80
+ ```js
81
+ import {CodeMirror6} from '@bhsd/codemirror-mediawiki';
82
+ ```
83
+
84
+ # Browser Usage
67
85
 
68
86
  You can download the code via CDN, for example:
69
87
 
88
+ ## JavaScript
89
+
70
90
  ```js
71
91
  // static import
72
92
  import {CodeMirror6} from 'https://cdn.jsdelivr.net/npm/@bhsd/codemirror-mediawiki';
@@ -91,6 +111,18 @@ or
91
111
  const {CodeMirror6} = await import('https://unpkg.com/@bhsd/codemirror-mediawiki');
92
112
  ```
93
113
 
114
+ ## CSS
115
+
116
+ ```html
117
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@bhsd/codemirror-mediawiki/mediawiki.css">
118
+ ```
119
+
120
+ or
121
+
122
+ ```html
123
+ <link rel="stylesheet" href="https://unpkg.com/@bhsd/codemirror-mediawiki/mediawiki.css">
124
+ ```
125
+
94
126
  # Constructor
95
127
 
96
128
  <details>
@@ -161,6 +193,21 @@ Whether the editor is visible, read-only.
161
193
 
162
194
  # Methods
163
195
 
196
+ ## destroy
197
+
198
+ <details>
199
+ <summary>Expand</summary>
200
+
201
+ *version added: 2.28.2*
202
+
203
+ 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.
204
+
205
+ ```js
206
+ cm.destroy();
207
+ ```
208
+
209
+ </details>
210
+
164
211
  ## extraKeys
165
212
 
166
213
  <details>
@@ -561,6 +608,12 @@ Show spaces and tabs as dots and arrows.
561
608
 
562
609
  Show the help information of a magic word when hovering.
563
610
 
611
+ ## inlayHints
612
+
613
+ *version added: 2.22.0*
614
+
615
+ Show inlay hints for anonymous parameters.
616
+
564
617
  ## openLinks
565
618
 
566
619
  *version added: 2.19.6*
@@ -579,23 +632,17 @@ Show the content of the `<ref>` tag defined elsewhere when hovering.
579
632
 
580
633
  Allow the editor to be scrolled down past the end of the document.
581
634
 
582
- ## tagMatching
583
-
584
- *version added: 2.4.1*
585
-
586
- Matched or unmatched tags are highlighted in cyan or dark red when the cursor is inside.
587
-
588
635
  ## signatureHelp
589
636
 
590
637
  *version added: 2.21.1*
591
638
 
592
639
  Show the parser function signature when typing.
593
640
 
594
- ## inlayHints
641
+ ## tagMatching
595
642
 
596
- *version added: 2.22.0*
643
+ *version added: 2.4.1*
597
644
 
598
- Show inlay hints for anonymous parameters.
645
+ Matched or unmatched tags are highlighted in cyan or dark red when the cursor is inside.
599
646
 
600
647
  # Known issues
601
648
 
package/dist/bidi.js ADDED
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @author MusikAnimal
3
+ * @license GPL-2.0-or-later
4
+ * @see https://gerrit.wikimedia.org/g/mediawiki/extensions/CodeMirror
5
+ */
6
+ import { EditorView, Direction, ViewPlugin, Decoration } from '@codemirror/view';
7
+ import { Prec, RangeSetBuilder } from '@codemirror/state';
8
+ import { syntaxTree } from '@codemirror/language';
9
+ import { getTag } from './matchTag';
10
+ import { tokens } from './config';
11
+ const isolateLTR = Decoration.mark({
12
+ class: 'cm-bidi-isolate cm-bidi-ltr',
13
+ bidiIsolate: Direction.LTR,
14
+ }), isolate = Decoration.mark({ class: 'cm-bidi-isolate' });
15
+ export const computeIsolates = ({ visibleRanges, state, textDirection }) => {
16
+ const set = new RangeSetBuilder();
17
+ if (textDirection === Direction.RTL) {
18
+ for (const { from, to } of visibleRanges) {
19
+ let node = syntaxTree(state).resolve(from, 1), td = 0, table = 0, parameter = 0;
20
+ while (node && node.to <= to) {
21
+ const { name, from: f, to: t, nextSibling } = node;
22
+ if (/-(?:ext|html)tag-bracket/u.test(name) && state.sliceDoc(f, t).includes('<')) {
23
+ const tag = getTag(state, nextSibling);
24
+ if (tag) {
25
+ set.add(tag.from, tag.to, isolateLTR);
26
+ }
27
+ }
28
+ else if (!td && !table && name.includes(tokens.tableDefinition)) {
29
+ if (/-html-(?:table|tr)/u.test(name)) {
30
+ table = state.doc.lineAt(f).to;
31
+ set.add(f, table, isolateLTR);
32
+ }
33
+ else {
34
+ td = f;
35
+ }
36
+ }
37
+ else if (table && f > table) {
38
+ table = 0;
39
+ }
40
+ else if (td && name.includes(tokens.tableDelimiter2)) {
41
+ set.add(td, f, isolateLTR);
42
+ td = 0;
43
+ }
44
+ else if (/-(?:template|parserfunction)-delimiter/u.test(name)) {
45
+ if (parameter) {
46
+ set.add(parameter, f, isolate);
47
+ }
48
+ parameter = t;
49
+ }
50
+ else if (parameter && /-(?:template|parserfunction)-bracket/u.test(name)) {
51
+ if (state.sliceDoc(f, f + 1) === '}') {
52
+ set.add(parameter, f, isolate);
53
+ }
54
+ parameter = 0;
55
+ }
56
+ node = node.nextSibling;
57
+ }
58
+ }
59
+ }
60
+ return set.finish();
61
+ };
62
+ export default ViewPlugin.fromClass(class {
63
+ constructor(view) {
64
+ this.isolates = computeIsolates(view);
65
+ this.tree = syntaxTree(view.state);
66
+ this.dir = view.textDirection;
67
+ }
68
+ update({ docChanged, viewportChanged, state, view }) {
69
+ const tree = syntaxTree(state), { textDirection } = view;
70
+ if (docChanged || viewportChanged || tree !== this.tree || textDirection !== this.dir) {
71
+ this.isolates = computeIsolates(view);
72
+ this.tree = tree;
73
+ this.dir = textDirection;
74
+ }
75
+ }
76
+ }, {
77
+ provide(plugin) {
78
+ const access = (view) => view.plugin(plugin)?.isolates ?? Decoration.none;
79
+ return Prec.lowest([
80
+ EditorView.decorations.of(access),
81
+ EditorView.bidiIsolatedRanges.of(access),
82
+ ]);
83
+ },
84
+ });
@@ -78,6 +78,8 @@ export declare class CodeMirror6 {
78
78
  * @param show 是否显示编辑器
79
79
  */
80
80
  toggle(show?: boolean): void;
81
+ /** 销毁实例 */
82
+ destroy(): void;
81
83
  /**
82
84
  * 添加额外快捷键
83
85
  * @param keys 快捷键