Skip to content

Commit

Permalink
build(WPHL): update WPHL to 3.2.3 (#1503)
Browse files Browse the repository at this point in the history
* build(WPHL): update WPHL to 3.2.3
  • Loading branch information
WaitSpringQW authored Sep 2, 2024
1 parent 148a0e5 commit 2299999
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 62 deletions.
45 changes: 22 additions & 23 deletions dist/Wikiplus-highlight/Wikiplus-highlight.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"clipboard": "^2.0.11",
"filter-altered-clicks": "^2.1.1",
"jsx-dom": "^8.1.4",
"monaco-editor": "^0.49.0",
"monaco-editor": "^0.50.0",
"select2": "^4.0.13",
"svgo": "^3.3.2",
"tippy.js": "^6.3.7",
Expand Down
24 changes: 14 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 26 additions & 26 deletions src/Wikiplus-highlight/modules/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ declare interface WPHL {
if (wphl?.version) {
return;
}
const version = '3.2.2';
const version = '3.2.3';
libs.wphl = {version, ...wphl}; // 开始加载

// 路径
Expand Down Expand Up @@ -59,9 +59,15 @@ declare interface WPHL {
*
* @param {string} value 页面内容
*/
const getPageMode = async (value: string): Promise<[string, (number | undefined)?]> => {
const getPageMode = async (value: string): Promise<[string, (number | undefined)?, (string | undefined)?]> => {
let WikiplusPages;
if (typeof _WikiplusPages === 'object') {
const pages = Object.values(_WikiplusPages).filter(({sectionCache}) => {
WikiplusPages = _WikiplusPages;
} else if (typeof Pages === 'object') {
WikiplusPages = Pages;
}
if (WikiplusPages) {
const pages = Object.values(WikiplusPages).filter(({sectionCache}) => {
return Object.values(sectionCache).includes(value);
});
if (
Expand Down Expand Up @@ -89,11 +95,12 @@ declare interface WPHL {
})
);
if (modes.size === 1) {
const [mode] = modes;
const [mode] = modes,
title = pages.length === 1 ? pages[0]!.title : undefined;
if (mode === 'gadget') {
return ['javascript', 8];
}
return mode === 'template' ? ['mediawiki', 10] : [mode!];
return mode === 'template' ? ['mediawiki', 10, title] : [mode!, undefined, title];
} else if (modes.size === 2) {
if (modes.has('javascript') && modes.has('gadget')) {
return ['javascript'];
Expand Down Expand Up @@ -124,9 +131,14 @@ declare interface WPHL {
document.querySelector<HTMLInputElement>('#Wikiplus-Quickedit-MinorEdit')!.checked = true;
return submit();
},
escapeEdit = /** 按下Esc键退出编辑 */ (): true => {
document.querySelector('#Wikiplus-Quickedit-Back')!.dispatchEvent(new MouseEvent('click'));
return true;
escapeEdit = /** 按下Esc键退出编辑 */ (): boolean => {
const settings: Record<string, unknown> | null = getObject('Wikiplus_Settings'),
escToExitQuickEdit = settings && (settings['esc_to_exit_quickedit'] || settings['escToExitQuickEdit']);
if (escToExitQuickEdit === true || escToExitQuickEdit === 'true') {
document.querySelector('#Wikiplus-Quickedit-Back')!.dispatchEvent(new MouseEvent('click'));
return true;
}
return false;
};

/**
Expand All @@ -136,10 +148,6 @@ declare interface WPHL {
* @param {boolean} setting 是否是Wikiplus设置(使用json语法)
*/
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']),
esc = escToExitQuickEdit === true || escToExitQuickEdit === 'true';

const cm = await (
await CodeMirror6
).fromTextArea($target[0]!, ...(setting ? (['json'] as [string]) : await getPageMode($target.val()!)));
Expand All @@ -148,24 +156,16 @@ declare interface WPHL {
if (!setting) {
// 普通Wikiplus编辑区
if (cm.editor) {
cm.editor.onKeyDown((e) => {
if (e.keyCode === monaco.KeyCode.KeyS && (e.ctrlKey || e.metaKey)) {
e.preventDefault();
if (e.shiftKey) {
submitMinor();
} else {
submit();
}
} else if (e.keyCode === monaco.KeyCode.Escape && esc) {
e.preventDefault();
escapeEdit();
}
});
/* eslint-disable no-bitwise */
cm.editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, submit);
cm.editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyS, submitMinor);
/* eslint-enable no-bitwise */
cm.editor.addCommand(monaco.KeyCode.Escape, escapeEdit);
} else {
cm.extraKeys([
{key: 'Mod-S', run: submit},
{key: 'Shift-Mod-S', run: submitMinor},
...(esc ? [{key: 'Esc', run: escapeEdit}] : []),
{key: 'Esc', run: escapeEdit},
]);
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/Wikiplus-highlight/modules/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ interface CodeMirror extends CodeMirror6 {
}

interface CodeMirrorStatic {
fromTextArea(textarea: HTMLTextAreaElement, lang?: string, ns?: number): Promise<CodeMirror>;
fromTextArea(textarea: HTMLTextAreaElement, lang?: string, ns?: number, page?: string): Promise<CodeMirror>;
}

type WikiplusPages = Record<number, {title: string; sectionCache: Record<string, string>}>;

declare global {
interface Window {
CodeMirror6: Promise<CodeMirrorStatic> | undefined;
Expand All @@ -20,7 +22,8 @@ declare global {

const monaco: typeof Monaco;

const _WikiplusPages: Record<number, {title: string; sectionCache: Record<string, string>}> | undefined;
const _WikiplusPages: WikiplusPages | undefined;
const Pages: WikiplusPages | undefined;
}

export {};

0 comments on commit 2299999

Please sign in to comment.