@bhsd/codemirror-mediawiki 3.9.1 → 3.10.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.
Files changed (51) hide show
  1. package/README.md +71 -11
  2. package/dist/bidi.d.ts +4 -8
  3. package/dist/bidi.js +33 -23
  4. package/dist/codemirror.js +15 -9
  5. package/dist/color.d.ts +1 -1
  6. package/dist/color.js +1 -1
  7. package/dist/config.d.ts +1 -0
  8. package/dist/config.js +1 -0
  9. package/dist/constants.d.ts +3 -2
  10. package/dist/constants.js +3 -2
  11. package/dist/css.js +9 -6
  12. package/dist/escape.d.ts +1 -1
  13. package/dist/escape.js +4 -3
  14. package/dist/fold.d.ts +2 -2
  15. package/dist/fold.js +113 -40
  16. package/dist/hover.d.ts +2 -2
  17. package/dist/hover.js +74 -62
  18. package/dist/index.d.ts +54 -16
  19. package/dist/index.js +91 -38
  20. package/dist/inlay.d.ts +1 -1
  21. package/dist/inlay.js +26 -25
  22. package/dist/javascript.js +45 -2
  23. package/dist/linter.d.ts +15 -2
  24. package/dist/linter.js +2 -2
  25. package/dist/lintsource.d.ts +15 -3
  26. package/dist/lintsource.js +13 -7
  27. package/dist/lua.d.ts +0 -2
  28. package/dist/lua.js +32 -26
  29. package/dist/main.min.js +31 -29
  30. package/dist/matchTag.js +4 -3
  31. package/dist/mediawiki.d.ts +4 -2
  32. package/dist/mediawiki.js +56 -44
  33. package/dist/mw.min.js +33 -37
  34. package/dist/mwConfig.js +2 -2
  35. package/dist/openLinks.d.ts +4 -2
  36. package/dist/openLinks.js +56 -54
  37. package/dist/ref.d.ts +1 -1
  38. package/dist/ref.js +92 -93
  39. package/dist/signature.d.ts +1 -1
  40. package/dist/signature.js +50 -49
  41. package/dist/statusBar.js +31 -9
  42. package/dist/theme.js +10 -23
  43. package/dist/token.d.ts +20 -6
  44. package/dist/token.js +26 -17
  45. package/dist/util.d.ts +17 -2
  46. package/dist/util.js +39 -1
  47. package/dist/wiki.min.js +32 -36
  48. package/i18n/en.json +2 -2
  49. package/i18n/zh-hans.json +2 -2
  50. package/i18n/zh-hant.json +2 -2
  51. package/package.json +14 -12
