@bhsd/codemirror-mediawiki 3.8.0 → 3.9.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 (52) hide show
  1. package/README.md +45 -2
  2. package/dist/bidi.js +3 -3
  3. package/dist/codemirror.d.ts +9 -1
  4. package/dist/codemirror.js +51 -31
  5. package/dist/color.d.ts +1 -2
  6. package/dist/color.js +5 -16
  7. package/dist/config.d.ts +3 -2
  8. package/dist/config.js +4 -13
  9. package/dist/constants.d.ts +2 -1
  10. package/dist/constants.js +2 -1
  11. package/dist/escape.d.ts +1 -1
  12. package/dist/escape.js +11 -10
  13. package/dist/fold.d.ts +2 -1
  14. package/dist/fold.js +9 -8
  15. package/dist/hover.d.ts +1 -1
  16. package/dist/hover.js +9 -8
  17. package/dist/html.js +6 -5
  18. package/dist/indent.js +1 -1
  19. package/dist/index.d.ts +2 -2
  20. package/dist/index.js +35 -38
  21. package/dist/inlay.d.ts +1 -1
  22. package/dist/inlay.js +11 -15
  23. package/dist/keymap.d.ts +2 -1
  24. package/dist/keymap.js +2 -3
  25. package/dist/linter.d.ts +3 -11
  26. package/dist/linter.js +19 -32
  27. package/dist/lintsource.d.ts +2 -2
  28. package/dist/lintsource.js +18 -33
  29. package/dist/lua.js +2 -1
  30. package/dist/main.min.js +27 -24
  31. package/dist/matchTag.js +2 -2
  32. package/dist/mediawiki.d.ts +2 -2
  33. package/dist/mediawiki.js +20 -17
  34. package/dist/mw.min.js +30 -27
  35. package/dist/mwConfig.js +4 -6
  36. package/dist/openLinks.js +9 -8
  37. package/dist/ref.d.ts +1 -1
  38. package/dist/ref.js +8 -6
  39. package/dist/signature.d.ts +1 -1
  40. package/dist/signature.js +3 -3
  41. package/dist/statusBar.js +8 -3
  42. package/dist/theme.js +1 -1
  43. package/dist/token.d.ts +2 -3
  44. package/dist/token.js +5 -3
  45. package/dist/util.d.ts +5 -0
  46. package/dist/util.js +7 -2
  47. package/dist/vue.js +2 -2
  48. package/dist/wiki.min.js +29 -26
  49. package/i18n/en.json +1 -1
  50. package/i18n/zh-hans.json +1 -1
  51. package/i18n/zh-hant.json +1 -1
  52. package/package.json +12 -10
