@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/dist/index.js CHANGED
@@ -1,34 +1,34 @@
1
1
  import { keymap, highlightSpecialChars, highlightActiveLine, highlightWhitespace, highlightTrailingWhitespace, scrollPastEnd, drawSelection, rectangularSelection, crosshairCursor, } from '@codemirror/view';
2
2
  import { EditorState } from '@codemirror/state';
3
3
  import { highlightSelectionMatches } from '@codemirror/search';
4
- import { closeBrackets, autocompletion, acceptCompletion, completionKeymap, startCompletion, } from '@codemirror/autocomplete';
4
+ import { autocompletion, closeBrackets, acceptCompletion, completionKeymap, startCompletion, } from '@codemirror/autocomplete';
5
5
  import { json } from '@codemirror/lang-json';
6
6
  import { autoCloseTags } from '@codemirror/lang-html';
7
7
  import { getLSP } from '@bhsd/browser';
8
- import { colorPicker as cssColorPicker, colorPickerTheme, makeColorPicker } from '@bhsd/codemirror-css-color-picker';
9
- import bidiIsolation from './bidi';
10
- import { CodeMirror6, avail, languages, linterRegistry, destroyListeners, plain, optionalFunctions, themes, } from './codemirror';
11
- import colorPicker, { discoverColors } from './color';
12
- import escape from './escape';
13
- import codeFolding, { mediaWikiFold, foldHandler } from './fold';
14
- import magicWordHover from './hover';
15
- import { detectIndent } from './indent';
16
- import inlayHints from './inlay';
17
- import toolKeymap from './keymap';
18
- import { getWikiLintSource, getJsLintSource, getCssLintSource, getJsonLintSource, getLuaLintSource, getVueLintSource, getHTMLLintSource, } from './lintsource';
19
- import bracketMatching from './matchBrackets';
20
- import tagMatchingState from './matchTag';
21
- import { mediawiki } from './mediawiki';
22
- import openLinks from './openLinks';
23
- import refHover from './ref';
24
- import signatureHelp from './signature';
25
- import { tagModes, getStaticMwConfig } from './static';
26
- import statusBar from './statusBar';
27
- import css from './css';
28
- import html from './html';
29
- import javascript from './javascript';
30
- import lua from './lua';
31
- import vue from './vue';
8
+ import { colorPicker } from '@bhsd/codemirror-css-color-picker';
9
+ import bidiIsolation from './bidi.js';
10
+ import { CodeMirror6, avail, languages, linterRegistry, destroyListeners, plain, optionalFunctions, themes, } from './codemirror.js';
11
+ import mediawikiColorPicker from './color.js';
12
+ import escapeKeymap from './escape.js';
13
+ import codeFolding, { mediaWikiFold, foldHandler } from './fold.js';
14
+ import magicWordHover from './hover.js';
15
+ import { detectIndent } from './indent.js';
16
+ import inlayHints from './inlay.js';
17
+ import formatKeymap from './keymap.js';
18
+ import { getWikiLintSource, getJsLintSource, getCssLintSource, getJsonLintSource, getLuaLintSource, getVueLintSource, getHTMLLintSource, } from './lintsource.js';
19
+ import bracketMatchingBase from './matchBrackets.js';
20
+ import tagMatchingState from './matchTag.js';
21
+ import { mediawikiBase } from './mediawiki.js';
22
+ import openLinks from './openLinks.js';
23
+ import refHover from './ref.js';
24
+ import signatureHelp from './signature.js';
25
+ import { tagModes, getStaticMwConfig } from './static.js';
26
+ import statusBar from './statusBar.js';
27
+ import css from './css.js';
28
+ import html from './html.js';
29
+ import javascript from './javascript.js';
30
+ import lua from './lua.js';
31
+ import vue from './vue.js';
32
32
  export { CodeMirror6 };
33
33
  /**
34
34
  * 注册通用扩展
@@ -63,7 +63,7 @@ export const registerHighlightSelectionMatches = () => {
63
63
  /** Register the `bracketMatching` extension */
