wikiplus-highlight 3.1.1 → 3.2.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.
Files changed (2) hide show
  1. package/dist/main.js +42 -52
  2. package/package.json +5 -5
package/dist/main.js CHANGED
@@ -9,23 +9,19 @@
9
9
  if (wphl === null || wphl === void 0 ? void 0 : wphl.version) {
10
10
  return;
11
11
  }
12
- const version = '3.1.1';
12
+ const version = '3.2.1';
13
13
  libs.wphl = { version, ...wphl }; // 开始加载
14
14
  // 路径
15
- const CDN = '//testingcf.jsdelivr.net', MW_CDN = `npm/@bhsd/codemirror-mediawiki@${libs.wphl.cmVersion || 'latest'}/dist/mw.min.js`, MONACO_CDN = `npm/monaco-wiki@${libs.wphl.monacoVersion || 'latest'}/dist/mw.min.js`, REPO_CDN = 'npm/wikiplus-highlight';
16
- const useMonaco = wphl === null || wphl === void 0 ? void 0 : wphl.useMonaco;
17
- if (useMonaco) {
18
- window.MonacoWikiEditor || (window.MonacoWikiEditor = (async () => {
19
- await $.ajax(`${CDN}/${MONACO_CDN}`, { dataType: 'script', scriptAttrs: { type: 'module' } });
20
- return MonacoWikiEditor;
21
- })());
22
- }
23
- else {
24
- window.CodeMirror6 || (window.CodeMirror6 = (async () => {
25
- await $.ajax(`${CDN}/${MW_CDN}`, { dataType: 'script', scriptAttrs: { type: 'module' } });
26
- return CodeMirror6;
27
- })());
28
- }
15
+ const CDN = '//testingcf.jsdelivr.net', MW_CDN = `npm/@bhsd/codemirror-mediawiki@${libs.wphl.cmVersion || 'latest'}/dist/mw.min.js`, REPO_CDN = 'npm/wikiplus-highlight';
16
+ window.CodeMirror6 || (window.CodeMirror6 = new Promise(resolve => {
17
+ const script = document.createElement('script');
18
+ script.addEventListener('load', () => {
19
+ resolve(CodeMirror6);
20
+ });
21
+ script.type = 'module';
22
+ script.src = `${CDN}/${MW_CDN}`;
23
+ document.head.append(script);
24
+ }));
29
25
  const { wgPageName: page, wgNamespaceNumber: ns, wgPageContentModel: contentmodel, } = mw.config.get();