package/README.md CHANGED
@@ -11,6 +11,8 @@ Here is a [demo](https://bhsd-harry.github.io/codemirror-mediawiki). To experime
11
11
 
12
12
  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://www.npmjs.com/package/wikiplus-highlight) and an [InPageEdit plugin](https://github.com/inpageedit/Plugins/blob/master/src/plugins/code-mirror/cm6.js) are built upon it. Please refer to a separate [README](./mw/README.md) file for the information.
13
13
 
14
+ If you are just looking for a CodeMirror 6 language mode and language support extensions for MediaWiki Wikitext, you can use [@bhsd/codemirror-wikitext](https://www.npmjs.com/package/@bhsd/codemirror-wikitext) instead.
15
+
14
16
  <details>
15
17
  <summary>Expand</summary>
16
18
 
@@ -45,6 +47,7 @@ Nonetheless, this repository also provides a customized version with additional
45
47
  - [lint](#lint)
46
48
  - [localize](#localize)
47
49
  - [prefer](#prefer)
50
+ - [replaceSelections](#replaceselections)
48
51
  - [scrollTo](#scrollto)
49
52
  - [setContent](#setcontent)
50
53
  - [setIndent](#setindent)
@@ -57,7 +60,7 @@ Nonetheless, this repository also provides a customized version with additional
57
60
  - [CDN](#cdn)
58
61
  - [Static methods](#static-methods)
59
62
  - [getMwConfig](#getmwconfig)
60
- - [replaceSelections](#replaceselections)
63
+ - [replaceSelections](#replaceselections-static)
61
64
  - [Extensions](#extensions)
62
65
  - [allowMultipleSelections](#allowmultipleselections)
63
66
  - [autocompletion](#autocompletion)
@@ -309,6 +312,23 @@ import {registerMediaWiki} from '@bhsd/codemirror-mediawiki';
309
312
  registerMediaWiki();
310
313
  ```
311
314
 
315
+ The MediaWiki mode provides the following key bindings for quick formatting:
316
+
317
+ - `Ctrl` + `0`: Plain paragraph
318
+ - `Ctrl` + `1-6`: Headings level 1 to 6
319
+ - `Ctrl` + `7`: Preformatted text
320
+ - `Ctrl` + `8`: Blockquote
321
+ - `Ctrl`/`Cmd` + `/`: Comment
322
+ - `Ctrl`/`Cmd` + `.`: Superscript
323
+ - `Ctrl`/`Cmd` + `,`: Subscript
324
+ - `Ctrl`/`Cmd` + `B`: Bold
325
+ - `Ctrl`/`Cmd` + `I`: Italic
326
+ - `Ctrl`/`Cmd` + `U`: Underline
327
+ - `Ctrl`/`Cmd` + `K`: Wiki link
328
+ - `Ctrl` + `Shift` + `5`: Strikethrough
329
+ - `Ctrl`/`Cmd` + `Shift` + `6`: Inline code
330
+ - `Ctrl`/`Cmd` + `Shift` + `K`: Ref tag
331
+
312
332
  If you want a more granular control over the extensions, you can import the `registerMediaWikiCore` function and the desired extensions:
313
333
 
314
334
  ```js
@@ -714,6 +734,22 @@ cm.prefer({
714
734
 
715
735
  </details>
716
736
 
737
+ ## replaceSelections
738
+
739
+ <details>
740
+ <summary>Expand</summary>
741
+
742
+ *version added: 3.9.0*
743
+
744
+ **param**: `(str: string, range: {from: number, to: number}) => string | [string, number, number?]` the replacement function
745
+ Replace the selected text with the return value of the replacement function.
746
+
747
+ ```js
748
+ cm.replaceSelections(str => str.toUpperCase());
749
+ ```
750
+
751
+ </details>
752
+
717
753
  ## scrollTo
718
754
 
719
755
  <details>
@@ -884,7 +920,7 @@ const mwConfig = CodeMirror6.getMwConfig(config);
884
920
 
885
921
  </details>
886
922
 
887
- ## replaceSelections
923
+ ## replaceSelections (static)
888
924
 
889
925
  <details>
890
926
  <summary>Expand</summary>
@@ -930,6 +966,11 @@ registerAllowMultipleSelections();
930
966
 
931
967
  Provide autocompletion for MediaWiki, CSS and JavaScript modes.
932
968
 
969
+ Key bindings:
970
+
971
+ - `Shift` + `Enter`: Trigger autocompletion
972
+ - `Tab`: Accept the selected suggestion
973
+
933
974
  For granular control over the bundled extensions, you can import the `registerAutocompletion` function:
934
975
 
935
976
  ```js
@@ -990,6 +1031,7 @@ Key bindings:
990
1031
  - `Ctrl` + `Shift` + `]`/`Cmd` + `Alt` + `]`: Unfold at the selected text
991
1032
  - `Ctrl` + `Alt` + `[`: Fold all
992
1033
  - `Ctrl` + `Alt` + `]`: Unfold all
1034
+ - `Ctrl` + `Alt` + `.`: Fold all `<ref>` tags
993
1035
 
994
1036
  For granular control over the bundled extensions, you can import the `registerCodeFolding` function:
995
1037
 
@@ -1029,6 +1071,7 @@ Key bindings:
1029
1071
 
1030
1072
  - `Ctrl`/`Cmd` + `[`: Escape the selected text with HTML entities
1031
1073
  - `Ctrl`/`Cmd` + `]`: Escape the selected text with URL encoding
1074
+ - `Ctrl`/`Cmd` + `\`: Escape the selected text with [magic words](https://www.mediawiki.org/wiki/Help:Magic_words#Escaped_characters)
1032
1075
 
1033
1076
  For granular control over the bundled extensions, you can import the `registerEscape` function:
1034
1077
 
package/dist/bidi.js CHANGED
@@ -6,9 +6,9 @@
6
6
  import { EditorView, Direction, ViewPlugin, Decoration } from '@codemirror/view';
7
7
  import { Prec, RangeSetBuilder } from '@codemirror/state';
8
8
  import { syntaxTree } from '@codemirror/language';
9
- import { tokens } from './config';
10
- import { isolateSelector, ltrSelector } from './constants';
11
- import { getTag } from './matchTag';
9
+ import { tokens } from './config.js';
10
+ import { isolateSelector, ltrSelector } from './constants.js';
11
+ import { getTag } from './matchTag.js';
12
12
  const cls = isolateSelector.slice(1), isolateLTR = Decoration.mark({
13
13
  class: `${cls} ${ltrSelector.slice(1)}`,
14
14
  bidiIsolate: Direction.LTR,
@@ -14,6 +14,7 @@ import type { Selection } from './matchBrackets';
14
14
  export type AddonMain<T> = (config?: T, cm?: CodeMirror6) => Extension;
15
15
  export type Addon<T> = [AddonMain<T>, Record<string, T>?];
16
16
  export type Dialect = 'sanitized-css' | undefined;
17
+ export type ReplaceFunction = (str: string, range: DocRange) => string | [string, number, number?];
17
18
  declare interface MenuItem {
18
19
  name: string;
19
20
  isActionable(this: void, cm: CodeMirror6): boolean;
@@ -32,6 +33,7 @@ export declare const menuRegistry: MenuItem[];
32
33
  export declare const destroyListeners: ((view: EditorView) => void)[];
33
34
  export declare const themes: Record<string, Extension>;
34
35
  export declare const optionalFunctions: OptionalFunctions;
36
+ export declare const replaceSelections: (view: EditorView, func: ReplaceFunction) => void;
35
37
  /** CodeMirror 6 editor */
36
38
  export declare class CodeMirror6 {
37
39
  #private;
@@ -139,12 +141,18 @@ export declare class CodeMirror6 {
139
141
  * @since 3.3.0
140
142
  */
141
143
  setTheme(theme: string): void;
144
+ /**
145
+ * Replace the current selection with the result of a function
146
+ * @param func function to produce the replacement text
147
+ * @since 3.9.0
148
+ */
149
+ replaceSelections(func: ReplaceFunction): void;
142
150
  /**
143
151
  * Replace the current selection with the result of a function
144
152
  * @param view EditorView instance
145
153
  * @param func function to produce the replacement text
146
154
  */
147
- static replaceSelections(view: EditorView, func: (str: string, range: DocRange) => string | [string, number, number?]): void;
155
+ static replaceSelections: (view: EditorView, func: ReplaceFunction) => void;
148
156
  /**
149
157
  * Convert a [WikiParser-Node](https://npmjs.com/package/wikiparser-node) configuration
150
158
  * to a CodeMirror-MediaWiki configuration
@@ -1,13 +1,19 @@
1
- import { EditorView, lineNumbers, keymap, highlightActiveLineGutter, } from '@codemirror/view';
2
- import { Compartment, EditorState, EditorSelection, SelectionRange } from '@codemirror/state';
1
+ import { EditorView, lineNumbers, keymap, highlightActiveLineGutter } from '@codemirror/view';
2
+ import { EditorSelection, Compartment, EditorState, SelectionRange, } from '@codemirror/state';
3
3
  import { syntaxHighlighting, defaultHighlightStyle, indentOnInput, indentUnit, ensureSyntaxTree, } from '@codemirror/language';
4
- import { defaultKeymap, historyKeymap, history, redo, indentWithTab } from '@codemirror/commands';
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';
7
7
  import elt from 'crelt';
8
- import { panelSelector, panelsSelector, diagnosticSelector } from './constants';
9
- import { light } from './theme';
10
- export const plain = () => EditorView.contentAttributes.of({ spellcheck: 'true' });
8
+ import { base, panelSelector, panelsSelector, diagnosticSelector, noDetectionLangs } from './constants.js';
9
+ import { light } from './theme.js';
10
+ export const plain = () => [
11
+ EditorView.contentAttributes.of({ spellcheck: 'true' }),
12
+ keymap.of([
13
+ { key: 'Enter', run: insertNewlineKeepIndent, shift: insertNewlineKeepIndent },
14
+ { key: 'Backspace', run: deleteCharBackwardStrict, preventDefault: true },
15
+ ]),
16
+ ];
11
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
18
  export const languages = { plain };
13
19
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -30,14 +36,30 @@ export const optionalFunctions = {
30
36
  const editExtensions = new Set(['closeBrackets', 'autocompletion', 'signatureHelp']);
31
37
  const linters = {};
32
38
  const phrases = {};
39
+ export const replaceSelections = (view, func) => {
40
+ const { state } = view;
41
+ view.dispatch(state.changeByRange(({ from, to }) => {
42
+ const result = func(state.sliceDoc(from, to), { from, to });
43
+ if (typeof result === 'string') {
44
+ return {
45
+ range: EditorSelection.range(from, from + result.length),
46
+ changes: { from, to, insert: result },
47
+ };
48
+ }
49
+ const [insert, start, end = start] = result;
50
+ return {
51
+ range: EditorSelection.range(start, end),
52
+ changes: { from, to, insert },
53
+ };
54
+ }));
55
+ };
33
56
  /** CodeMirror 6 editor */
34
57
  export class CodeMirror6 {
35
- static #CDN;
36
58
  static get CDN() {
37
- return CodeMirror6.#CDN;
59
+ return base.CDN;
38
60
  }
39
61
  static set CDN(url) {
40
- CodeMirror6.#CDN = url;
62
+ base.CDN = url;
41
63
  }
42
64
  #textarea;
43
65
  #language = new Compartment();
@@ -89,9 +111,13 @@ export class CodeMirror6 {
89
111
  * @param config 语言设置
90
112
  */
91
113
  #getLanguage(config) {
114
+ const isMW = this.#lang === 'mediawiki';
115
+ if (isMW || this.#lang === 'html') {
116
+ config ??= this.langConfig;
117
+ }
92
118
  const lang = (languages[this.#lang] ?? plain)(config);
93
119
  this.#nestedMWLanguage = lang.nestedMWLanguage;
94
- if (this.#lang === 'mediawiki') {
120
+ if (isMW) {
95
121
  this.langConfig = config;
96
122
  }
97
123
  return lang;
@@ -111,7 +137,7 @@ export class CodeMirror6 {
111
137
  this.#phrases.of(EditorState.phrases.of(phrases)),
112
138
  this.#lineWrapping.of(EditorView.lineWrapping),
113
139
  this.#theme.of(light),
114
- syntaxHighlighting(defaultHighlightStyle),
140
+ syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
115
141
  EditorView.contentAttributes.of({
116
142
  accesskey: accessKey,
117
143
  tabindex: String(tabIndex),
@@ -160,7 +186,7 @@ export class CodeMirror6 {
160
186
  textarea.value = doc.toString();
161
187
  textarea.dispatchEvent(new InputEvent('input'));
162
188
  }, 400);
163
- if (!startDoc.toString().trim()) {
189
+ if (!noDetectionLangs.has(this.#lang) && !startDoc.toString().trim()) {
164
190
  this.setIndent(this.#indentStr);
165
191
  }
166
192
  }
@@ -251,7 +277,7 @@ export class CodeMirror6 {
251
277
  const diagnostics = (await source(state)).map((diagnostic) => ({
252
278
  ...diagnostic,
253
279
  renderMessage(view) {
254
- const span = elt('span', { class: diagnosticSelector.slice(1) }, diagnostic.message);
280
+ const span = elt('span', { class: diagnosticSelector.slice(1) }, diagnostic.renderMessage?.(view) ?? diagnostic.message);
255
281
  span.addEventListener('click', () => {
256
282
  view.dispatch({
257
283
  selection: { anchor: diagnostic.from, head: diagnostic.to },
@@ -355,7 +381,7 @@ export class CodeMirror6 {
355
381
  * @param opt linter options
356
382
  */
357
383
  async getLinter(opt) {
358
- return linterRegistry[this.#lang]?.(CodeMirror6.CDN, opt, this.#view, this.#nestedMWLanguage);
384
+ return linterRegistry[this.#lang]?.(opt, this.#view, this.#nestedMWLanguage);
359
385
  }
360
386
  /**
361
387
  * Set content
@@ -473,24 +499,18 @@ export class CodeMirror6 {
473
499
  }
474
500
  /**
475
501
  * Replace the current selection with the result of a function
476
- * @param view EditorView instance
477
502
  * @param func function to produce the replacement text
503
+ * @since 3.9.0
478
504
  */
479
- static replaceSelections(view, func) {
480
- const { state } = view;
481
- view.dispatch(state.changeByRange(({ from, to }) => {
482
- const result = func(state.sliceDoc(from, to), { from, to });
483
- if (typeof result === 'string') {
484
- return {
485
- range: EditorSelection.range(from, from + result.length),
486
- changes: { from, to, insert: result },
487
- };
488
- }
489
- const [insert, start, end = start] = result;
490
- return {
491
- range: EditorSelection.range(start, end),
492
- changes: { from, to, insert },
493
- };
494
- }));
505
+ replaceSelections(func) {
506
+ if (this.#view) {
507
+ replaceSelections(this.#view, func);
508
+ }
495
509
  }
510
+ /**
511
+ * Replace the current selection with the result of a function
512
+ * @param view EditorView instance
513
+ * @param func function to produce the replacement text
514
+ */
515
+ static replaceSelections = replaceSelections;
496
516
  }
package/dist/color.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import type { Text, Extension } from '@codemirror/state';
2
2
  import type { Tree } from '@lezer/common';
3
- import type { StyleSpec } from 'style-mod';
4
3
  import type { WidgetOptions } from '@bhsd/codemirror-css-color-picker';
5
4
  export declare const discoverColors: (_: Tree, from: number, to: number, type: string, doc: Text) => WidgetOptions[] | null;
6
- declare const _default: ([e, style]?: [Extension?, StyleSpec?]) => Extension;
5
+ declare const _default: () => Extension;
7
6
  export default _default;
package/dist/color.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { splitColors, numToHex } from '@bhsd/common';
2
- import { EditorView } from '@codemirror/view';
3
- import { parseCallExpression, parseColorLiteral, ColorType, wrapperClassName } from '@bhsd/codemirror-css-color-picker';
2
+ import { parseCallExpression, parseColorLiteral, ColorType, colorPickerTheme, makeColorPicker, } from '@bhsd/codemirror-css-color-picker';
4
3
  export const discoverColors = (_, from, to, type, doc) => {
5
4
  if (!/mw-(?:(?:ext|html)tag-attribute-value|table-definition)/u.test(type)
6
5
  && (!/mw-(?:template|parserfunction)(?:$|_)/u.test(type)
@@ -27,17 +26,7 @@ export const discoverColors = (_, from, to, type, doc) => {
27
26
  };
28
27
  }).filter(options => options !== null);
29
28
  };
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
- : []);
29
+ export default () => [
30
+ makeColorPicker({ discoverColors }),
31
+ colorPickerTheme,
32
+ ];
package/dist/config.d.ts CHANGED
@@ -90,11 +90,12 @@ tokens: {
90
90
  templateVariableBracket: string;
91
91
  templateVariableDelimiter: string;
92
92
  templateVariableName: string;
93
- },
93
+ };
94
+ export type TagName = keyof typeof tokens;
94
95
  /**
95
96
  * These are custom tokens (a.k.a. tags) that aren't mapped to any of the standardized tags.
96
97
  *
97
98
  * @see https://codemirror.net/docs/ref/#language.StreamParser.tokenTable
98
99
  * @see https://lezer.codemirror.net/docs/ref/#highlight.Tag%5Edefine
99
100
  */
100
- tokenTable: Record<string, Tag>;
101
+ export declare const tokenTable: Record<string, Tag>;
package/dist/config.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // src/config.ts
2
- import { tags, Tag } from "@lezer/highlight";
2
+ import {
3
+ Tag
4
+ } from "@lezer/highlight";
3
5
 
4
6
  // ../wikiparser-node/config/default.json
5
7
  var html = [
@@ -151,18 +153,7 @@ var tokens = {
151
153
  };
152
154
  var tokenTable = /* @__PURE__ */ (() => {
153
155
  const table = {
154
- variable: tags.variableName,
155
- "variable-2": tags.special(tags.variableName),
156
- "string-2": tags.special(tags.string),
157
- def: tags.definition(tags.variableName),
158
- tag: tags.tagName,
159
- attribute: tags.attributeName,
160
- type: tags.typeName,
161
- builtin: tags.standard(tags.variableName),
162
- qualifier: tags.modifier,
163
- error: tags.invalid,
164
- header: tags.heading,
165
- property: tags.propertyName
156
+ //
166
157
  };
167
158
  for (const className of Object.values(tokens)) {
168
159
  table[className] = Tag.define();
@@ -1 +1,2 @@
1
- export declare const panelSelector = ".cm-panel", panelsSelector = ".cm-panels", diagnosticSelector = ".cm-diagnosticText-clickable", foldSelector = ".cm-tooltip-fold", hoverSelector = ".cm-tooltip-hover", matchingCls = "cm-matchingTag", nonmatchingCls = "cm-nonmatchingTag", isolateSelector = ".cm-bidi-isolate", ltrSelector = ".cm-bidi-ltr", menuSelector = ".cm-status-fix-menu", messageSelector = ".cm-status-message", actionSelector = ".cm-diagnosticAction", 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", 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;
package/dist/constants.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { wmf } from '@bhsd/common';
2
- export const panelSelector = '.cm-panel', panelsSelector = '.cm-panels', diagnosticSelector = '.cm-diagnosticText-clickable', foldSelector = '.cm-tooltip-fold', hoverSelector = '.cm-tooltip-hover', matchingCls = 'cm-matchingTag', nonmatchingCls = 'cm-nonmatchingTag', isolateSelector = '.cm-bidi-isolate', ltrSelector = '.cm-bidi-ltr', menuSelector = '.cm-status-fix-menu', messageSelector = '.cm-status-message', actionSelector = '.cm-diagnosticAction', isWMF = /* @__PURE__ */ (() => typeof location === 'object'
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';
3
+ export const isWMF = /* @__PURE__ */ (() => typeof location === 'object'
3
4
  && new RegExp(String.raw `\.(?:${wmf})\.org$`, 'u').test(location.hostname))(), isMac = /* @__PURE__ */ (() => {
4
5
  const { vendor, userAgent, maxTouchPoints, platform } = navigator;
5
6
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
package/dist/escape.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { CodeMirror6 } from './codemirror';
2
1
  import type { Extension } from '@codemirror/state';
2
+ import type { CodeMirror6 } from './codemirror';
3
3
  export declare const escapeHTML: (str: string) => string, escapeURI: (str: string) => string;
4
4
  declare const _default: (cm: CodeMirror6) => Extension;
5
5
  export default _default;
package/dist/escape.js CHANGED
@@ -3,7 +3,8 @@ import { EditorSelection } from '@codemirror/state';
3
3
  import { indentMore, indentLess } from '@codemirror/commands';
4
4
  import { getLSP } from '@bhsd/browser';
5
5
  import elt from 'crelt';
6
- import { CodeMirror6, menuRegistry } from './codemirror';
6
+ import { base } from './constants.js';
7
+ import { replaceSelections, menuRegistry, } from './codemirror.js';
7
8
  const entity = { '"': 'quot', "'": 'apos', '<': 'lt', '>': 'gt', '&': 'amp', ' ': 'nbsp' };
8
9
  /**
9
10
  * 根据函数转换选中文本
@@ -12,7 +13,7 @@ const entity = { '"': 'quot', "'": 'apos', '<': 'lt', '>': 'gt', '&': 'amp', ' '
12
13
  */
13
14
  const convert = (func, cmd) => (view) => {
14
15
  if (view.state.selection.ranges.some(({ empty }) => !empty)) {
15
- CodeMirror6.replaceSelections(view, func);
16
+ replaceSelections(view, func);
16
17
  return true;
17
18
  }
18
19
  return cmd(view);
@@ -32,8 +33,8 @@ export const escapeHTML = (str) => [...str].map(c => {
32
33
  }
33
34
  return encodeURIComponent(str);
34
35
  };
35
- const escapeWiki = (cm) => {
36
- const view = cm.view, { state } = view, { ranges } = state.selection, lsp = getLSP(view, false, cm.getWikiConfig, CodeMirror6.CDN);
36
+ const escapeWiki = (view, getConfig) => {
37
+ const { state } = view, { ranges } = state.selection, lsp = getLSP(view, false, getConfig, base.CDN);
37
38
  if (lsp && 'provideRefactoringAction' in lsp && ranges.some(({ empty }) => !empty)) {
38
39
  (async () => {
39
40
  const replacements = new WeakMap();
@@ -71,19 +72,19 @@ menuRegistry.push({
71
72
  if (!items) {
72
73
  const view = cm.view, btnHTML = elt('div', 'HTML escape'), btnURI = elt('div', 'URI encode/decode');
73
74
  btnHTML.addEventListener('click', e => {
74
- CodeMirror6.replaceSelections(view, escapeHTML);
75
+ replaceSelections(view, escapeHTML);
75
76
  handlerBase(view, e);
76
77
  });
77
78
  btnURI.addEventListener('click', e => {
78
- CodeMirror6.replaceSelections(view, escapeURI);
79
+ replaceSelections(view, escapeURI);
79
80
  handlerBase(view, e);
80
81
  });
81
82
  items = [btnHTML, btnURI];
82
- const lsp = getLSP(view, false, cm.getWikiConfig, CodeMirror6.CDN);
83
+ const lsp = getLSP(view, false, cm.getWikiConfig, base.CDN);
83
84
  if (lsp && 'provideRefactoringAction' in lsp) {
84
85
  const btnWiki = elt('div', 'Escape with magic words');
85
86
  btnWiki.addEventListener('click', e => {
86
- escapeWiki(cm);
87
+ escapeWiki(view, cm.getWikiConfig);
87
88
  handlerBase(view, e);
88
89
  });
89
90
  items.unshift(btnWiki);
@@ -97,8 +98,8 @@ export default (cm) => keymap.of([
97
98
  { key: 'Mod-]', run: convert(escapeURI, indentMore) },
98
99
  {
99
100
  key: 'Mod-\\',
100
- run() {
101
- return escapeWiki(cm);
101
+ run(view) {
102
+ return escapeWiki(view, cm.getWikiConfig);
102
103
  },
103
104
  },
104
105
  ]);
package/dist/fold.d.ts CHANGED
@@ -15,7 +15,8 @@ export interface DocRange {
15
15
  */
16
16
  export declare const foldable: (state: EditorState, posOrNode: number | SyntaxNode, tree?: Tree | null, refOnly?: boolean) => DocRange | false;
17
17
  export declare const foldableLine: ({ state, viewport: { to: end }, viewportLineBlocks }: EditorView, { from: f, to: t }: DocRange) => DocRange | false;
18
- export declare const foldRef: Command, unfoldRef: Command;
18
+ export declare const foldRef: Command;
19
+ export declare const unfoldRef: Command;
19
20
  declare const _default: (e?: Extension | undefined) => Extension;
20
21
  export default _default;
21
22
  export declare const mediaWikiFold: Extension;
package/dist/fold.js CHANGED
@@ -1,12 +1,12 @@
1
- import { showTooltip, keymap, GutterMarker, gutter, ViewPlugin, EditorView } from '@codemirror/view';
2
- import { StateField, RangeSetBuilder, RangeSet } from '@codemirror/state';
3
- import { syntaxTree, ensureSyntaxTree, foldEffect, unfoldEffect, foldedRanges, unfoldAll, codeFolding, foldGutter, foldKeymap, foldState, language, } from '@codemirror/language';
1
+ import { keymap, GutterMarker, gutter, ViewPlugin, EditorView, showTooltip, } from '@codemirror/view';
2
+ import { RangeSetBuilder, RangeSet, StateField, } from '@codemirror/state';
3
+ import { syntaxTree, ensureSyntaxTree, foldEffect, unfoldEffect, foldedRanges, unfoldAll, codeFolding, foldState, language, foldGutter, foldKeymap, } from '@codemirror/language';
4
4
  import { getRegex } from '@bhsd/common';
5
5
  import elt from 'crelt';
6
- import { tokens } from './config';
7
- import { foldSelector } from './constants';
8
- import { matchTag, getTag } from './matchTag';
9
- import { braceStackUpdate } from './util';
6
+ import { tokens } from './config.js';
7
+ import { foldSelector } from './constants.js';
8
+ import { matchTag, getTag } from './matchTag.js';
9
+ import { braceStackUpdate } from './util.js';
10
10
  const getExtRegex = /* @__PURE__ */ getRegex(tag => new RegExp(`mw-tag-${tag}(?![a-z])`, 'u'));
11
11
  const updateSelection = (pos, { to }) => Math.max(pos, to), updateAll = (pos, { from, to }) => from <= pos && to > pos ? to : pos;
12
12
  /**
@@ -324,7 +324,8 @@ const foldCommand = (refOnly) => view => {
324
324
  const { state } = view, tree = ensureSyntaxTree(state, state.doc.length, 1e3) ?? syntaxTree(state), effects = [], anchor = traverse(state, tree, effects, tree.topNode.firstChild, Infinity, getAnchor(state), updateAll, refOnly);
325
325
  return execute(view, effects, anchor);
326
326
  };
327
- export const foldRef = /* @__PURE__ */ foldCommand(true), unfoldRef = (view) => {
327
+ export const foldRef = /* @__PURE__ */ foldCommand(true);
328
+ export const unfoldRef = (view) => {
328
329
  const { state } = view, tree = syntaxTree(state), effects = [];
329
330
  foldedRanges(state).between(0, state.doc.length, (i, j) => {
330
331
  const node = tree.resolve(i, -1);
package/dist/hover.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CodeMirror6 } from './codemirror';
2
1
  import type { Extension } from '@codemirror/state';
2
+ import type { CodeMirror6 } from './codemirror.js';
3
3
  declare const _default: (cm: CodeMirror6) => Extension;
4
4
  export default _default;
package/dist/hover.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { hoverTooltip, EditorView } from '@codemirror/view';
2
2
  import { ensureSyntaxTree } from '@codemirror/language';
3
- import { loadScript, getLSP } from '@bhsd/browser';
4
- import { tokens } from './config';
5
- import { hoverSelector } from './constants';
6
- import { CodeMirror6 } from './codemirror';
7
- import { escHTML, indexToPos, posToIndex, createTooltipView } from './util';
3
+ import { getLSP, loadScript, } from '@bhsd/browser';
4
+ import { tokens } from './config.js';
5
+ import { base, hoverSelector } from './constants.js';
6
+ import { indexToPos, posToIndex, createTooltipView, escHTML, } from './util.js';
8
7
  export default (cm) => [
9
8
  hoverTooltip(async (view, pos, side) => {
10
- const { state } = view, { doc } = state, { paramSuggest, tags } = cm.langConfig;
11
- let hover = await getLSP(view, false, cm.getWikiConfig, CodeMirror6.CDN)
9
+ const { state } = view, { doc } = state;
10
+ const { paramSuggest, tags } = cm.langConfig;
11
+ let hover = await getLSP(view, false, cm.getWikiConfig, base.CDN)
12
12
  ?.provideHover(doc.toString(), indexToPos(doc, pos));
13
13
  if (!hover && paramSuggest && 'templatedata' in tags) {
14
14
  const node = ensureSyntaxTree(state, pos + Math.max(side, 0))?.resolve(pos, side);
@@ -29,7 +29,7 @@ export default (cm) => [
29
29
  }
30
30
  }
31
31
  if (hover) {
32
- const { CDN = '' } = CodeMirror6;
32
+ const { CDN = '' } = base;
33
33
  await loadScript(`${CDN}${CDN && '/'}npm/marked/lib/marked.umd.js`, 'marked', true);
34
34
  const { end } = hover.range;
35
35
  return {
@@ -60,6 +60,7 @@ export default (cm) => [
60
60
  lineHeight: 1.4,
61
61
  },
62
62
  [`${hoverSelector} code`]: {
63
+ color: 'inherit',
63
64
  padding: '.1em .4em',
64
65
  borderRadius: '.4em',
65
66
  },
package/dist/html.js CHANGED
@@ -2,12 +2,12 @@ import { configureNesting } from '@lezer/html';
2
2
  import { htmlLanguage, htmlCompletionSourceWith } from '@codemirror/lang-html';
3
3
  import { javascript, javascriptLanguage } from '@codemirror/lang-javascript';
4
4
  import { cssLanguage } from '@codemirror/lang-css';
5
- import { LanguageSupport } from '@codemirror/language';
6
- import { cssCompletion } from './css';
7
- import { jsCompletion } from './javascript';
8
- import { mediawiki } from './mediawiki';
5
+ import { LanguageSupport, syntaxHighlighting, defaultHighlightStyle, HighlightStyle } from '@codemirror/language';
6
+ import { cssCompletion } from './css.js';
7
+ import { jsCompletion } from './javascript.js';
8
+ import { mediawikiBase } from './mediawiki.js';
9
9
  export default (config) => {
10
- const { language, support } = mediawiki(config), lang = new LanguageSupport(htmlLanguage.configure({
10
+ const { language, support } = mediawikiBase(config), lang = new LanguageSupport(htmlLanguage.configure({
11
11
  wrap: configureNesting([
12
12
  { tag: 'script', parser: javascriptLanguage.parser },
13
13
  { tag: 'style', parser: cssLanguage.parser },
@@ -25,6 +25,7 @@ export default (config) => {
25
25
  jsCompletion,
26
26
  cssCompletion(),
27
27
  support,
28
+ syntaxHighlighting(HighlightStyle.define(defaultHighlightStyle.specs, { themeType: 'light' })),
28
29
  ]);
29
30
  Object.assign(lang, { nestedMWLanguage: language });
30
31
  return lang;
package/dist/indent.js CHANGED
@@ -1,4 +1,4 @@
1
- const noDetectionLangs = new Set(['plain', 'mediawiki']);
1
+ import { noDetectionLangs } from './constants.js';
2
2
  const getLines = (text) => text.children?.flatMap(getLines) ?? text.text;
3
3
  /**
4
4
  * 检测文本的缩进方式
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CodeMirror6 } from './codemirror';
1
+ import { CodeMirror6 } from './codemirror.js';
2
2
  import type { Extension } from '@codemirror/state';
3
3
  import type { LanguageSupport } from '@codemirror/language';
4
4
  import type { LintSourceGetter } from './lintsource';
@@ -102,4 +102,4 @@ export declare const registerLanguage: (name: string, lang: (config?: unknown) =
102
102
  */
103
103
  export declare const registerLanguageCore: (name: string, lang: (config?: unknown) => LanguageSupport, lintSource?: LintSourceGetter) => void;
104
104
  export declare const registerTheme: (name: string, theme: Extension) => void;
105
- export { nord } from './theme';
105
+ export { nord } from './theme.js';