@bhsd/codemirror-mediawiki 3.6.7 → 3.7.1

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.
@@ -2,6 +2,7 @@ import { EditorView } from '@codemirror/view';
2
2
  import type { KeyBinding } from '@codemirror/view';
3
3
  import type { Extension } from '@codemirror/state';
4
4
  import type { SyntaxNode } from '@lezer/common';
5
+ import type { ConfigGetter } from '@bhsd/browser';
5
6
  import type { ConfigData } from 'wikiparser-node';
6
7
  import type { DocRange, foldHandler } from './fold';
7
8
  import type { detectIndent } from './indent';
@@ -9,6 +10,7 @@ import type { Option, LiveOption } from './linter';
9
10
  import type { LintSource, LintSources, LintSourceGetter } from './lintsource';
10
11
  import type statusBar from './statusBar';
11
12
  import type { MwConfig } from './token';
13
+ import type { Selection } from './matchBrackets';
12
14
  export type AddonMain<T> = (config?: T, cm?: CodeMirror6) => Extension;
13
15
  export type Addon<T> = [AddonMain<T>, Record<string, T>?];
14
16
  export type Dialect = 'sanitized-css' | undefined;
@@ -35,7 +37,7 @@ export declare class CodeMirror6 {
35
37
  #private;
36
38
  /** only for sanitized-css */
37
39
  dialect: Dialect;
38
- getWikiConfig?: () => Promise<ConfigData>;
40
+ getWikiConfig?: ConfigGetter;
39
41
  langConfig: MwConfig | undefined;
40
42
  /** textarea element */
41
43
  get textarea(): HTMLTextAreaElement;
@@ -128,10 +130,7 @@ export declare class CodeMirror6 {
128
130
  * Scroll to the specified position
129
131
  * @param position position or selection range
130
132
  */
131
- scrollTo(position?: number | {
132
- anchor: number;
133
- head: number;
134
- }): void;
133
+ scrollTo(position?: number | Selection): void;
135
134
  /**
136
135
  * Set the editor theme
137
136
  * @param theme theme name
@@ -97,7 +97,7 @@ export class CodeMirror6 {
97
97
  let timer;
98
98
  const { textarea, lang } = this, { value, dir: d, accessKey, tabIndex, lang: l, readOnly } = textarea, extensions = [
99
99
  this.#language.of(this.#getLanguage(config)),
100
- this.#linter.of(linters[lang] ?? []),
100
+ this.#linter.of(linters[lang]?.(this) ?? []),
101
101
  this.#extensions.of([]),
102
102
  this.#dir.of(EditorView.editorAttributes.of({ dir: d })),
103
103
  this.#extraKeys.of([]),
@@ -219,9 +219,9 @@ export class CodeMirror6 {
219
219
  const ext = this.#getLanguage(config);
220
220
  this.#effects([
221
221
  this.#language.reconfigure(ext),
222
- this.#linter.reconfigure(linters[lang] ?? []),
222
+ this.#linter.reconfigure(linters[lang]?.(this) ?? []),
223
223
  ]);
224
- this.#minHeight(Boolean(linters[lang]));
224
+ this.#minHeight(lang in linters);
225
225
  this.prefer({});
226
226
  }
227
227
  }
@@ -231,7 +231,7 @@ export class CodeMirror6 {
231
231
  */
232
232
  lint(lintSource) {
233
233
  const lintSources = typeof lintSource === 'function' ? [lintSource] : lintSource;
234
- const linterExtension = lintSources
234
+ const linterExtension = (cm) => lintSources
235
235
  ? [
236
236
  ...lintSources.map(source => linter(async ({ state }) => {
237
237
  const diagnostics = (await source(state)).map((diagnostic) => ({
@@ -256,7 +256,7 @@ export class CodeMirror6 {
256
256
  })),
257
257
  lintGutter(),
258
258
  keymap.of(lintKeymap),
259
- optionalFunctions.statusBar(this, lintSources[0].fixer),
259
+ optionalFunctions.statusBar(cm, lintSources[0].fixer),
260
260
  ]
261
261
  : [];
262
262
  if (lintSource) {
@@ -266,7 +266,7 @@ export class CodeMirror6 {
266
266
  delete linters[this.#lang];
267
267
  }
268
268
  if (this.#view) {
269
- this.#effects(this.#linter.reconfigure(linterExtension));
269
+ this.#effects(this.#linter.reconfigure(linterExtension(this)));
270
270
  this.#minHeight(Boolean(lintSource));
271
271
  }
272
272
  }
package/dist/fold.js CHANGED
@@ -338,7 +338,14 @@ export const foldRef = /* @__PURE__ */ foldCommand(true), unfoldRef = (view) =>
338
338
  }
339
339
  return false;
340
340
  };
341
- export default ((e = defaultFoldExtension) => e);
341
+ export default ((e = defaultFoldExtension) => [
342
+ e,
343
+ EditorView.theme({
344
+ '.cm-foldGutter': {
345
+ order: 2,
346
+ },
347
+ }),
348
+ ]);
342
349
  export const mediaWikiFold = /* @__PURE__ */ (() => [
343
350
  codeFolding({
344
351
  placeholderDOM(view) {
@@ -1,13 +1,16 @@
1
1
  import type { EditorView } from '@codemirror/view';
2
2
  import type { EditorState, Text } from '@codemirror/state';
3
3
  import type { Language } from '@codemirror/language';
4
- import type { Diagnostic } from '@codemirror/lint';
4
+ import type { Diagnostic, Action } from '@codemirror/lint';
5
5
  import type { Option, LiveOption } from './linter';
6
6
  export type LintSource = ((state: EditorState) => Diagnostic[] | Promise<Diagnostic[]>) & {
7
7
  fixer?: (doc: Text, rule?: string) => string | Promise<string>;
8
8
  };
9
9
  export type LintSources = LintSource | [LintSource] | [LintSource, LintSource];
10
10
  export type LintSourceGetter = (opt?: Option | LiveOption, view?: EditorView, nestedMWLanguage?: Language) => LintSource | Promise<LintSource>;
11
+ export interface ExtendedAction extends Action {
12
+ tooltip: string | undefined;
13
+ }
11
14
  /**
12
15
  * 获取Linter选项
13
16
  * @param opt Linter选项
@@ -74,9 +74,14 @@ const jsLintSource = (esLint, code, opt, doc, f = 0, t) => esLint(code, opt)
74
74
  if (fix || suggestions.length > 0) {
75
75
  diagnostic.actions = [
76
76
  ...fix ? [{ name: 'fix', fix }] : [],
77
- ...suggestions.map(suggestion => ({ name: suggestion.messageId || 'suggestion', fix: suggestion.fix })),
78
- ].map(({ name, fix: { range: [from, to], text } }) => ({
77
+ ...suggestions.map(suggestion => ({
78
+ name: suggestion.messageId || 'suggestion',
79
+ fix: suggestion.fix,
80
+ tooltip: suggestion.desc,
81
+ })),
82
+ ].map(({ name, fix: { range: [from, to], text }, tooltip }) => ({
79
83
  name,
84
+ tooltip,
80
85
  apply(view) {
81
86
  view.dispatch({
82
87
  changes: { from: from + f, to: to + f, insert: text },