父节点
3c77069618
当前提交
83674d879f
|
@ -552,11 +552,13 @@
|
|||
"unicorn/no-array-method-this-argument": 2,
|
||||
"unicorn/no-array-push-push": 2,
|
||||
"unicorn/no-array-reduce": 2,
|
||||
"unicorn/no-await-in-promise-methods": 2,
|
||||
"unicorn/no-instanceof-array": 2,
|
||||
"unicorn/no-invalid-remove-event-listener": 2,
|
||||
"unicorn/no-lonely-if": 2,
|
||||
"unicorn/no-negated-condition": 2,
|
||||
"unicorn/no-object-as-default-parameter": 2,
|
||||
"unicorn/no-single-promise-in-promise-methods": 2,
|
||||
"unicorn/no-static-only-class": 2,
|
||||
"unicorn/no-this-assignment": 2,
|
||||
"unicorn/no-typeof-undefined": [
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "npm" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
target-branch: "main"
|
||||
assignees:
|
||||
- "bhsd-harry"
|
||||
commit-message:
|
||||
prefix: "npm"
|
||||
versioning-strategy: increase-if-necessary
|
||||
ignore:
|
||||
- dependency-name: "*"
|
||||
update-types: ["version-update:semver-minor"]
|
|
@ -1,3 +1,11 @@
|
|||
## v3.2.0
|
||||
|
||||
*2024-05-01*
|
||||
|
||||
**Changed**
|
||||
|
||||
- Alternative highlighting with [Monaco Editor](https://microsoft.github.io/monaco-editor/) is now provided by [CodeMirror-MediaWiki](https://github.com/bhsd-harry/codemirror-mediawiki)
|
||||
|
||||
## v3.1.0
|
||||
|
||||
*2024-04-19*
|
||||
|
|
|
@ -29,11 +29,11 @@
|
|||
"build": "tsc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@bhsd/codemirror-mediawiki": "^2.6.8",
|
||||
"@bhsd/codemirror-mediawiki": "^2.10.0",
|
||||
"@stylistic/eslint-plugin": "^1.5.4",
|
||||
"@stylistic/stylelint-plugin": "^2.0.0",
|
||||
"@types/jquery": "^3.5.29",
|
||||
"@types/oojs-ui": "^0.47.6",
|
||||
"@types/oojs-ui": "^0.49.0",
|
||||
"@typescript-eslint/eslint-plugin": "^7.1.0",
|
||||
"@typescript-eslint/parser": "^7.1.0",
|
||||
"eslint": "^8.56.0",
|
||||
|
@ -43,8 +43,8 @@
|
|||
"eslint-plugin-json-es": "^1.5.7",
|
||||
"eslint-plugin-promise": "^6.1.1",
|
||||
"eslint-plugin-regexp": "^2.2.0",
|
||||
"eslint-plugin-unicorn": "^51.0.1",
|
||||
"monaco-wiki": "^0.2.0",
|
||||
"eslint-plugin-unicorn": "^52.0.0",
|
||||
"monaco-editor": "^0.48.0",
|
||||
"stylelint": "^16.1.0",
|
||||
"stylelint-config-recommended": "^14.0.0",
|
||||
"types-mediawiki": "^1.4.0",
|
||||
|
|
|
@ -1,27 +1,21 @@
|
|||
import 'types-mediawiki';
|
||||
import type {KeyCode} from 'monaco-editor';
|
||||
import type {MonacoWikiEditor} from 'monaco-wiki/dist/mw/base';
|
||||
import type {editor, KeyCode} from 'monaco-editor';
|
||||
import type {CodeMirror6} from '@bhsd/codemirror-mediawiki';
|
||||
|
||||
interface MonacoEditor {
|
||||
fromTextArea(textarea: HTMLTextAreaElement, lang?: string): Promise<MonacoWikiEditor>;
|
||||
interface CodeMirror extends CodeMirror6 {
|
||||
editor?: editor.IStandaloneCodeEditor;
|
||||
}
|
||||
|
||||
interface CodeMirror {
|
||||
fromTextArea(textarea: HTMLTextAreaElement, lang?: string, ns?: number): Promise<CodeMirror6>;
|
||||
interface CodeMirrorStatic {
|
||||
fromTextArea(textarea: HTMLTextAreaElement, lang?: string, ns?: number): Promise<CodeMirror>;
|
||||
}
|
||||
|
||||
type MonacoOrPromise = MonacoEditor | Promise<MonacoEditor>;
|
||||
type CodeMirrorOrPromise = CodeMirror | Promise<CodeMirror>;
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
MonacoWikiEditor: MonacoOrPromise | undefined;
|
||||
CodeMirror6: CodeMirrorOrPromise | undefined;
|
||||
CodeMirror6: Promise<CodeMirrorStatic> | undefined;
|
||||
}
|
||||
|
||||
const MonacoWikiEditor: MonacoOrPromise;
|
||||
const CodeMirror6: CodeMirrorOrPromise;
|
||||
const CodeMirror6: CodeMirrorStatic | Promise<CodeMirrorStatic>;
|
||||
|
||||
const _WikiplusPages: Record<number, {title: string, sectionCache: Record<string, string>}> | undefined;
|
||||
|
||||
|
|
107
src/main.ts
107
src/main.ts
|
@ -7,8 +7,6 @@
|
|||
declare interface WPHL {
|
||||
version?: string;
|
||||
cmVersion?: string;
|
||||
monacoVersion?: string;
|
||||
useMonaco?: boolean;
|
||||
}
|
||||
|
||||
((): void => {
|
||||
|
@ -23,27 +21,12 @@ declare interface WPHL {
|
|||
// 路径
|
||||
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';
|
||||
|
||||
const useMonaco = wphl?.useMonaco;
|
||||
if (useMonaco) {
|
||||
window.MonacoWikiEditor ||= (async () => {
|
||||
await $.ajax(
|
||||
`${CDN}/${MONACO_CDN}`,
|
||||
{dataType: 'script', scriptAttrs: {type: 'module'}} as JQuery.AjaxSettings,
|
||||
);
|
||||
return MonacoWikiEditor;
|
||||
})();
|
||||
} else {
|
||||
window.CodeMirror6 ||= (async () => {
|
||||
await $.ajax(
|
||||
`${CDN}/${MW_CDN}`,
|
||||
{dataType: 'script', scriptAttrs: {type: 'module'}} as JQuery.AjaxSettings,
|
||||
);
|
||||
return CodeMirror6;
|
||||
})();
|
||||
}
|
||||
window.CodeMirror6 ||= (async () => {
|
||||
await $.ajax(`${CDN}/${MW_CDN}`, {dataType: 'script', scriptAttrs: {type: 'module'}} as JQuery.AjaxSettings);
|
||||
return CodeMirror6;
|
||||
})();
|
||||
|
||||
const {
|
||||
wgPageName: page,
|
||||
|
@ -142,15 +125,18 @@ declare interface WPHL {
|
|||
*/
|
||||
const renderEditor = async ($target: JQuery<HTMLTextAreaElement>, setting: boolean): Promise<void> => {
|
||||
const settings: Record<string, unknown> | null = getObject('Wikiplus_Settings'),
|
||||
escToExitQuickEdit = settings && (settings['esc_to_exit_quickedit'] || settings['escToExitQuickEdit']);
|
||||
escToExitQuickEdit = settings && (settings['esc_to_exit_quickedit'] || settings['escToExitQuickEdit']),
|
||||
esc = escToExitQuickEdit === true || escToExitQuickEdit === 'true';
|
||||
|
||||
if (useMonaco) {
|
||||
const lang = setting ? 'json' : (await getPageMode($target.val()!))[0],
|
||||
{editor} = await (await MonacoWikiEditor).fromTextArea($target[0]!, lang);
|
||||
editor.getDomNode()!.id = 'Wikiplus-CodeMirror';
|
||||
const cm = await (await CodeMirror6).fromTextArea(
|
||||
$target[0]!,
|
||||
...setting ? ['json'] as [string] : await getPageMode($target.val()!),
|
||||
);
|
||||
(cm.view?.dom || cm.editor!.getDomNode()!).id = 'Wikiplus-CodeMirror';
|
||||
|
||||
if (!setting) { // 普通Wikiplus编辑区
|
||||
editor.onKeyUp(e => {
|
||||
if (!setting) { // 普通Wikiplus编辑区
|
||||
if (cm.editor) {
|
||||
cm.editor.onKeyUp(e => {
|
||||
if (e.keyCode === 49 as MonacoKeyCode && (e.ctrlKey || e.metaKey)) {
|
||||
e.preventDefault();
|
||||
if (e.shiftKey) {
|
||||
|
@ -158,57 +144,44 @@ declare interface WPHL {
|
|||
} else {
|
||||
submit();
|
||||
}
|
||||
} else if (
|
||||
e.keyCode === 9 as MonacoKeyCode
|
||||
&& (escToExitQuickEdit === true || escToExitQuickEdit === 'true')
|
||||
) {
|
||||
} else if (e.keyCode === 9 as MonacoKeyCode && esc) {
|
||||
e.preventDefault();
|
||||
escapeEdit();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const cm = await (await CodeMirror6).fromTextArea(
|
||||
$target[0]!,
|
||||
...setting ? ['json'] as [string] : await getPageMode($target.val()!),
|
||||
);
|
||||
cm.view.dom.id = 'Wikiplus-CodeMirror';
|
||||
|
||||
if (!setting) { // 普通Wikiplus编辑区
|
||||
} else {
|
||||
cm.extraKeys([
|
||||
{key: 'Mod-S', run: submit},
|
||||
{key: 'Shift-Mod-S', run: submitMinor},
|
||||
...escToExitQuickEdit === true || escToExitQuickEdit === 'true'
|
||||
? [{key: 'Esc', run: escapeEdit}]
|
||||
: [],
|
||||
...esc ? [{key: 'Esc', run: escapeEdit}] : [],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/** @todo 以下过渡代码添加于2024-02-07,将于一段时间后弃用 */
|
||||
const oldKey = 'Wikiplus-highlight-addons',
|
||||
oldPrefs: string[] | null = getObject(oldKey),
|
||||
mapping: Record<string, string> = {
|
||||
activeLine: 'highlightActiveLine',
|
||||
trailingspace: 'highlightTrailingWhitespace',
|
||||
matchBrackets: 'bracketMatching',
|
||||
closeBrackets: 'closeBrackets',
|
||||
matchTags: 'tagMatching',
|
||||
fold: 'codeFolding',
|
||||
wikiEditor: 'wikiEditor',
|
||||
escape: 'escape',
|
||||
contextmenu: 'openLinks',
|
||||
lint: 'lint',
|
||||
};
|
||||
localStorage.removeItem(oldKey);
|
||||
if (oldPrefs) {
|
||||
const obj: Record<string, true> = {};
|
||||
for (const k of oldPrefs) {
|
||||
if (k in mapping) {
|
||||
obj[mapping[k]!] = true;
|
||||
}
|
||||
/** @todo 以下过渡代码添加于2024-02-07,将于一段时间后弃用 */
|
||||
const oldKey = 'Wikiplus-highlight-addons',
|
||||
oldPrefs: string[] | null = getObject(oldKey),
|
||||
mapping: Record<string, string> = {
|
||||
activeLine: 'highlightActiveLine',
|
||||
trailingspace: 'highlightTrailingWhitespace',
|
||||
matchBrackets: 'bracketMatching',
|
||||
closeBrackets: 'closeBrackets',
|
||||
matchTags: 'tagMatching',
|
||||
fold: 'codeFolding',
|
||||
wikiEditor: 'wikiEditor',
|
||||
escape: 'escape',
|
||||
contextmenu: 'openLinks',
|
||||
lint: 'lint',
|
||||
};
|
||||
localStorage.removeItem(oldKey);
|
||||
if (oldPrefs) {
|
||||
const obj: Record<string, true> = {};
|
||||
for (const k of oldPrefs) {
|
||||
if (k in mapping) {
|
||||
obj[mapping[k]!] = true;
|
||||
}
|
||||
cm.prefer(obj);
|
||||
}
|
||||
cm.prefer(obj);
|
||||
}
|
||||
|
||||
const jump = document.querySelector<HTMLAnchorElement>('#Wikiplus-Quickedit-Jump > a');
|
||||
|
|
正在加载...
在新工单中引用