30
26
  const CONTENTMODELS = {
31
27
  'sanitized-css': 'css',
@@ -109,12 +105,13 @@
109
105
  * @param setting 是否是Wikiplus设置(使用json语法)
110
106
  */
111
107
  const renderEditor = async ($target, setting) => {
112
- const settings = getObject('Wikiplus_Settings'), escToExitQuickEdit = settings && (settings['esc_to_exit_quickedit'] || settings['escToExitQuickEdit']);
113
- if (useMonaco) {
114
- const lang = setting ? 'json' : (await getPageMode($target.val()))[0], { editor } = await (await MonacoWikiEditor).fromTextArea($target[0], lang);
115
- editor.getDomNode().id = 'Wikiplus-CodeMirror';
116
- if (!setting) { // 普通Wikiplus编辑区
117
- editor.onKeyUp(e => {
108
+ var _a;
109
+ const settings = getObject('Wikiplus_Settings'), escToExitQuickEdit = settings && (settings['esc_to_exit_quickedit'] || settings['escToExitQuickEdit']), esc = escToExitQuickEdit === true || escToExitQuickEdit === 'true';
110
+ const cm = await (await CodeMirror6).fromTextArea($target[0], ...setting ? ['json'] : await getPageMode($target.val()));
111
+ (((_a = cm.view) === null || _a === void 0 ? void 0 : _a.dom) || cm.editor.getDomNode()).id = 'Wikiplus-CodeMirror';
112
+ if (!setting) { // 普通Wikiplus编辑区
113
+ if (cm.editor) {
114
+ cm.editor.onKeyUp(e => {
118
115
  if (e.keyCode === 49 && (e.ctrlKey || e.metaKey)) {
119
116
  e.preventDefault();
120
117
  if (e.shiftKey) {
@@ -124,49 +121,42 @@
124
121
  submit();
125
122
  }
126
123
  }
127
- else if (e.keyCode === 9
128
- && (escToExitQuickEdit === true || escToExitQuickEdit === 'true')) {
124
+ else if (e.keyCode === 9 && esc) {
129
125
  e.preventDefault();
130
126
  escapeEdit();
131
127
  }
132
128
  });
133
129
  }
134
- }
135
- else {
136
- const cm = await (await CodeMirror6).fromTextArea($target[0], ...setting ? ['json'] : await getPageMode($target.val()));
137
- cm.view.dom.id = 'Wikiplus-CodeMirror';
138
- if (!setting) { // 普通Wikiplus编辑区
130
+ else {
139
131
  cm.extraKeys([
140
132
  { key: 'Mod-S', run: submit },
141
133
  { key: 'Shift-Mod-S', run: submitMinor },
142
- ...escToExitQuickEdit === true || escToExitQuickEdit === 'true'
143
- ? [{ key: 'Esc', run: escapeEdit }]
144
- : [],
134
+ ...esc ? [{ key: 'Esc', run: escapeEdit }] : [],
145
135
  ]);
146
136
  }
147
- /** @todo 以下过渡代码添加于2024-02-07,将于一段时间后弃用 */
148
- const oldKey = 'Wikiplus-highlight-addons', oldPrefs = getObject(oldKey), mapping = {
149
- activeLine: 'highlightActiveLine',
150
- trailingspace: 'highlightTrailingWhitespace',
151
- matchBrackets: 'bracketMatching',
152
- closeBrackets: 'closeBrackets',
153
- matchTags: 'tagMatching',
154
- fold: 'codeFolding',
155
- wikiEditor: 'wikiEditor',
156
- escape: 'escape',
157
- contextmenu: 'openLinks',
158
- lint: 'lint',
159
- };
160
- localStorage.removeItem(oldKey);
161
- if (oldPrefs) {
162
- const obj = {};
163
- for (const k of oldPrefs) {
164
- if (k in mapping) {
165
- obj[mapping[k]] = true;
166
- }
137
+ }
138
+ /** @todo 以下过渡代码添加于2024-02-07,将于一段时间后弃用 */
139
+ const oldKey = 'Wikiplus-highlight-addons', oldPrefs = getObject(oldKey), mapping = {
140
+ activeLine: 'highlightActiveLine',
141
+ trailingspace: 'highlightTrailingWhitespace',
142
+ matchBrackets: 'bracketMatching',
143
+ closeBrackets: 'closeBrackets',
144
+ matchTags: 'tagMatching',
145
+ fold: 'codeFolding',
146
+ wikiEditor: 'wikiEditor',
147
+ escape: 'escape',
148
+ contextmenu: 'openLinks',
149
+ lint: 'lint',
150
+ };
151
+ localStorage.removeItem(oldKey);
152
+ if (oldPrefs) {
153
+ const obj = {};
154
+ for (const k of oldPrefs) {
155
+ if (k in mapping) {
156
+ obj[mapping[k]] = true;
167
157
  }
168
- cm.prefer(obj);
169
158
  }
159
+ cm.prefer(obj);
170
160
  }
171
161
  const jump = document.querySelector('#Wikiplus-Quickedit-Jump > a');
172
162
  if (jump) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikiplus-highlight",
3
- "version": "3.1.1",
3
+ "version": "3.2.1",
4
4
  "description": "A plugin for the MediaWiki front-end add-on \"Wikiplus\"",
5
5
  "keywords": [
6
6
  "mediawiki",
@@ -29,11 +29,11 @@
29
29
  "build": "tsc"
30
30
  },
31
31
  "devDependencies": {
32
- "@bhsd/codemirror-mediawiki": "^2.6.8",
32
+ "@bhsd/codemirror-mediawiki": "^2.10.0",
33
33
  "@stylistic/eslint-plugin": "^1.5.4",
34
34
  "@stylistic/stylelint-plugin": "^2.0.0",
35
35
  "@types/jquery": "^3.5.29",
36
- "@types/oojs-ui": "^0.47.6",
36
+ "@types/oojs-ui": "^0.49.0",
37
37
  "@typescript-eslint/eslint-plugin": "^7.1.0",
38
38
  "@typescript-eslint/parser": "^7.1.0",
39
39
  "eslint": "^8.56.0",
@@ -43,8 +43,8 @@
43
43
  "eslint-plugin-json-es": "^1.5.7",
44
44
  "eslint-plugin-promise": "^6.1.1",
45
45
  "eslint-plugin-regexp": "^2.2.0",
46
- "eslint-plugin-unicorn": "^51.0.1",
47
- "monaco-wiki": "^0.2.0",
46
+ "eslint-plugin-unicorn": "^52.0.0",
47
+ "monaco-editor": "^0.48.0",
48
48
  "stylelint": "^16.1.0",
49
49
  "stylelint-config-recommended": "^14.0.0",
50
50
  "types-mediawiki": "^1.4.0",