package/README.md CHANGED
@@ -19,6 +19,7 @@ If you are just looking for a CodeMirror 6 language mode and language support ex
19
19
  - [Installation](#installation)
20
20
  - [Browser Usage](#browser-usage)
21
21
  - [Language modes](#language-modes)
22
+ - [abusefilter](#abusefilter)
22
23
  - [css](#css)
23
24
  - [html](#html)
24
25
  - [javascript](#javascript)
@@ -64,6 +65,7 @@ If you are just looking for a CodeMirror 6 language mode and language support ex
64
65
  - [Extensions](#extensions)
65
66
  - [allowMultipleSelections](#allowmultipleselections)
66
67
  - [autocompletion](#autocompletion)
68
+ - [bidiIsolates](#bidiisolates)
67
69
  - [bracketMatching](#bracketmatching)
68
70
  - [closeBrackets](#closebrackets)
69
71
  - [codeFolding](#codefolding)
@@ -103,6 +105,7 @@ import {
103
105
  registerJSON,
104
106
  registerLua,
105
107
  registerVue,
108
+ registerAbuseFilter,
106
109
  } from '@bhsd/codemirror-mediawiki';
107
110
  ```
108
111
 
@@ -124,6 +127,7 @@ import {
124
127
  registerJSON,
125
128
  registerLua,
126
129
  registerVue,
130
+ registerAbuseFilter,
127
131
  } from 'https://cdn.jsdelivr.net/npm/@bhsd/codemirror-mediawiki';
128
132
  ```
129
133
 
@@ -139,6 +143,7 @@ import {
139
143
  registerJSON,
140
144
  registerLua,
141
145
  registerVue,
146
+ registerAbuseFilter,
142
147
  } from 'https://unpkg.com/@bhsd/codemirror-mediawiki/dist/main.min.js';
143
148
  ```
144
149
 
@@ -155,6 +160,7 @@ const {
155
160
  registerJSON,
156
161
  registerLua,
157
162
  registerVue,
163
+ registerAbuseFilter,
158
164
  } = await import('https://cdn.jsdelivr.net/npm/@bhsd/codemirror-mediawiki');
159
165
  ```
160
166
 
@@ -170,6 +176,7 @@ const {
170
176
  registerJSON,
171
177
  registerLua,
172
178
  registerVue,
179
+ registerAbuseFilter,
173
180
  } = await import('https://unpkg.com/@bhsd/codemirror-mediawiki/dist/main.min.js');
174
181
  ```
175
182
 
@@ -177,6 +184,29 @@ const {
177
184
 
178
185
  # Language modes
179
186
 
187
+ ## abusefilter
188
+
189
+ *version added: 3.10.0*
190
+
191
+ <details>
192
+ <summary>Expand</summary>
193
+
194
+ You can bundle the [AbuseFilter](https://www.mediawiki.org/wiki/Extension:AbuseFilter) mode by importing the `registerAbuseFilter` function:
195
+
196
+ ```js
197
+ import {registerAbuseFilter} from '@bhsd/codemirror-mediawiki';
198
+ registerAbuseFilter();
199
+ ```
200
+
201
+ If you want a more granular control over the extensions, you can import the `registerAbuseFilterCore` function and the desired extensions:
202
+
203
+ ```js
204
+ import {registerAbuseFilterCore} from '@bhsd/codemirror-mediawiki';
205
+ registerAbuseFilterCore();
206
+ ```
207
+
208
+ </details>
209
+
180
210
  ## css
181
211
 
182
212
  <details>
@@ -228,9 +258,11 @@ In addition to the common [extensions](#extensions), here are some HTML-specific
228
258
 
229
259
  ```js
230
260
  import {
261
+ registerBracketMatchingForHTML,
231
262
  registerCloseBracketsForHTML,
232
263
  registerColorPickerForHTML,
233
264
  } from '@bhsd/codemirror-mediawiki';
265
+ registerBracketMatchingForHTML();
234
266
  registerCloseBracketsForHTML();
235
267
  registerColorPickerForHTML();
236
268
  ```
@@ -309,7 +341,8 @@ You can bundle the MediaWiki mode by importing the `registerMediaWiki` function:
309
341
 
310
342
  ```js
311
343
  import {registerMediaWiki} from '@bhsd/codemirror-mediawiki';
312
- registerMediaWiki();
344
+ // optionally pass the article path of a MediaWiki site
345
+ registerMediaWiki('https://www.mediawiki.org/wiki/');
313
346
  ```
314
347
 
315
348
  The MediaWiki mode provides the following key bindings for quick formatting:
@@ -333,7 +366,8 @@ If you want a more granular control over the extensions, you can import the `reg
333
366
 
334
367
  ```js
335
368
  import {registerMediaWikiCore} from '@bhsd/codemirror-mediawiki';
336
- registerMediaWikiCore();
369
+ // optionally pass the article path of a MediaWiki site
370
+ registerMediaWikiCore('https://www.mediawiki.org/wiki/');
337
371
  ```
338
372
 
339
373
  In addition to the common [extensions](#extensions), here are some MediaWiki-specific extensions. Note that these extensions may not take effect if the corresponding common extensions are not registered:
@@ -448,7 +482,7 @@ registerTheme('one-dark', oneDark);
448
482
 
449
483
  **param**: `HTMLTextAreaElement` the textarea element to be replaced by CodeMirror
450
484
  **param**: `string` the language mode to be used, default as plain text
451
- **param**: `unknown` the language configuration, only required for the MediaWiki mode and the mixed MediaWiki-HTML mode
485
+ **param**: `unknown` the language configuration, only required for the [MediaWiki](#mediawiki) mode and the [mixed MediaWiki-HTML](#html) mode
452
486
  **param**: `boolean` whether to initialize immediately, default as true
453
487
 
454
488
  ```js
@@ -461,6 +495,7 @@ cm = new CodeMirror6(textarea, 'javascript');
461
495
  cm = new CodeMirror6(textarea, 'json');
462
496
  cm = new CodeMirror6(textarea, 'lua');
463
497
  cm = new CodeMirror6(textarea, 'vue');
498
+ cm = new CodeMirror6(textarea, 'abusefilter', dialect);
464
499
  ```
465
500
 
466
501
  </details>
@@ -806,7 +841,7 @@ cm.setIndent('\t');
806
841
  <summary>Expand</summary>
807
842
 
808
843
  **param**: `string` the language mode to be used, default as plain text
809
- **param**: `unknown` the optional language configuration
844
+ **param**: `unknown` the language configuration, only required for the [MediaWiki](#mediawiki) mode and the [mixed MediaWiki-HTML](#html) mode
810
845
  Set the language mode.
811
846
 
812
847
  ```js
@@ -817,6 +852,7 @@ cm.setLanguage('javascript');
817
852
  cm.setLanguage('json');
818
853
  cm.setLanguage('lua');
819
854
  cm.setLanguage('vue');
855
+ cm.setLanguage('abusefilter', dialect);
820
856
  ```
821
857
 
822
858
  </details>
@@ -964,7 +1000,7 @@ registerAllowMultipleSelections();
964
1000
 
965
1001
  *version added: 2.5.1*
966
1002
 
967
- Provide autocompletion for MediaWiki, CSS and JavaScript modes.
1003
+ Provide autocompletion.
968
1004
 
969
1005
  Key bindings:
970
1006
 
@@ -980,6 +1016,24 @@ registerAutocompletion();
980
1016
 
981
1017
  </details>
982
1018
 
1019
+ ## bidiIsolates
1020
+
1021
+ <details>
1022
+ <summary>Expand</summary>
1023
+
1024
+ *version added: 3.10.0*
1025
+
1026
+ When Wikitext contains right-to-left text, isolate bidirectional text from the surrounding text.
1027
+
1028
+ This extension is not included in the [`mediawiki`](#mediawiki) language support by default. You need to import the `registerBidiIsolates` function:
1029
+
1030
+ ```js
1031
+ import {registerBidiIsolates} from '@bhsd/codemirror-mediawiki';
1032
+ registerBidiIsolates();
1033
+ ```
1034
+
1035
+ </details>
1036
+
983
1037
  ## bracketMatching
984
1038
 
985
1039
  <details>
@@ -1077,7 +1131,8 @@ For granular control over the bundled extensions, you can import the `registerEs
1077
1131
 
1078
1132
  ```js
1079
1133
  import {registerEscape} from '@bhsd/codemirror-mediawiki';
1080
- registerEscape();
1134
+ // optionally pass the article path of a MediaWiki site
1135
+ registerEscape('https://www.mediawiki.org/wiki/');
1081
1136
  ```
1082
1137
 
1083
1138
  </details>
@@ -1181,7 +1236,8 @@ For granular control over the bundled extensions, you can import the `registerHo
1181
1236
 
1182
1237
  ```js
1183
1238
  import {registerHover} from '@bhsd/codemirror-mediawiki';
1184
- registerHover();
1239
+ // optionally pass the article path of a MediaWiki site
1240
+ registerHover('https://www.mediawiki.org/wiki/');
1185
1241
  ```
1186
1242
 
1187
1243
  </details>
@@ -1199,7 +1255,8 @@ For granular control over the bundled extensions, you can import the `registerIn
1199
1255
 
1200
1256
  ```js
1201
1257
  import {registerInlayHints} from '@bhsd/codemirror-mediawiki';
1202
- registerInlayHints();
1258
+ // optionally pass the article path of a MediaWiki site
1259
+ registerInlayHints('https://www.mediawiki.org/wiki/');
1203
1260
  ```
1204
1261
 
1205
1262
  </details>
@@ -1217,7 +1274,8 @@ For granular control over the bundled extensions, you can import the `registerOp
1217
1274
 
1218
1275
  ```js
1219
1276
  import {registerOpenLinks} from '@bhsd/codemirror-mediawiki';
1220
- registerOpenLinks();
1277
+ // optionally pass the article path of a MediaWiki site
1278
+ registerOpenLinks('https://www.mediawiki.org/wiki/');
1221
1279
  ```
1222
1280
 
1223
1281
  </details>
@@ -1235,7 +1293,8 @@ For granular control over the bundled extensions, you can import the `registerRe
1235
1293
 
1236
1294
  ```js
1237
1295
  import {registerRefHover} from '@bhsd/codemirror-mediawiki';
1238
- registerRefHover();
1296
+ // optionally pass the article path of a MediaWiki site
1297
+ registerRefHover('https://www.mediawiki.org/wiki/');
1239
1298
  ```
1240
1299
 
1241
1300
  </details>
@@ -1271,7 +1330,8 @@ For granular control over the bundled extensions, you can import the `registerSi
1271
1330
 
1272
1331
  ```js
1273
1332
  import {registerSignatureHelp} from '@bhsd/codemirror-mediawiki';
1274
- registerSignatureHelp();
1333
+ // optionally pass the article path of a MediaWiki site
1334
+ registerSignatureHelp('https://www.mediawiki.org/wiki/');
1275
1335
  ```
1276
1336
 
1277
1337
  </details>
package/dist/bidi.d.ts CHANGED
@@ -3,13 +3,9 @@
3
3
  * @license GPL-2.0-or-later
4
4
  * @see https://gerrit.wikimedia.org/g/mediawiki/extensions/CodeMirror
5
5
  */
6
- import { EditorView, Direction, ViewPlugin } from '@codemirror/view';
7
- import type { ViewUpdate, DecorationSet } from '@codemirror/view';
6
+ import { EditorView } from '@codemirror/view';
7
+ import type { DecorationSet } from '@codemirror/view';
8
+ import type { Extension } from '@codemirror/state';
8
9
  export declare const computeIsolates: ({ visibleRanges, state, textDirection }: EditorView) => DecorationSet;
9
- declare const _default: ViewPlugin<{
10
- isolates: DecorationSet;
11
- tree: import("@lezer/common").Tree;
12
- dir: Direction;
13
- update({ docChanged, viewportChanged, state, view }: ViewUpdate): void;
14
- }, undefined>;
10
+ declare const _default: Extension[];
15
11
  export default _default;
package/dist/bidi.js CHANGED
@@ -7,9 +7,8 @@ import { EditorView, Direction, ViewPlugin, Decoration } from '@codemirror/view'
7
7
  import { Prec, RangeSetBuilder } from '@codemirror/state';
8
8
  import { syntaxTree } from '@codemirror/language';
9
9
  import { tokens } from './config.js';
10
- import { isolateSelector, ltrSelector } from './constants.js';
11
10
  import { getTag } from './matchTag.js';
12
- const cls = isolateSelector.slice(1), isolateLTR = Decoration.mark({
11
+ const isolateSelector = '.cm-bidi-isolate', ltrSelector = '.cm-bidi-ltr', cls = isolateSelector.slice(1), isolateLTR = Decoration.mark({
13
12
  class: `${cls} ${ltrSelector.slice(1)}`,
14
13
  bidiIsolate: Direction.LTR,
15
14
  }), isolate = Decoration.mark({ class: cls });
@@ -60,26 +59,37 @@ export const computeIsolates = ({ visibleRanges, state, textDirection }) => {
60
59
  }
61
60
  return set.finish();
62
61
  };
63
- export default ViewPlugin.fromClass(class {
64
- constructor(view) {
65
- this.isolates = computeIsolates(view);
66
- this.tree = syntaxTree(view.state);
67
- this.dir = view.textDirection;
68
- }
69
- update({ docChanged, viewportChanged, state, view }) {
70
- const tree = syntaxTree(state), { textDirection } = view;
71
- if (docChanged || viewportChanged || tree !== this.tree || textDirection !== this.dir) {
62
+ export default [
63
+ ViewPlugin.fromClass(class {
64
+ constructor(view) {
72
65
  this.isolates = computeIsolates(view);
73
- this.tree = tree;
74
- this.dir = textDirection;
66
+ this.tree = syntaxTree(view.state);
67
+ this.dir = view.textDirection;
75
68
  }
76
- }
77
- }, {
78
- provide(plugin) {
79
- const access = (view) => view.plugin(plugin)?.isolates ?? Decoration.none;
80
- return Prec.lowest([
81
- EditorView.decorations.of(access),
82
- EditorView.bidiIsolatedRanges.of(access),
83
- ]);
84
- },
85
- });
69
+ update({ docChanged, viewportChanged, state, view }) {
70
+ const tree = syntaxTree(state), { textDirection } = view;
71
+ if (docChanged || viewportChanged || tree !== this.tree || textDirection !== this.dir) {
72
+ this.isolates = computeIsolates(view);
73
+ this.tree = tree;
74
+ this.dir = textDirection;
75
+ }
76
+ }
77
+ }, {
78
+ provide(plugin) {
79
+ const access = (view) => view.plugin(plugin)?.isolates ?? Decoration.none;
80
+ return Prec.lowest([
81
+ EditorView.decorations.of(access),
82
+ EditorView.bidiIsolatedRanges.of(access),
83
+ ]);
84
+ },
85
+ }),
86
+ EditorView.theme({
87
+ [`${isolateSelector}, &[dir="rtl"] .cm-mw-template-name`]: {
88
+ unicodeBidi: 'isolate',
89
+ },
90
+ [ltrSelector]: {
91
+ direction: 'ltr',
92
+ display: 'inline-block',
93
+ },
94
+ }),
95
+ ];
@@ -1,6 +1,6 @@
1
1
  import { EditorView, lineNumbers, keymap, highlightActiveLineGutter } from '@codemirror/view';
2
2
  import { EditorSelection, Compartment, EditorState, SelectionRange, } from '@codemirror/state';
3
- import { syntaxHighlighting, defaultHighlightStyle, indentOnInput, indentUnit, ensureSyntaxTree, } from '@codemirror/language';
3
+ import { syntaxHighlighting, defaultHighlightStyle, indentOnInput, indentUnit, ensureSyntaxTree, syntaxTree, } from '@codemirror/language';
4
4
  import { defaultKeymap, historyKeymap, history, redo, indentWithTab, insertNewlineKeepIndent, deleteCharBackwardStrict, } from '@codemirror/commands';
5
5
  import { search, searchKeymap } from '@codemirror/search';
6
6
  import { linter, lintGutter, lintKeymap } from '@codemirror/lint';
@@ -16,8 +16,7 @@ export const plain = () => [
16
16
  ];
17
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
18
  export const languages = { plain };
19
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
- export const avail = {};
19
+ export const avail = {}; // eslint-disable-line @typescript-eslint/no-explicit-any
21
20
  export const linterRegistry = {};
22
21
  export const menuRegistry = [];
23
22
  export const destroyListeners = [];
@@ -33,13 +32,13 @@ export const optionalFunctions = {
33
32
  return () => { };
34
33
  },
35
34
  };
36
- const editExtensions = new Set(['closeBrackets', 'autocompletion', 'signatureHelp']);
35
+ const editExtensions = new Set(['closeBrackets', 'autocompletion', 'signatureHelp', 'escape']);
37
36
  const linters = {};
38
37
  const phrases = {};
39
38
  export const replaceSelections = (view, func) => {
40
39
  const { state } = view;
41
- view.dispatch(state.changeByRange(({ from, to }) => {
42
- const result = func(state.sliceDoc(from, to), { from, to });
40
+ view.dispatch(state.changeByRange(range => {
41
+ const { from, to } = range, result = func(state.sliceDoc(from, to), range);
43
42
  if (typeof result === 'string') {
44
43
  return {
45
44
  range: EditorSelection.range(from, from + result.length),
@@ -172,18 +171,18 @@ export class CodeMirror6 {
172
171
  '& .cm-lineNumbers .cm-gutterElement': {
173
172
  textAlign: 'end',
174
173
  },
175
- [`.cm-textfield,.cm-button,${panelSelector}.cm-search label,${panelSelector}.cm-gotoLine label`]: {
174
+ [`.cm-textfield, .cm-button,${panelSelector}.cm-search label,${panelSelector}.cm-gotoLine label`]: {
176
175
  fontSize: 'inherit',
177
176
  },
178
177
  [`${panelSelector} [name="close"]`]: {
179
178
  color: 'inherit',
180
179
  },
181
180
  }),
182
- EditorView.updateListener.of(({ state: { doc }, startState: { doc: startDoc }, docChanged, focusChanged, }) => {
181
+ EditorView.updateListener.of(({ state, startState: { doc: startDoc }, docChanged, focusChanged, selectionSet, }) => {
183
182
  if (docChanged) {
184
183
  clearTimeout(timer);
185
184
  timer = setTimeout(() => {
186
- textarea.value = doc.toString();
185
+ textarea.value = state.doc.toString();
187
186
  textarea.dispatchEvent(new InputEvent('input'));
188
187
  }, 400);
189
188
  if (!noDetectionLangs.has(this.#lang) && !startDoc.toString().trim()) {
@@ -193,6 +192,13 @@ export class CodeMirror6 {
193
192
  if (focusChanged) {
194
193
  textarea.dispatchEvent(new FocusEvent(this.#view.hasFocus ? 'focus' : 'blur'));
195
194
  }
195
+ if (selectionSet && this.lang === 'mediawiki'
196
+ && ['localhost:8080', 'bhsd-harry.github.io'].includes(location.host)) {
197
+ const tree = syntaxTree(state), { head } = state.selection.main, { name } = tree.resolve(head), innerName = tree.resolveInner(head).name;
198
+ if (name !== innerName) {
199
+ console.error(`Cursor at ${head}: ${name} (inner: ${innerName})`);
200
+ }
201
+ }
196
202
  }),
197
203
  ...readOnly
198
204
  ? [
package/dist/color.d.ts CHANGED
@@ -2,5 +2,5 @@ import type { Text, Extension } from '@codemirror/state';
2
2
  import type { Tree } from '@lezer/common';
3
3
  import type { WidgetOptions } from '@bhsd/codemirror-css-color-picker';
4
4
  export declare const discoverColors: (_: Tree, from: number, to: number, type: string, doc: Text) => WidgetOptions[] | null;
5
- declare const _default: () => Extension;
5
+ declare const _default: Extension[];
6
6
  export default _default;
package/dist/color.js CHANGED
@@ -26,7 +26,7 @@ export const discoverColors = (_, from, to, type, doc) => {
26
26
  };
27
27
  }).filter(options => options !== null);
28
28
  };
29
- export default () => [
29
+ export default [
30
30
  makeColorPicker({ discoverColors }),
31
31
  colorPickerTheme,
32
32
  ];
package/dist/config.d.ts CHANGED
@@ -64,6 +64,7 @@ tokens: {
64
64
  magicLink: string;
65
65
  pageName: string;
66
66
  parserFunction: string;
67
+ parserFunctionArgumentName: string;
67
68
  parserFunctionBracket: string;
68
69
  parserFunctionDelimiter: string;
69
70
  parserFunctionName: string;
package/dist/config.js CHANGED
@@ -124,6 +124,7 @@ var tokens = {
124
124
  magicLink: "mw-magic-link",
125
125
  pageName: "mw-pagename",
126
126
  parserFunction: "mw-parserfunction",
127
+ parserFunctionArgumentName: "mw-parserfunction-argument-name",
127
128
  parserFunctionBracket: "mw-parserfunction-bracket",
128
129
  parserFunctionDelimiter: "mw-parserfunction-delimiter",
129
130
  parserFunctionName: "mw-parserfunction-name",
@@ -1,2 +1,3 @@
1
- export declare const base: Record<'CDN', string | undefined>, hoverSelector = ".cm-tooltip-hover-mw", diagnosticSelector = ".cm-diagnosticText-clickable", panelSelector = ".cm-panel", panelsSelector = ".cm-panels", foldSelector = ".cm-tooltip-fold", isolateSelector = ".cm-bidi-isolate", ltrSelector = ".cm-bidi-ltr", menuSelector = ".cm-status-fix-menu", messageSelector = ".cm-status-message", actionSelector = ".cm-diagnosticAction", noDetectionLangs: Set<string>, matchingCls = "cm-matchingTag", nonmatchingCls = "cm-nonmatchingTag";
2
- export declare const isWMF: boolean, isMac: boolean;
1
+ export declare const base: Record<'CDN', string | undefined>, hoverSelector = ".cm-tooltip-hover-mw", diagnosticSelector = ".cm-diagnosticText-clickable", panelSelector = ".cm-panel", panelsSelector = ".cm-panels", actionSelector = ".cm-diagnosticAction", noDetectionLangs: Set<string>, bgDark = "#4c566a", matchingCls = "cm-matchingTag", nonmatchingCls = "cm-nonmatchingTag";
2
+ export declare const isWMF: boolean;
3
+ export declare const isMac: boolean;
package/dist/constants.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { wmf } from '@bhsd/common';
2
- export const base = { CDN: undefined }, hoverSelector = '.cm-tooltip-hover-mw', diagnosticSelector = '.cm-diagnosticText-clickable', panelSelector = '.cm-panel', panelsSelector = '.cm-panels', foldSelector = '.cm-tooltip-fold', isolateSelector = '.cm-bidi-isolate', ltrSelector = '.cm-bidi-ltr', menuSelector = '.cm-status-fix-menu', messageSelector = '.cm-status-message', actionSelector = '.cm-diagnosticAction', noDetectionLangs = new Set(['plain', 'mediawiki']), matchingCls = 'cm-matchingTag', nonmatchingCls = 'cm-nonmatchingTag';
2
+ export const base = { CDN: undefined }, hoverSelector = '.cm-tooltip-hover-mw', diagnosticSelector = '.cm-diagnosticText-clickable', panelSelector = '.cm-panel', panelsSelector = '.cm-panels', actionSelector = '.cm-diagnosticAction', noDetectionLangs = new Set(['plain', 'mediawiki']), bgDark = '#4c566a', matchingCls = 'cm-matchingTag', nonmatchingCls = 'cm-nonmatchingTag';
3
3
  export const isWMF = /* @__PURE__ */ (() => typeof location === 'object'
4
- && new RegExp(String.raw `\.(?:${wmf})\.org$`, 'u').test(location.hostname))(), isMac = /* @__PURE__ */ (() => {
4
+ && new RegExp(String.raw `\.(?:${wmf})\.org$`, 'u').test(location.hostname))();
5
+ export const isMac = /* @__PURE__ */ (() => {
5
6
  const { vendor, userAgent, maxTouchPoints, platform } = navigator;
6
7
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
7
8
  return vendor?.includes('Apple Computer')
package/dist/css.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import { cssLanguage, cssCompletionSource } from '@codemirror/lang-css';
2
2
  import { LanguageSupport, syntaxTree } from '@codemirror/language';
3
- export const cssCompletion = (dialect) => cssLanguage.data.of({
4
- autocomplete(context) {
3
+ import { sliceDoc } from './util.js';
4
+ const cssWideKeywords = /* @__PURE__ */ (() => ['revert', 'revert-layer'].map((label) => ({ label, type: 'keyword' })))();
5
+ export const cssCompletion = (dialect) => {
6
+ const source = context => {
5
7
  const { state, pos } = context, node = syntaxTree(state).resolveInner(pos, -1), result = cssCompletionSource(context);
6
8
  if (result) {
7
9
  if (node.name === 'ValueName') {
8
- const options = [{ label: 'revert', type: 'keyword' }, ...result.options];
10
+ const options = [...cssWideKeywords, ...result.options];
9
11
  let { prevSibling } = node;
10
12
  while (prevSibling && prevSibling.name !== 'PropertyName') {
11
13
  ({ prevSibling } = prevSibling);
@@ -13,7 +15,7 @@ export const cssCompletion = (dialect) => cssLanguage.data.of({
13
15
  if (prevSibling) {
14
16
  for (let i = 0; i < options.length; i++) {
15
17
  const option = options[i];
16
- if (CSS.supports(state.sliceDoc(prevSibling.from, node.from) + option.label)) {
18
+ if (CSS.supports(sliceDoc(state, prevSibling), option.label)) {
17
19
  options.splice(i, 1, { ...option, boost: 50 });
18
20
  }
19
21
  }
@@ -26,6 +28,7 @@ export const cssCompletion = (dialect) => cssLanguage.data.of({
26
28
  }
27
29
  }
28
30
  return result;
29
- },
30
- });
31
+ };
32
+ return cssLanguage.data.of({ autocomplete: source });
33
+ };
31
34
  export default (dialect) => new LanguageSupport(cssLanguage, cssCompletion(dialect));
package/dist/escape.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Extension } from '@codemirror/state';
2
2
  import type { CodeMirror6 } from './codemirror';
3
3
  export declare const escapeHTML: (str: string) => string, escapeURI: (str: string) => string;
4
- declare const _default: (cm: CodeMirror6) => Extension;
4
+ declare const _default: (articlePath?: string) => (cm: CodeMirror6) => Extension;
5
5
  export default _default;
package/dist/escape.js CHANGED
@@ -5,6 +5,7 @@ import { getLSP } from '@bhsd/browser';
5
5
  import elt from 'crelt';
6
6
  import { base } from './constants.js';
7
7
  import { replaceSelections, menuRegistry, } from './codemirror.js';
8
+ import { sliceDoc, toConfigGetter, } from './util.js';
8
9
  const entity = { '"': 'quot', "'": 'apos', '<': 'lt', '>': 'gt', '&': 'amp', ' ': 'nbsp' };
9
10
  /**
10
11
  * 根据函数转换选中文本
@@ -40,7 +41,7 @@ const escapeWiki = (view, getConfig) => {
40
41
  const replacements = new WeakMap();
41
42
  for (const range of ranges) {
42
43
  // eslint-disable-next-line no-await-in-loop
43
- const [action] = await lsp.provideRefactoringAction(state.sliceDoc(range.from, range.to));
44
+ const [action] = await lsp.provideRefactoringAction(sliceDoc(state, range));
44
45
  replacements.set(range, action?.edit.changes[''][0].newText);
45
46
  }
46
47
  view.dispatch(state.changeByRange(range => {
@@ -93,13 +94,13 @@ menuRegistry.push({
93
94
  return items;
94
95
  },
95
96
  });
96
- export default (cm) => keymap.of([
97
+ export default (articlePath) => (cm) => keymap.of([
97
98
  { key: 'Mod-[', run: convert(escapeHTML, indentLess) },
98
99
  { key: 'Mod-]', run: convert(escapeURI, indentMore) },
99
100
  {
100
101
  key: 'Mod-\\',
101
102
  run(view) {
102
- return escapeWiki(view, cm.getWikiConfig);
103
+ return escapeWiki(view, toConfigGetter(cm.getWikiConfig, articlePath));
103
104
  },
104
105
  },
105
106
  ]);
package/dist/fold.d.ts CHANGED
@@ -14,12 +14,12 @@ export interface DocRange {
14
14
  * @param refOnly 是否仅检查`<ref>`标签
15
15
  */
16
16
  export declare const foldable: (state: EditorState, posOrNode: number | SyntaxNode, tree?: Tree | null, refOnly?: boolean) => DocRange | false;
17
- export declare const foldableLine: ({ state, viewport: { to: end }, viewportLineBlocks }: EditorView, { from: f, to: t }: DocRange) => DocRange | false;
17
+ export declare const foldableLine: ({ state, viewportLineBlocks }: EditorView, { from: f, to: t }: DocRange) => DocRange | false;
18
18
  export declare const foldRef: Command;
19
19
  export declare const unfoldRef: Command;
20
20
  declare const _default: (e?: Extension | undefined) => Extension;
21
21
  export default _default;
22
- export declare const mediaWikiFold: Extension;
22
+ export declare const mediawikiFold: Extension;
23
23
  /**
24
24
  * 点击提示折叠模板参数
25
25
  * @param view