wikiplus-highlight 3.1.1 → 3.2.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 (2) hide show
  1. package/dist/main.js +37 -52
  2. package/package.json +5 -5
package/dist/main.js CHANGED
@@ -9,23 +9,14 @@
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.0';
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 = (async () => {
17
+ await $.ajax(`${CDN}/${MW_CDN}`, { dataType: 'script', scriptAttrs: { type: 'module' } });
18
+ return CodeMirror6;
19
+ })());
29
20
  const { wgPageName: page, wgNamespaceNumber: ns, wgPageContentModel: contentmodel, } = mw.config.get();
30
21
  const CONTENTMODELS = {
31
22
  'sanitized-css': 'css',
@@ -109,12 +100,13 @@
109
100
  * @param setting 是否是Wikiplus设置(使用json语法)
110
101
  */
111
102
  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 => {
103
+ var _a;
104
+ const settings = getObject('Wikiplus_Settings'), escToExitQuickEdit = settings && (settings['esc_to_exit_quickedit'] || settings['escToExitQuickEdit']), esc = escToExitQuickEdit === true || escToExitQuickEdit === 'true';
105
+ const cm = await (await CodeMirror6).fromTextArea($target[0], ...setting ? ['json'] : await getPageMode($target.val()));
106
+ (((_a = cm.view) === null || _a === void 0 ? void 0 : _a.dom) || cm.editor.getDomNode()).id = 'Wikiplus-CodeMirror';
107
+ if (!setting) { // 普通Wikiplus编辑区
108
+ if (cm.editor) {
109
+ cm.editor.onKeyUp(e => {
118
110
  if (e.keyCode === 49 && (e.ctrlKey || e.metaKey)) {
119
111
  e.preventDefault();
120
112
  if (e.shiftKey) {
@@ -124,49 +116,42 @@
124
116
  submit();
125
117
  }
126
118
  }
127
- else if (e.keyCode === 9
128
- && (escToExitQuickEdit === true || escToExitQuickEdit === 'true')) {
119
+ else if (e.keyCode === 9 && esc) {
129
120
  e.preventDefault();
130
121
  escapeEdit();
131
122
  }
132
123
  });
133
124
  }
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编辑区
125
+ else {
139
126
  cm.extraKeys([
140
127
  { key: 'Mod-S', run: submit },
141
128
  { key: 'Shift-Mod-S', run: submitMinor },
142
- ...escToExitQuickEdit === true || escToExitQuickEdit === 'true'
143
- ? [{ key: 'Esc', run: escapeEdit }]
144
- : [],
129
+ ...esc ? [{ key: 'Esc', run: escapeEdit }] : [],
145
130
  ]);
146
131
  }
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
- }
132
+ }
133
+ /** @todo 以下过渡代码添加于2024-02-07,将于一段时间后弃用 */
134
+ const oldKey = 'Wikiplus-highlight-addons', oldPrefs = getObject(oldKey), mapping = {
135
+ activeLine: 'highlightActiveLine',
136
+ trailingspace: 'highlightTrailingWhitespace',
137
+ matchBrackets: 'bracketMatching',
138
+ closeBrackets: 'closeBrackets',
139
+ matchTags: 'tagMatching',
140
+ fold: 'codeFolding',
141
+ wikiEditor: 'wikiEditor',
142
+ escape: 'escape',
143
+ contextmenu: 'openLinks',
144
+ lint: 'lint',
145
+ };
146
+ localStorage.removeItem(oldKey);
147
+ if (oldPrefs) {
148
+ const obj = {};
149
+ for (const k of oldPrefs) {
150
+ if (k in mapping) {
151
+ obj[mapping[k]] = true;
167
152
  }
168
- cm.prefer(obj);
169
153
  }
154
+ cm.prefer(obj);
170
155
  }
171
156
  const jump = document.querySelector('#Wikiplus-Quickedit-Jump > a');
172
157
  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.0",
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",