@bhsd/codemirror-mediawiki 3.11.1 → 3.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/openLinks.js CHANGED
@@ -2,8 +2,7 @@ import { EditorView } from '@codemirror/view';
2
2
  import { ensureSyntaxTree } from '@codemirror/language';
3
3
  import { tokens } from './config.js';
4
4
  import { isMac } from './constants.js';
5
- import { hasTag } from './util.js';
6
- const tags = ['extLinkProtocol', 'extLink', 'freeExtLinkProtocol', 'freeExtLink', 'magicLink', 'pageName'], links = ['extlink-protocol', 'extlink', 'free-extlink-protocol', 'free-extlink', 'magic-link'], pagename = '.cm-mw-pagename', wikiLinks = [
5
+ const links = ['extlink-protocol', 'extlink', 'free-extlink-protocol', 'free-extlink', 'magic-link'], pagename = '.cm-mw-pagename', wikiLinks = [
7
6
  'template-name',
8
7
  'link-pagename',
9
8
  `parserfunction${pagename}`,
@@ -36,21 +35,18 @@ export const mouseEventListener = (e, view, isbnParser, titleParser) => {
36
35
  || !(e.target instanceof Element && getComputedStyle(e.target).textDecorationLine === 'underline')) {
37
36
  return undefined;
38
37
  }
39
- const position = view.posAtCoords(e);
40
- if (!position) {
38
+ const posAndSide = view.posAndSideAtCoords(e);
39
+ if (!posAndSide) {
41
40
  return undefined;
42
41
  }
43
- const { state } = view, tree = ensureSyntaxTree(state, position);
42
+ const { pos, assoc } = posAndSide, { state } = view, tree = ensureSyntaxTree(state, pos);
44
43
  if (!tree) {
45
44
  return undefined;
46
45
  }
47
- let node = tree.resolve(position, -1);
46
+ let node = tree.resolve(pos, assoc);
48
47
  if (node.name.includes(tokens.linkToSection)) {
49
48
  node = node.prevSibling;
50
49
  }
51
- else if (node.to === position && !hasTag(new Set(node.name.split('_')), tags)) {
52
- node = tree.resolve(position, 1);
53
- }
54
50
  const { name, from, to } = node;
55
51
  if (name.includes('-extlink-protocol')) {
56
52
  return wrapURL(state.sliceDoc(from, node.nextSibling.to));
package/dist/statusBar.js CHANGED
@@ -92,6 +92,13 @@ const updateMenu = (cm, allDiagnostics, main, classList, optionAll, menu, fixer)
92
92
  menu.replaceChildren(...actions, ...quickfix);
93
93
  }
94
94
  };
95
+ const updatePosition = (doc, { head, empty, from, to }, position) => {
96
+ const { number, from: f } = doc.lineAt(head);
97
+ position.textContent = `${number}:${head - f}`;
98
+ if (!empty) {
99
+ position.textContent += ` (${to - from})`;
100
+ }
101
+ };
95
102
  export default (cm, fixer) => [
96
103
  showPanel.of(view => {
97
104
  let diagnostics = [];
@@ -119,10 +126,11 @@ export default (cm, fixer) => [
119
126
  });
120
127
  view.dom.append(menu);
121
128
  }
122
- const error = getLintMarker(view, 'error'), warning = getLintMarker(view, 'warning'), fix = getLintMarker(view, 'fix', menu), { classList } = fix.firstChild, optionAll = elt('div', 'Fix all auto-fixable problems'), worker = elt('div', { class: workerSelector.slice(1) }, error, warning, fix), message = elt('div', { class: messageSelector.slice(1) }), position = elt('div', { class: lineCls }, '0:0'), dom = elt('div', { class: `${panelSelector.slice(1)} ${statusSelector.slice(1)}` }, worker, message, position);
129
+ const error = getLintMarker(view, 'error'), warning = getLintMarker(view, 'warning'), fix = getLintMarker(view, 'fix', menu), { classList } = fix.firstChild, optionAll = elt('div', 'Fix all auto-fixable problems'), worker = elt('div', { class: workerSelector.slice(1) }, error, warning, fix), message = elt('div', { class: messageSelector.slice(1) }), position = elt('div', { class: lineCls }), dom = elt('div', { class: `${panelSelector.slice(1)} ${statusSelector.slice(1)}` }, worker, message, position);
123
130
  position.addEventListener('click', () => {
124
131
  gotoLine(view);
125
132
  });
133
+ updatePosition(view.state.doc, view.state.selection.main, position);
126
134
  return {
127
135
  dom,
128
136
  update({ state: { selection: { main }, doc }, transactions, docChanged, selectionSet }) {
@@ -141,11 +149,7 @@ export default (cm, fixer) => [
141
149
  if (docChanged || selectionSet) {
142
150
  updateDiagnosticMessage(view, diagnostics, main, message);
143
151
  updateMenu(cm, diagnostics, main, classList, optionAll, menu, fixer);
144
- const { number, from } = doc.lineAt(main.head);
145
- position.textContent = `${number}:${main.head - from}`;
146
- if (!main.empty) {
147
- position.textContent += ` (${main.to - main.from})`;
148
- }
152
+ updatePosition(doc, main, position);
149
153
  }
150
154
  },
151
155
  };
package/dist/token.js CHANGED
@@ -996,8 +996,8 @@ let MediaWiki = (() => {
996
996
  eatDoubleUnderscore(style, ch, stream, state) {
997
997
  const { doubleUnderscore } = this.config, underscore = ch.repeat(2), name = stream.match(doubleUnderscoreRegex[ch]);
998
998
  if (name) {
999
- if (Object.prototype.hasOwnProperty.call(doubleUnderscore[0], underscore + name[0].toLowerCase())
1000
- || Object.prototype.hasOwnProperty.call(doubleUnderscore[1], underscore + name[0])) {
999
+ if (Object.hasOwn(doubleUnderscore[0], underscore + name[0].toLowerCase())
1000
+ || Object.hasOwn(doubleUnderscore[1], underscore + name[0])) {
1001
1001
  return tokens.doubleUnderscore;
1002
1002
  }
1003
1003
  else if (!stream.eol()) {
@@ -1421,10 +1421,8 @@ let MediaWiki = (() => {
1421
1421
  else if (delimiter !== ':') {
1422
1422
  ff = f.trim();
1423
1423
  }
1424
- const ffLower = ff.toLowerCase(), { functionSynonyms, variableIDs, functionHooks } = this.config, canonicalName = Object.prototype.hasOwnProperty.call(functionSynonyms[1], ff)
1425
- && functionSynonyms[1][ff]
1426
- || Object.prototype.hasOwnProperty.call(functionSynonyms[0], ffLower)
1427
- && functionSynonyms[0][ffLower];
1424
+ const ffLower = ff.toLowerCase(), { functionSynonyms, variableIDs, functionHooks } = this.config, canonicalName = Object.hasOwn(functionSynonyms[1], ff) && functionSynonyms[1][ff]
1425
+ || Object.hasOwn(functionSynonyms[0], ffLower) && functionSynonyms[0][ffLower];
1428
1426
  if ((!delimiter || fullWidth || delimiter === ':' || delimiter === '}')
1429
1427
  && canonicalName
1430
1428
  && !substs.has(canonicalName)
package/dist/util.d.ts CHANGED
@@ -3,7 +3,6 @@ import type { Text, EditorState, SelectionRange } from '@codemirror/state';
3
3
  import type { SyntaxNode } from '@lezer/common';
4
4
  import type { Position } from 'vscode-languageserver-types';
5
5
  import type { ConfigGetter } from '@bhsd/browser';
6
- import type { TagName } from './config';
7
6
  /**
8
7
  * 转义HTML字符串
9
8
  * @param text 原字符串
@@ -56,13 +55,6 @@ export declare const isTemplate: (node: SyntaxNode) => boolean;
56
55
  * @test
57
56
  */
58
57
  export declare const findTemplateName: (state: EditorState, node: SyntaxNode) => [string | null, string];
59
- /**
60
- * 判断节点是否包含指定类型
61
- * @param types 节点类型
62
- * @param names 指定类型
63
- * @test
64
- */
65
- export declare const hasTag: (types: Set<string>, names: TagName | TagName[]) => boolean;
66
58
  export declare const toConfigGetter: (configGetter?: ConfigGetter, articlePath?: string) => ConfigGetter | undefined;
67
59
  /**
68
60
  * 获取字符串开头的空白字符
package/dist/util.js CHANGED
@@ -109,13 +109,6 @@ export const findTemplateName = (state, node) => {
109
109
  }
110
110
  return [prevSibling && page, parameter];
111
111
  };
112
- /**
113
- * 判断节点是否包含指定类型
114
- * @param types 节点类型
115
- * @param names 指定类型
116
- * @test
117
- */
118
- export const hasTag = (types, names) => (Array.isArray(names) ? names : [names]).some(name => types.has(name in tokens ? tokens[name] : name));
119
112
  export const toConfigGetter = (configGetter, articlePath) => articlePath
120
113
  ? async () => Object.assign(await (configGetter ?? wikiparse.getConfig)(), { articlePath })
121
114
  : configGetter;