@bhsd/codemirror-mediawiki 2.1.10 → 2.1.11

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/mw/dist/base.js CHANGED
@@ -1,7 +1,7 @@
1
- import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.10/dist/main.min.js';
1
+ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.11/dist/main.min.js';
2
2
  (() => {
3
3
  var _a;
4
- mw.loader.load('https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.10/mediawiki.min.css', 'text/css');
4
+ mw.loader.load('https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.11/mediawiki.min.css', 'text/css');
5
5
  mw.loader.addStyleTag('.wikiEditor-ui-toolbar{z-index:7}');
6
6
  const instances = new WeakMap();
7
7
  const getInstance = ($ele) => instances.get($ele[0]);
@@ -55,7 +55,7 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
55
55
  return this;
56
56
  },
57
57
  };
58
- const USING_LOCAL = mw.loader.getState('ext.CodeMirror') !== null, DATA_MODULE = mw.loader.getState('ext.CodeMirror.data') ? 'ext.CodeMirror.data' : 'ext.CodeMirror', ALL_SETTINGS_CACHE = (_a = JSON.parse(localStorage.getItem('InPageEditMwConfig'))) !== null && _a !== void 0 ? _a : {}, SITE_ID = `${mw.config.get('wgServerName')}${mw.config.get('wgScriptPath')}`, SITE_SETTINGS = ALL_SETTINGS_CACHE[SITE_ID], VALID = (SITE_SETTINGS === null || SITE_SETTINGS === void 0 ? void 0 : SITE_SETTINGS.time) > Date.now() - 86400 * 1000 * 30;
58
+ const USING_LOCAL = mw.loader.getState('ext.CodeMirror') !== null, DATA_MODULE = mw.loader.getState('ext.CodeMirror.data') ? 'ext.CodeMirror.data' : 'ext.CodeMirror', ALL_SETTINGS_CACHE = (_a = JSON.parse(localStorage.getItem('InPageEditMwConfig'))) !== null && _a !== void 0 ? _a : {}, SITE_ID = `${mw.config.get('wgServerName')}${mw.config.get('wgScriptPath')}`, SITE_SETTINGS = ALL_SETTINGS_CACHE[SITE_ID], VALID = Number(SITE_SETTINGS === null || SITE_SETTINGS === void 0 ? void 0 : SITE_SETTINGS.time) > Date.now() - 86400 * 1000 * 30;
59
59
  const getConfig = (magicWords, rule, flip) => {
60
60
  const words = magicWords.filter(rule).filter(({ 'case-sensitive': i }) => i !== flip)
61
61
  .flatMap(({ aliases, name, 'case-sensitive': i }) => aliases.map(alias => ({
@@ -166,7 +166,7 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
166
166
  const { lang } = this;
167
167
  let opt;
168
168
  if (typeof optOrNs === 'number') {
169
- if (lang === 'mediawiki' && (optOrNs === 10 || optOrNs === 828)) {
169
+ if (lang === 'mediawiki' && (optOrNs === 10 || optOrNs === 828 || optOrNs === 2)) {
170
170
  opt = { include: true };
171
171
  }
172
172
  else if (lang === 'javascript' && (optOrNs === 8 || optOrNs === 2300)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhsd/codemirror-mediawiki",
3
- "version": "2.1.10",
3
+ "version": "2.1.11",
4
4
  "description": "Modified CodeMirror mode based on wikimedia/mediawiki-extensions-CodeMirror",
5
5
  "keywords": [
6
6
  "mediawiki",
@@ -35,7 +35,8 @@
35
35
  "lint:ts": "tsc --noEmit && tsc --project mw/tsconfig.json --noEmit && eslint --cache .",
36
36
  "lint:css": "stylelint *.css",
37
37
  "lint": "npm run lint:ts && npm run lint:css",
38
- "test": "npm run build:core && npm run build:gh-page && http-server .. -c-1 --cors &",
38
+ "server": "http-server .. -c-1 --cors &",
39
+ "test": "npm run build:core && npm run build:gh-page && npm run server",
39
40
  "test:end": "pkill -x http-server"
40
41
  },
41
42
  "engines": {
package/src/codemirror.ts CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  highlightActiveLine,
8
8
  highlightWhitespace,
9
9
  highlightTrailingWhitespace,
10
+ drawSelection,
10
11
  } from '@codemirror/view';
11
12
  import {
12
13
  syntaxHighlighting,
@@ -52,6 +53,13 @@ const avail: Record<string, [(config?: any) => Extension, Record<string, unknown
52
53
  highlightTrailingWhitespace: [highlightTrailingWhitespace, {}],
53
54
  bracketMatching: [bracketMatching, {mediawiki: {brackets: '[]{}'}}],
54
55
  closeBrackets: [closeBrackets, {}],
56
+ allowMultipleSelections: [
57
+ (): Extension => [
58
+ EditorState.allowMultipleSelections.of(true),
59
+ drawSelection(),
60
+ ],
61
+ {},
62
+ ],
55
63
  };
56
64
 
57
65
  /**
@@ -260,8 +268,12 @@ export class CodeMirror6 {
260
268
  this.#view.dispatch({
261
269
  effects: [
262
270
  this.#extensions.reconfigure(names.map(name => {
263
- const [extension, configs] = avail[name]!;
264
- return extension(configs[this.#lang]);
271
+ const option = avail[name];
272
+ if (option) {
273
+ const [extension, configs] = option;
274
+ return extension(configs[this.#lang]);
275
+ }
276
+ return [];
265
277
  })),
266
278
  ],
267
279
  });
package/src/mediawiki.ts CHANGED
@@ -151,7 +151,8 @@ class MediaWiki {
151
151
  }));
152
152
  }
153
153
 
154
- eatHtmlEntity(stream: StringStream, style: string): string { // eslint-disable-line class-methods-use-this
154
+ // eslint-disable-next-line @typescript-eslint/class-methods-use-this
155
+ eatHtmlEntity(stream: StringStream, style: string): string {
155
156
  const entity = stream.match(/^(?:#x[a-f\d]+|#\d+|[a-z\d]+);/iu) as RegExpMatchArray | false;
156
157
  return entity && isHtmlEntity(`&${entity[0]}`) ? modeConfig.tags.htmlEntity : style;
157
158
  }
@@ -164,7 +165,7 @@ class MediaWiki {
164
165
  );
165
166
  }
166
167
 
167
- // eslint-disable-next-line class-methods-use-this
168
+ // eslint-disable-next-line @typescript-eslint/class-methods-use-this
168
169
  makeLocalStyle(style: string, state: State, endGround?: 'nTemplate' | 'nLink' | 'nExt'): string {
169
170
  let ground = '';
170
171
 
@@ -619,8 +620,7 @@ class MediaWiki {
619
620
  eatExtTagArea(name: string): Tokenizer {
620
621
  return (stream, state) => {
621
622
  const from = stream.pos,
622
- pattern = new RegExp(`</${name}\\s*(?:>|$)`, 'iu'),
623
- m = pattern.exec(from ? stream.string.slice(from) : stream.string);
623
+ m = new RegExp(`</${name}\\s*(?:>|$)`, 'iu').exec(from ? stream.string.slice(from) : stream.string);
624
624
  let origString: string | false = false;
625
625
 
626
626
  if (m) {
@@ -633,9 +633,8 @@ class MediaWiki {
633
633
  }
634
634
  return state.tokenize(stream, state);
635
635
  }
636
- const to = m.index + from;
637
636
  origString = stream.string;
638
- stream.string = origString.slice(0, to);
637
+ stream.string = origString.slice(0, m.index + from);
639
638
  }
640
639
 
641
640
  state.stack.push(state.tokenize);
@@ -653,7 +652,8 @@ class MediaWiki {
653
652
  };
654
653
  }
655
654
 
656
- inExtTokens(origString: string | false): Tokenizer { // eslint-disable-line class-methods-use-this
655
+ // eslint-disable-next-line @typescript-eslint/class-methods-use-this
656
+ inExtTokens(origString: string | false): Tokenizer {
657
657
  return (stream, state) => {
658
658
  let ret: string;
659
659
  if (state.extMode === false) {
@@ -779,10 +779,11 @@ class MediaWiki {
779
779
 
780
780
  eatWikiText(style: string): Tokenizer {
781
781
  return (stream, state) => {
782
- let ch: string | void; // eslint-disable-line @typescript-eslint/no-invalid-void-type
783
- const sol = stream.sol();
782
+ let ch: string;
784
783
 
785
- if (sol) {
784
+ if (stream.eol()) {
785
+ return '';
786
+ } else if (stream.sol()) {
786
787
  if (stream.match('//')) {
787
788
  return this.makeStyle(style, state);
788
789
  // highlight free external links, see T108448
@@ -791,7 +792,7 @@ class MediaWiki {
791
792
  state.tokenize = this.inFreeExternalLink.bind(this);
792
793
  return this.makeStyle(modeConfig.tags.freeExtLinkProtocol, state);
793
794
  }
794
- ch = stream.next();
795
+ ch = stream.next()!;
795
796
  switch (ch) {
796
797
  case '-':
797
798
  if (stream.match(/^-{3,}/u)) {
@@ -863,7 +864,7 @@ class MediaWiki {
863
864
  // pass
864
865
  }
865
866
  } else {
866
- ch = stream.next();
867
+ ch = stream.next()!;
867
868
  }
868
869
 
869
870
  switch (ch) {
@@ -1101,12 +1102,7 @@ class MediaWiki {
1101
1102
  },
1102
1103
 
1103
1104
  token: (stream, state): string => {
1104
- let style: string,
1105
- p: number | null = null,
1106
- t: Token,
1107
- f: number | null,
1108
- tmpTokens: Token[] = [];
1109
- const readyTokens: Token[] = [];
1105
+ let t: Token;
1110
1106
 
1111
1107
  if (this.oldTokens.length > 0) {
1112
1108
  // just send saved tokens till they exists
@@ -1122,6 +1118,11 @@ class MediaWiki {
1122
1118
  this.firstSpace = null;
1123
1119
  }
1124
1120
 
1121
+ let style: string,
1122
+ p: number | null = null,
1123
+ f: number | null;
1124
+ const tmpTokens: Token[] = [],
1125
+ readyTokens: Token[] = [];
1125
1126
  do {
1126
1127
  // get token style
1127
1128
  style = state.tokenize(stream, state);
@@ -1135,7 +1136,7 @@ class MediaWiki {
1135
1136
  if (tmpTokens.length > 0) {
1136
1137
  // save tokens
1137
1138
  readyTokens.push(...tmpTokens);
1138
- tmpTokens = [];
1139
+ tmpTokens.length = 0;
1139
1140
  }
1140
1141
  }
1141
1142
  // save token
@@ -1217,10 +1218,9 @@ for (const [language, parser] of Object.entries(plugins)) {
1217
1218
  * @param config Configuration for the MediaWiki mode
1218
1219
  */
1219
1220
  export const mediawiki = (config: MwConfig): LanguageSupport => {
1220
- const mode = new MediaWiki(config);
1221
- const parser = mode.mediawiki;
1222
- const lang = StreamLanguage.define(parser);
1223
- const highlighter = syntaxHighlighting(HighlightStyle.define(mode.getTagStyles()) as Highlighter);
1221
+ const mode = new MediaWiki(config),
1222
+ lang = StreamLanguage.define(mode.mediawiki),
1223
+ highlighter = syntaxHighlighting(HighlightStyle.define(mode.getTagStyles()) as Highlighter);
1224
1224
  return new LanguageSupport(lang, highlighter);
1225
1225
  };
1226
1226