@bhsd/codemirror-mediawiki 3.11.4 → 3.12.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.
package/dist/statusBar.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import { showPanel, EditorView } from '@codemirror/view';
2
- import { nextDiagnostic, setDiagnosticsEffect } from '@codemirror/lint';
2
+ import { setDiagnosticsEffect, } from '@codemirror/lint';
3
3
  import { gotoLine } from '@codemirror/search';
4
4
  import elt from 'crelt';
5
5
  import { menuRegistry } from './codemirror.js';
6
6
  import { panelSelector, diagnosticSelector, actionSelector, bgDark, } from './constants.js';
7
+ import { nextDiagnostic } from './lint.js';
7
8
  const statusSelector = '.cm-panel-status', workerSelector = '.cm-status-worker', errorSelector = '.cm-status-error', warningSelector = '.cm-status-warning', enabledSelector = '.cm-status-fix-enabled', disabledSelector = '.cm-status-fix-disabled', menuSelector = '.cm-status-fix-menu', menuHover = `${menuSelector}>div:hover`, messageSelector = '.cm-status-message', workerCls = 'cm-status-worker-enabled', lineCls = 'cm-status-line';
8
- function getLintMarker(view, severity, menu) {
9
+ function getLintMarker(cm, severity, menu) {
10
+ const view = cm.view;
9
11
  const marker = elt('div', { class: `cm-status-${severity}` }), icon = elt('div');
10
12
  if (severity === 'fix') {
11
13
  icon.className = disabledSelector.slice(1);
@@ -28,7 +30,7 @@ function getLintMarker(view, severity, menu) {
28
30
  marker.append(icon, elt('div', '0'));
29
31
  marker.addEventListener('click', () => {
30
32
  if (marker.parentElement?.classList.contains(workerCls)) {
31
- nextDiagnostic(view);
33
+ nextDiagnostic(cm);
32
34
  view.focus();
33
35
  }
34
36
  });
@@ -49,6 +51,12 @@ const updateDiagnosticMessage = (view, allDiagnostics, main, msg) => {
49
51
  msg.textContent = '';
50
52
  }
51
53
  else {
54
+ const cmp = main.head === main.from
55
+ ? (a, b) => Math.abs(a.from - main.from) - Math.abs(b.from - main.from)
56
+ || Math.abs(a.to - main.to) - Math.abs(b.to - main.to)
57
+ : (a, b) => Math.abs(a.to - main.to) - Math.abs(b.to - main.to)
58
+ || Math.abs(a.from - main.from) - Math.abs(b.from - main.from);
59
+ diagnostics.sort(cmp);
52
60
  const diagnostic = diagnostics.find(({ from, to }) => from <= main.head && to >= main.head) ?? diagnostics[0];
53
61
  if (diagnostic.renderMessage) {
54
62
  msg.replaceChildren(diagnostic.renderMessage(view));
@@ -126,7 +134,7 @@ export default (cm, fixer) => [
126
134
  });
127
135
  view.dom.append(menu);
128
136
  }
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);
137
+ const error = getLintMarker(cm, 'error'), warning = getLintMarker(cm, 'warning'), fix = getLintMarker(cm, '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);
130
138
  position.addEventListener('click', () => {
131
139
  gotoLine(view);
132
140
  });
package/dist/theme.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Extension } from '@codemirror/state';
2
- export declare const getLightHighlightStyle: () => Extension;
2
+ export declare const lightHighlightStyle: Extension;
3
3
  export declare const light: Extension,
4
4
  /**
5
5
  * @author 鬼影233
package/dist/theme.js CHANGED
@@ -3,7 +3,7 @@ import { syntaxHighlighting, HighlightStyle, defaultHighlightStyle } from '@code
3
3
  import { nord as nordBase } from 'cm6-theme-nord';
4
4
  import { matchingCls, nonmatchingCls, actionSelector, panelsSelector, bgDark, } from './constants.js';
5
5
  const focused = '&.cm-focused', matching = `${focused} .${matchingCls}`, nonmatching = `${focused} .${nonmatchingCls}`;
6
- export const getLightHighlightStyle = () => syntaxHighlighting(HighlightStyle.define(defaultHighlightStyle.specs, { themeType: 'light' }));
6
+ export const lightHighlightStyle = /* @__PURE__ */ (() => syntaxHighlighting(HighlightStyle.define(defaultHighlightStyle.specs, { themeType: 'light' })))();
7
7
  export const light = /* @__PURE__ */ EditorView.theme({
8
8
  '&': {
9
9
  backgroundColor: '#fff',
package/dist/token.d.ts CHANGED
@@ -153,7 +153,7 @@ export declare class MediaWiki {
153
153
  */
154
154
  registerGroundTokens(): void;
155
155
  inChars({ length }: string, tag: TagName): Tokenizer<string>;
156
- inStr(str: string, tag: TagName | false, errorTag?: TagName): Tokenizer<string>;
156
+ inStr(str: string, tag: string | false, errorTag?: string): Tokenizer<string>;
157
157
  eatWikiText(style: string): Tokenizer;
158
158
  eatApostrophes(obj: Pick<State, 'bold' | 'italic'>): Tokenizer<string | false>;
159
159
  eatExternalLinkProtocol({ length }: string, free?: boolean): Tokenizer;
@@ -168,7 +168,7 @@ export declare class MediaWiki {
168
168
  inTableDefinition(tr?: boolean, quote?: string): Tokenizer;
169
169
  get inTable(): Tokenizer;
170
170
  inTableCell(style: string, needAttr?: boolean, firstLine?: boolean): Tokenizer;
171
- inSectionHeader(str: string): Tokenizer;
171
+ inSectionHeader(str: string, level: number): Tokenizer;
172
172
  get inComment(): Tokenizer<string>;
173
173
  eatExtTag(tagname: string, isCloseTag: boolean, state: State): string;
174
174
  eatHtmlTag(tagname: string, isCloseTag: boolean, state: State): string;
package/dist/token.js CHANGED
@@ -112,7 +112,8 @@ const startState = (tokenize, tags, urlProtocols, sof = false) => ({
112
112
  */
113
113
  const copyState = (state) => {
114
114
  const result = { ...state };
115
- for (const [key, val] of Object.entries(state)) {
115
+ for (const key in result) { // eslint-disable-line guard-for-in
116
+ const val = result[key];
116
117
  if (Array.isArray(val)) {
117
118
  // @ts-expect-error initial value
118
119
  result[key] = [...val];
@@ -122,7 +123,7 @@ const copyState = (state) => {
122
123
  }
123
124
  else if (key !== 'data' && val && typeof val === 'object') {
124
125
  // @ts-expect-error initial value
125
- result[key] = { ...val };
126
+ result[key] = { ...val }; // eslint-disable-line @typescript-eslint/no-misused-spread
126
127
  }
127
128
  }
128
129
  return result;
@@ -261,6 +262,7 @@ export const makeLocalStyle = (style, state, endGround) => {
261
262
  const makeLocalTagStyle = (tag, state, endGround) => makeLocalStyle(tokens[tag], state, endGround);
262
263
  const makeStyle = (style, state, endGround) => [makeLocalStyle(style, state, endGround)];
263
264
  const makeTagStyle = (tag, state, endGround) => makeStyle(tokens[tag], state, endGround);
265
+ const getTagStyle = (tag) => tag in tokens ? tokens[tag] : tag;
264
266
  /**
265
267
  * Remembers position and status for rollbacking.
266
268
  * It is needed for changing from bold to italic with apostrophes before it, if required.
@@ -576,21 +578,21 @@ let MediaWiki = (() => {
576
578
  };
577
579
  }
578
580
  inStr(str, tag, errorTag = 'error') {
581
+ tag &&= getTagStyle(tag);
582
+ errorTag = getTagStyle(errorTag);
579
583
  return (stream, state) => {
580
584
  if (stream.match(str, Boolean(tag))) {
581
585
  pop(state);
582
- return tag ? makeLocalTagStyle(tag, state) : '';
586
+ return tag ? makeLocalStyle(tag, state) : '';
583
587
  }
584
588
  else if (!stream.skipTo(str)) {
585
589
  stream.skipToEnd();
586
590
  }
587
- return makeLocalTagStyle(errorTag, state);
591
+ return makeLocalStyle(errorTag, state);
588
592
  };
589
593
  }
590
594
  eatWikiText(style) {
591
- if (style in tokens) {
592
- style = tokens[style];
593
- }
595
+ style = getTagStyle(style);
594
596
  const regex = /^(?:(?:RFC|PMID)[\p{Zs}\t]+\d+|ISBN[\p{Zs}\t]+(?:97[89][\p{Zs}\t-]?)?(?:\d[\p{Zs}\t-]?){9}[\dxX])\b/u;
595
597
  return (stream, state) => {
596
598
  let ch;
@@ -641,8 +643,9 @@ let MediaWiki = (() => {
641
643
  // Title
642
644
  if (tmp) {
643
645
  stream.backUp(tmp[2].length);
644
- chain(state, this.inSectionHeader(tmp[3]));
645
- return makeLocalStyle(`${tokens.sectionHeader} mw-section--${tmp[1].length + 1}`, state);
646
+ const level = tmp[1].length + 1;
647
+ chain(state, this.inSectionHeader(tmp[3], level));
648
+ return makeLocalStyle(`${tokens.sectionHeader} mw-section--${level}`, state);
646
649
  }
647
650
  break;
648
651
  }
@@ -1137,7 +1140,8 @@ let MediaWiki = (() => {
1137
1140
  : this.eatWikiText(style)(stream, state);
1138
1141
  };
1139
1142
  }
1140
- inSectionHeader(str) {
1143
+ inSectionHeader(str, level) {
1144
+ const headerStyle = `${tokens.sectionHeader} mw-section--${level}`, style = `${tokens.section} mw-section--${level}`;
1141
1145
  return (stream, state) => {
1142
1146
  if (stream.sol()) {
1143
1147
  pop(state);
@@ -1146,16 +1150,16 @@ let MediaWiki = (() => {
1146
1150
  else if (stream.match(headerRegex)) {
1147
1151
  if (stream.eol()) {
1148
1152
  stream.backUp(str.length);
1149
- state.tokenize = this.inStr(str, 'sectionHeader');
1153
+ state.tokenize = this.inStr(str, headerStyle);
1150
1154
  }
1151
1155
  else if (stream.match(/^<!--(?!.*?-->.*?=)/u, false)) {
1152
1156
  // T171074: handle trailing comments
1153
1157
  stream.backUp(str.length);
1154
- state.tokenize = this.inStr('<!--', false, 'sectionHeader');
1158
+ state.tokenize = this.inStr('<!--', false, headerStyle);
1155
1159
  }
1156
- return makeLocalTagStyle('section', state);
1160
+ return makeLocalStyle(style, state);
1157
1161
  }
1158
- return this.eatWikiText('section')(stream, state);
1162
+ return this.eatWikiText(style)(stream, state);
1159
1163
  };
1160
1164
  }
1161
1165
  get inComment() {
@@ -1734,8 +1738,13 @@ let MediaWiki = (() => {
1734
1738
  stream.pos === oldToken?.pos
1735
1739
  && stream.string === oldToken.string
1736
1740
  && cmpNesting(state, oldToken.state)) {
1737
- const { pos, string, state: { bold, italic, ...other }, style } = readyTokens[0];
1738
- Object.assign(state, other);
1741
+ const { pos, string, state: other, style } = readyTokens[0];
1742
+ for (const key in other) {
1743
+ if (key !== 'bold' && key !== 'italic') {
1744
+ // @ts-expect-error assign readonly properties
1745
+ state[key] = other[key];
1746
+ }
1747
+ }
1739
1748
  if (!(state.extName && state.extMode)
1740
1749
  && state.nLink === 0
1741
1750
  && typeof style === 'string'