64
64
  export const registerBracketMatching = () => {
65
65
  registerExtension('bracketMatching', ([config, e = []] = []) => [
66
- bracketMatching(config),
66
+ bracketMatchingBase(config),
67
67
  e,
68
68
  ]);
69
69
  };
@@ -101,7 +101,7 @@ export const registerCodeFolding = () => {
101
101
  };
102
102
  /** Register the `colorPicker` extension */
103
103
  export const registerColorPicker = () => {
104
- registerExtension('colorPicker', colorPicker);
104
+ registerExtension('colorPicker', (e = []) => e);
105
105
  };
106
106
  /** 注册所有通用扩展(除`colorPicker`) */
107
107
  const registerExtensions = () => {
@@ -167,7 +167,7 @@ export const registerOpenLinks = () => {
167
167
  };
168
168
  /** Register the `escape` extension */
169
169
  export const registerEscape = () => {
170
- registerExtensionForMediaWiki('escape', escape);
170
+ registerExtensionForMediaWiki('escape', escapeKeymap);
171
171
  };
172
172
  /** Register the `refHover` extension */
173
173
  export const registerRefHover = () => {
@@ -187,10 +187,7 @@ export const registerInlayHints = () => {
187
187
  };
188
188
  /** Register the `colorPicker` extension for MediaWiki */
189
189
  export const registerColorPickerForMediaWiki = () => {
190
- registerLangExtension('mediawiki', 'colorPicker', [
191
- [makeColorPicker({ discoverColors }), colorPickerTheme],
192
- { marginLeft: '.6ch' },
193
- ]);
190
+ registerLangExtension('mediawiki', 'colorPicker', mediawikiColorPicker());
194
191
  };
195
192
  /** Register the `bracketMatching` extension for MediaWiki */
196
193
  export const registerBracketMatchingForMediaWiki = () => {
@@ -217,10 +214,10 @@ const registerLintSource = (lang, lintSource) => {
217
214
  export const registerMediaWikiCore = () => {
218
215
  CodeMirror6.getMwConfig = (config) => getStaticMwConfig(config, tagModes);
219
216
  languages['mediawiki'] = (config) => [
220
- mediawiki(config),
217
+ mediawikiBase(config),
221
218
  plain(),
222
219
  bidiIsolation,
223
- toolKeymap,
220
+ keymap.of(formatKeymap),
224
221
  ];
225
222
  registerLintSource('mediawiki', getWikiLintSource);
226
223
  destroyListeners.push(view => {
@@ -242,7 +239,7 @@ export const registerCloseBracketsForHTML = () => {
242
239
  };
243
240
  /** Register the `colorPicker` extension for mixed MediaWiki-HTML */
244
241
  export const registerColorPickerForHTML = () => {
245
- registerLangExtension('html', 'colorPicker', [cssColorPicker]);
242
+ registerLangExtension('html', 'colorPicker', colorPicker);
246
243
  };
247
244
  /** Register mixed MediaWiki-HTML core language support */
248
245
  export const registerHTMLCore = () => {
@@ -269,7 +266,7 @@ export const registerCSS = () => {
269
266
  };
270
267
  /** Register the `colorPicker` extension for CSS */
271
268
  export const registerColorPickerForCSS = () => {
272
- registerLangExtension('css', 'colorPicker', [cssColorPicker]);
269
+ registerLangExtension('css', 'colorPicker', colorPicker);
273
270
  };
274
271
  /** Register CSS core language support */
275
272
  export const registerCSSCore = () => {
@@ -312,7 +309,7 @@ export const registerCloseBracketsForVue = () => {
312
309
  };
313
310
  /** Register the `colorPicker` extension for Vue */
314
311
  export const registerColorPickerForVue = () => {
315
- registerLangExtension('vue', 'colorPicker', [cssColorPicker]);
312
+ registerLangExtension('vue', 'colorPicker', colorPicker);
316
313
  };
317
314
  /** Register Vue core language support */
318
315
  export const registerVueCore = () => {
@@ -345,4 +342,4 @@ export const registerLanguageCore = (name, lang, lintSource) => {
345
342
  export const registerTheme = (name, theme) => {
346
343
  themes[name] = theme;
347
344
  };
348
- export { nord } from './theme';
345
+ export { nord } from './theme.js';
package/dist/inlay.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';
3
3
  declare const _default: (cm: CodeMirror6) => Extension;
4
4
  export default _default;
package/dist/inlay.js CHANGED
@@ -2,8 +2,8 @@ import { StateField, StateEffect } from '@codemirror/state';
2
2
  import { Decoration, EditorView, WidgetType, ViewPlugin } from '@codemirror/view';
3
3
  import { getLSP } from '@bhsd/browser';
4
4
  import elt from 'crelt';
5
- import { posToIndex } from './util';
6
- import { CodeMirror6 } from './codemirror';
5
+ import { base } from './constants.js';
6
+ import { posToIndex, } from './util.js';
7
7
  const cls = 'cm-inlay-hint';
8
8
  class InlayHintWidget extends WidgetType {
9
9
  constructor(label) {
@@ -39,7 +39,7 @@ const stateEffect = StateEffect.define(), field = StateField.define({
39
39
  return EditorView.decorations.from(f);
40
40
  },
41
41
  });
42
- const updateField = async ({ view, docChanged }) => {
42
+ const update = async ({ view, docChanged }) => {
43
43
  if (docChanged) {
44
44
  const text = view.state.doc.toString();
45
45
  view.dispatch({
@@ -52,18 +52,14 @@ const updateField = async ({ view, docChanged }) => {
52
52
  };
53
53
  export default (cm) => [
54
54
  field,
55
- ViewPlugin.fromClass(class {
56
- constructor(view) {
57
- const timer = setInterval(() => {
58
- if (getLSP(view, false, cm.getWikiConfig, CodeMirror6.CDN)) {
59
- clearInterval(timer);
60
- void updateField({ view, docChanged: true });
61
- }
62
- }, 100);
63
- }
64
- update(update) {
65
- void updateField(update);
66
- }
55
+ ViewPlugin.define(view => {
56
+ const timer = setInterval(() => {
57
+ if (getLSP(view, false, cm.getWikiConfig, base.CDN)) {
58
+ clearInterval(timer);
59
+ void update({ view, docChanged: true });
60
+ }
61
+ }, 100);
62
+ return { update };
67
63
  }),
68
64
  EditorView.theme({
69
65
  [`.${cls}`]: {
package/dist/keymap.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- declare const _default: import("@codemirror/state").Extension;
1
+ import type { KeyBinding } from '@codemirror/view';
2
+ declare const _default: KeyBinding[];
2
3
  export default _default;
package/dist/keymap.js CHANGED
@@ -1,6 +1,5 @@
1
- import { keymap } from '@codemirror/view';
2
1
  import { EditorSelection } from '@codemirror/state';
3
- import { keybindings, encapsulateLines } from './keybindings';
2
+ import { keybindings, encapsulateLines } from './keybindings.js';
4
3
  /**
5
4
  * 生成keymap
6
5
  * @param opt 快捷键设置
@@ -33,4 +32,4 @@ const getKeymap = ({ key, pre = '', post = '', splitlines }) => ({
33
32
  },
34
33
  preventDefault: true,
35
34
  });
36
- export default keymap.of(keybindings.map(getKeymap));
35
+ export default keybindings.map(getKeymap);
package/dist/linter.d.ts CHANGED
@@ -4,7 +4,6 @@ import type { Warning } from 'stylelint';
4
4
  import type { Diagnostic } from 'luacheck-browserify';
5
5
  export type Option = Record<string, unknown> | null | undefined;
6
6
  export type LiveOption = (runtime?: boolean) => Option | Promise<Option>;
7
- declare type getLinter<T> = () => (text: string) => T;
8
7
  declare type asyncLinter<T, S = Record<string, unknown>> = ((text: string, config?: Option) => T) & {
9
8
  config?: S;
10
9
  fixer?: (code: string, rule?: string) => string | Promise<string>;
@@ -19,17 +18,12 @@ declare interface MixedDiagnostic extends Omit<DiagnosticBase, 'range'> {
19
18
  from?: number;
20
19
  to?: number;
21
20
  }
22
- declare interface JsonError {
23
- message: string;
24
- severity: 'error';
25
- line: string | undefined;
26
- column: string | undefined;
27
- position: string | undefined;
28
- }
29
- export declare const stylelintRepo = "npm/@bhsd/stylelint-browserify", eslintRepo = "npm/@bhsd/eslint-browserify", luacheckRepo = "npm/luacheck-browserify", wikilintRepo = "npm/wikiparser-node";
21
+ export declare const stylelintRepo = "npm/@bhsd/stylelint-browserify";
22
+ export declare const eslintRepo = "npm/@bhsd/eslint-browserify", luacheckRepo = "npm/luacheck-browserify";
30
23
  /**
31
24
  * 获取 Wikitext LSP
32
25
  * @param opt 选项
26
+ * @param opt.cdn jsDelivr CDN,不含库名
33
27
  * @param obj 对象
34
28
  */
35
29
  export declare const getWikiLinter: getAsyncLinter<Promise<MixedDiagnostic[]>, Option, object>;
@@ -49,6 +43,4 @@ export declare const getCssLinter: getAsyncLinter<Promise<Warning[]>, string>;
49
43
  * @param cdn CDN 地址
50
44
  */
51
45
  export declare const getLuaLinter: getAsyncLinter<Promise<Diagnostic[]>, string>;
52
- /** JSON.parse */
53
- export declare const getJsonLinter: getLinter<JsonError[]>;
54
46
  export {};
package/dist/linter.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { sanitizeInlineStyle } from '@bhsd/common';
2
2
  import { loadScript, getWikiparse, getLSP } from '@bhsd/browser';
3
3
  import { styleLint } from '@bhsd/stylelint-util';
4
- export const stylelintRepo = 'npm/@bhsd/stylelint-browserify', eslintRepo = 'npm/@bhsd/eslint-browserify', luacheckRepo = 'npm/luacheck-browserify', wikilintRepo = 'npm/wikiparser-node';
4
+ export const stylelintRepo = 'npm/@bhsd/stylelint-browserify';
5
+ export const eslintRepo = 'npm/@bhsd/eslint-browserify', luacheckRepo = 'npm/luacheck-browserify';
5
6
  /**
6
7
  * 计算位置
7
8
  * @param range 范围
@@ -42,19 +43,26 @@ const isStylelintConfig = (config) => Boolean(config && ('extends' in config ||
42
43
  /**
43
44
  * 获取 Wikitext LSP
44
45
  * @param opt 选项
46
+ * @param opt.cdn jsDelivr CDN,不含库名
45
47
  * @param obj 对象
46
48
  */
47
49
  export const getWikiLinter = async (opt, obj) => {
48
50
  const cdn = opt?.['cdn'];
49
- await getWikiparse(opt?.['getConfig'], opt?.['i18n'], cdn && `${cdn}/${wikilintRepo}`);
50
- const lsp = getLSP(obj, opt?.['include']), cssLint = await getCssLinter(cdn && `${cdn}/${stylelintRepo}`);
51
+ await getWikiparse(opt?.['getConfig'], opt?.['i18n'], cdn);
52
+ const lsp = getLSP(obj, opt?.['include']);
53
+ const cssLint = await getCssLinter(cdn && `${cdn}/${stylelintRepo}`);
51
54
  const linter = async (text, config) => {
52
- const defaultSeverity = config?.['defaultSeverity'] ?? 2, diagnostics = (await lsp.provideDiagnostics(text)).filter(({ code, severity }) => Number(config?.[code] ?? defaultSeverity) > Number(severity === 2)), tokens = 'findStyleTokens' in lsp && config?.['invalid-css'] !== '0' ? await lsp.findStyleTokens() : [];
55
+ const defaultSeverity = config?.['defaultSeverity'] ?? 2, diagnostics = (await lsp.provideDiagnostics(text))
56
+ .filter(({ code, severity }) => Number(config?.[code] ?? defaultSeverity) > Number(severity === 2)), tokens = 'findStyleTokens' in lsp
57
+ && config?.['invalid-css'] !== '0'
58
+ ? await lsp.findStyleTokens()
59
+ : [];
53
60
  if (tokens.length === 0) {
54
61
  return diagnostics;
55
62
  }
56
63
  const lines = tokens.map((token, i) => `${getPrefix(token, i)}${sanitizeInlineStyle(token.childNodes[1].childNodes[0].data)
57
- .replace(/\n/gu, ' ')}\n}`), cssConfig = config?.['css'], isConfig = isStylelintConfig(cssConfig), rules = {};
64
+ .replace(/\n/gu, ' ')}\n}`);
65
+ const cssConfig = config?.['css'], isConfig = isStylelintConfig(cssConfig), rules = {};
58
66
  for (const [key, value] of Object.entries((isConfig ? cssConfig.rules : cssConfig) ?? {})) {
59
67
  if (!value) {
60
68
  rules[key] = value;
@@ -62,12 +70,13 @@ export const getWikiLinter = async (opt, obj) => {
62
70
  }
63
71
  return [
64
72
  ...diagnostics,
65
- ...(await cssLint(lines.join('\n'), isConfig ? { ...cssConfig, rules } : rules))
66
- .map(({ line, column, endLine, endColumn, rule, severity, text: message, fix }) => {
73
+ ...(await cssLint(lines.join('\n'), isConfig ? { ...cssConfig, rules } : rules)).map(({ line, column, endLine, endColumn, rule, severity, text: message, fix }) => {
67
74
  const i = Math.ceil(line / 3), { range } = tokens[i - 1].childNodes[1].childNodes[0], from = offsetAt(range, line - 3 * i, column - 1), diagnostic = {
68
75
  from,
69
76
  to: endLine === undefined ? from : offsetAt(range, endLine - 3 * i, endColumn - 1),
70
- severity: severity === 'error' ? 1 : 2,
77
+ severity: severity === 'error'
78
+ ? 1
79
+ : 2,
71
80
  source: 'Stylelint',
72
81
  code: rule,
73
82
  message,
@@ -133,7 +142,8 @@ export const getJsLinter = async (cdn = eslintRepo) => {
133
142
  }
134
143
  delete config.extends;
135
144
  linter.config = config;
136
- return esLinter.verify(text, config);
145
+ return esLinter.verify(text, config)
146
+ .filter(({ ruleId, message }) => message !== `Definition for rule '${ruleId}' was not found.`);
137
147
  };
138
148
  linter.fixer = (code, rule) => esLinter.verifyAndFix(code, rule ? { ...linter.config, rules: { [rule]: linter.config.rules?.[rule] ?? 2 } } : linter.config).output;
139
149
  return linter;
@@ -167,26 +177,3 @@ export const getLuaLinter = async (cdn = luacheckRepo) => {
167
177
  const luachecker = await luacheck(undefined);
168
178
  return async (text) => (await luachecker.queue(text)).filter(({ severity }) => severity);
169
179
  };
170
- /** JSON.parse */
171
- export const getJsonLinter = () => str => {
172
- try {
173
- if (str.trim()) {
174
- JSON.parse(str);
175
- }
176
- }
177
- catch (e) {
178
- if (e instanceof SyntaxError) {
179
- const { message } = e, line = /\bline (\d+)/u.exec(message)?.[1], column = /\bcolumn (\d+)/u.exec(message)?.[1], position = /\bposition (\d+)/u.exec(message)?.[1];
180
- return [
181
- {
182
- message,
183
- severity: 'error',
184
- line,
185
- column,
186
- position,
187
- },
188
- ];
189
- }
190
- }
191
- return [];
192
- };
@@ -1,5 +1,5 @@
1
1
  import type { EditorView } from '@codemirror/view';
2
- import type { EditorState, Text } from '@codemirror/state';
2
+ import type { Text, EditorState } from '@codemirror/state';
3
3
  import type { Language } from '@codemirror/language';
4
4
  import type { Diagnostic, Action } from '@codemirror/lint';
5
5
  import type { Option, LiveOption } from './linter';
@@ -7,7 +7,7 @@ export type LintSource = ((state: EditorState) => Diagnostic[] | Promise<Diagnos
7
7
  fixer?: (doc: Text, rule?: string) => string | Promise<string>;
8
8
  };
9
9
  export type LintSources = LintSource | [LintSource] | [LintSource, LintSource];
10
- export type LintSourceGetter = (cdn?: string, opt?: Option | LiveOption, view?: EditorView, nestedMWLanguage?: Language) => LintSource | Promise<LintSource>;
10
+ export type LintSourceGetter = (opt?: Option | LiveOption, view?: EditorView, nestedMWLanguage?: Language) => LintSource | Promise<LintSource>;
11
11
  export interface ExtendedAction extends Action {
12
12
  tooltip: string | undefined;
13
13
  }
@@ -1,9 +1,10 @@
1
1
  import { ensureSyntaxTree } from '@codemirror/language';
2
2
  import { cssLanguage } from '@codemirror/lang-css';
3
3
  import { javascriptLanguage } from '@codemirror/lang-javascript';
4
- import { sanitizeInlineStyle } from '@bhsd/common';
5
- import { getWikiLinter, getJsLinter, getCssLinter, getJsonLinter, getLuaLinter, stylelintRepo, eslintRepo, luacheckRepo, } from './linter';
6
- import { posToIndex } from './util';
4
+ import { sanitizeInlineStyle, lintJSON } from '@bhsd/common';
5
+ import { getWikiLinter, getJsLinter, getCssLinter, getLuaLinter, stylelintRepo, eslintRepo, luacheckRepo, } from './linter.js';
6
+ import { posToIndex, } from './util.js';
7
+ import { base } from './constants.js';
7
8
  /**
8
9
  * 获取Linter选项
9
10
  * @param opt Linter选项
@@ -55,8 +56,8 @@ const wikiLintSource = async (wikiLint, text, opt, doc, f = 0, t) => (await wiki
55
56
  ? getRange(doc, r.start.line + 1, r.start.character + 1, r.end.line + 1, r.end.character + 1, f, t)
56
57
  : { from: from + f, to: (to ?? from) + f },
57
58
  }));
58
- export const getWikiLintSource = async (cdn, opt, v) => {
59
- const wikiLint = await getWikiLinter({ ...await getOpt(opt), cdn }, v);
59
+ export const getWikiLintSource = async (opt, v) => {
60
+ const wikiLint = await getWikiLinter({ ...await getOpt(opt), cdn: base.CDN }, v);
60
61
  const lintSource = async ({ doc }) => wikiLintSource(wikiLint, doc.toString(), await getOpt(opt, true), doc);
61
62
  if (wikiLint.fixer) {
62
63
  lintSource.fixer = (_, rule) => wikiLint.fixer('', rule);
@@ -91,8 +92,8 @@ const jsLintSource = (esLint, code, opt, doc, f = 0, t) => esLint(code, opt)
91
92
  }
92
93
  return diagnostic;
93
94
  });
94
- export const getJsLintSource = async (cdn, opt) => {
95
- const esLint = await getJsLinter(cdn && `${cdn}/${eslintRepo}`);
95
+ export const getJsLintSource = async (opt) => {
96
+ const { CDN } = base, esLint = await getJsLinter(CDN && `${CDN}/${eslintRepo}`);
96
97
  const lintSource = async ({ doc }) => jsLintSource(esLint, doc.toString(), await getOpt(opt), doc);
97
98
  lintSource.fixer = (doc, rule) => esLint.fixer(doc.toString(), rule);
98
99
  return lintSource;
@@ -125,14 +126,14 @@ const cssLintSource = async (styleLint, code, opt, doc, f = 0, t) => {
125
126
  return diagnostic;
126
127
  });
127
128
  };
128
- export const getCssLintSource = async (cdn, opt) => {
129
- const styleLint = await getCssLinter(cdn && `${cdn}/${stylelintRepo}`);
129
+ export const getCssLintSource = async (opt) => {
130
+ const { CDN } = base, styleLint = await getCssLinter(CDN && `${CDN}/${stylelintRepo}`);
130
131
  const lintSource = async ({ doc }) => cssLintSource(styleLint, doc.toString(), await getOpt(opt), doc);
131
132
  lintSource.fixer = async (doc, rule) => styleLint.fixer(doc.toString(), rule);
132
133
  return lintSource;
133
134
  };
134
- export const getVueLintSource = async (cdn, opt) => {
135
- const styleLint = await getCssLinter(cdn && `${cdn}/${stylelintRepo}`), esLint = await getJsLinter(cdn && `${cdn}/${eslintRepo}`);
135
+ export const getVueLintSource = async (opt) => {
136
+ const { CDN } = base, styleLint = await getCssLinter(CDN && `${CDN}/${stylelintRepo}`), esLint = await getJsLinter(CDN && `${CDN}/${eslintRepo}`);
136
137
  return async (state) => {
137
138
  const { doc } = state, option = await getOpt(opt, true) ?? {}, js = option['js'], css = option['css'];
138
139
  return [
@@ -153,8 +154,8 @@ export const getVueLintSource = async (cdn, opt) => {
153
154
  ];
154
155
  };
155
156
  };
156
- export const getHTMLLintSource = async (cdn, opt, view, language) => {
157
- const vueLintSource = await getVueLintSource(cdn, opt), wikiLint = await getWikiLinter({ include: false, ...await getOpt(opt), cdn }, view);
157
+ export const getHTMLLintSource = async (opt, view, language) => {
158
+ const vueLintSource = await getVueLintSource(opt), wikiLint = await getWikiLinter({ include: false, ...await getOpt(opt), cdn: base.CDN }, view);
158
159
  return async (state) => {
159
160
  const { doc } = state, option = await getOpt(opt, true) ?? {}, wiki = option['wiki'];
160
161
  return [
@@ -164,26 +165,10 @@ export const getHTMLLintSource = async (cdn, opt, view, language) => {
164
165
  ];
165
166
  };
166
167
  };
167
- export const getJsonLintSource = () => {
168
- const jsonLint = getJsonLinter();
169
- return ({ doc }) => {
170
- const [e] = jsonLint(doc.toString());
171
- if (e) {
172
- const { message, severity, line, column, position } = e;
173
- let from = 0;
174
- if (position) {
175
- from = Number(position);
176
- }
177
- else if (line && column) {
178
- from = pos(doc, Number(line), Number(column));
179
- }
180
- return [{ message, severity, from, to: from }];
181
- }
182
- return [];
183
- };
184
- };
185
- export const getLuaLintSource = async (cdn) => {
186
- const luaLint = await getLuaLinter(cdn && `${cdn}/${luacheckRepo}`);
168
+ export const getJsonLintSource = () => ({ doc }) => lintJSON(doc.toString())
169
+ .map(({ message, position, severity }) => ({ message, severity, from: position, to: position }));
170
+ export const getLuaLintSource = async () => {
171
+ const { CDN } = base, luaLint = await getLuaLinter(CDN && `${CDN}/${luacheckRepo}`);
187
172
  return async ({ doc }) => (await luaLint(doc.toString()))
188
173
  .map(({ line, column, end_column: endColumn, msg: message, severity }) => ({
189
174
  source: 'Luacheck',
package/dist/lua.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { lua } from '@codemirror/legacy-modes/mode/lua';
3
3
  import { syntaxTree, LanguageSupport, StreamLanguage, foldService } from '@codemirror/language';
4
4
  import { snippetCompletion } from '@codemirror/autocomplete';
5
+ import { leadingSpaces } from './util.js';
5
6
  const map = {
6
7
  1: 'constant',
7
8
  2: 'function',
@@ -409,7 +410,7 @@ const support = foldService.of(({ doc, tabSize }, start, from) => {
409
410
  if (!text.trim()) {
410
411
  return null;
411
412
  }
412
- const getIndent = (line) => /^\s*/u.exec(line)[0].replace(/\t/gu, ' '.repeat(tabSize)).length;
413
+ const getIndent = (line) => leadingSpaces(line).replace(/\t/gu, ' '.repeat(tabSize)).length;
413
414
  const indent = getIndent(text);
414
415
  let j = number, empty = true;
415
416
  for (; j < doc.lines; j++) {