mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
This commit is contained in:
parent
dc1525686c
commit
97c4878376
4 changed files with 128 additions and 117 deletions
|
|
@ -373,6 +373,10 @@ export class Plugin {
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public updateProtyleToolbar(toolbar: Array<string | IMenuItem>) {
|
||||||
|
return toolbar;
|
||||||
|
}
|
||||||
|
|
||||||
set protyleOptions(options: IProtyleOptions) {
|
set protyleOptions(options: IProtyleOptions) {
|
||||||
this.protyleOptionsValue = options;
|
this.protyleOptionsValue = options;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ import {insertEmptyBlock} from "../../block/util";
|
||||||
import {matchHotKey} from "../util/hotKey";
|
import {matchHotKey} from "../util/hotKey";
|
||||||
import {hideElements} from "../ui/hideElements";
|
import {hideElements} from "../ui/hideElements";
|
||||||
import {electronUndo} from "../undo";
|
import {electronUndo} from "../undo";
|
||||||
import {previewTemplate} from "./util";
|
import {previewTemplate, toolbarKeyToMenu} from "./util";
|
||||||
import {hideMessage, showMessage} from "../../dialog/message";
|
import {hideMessage, showMessage} from "../../dialog/message";
|
||||||
import {InlineMath} from "./InlineMath";
|
import {InlineMath} from "./InlineMath";
|
||||||
import {InlineMemo} from "./InlineMemo";
|
import {InlineMemo} from "./InlineMemo";
|
||||||
|
|
@ -68,7 +68,9 @@ export class Toolbar {
|
||||||
this.subElement.className = "protyle-util fn__none";
|
this.subElement.className = "protyle-util fn__none";
|
||||||
/// #endif
|
/// #endif
|
||||||
this.toolbarHeight = 29;
|
this.toolbarHeight = 29;
|
||||||
|
protyle.app.plugins.forEach(item => {
|
||||||
|
options.toolbar = toolbarKeyToMenu(item.updateProtyleToolbar(options.toolbar));
|
||||||
|
});
|
||||||
options.toolbar.forEach((menuItem: IMenuItem) => {
|
options.toolbar.forEach((menuItem: IMenuItem) => {
|
||||||
const itemElement = this.genItem(protyle, menuItem);
|
const itemElement = this.genItem(protyle, menuItem);
|
||||||
this.element.appendChild(itemElement);
|
this.element.appendChild(itemElement);
|
||||||
|
|
|
||||||
|
|
@ -95,3 +95,121 @@ export const removeInlineType = (inlineElement: HTMLElement, type: string, range
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const toolbarKeyToMenu = (toolbar: Array<string | IMenuItem>) => {
|
||||||
|
const toolbarItem: IMenuItem [] = [{
|
||||||
|
name: "block-ref",
|
||||||
|
hotkey: window.siyuan.config.keymap.editor.insert.ref.custom,
|
||||||
|
lang: "ref",
|
||||||
|
icon: "iconRef",
|
||||||
|
tipPosition: "ne",
|
||||||
|
}, {
|
||||||
|
name: "a",
|
||||||
|
hotkey: window.siyuan.config.keymap.editor.insert.link.custom,
|
||||||
|
lang: "link",
|
||||||
|
icon: "iconLink",
|
||||||
|
tipPosition: "n",
|
||||||
|
}, {
|
||||||
|
name: "strong",
|
||||||
|
lang: "bold",
|
||||||
|
hotkey: window.siyuan.config.keymap.editor.insert.bold.custom,
|
||||||
|
icon: "iconBold",
|
||||||
|
tipPosition: "n",
|
||||||
|
}, {
|
||||||
|
name: "em",
|
||||||
|
lang: "italic",
|
||||||
|
hotkey: window.siyuan.config.keymap.editor.insert.italic.custom,
|
||||||
|
icon: "iconItalic",
|
||||||
|
tipPosition: "n",
|
||||||
|
}, {
|
||||||
|
name: "u",
|
||||||
|
lang: "underline",
|
||||||
|
hotkey: window.siyuan.config.keymap.editor.insert.underline.custom,
|
||||||
|
icon: "iconUnderline",
|
||||||
|
tipPosition: "n",
|
||||||
|
}, {
|
||||||
|
name: "s",
|
||||||
|
lang: "strike",
|
||||||
|
hotkey: window.siyuan.config.keymap.editor.insert.strike.custom,
|
||||||
|
icon: "iconStrike",
|
||||||
|
tipPosition: "n",
|
||||||
|
}, {
|
||||||
|
name: "mark",
|
||||||
|
lang: "mark",
|
||||||
|
hotkey: window.siyuan.config.keymap.editor.insert.mark.custom,
|
||||||
|
icon: "iconMark",
|
||||||
|
tipPosition: "n",
|
||||||
|
}, {
|
||||||
|
name: "sup",
|
||||||
|
lang: "sup",
|
||||||
|
hotkey: window.siyuan.config.keymap.editor.insert.sup.custom,
|
||||||
|
icon: "iconSup",
|
||||||
|
tipPosition: "n",
|
||||||
|
}, {
|
||||||
|
name: "sub",
|
||||||
|
lang: "sub",
|
||||||
|
hotkey: window.siyuan.config.keymap.editor.insert.sub.custom,
|
||||||
|
icon: "iconSub",
|
||||||
|
tipPosition: "n",
|
||||||
|
}, {
|
||||||
|
name: "kbd",
|
||||||
|
lang: "kbd",
|
||||||
|
hotkey: window.siyuan.config.keymap.editor.insert.kbd.custom,
|
||||||
|
icon: "iconKeymap",
|
||||||
|
tipPosition: "n",
|
||||||
|
}, {
|
||||||
|
name: "tag",
|
||||||
|
lang: "tag",
|
||||||
|
hotkey: window.siyuan.config.keymap.editor.insert.tag.custom,
|
||||||
|
icon: "iconTags",
|
||||||
|
tipPosition: "n",
|
||||||
|
}, {
|
||||||
|
name: "code",
|
||||||
|
lang: "inline-code",
|
||||||
|
hotkey: window.siyuan.config.keymap.editor.insert["inline-code"].custom,
|
||||||
|
icon: "iconInlineCode",
|
||||||
|
tipPosition: "n",
|
||||||
|
}, {
|
||||||
|
name: "inline-math",
|
||||||
|
lang: "inline-math",
|
||||||
|
hotkey: window.siyuan.config.keymap.editor.insert["inline-math"].custom,
|
||||||
|
icon: "iconMath",
|
||||||
|
tipPosition: "n",
|
||||||
|
}, {
|
||||||
|
name: "inline-memo",
|
||||||
|
lang: "memo",
|
||||||
|
hotkey: window.siyuan.config.keymap.editor.insert.memo.custom,
|
||||||
|
icon: "iconM",
|
||||||
|
tipPosition: "n",
|
||||||
|
}, {
|
||||||
|
name: "text",
|
||||||
|
lang: "appearance",
|
||||||
|
hotkey: window.siyuan.config.keymap.editor.insert.appearance.custom,
|
||||||
|
icon: "iconFont",
|
||||||
|
tipPosition: "n",
|
||||||
|
}, {
|
||||||
|
name: "clear",
|
||||||
|
lang: "clearInline",
|
||||||
|
hotkey: window.siyuan.config.keymap.editor.insert.clearInline.custom,
|
||||||
|
icon: "iconClear",
|
||||||
|
tipPosition: "n",
|
||||||
|
}, {
|
||||||
|
name: "|",
|
||||||
|
}];
|
||||||
|
const toolbarResult: IMenuItem[] = [];
|
||||||
|
toolbar.forEach((menuItem: IMenuItem) => {
|
||||||
|
let currentMenuItem = menuItem;
|
||||||
|
toolbarItem.find((defaultMenuItem: IMenuItem) => {
|
||||||
|
if (typeof menuItem === "string" && defaultMenuItem.name === menuItem) {
|
||||||
|
currentMenuItem = defaultMenuItem;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (typeof menuItem === "object" && defaultMenuItem.name === menuItem.name) {
|
||||||
|
currentMenuItem = Object.assign({}, defaultMenuItem, menuItem);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
toolbarResult.push(currentMenuItem);
|
||||||
|
});
|
||||||
|
return toolbarResult;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {Constants} from "../../constants";
|
||||||
import {merge} from "./merge";
|
import {merge} from "./merge";
|
||||||
import {hintEmbed, hintRef, hintSlash, hintTag} from "../hint/extend";
|
import {hintEmbed, hintRef, hintSlash, hintTag} from "../hint/extend";
|
||||||
import {isMobile} from "../../util/functions";
|
import {isMobile} from "../../util/functions";
|
||||||
|
import {toolbarKeyToMenu} from "../toolbar/util";
|
||||||
|
|
||||||
export class Options {
|
export class Options {
|
||||||
public options: IProtyleOptions;
|
public options: IProtyleOptions;
|
||||||
|
|
@ -152,120 +153,6 @@ export class Options {
|
||||||
}
|
}
|
||||||
|
|
||||||
private mergeToolbar(toolbar: Array<string | IMenuItem>) {
|
private mergeToolbar(toolbar: Array<string | IMenuItem>) {
|
||||||
const toolbarItem: IMenuItem [] = [{
|
return toolbarKeyToMenu(toolbar);
|
||||||
name: "block-ref",
|
|
||||||
hotkey: window.siyuan.config.keymap.editor.insert.ref.custom,
|
|
||||||
lang: "ref",
|
|
||||||
icon: "iconRef",
|
|
||||||
tipPosition: "ne",
|
|
||||||
}, {
|
|
||||||
name: "a",
|
|
||||||
hotkey: window.siyuan.config.keymap.editor.insert.link.custom,
|
|
||||||
lang: "link",
|
|
||||||
icon: "iconLink",
|
|
||||||
tipPosition: "n",
|
|
||||||
}, {
|
|
||||||
name: "strong",
|
|
||||||
lang: "bold",
|
|
||||||
hotkey: window.siyuan.config.keymap.editor.insert.bold.custom,
|
|
||||||
icon: "iconBold",
|
|
||||||
tipPosition: "n",
|
|
||||||
}, {
|
|
||||||
name: "em",
|
|
||||||
lang: "italic",
|
|
||||||
hotkey: window.siyuan.config.keymap.editor.insert.italic.custom,
|
|
||||||
icon: "iconItalic",
|
|
||||||
tipPosition: "n",
|
|
||||||
}, {
|
|
||||||
name: "u",
|
|
||||||
lang: "underline",
|
|
||||||
hotkey: window.siyuan.config.keymap.editor.insert.underline.custom,
|
|
||||||
icon: "iconUnderline",
|
|
||||||
tipPosition: "n",
|
|
||||||
}, {
|
|
||||||
name: "s",
|
|
||||||
lang: "strike",
|
|
||||||
hotkey: window.siyuan.config.keymap.editor.insert.strike.custom,
|
|
||||||
icon: "iconStrike",
|
|
||||||
tipPosition: "n",
|
|
||||||
}, {
|
|
||||||
name: "mark",
|
|
||||||
lang: "mark",
|
|
||||||
hotkey: window.siyuan.config.keymap.editor.insert.mark.custom,
|
|
||||||
icon: "iconMark",
|
|
||||||
tipPosition: "n",
|
|
||||||
}, {
|
|
||||||
name: "sup",
|
|
||||||
lang: "sup",
|
|
||||||
hotkey: window.siyuan.config.keymap.editor.insert.sup.custom,
|
|
||||||
icon: "iconSup",
|
|
||||||
tipPosition: "n",
|
|
||||||
}, {
|
|
||||||
name: "sub",
|
|
||||||
lang: "sub",
|
|
||||||
hotkey: window.siyuan.config.keymap.editor.insert.sub.custom,
|
|
||||||
icon: "iconSub",
|
|
||||||
tipPosition: "n",
|
|
||||||
}, {
|
|
||||||
name: "kbd",
|
|
||||||
lang: "kbd",
|
|
||||||
hotkey: window.siyuan.config.keymap.editor.insert.kbd.custom,
|
|
||||||
icon: "iconKeymap",
|
|
||||||
tipPosition: "n",
|
|
||||||
}, {
|
|
||||||
name: "tag",
|
|
||||||
lang: "tag",
|
|
||||||
hotkey: window.siyuan.config.keymap.editor.insert.tag.custom,
|
|
||||||
icon: "iconTags",
|
|
||||||
tipPosition: "n",
|
|
||||||
}, {
|
|
||||||
name: "code",
|
|
||||||
lang: "inline-code",
|
|
||||||
hotkey: window.siyuan.config.keymap.editor.insert["inline-code"].custom,
|
|
||||||
icon: "iconInlineCode",
|
|
||||||
tipPosition: "n",
|
|
||||||
}, {
|
|
||||||
name: "inline-math",
|
|
||||||
lang: "inline-math",
|
|
||||||
hotkey: window.siyuan.config.keymap.editor.insert["inline-math"].custom,
|
|
||||||
icon: "iconMath",
|
|
||||||
tipPosition: "n",
|
|
||||||
}, {
|
|
||||||
name: "inline-memo",
|
|
||||||
lang: "memo",
|
|
||||||
hotkey: window.siyuan.config.keymap.editor.insert.memo.custom,
|
|
||||||
icon: "iconM",
|
|
||||||
tipPosition: "n",
|
|
||||||
}, {
|
|
||||||
name: "text",
|
|
||||||
lang: "appearance",
|
|
||||||
hotkey: window.siyuan.config.keymap.editor.insert.appearance.custom,
|
|
||||||
icon: "iconFont",
|
|
||||||
tipPosition: "n",
|
|
||||||
}, {
|
|
||||||
name: "clear",
|
|
||||||
lang: "clearInline",
|
|
||||||
hotkey: window.siyuan.config.keymap.editor.insert.clearInline.custom,
|
|
||||||
icon: "iconClear",
|
|
||||||
tipPosition: "n",
|
|
||||||
}, {
|
|
||||||
name: "|",
|
|
||||||
}];
|
|
||||||
const toolbarResult: IMenuItem[] = [];
|
|
||||||
toolbar.forEach((menuItem: IMenuItem) => {
|
|
||||||
let currentMenuItem = menuItem;
|
|
||||||
toolbarItem.find((defaultMenuItem: IMenuItem) => {
|
|
||||||
if (typeof menuItem === "string" && defaultMenuItem.name === menuItem) {
|
|
||||||
currentMenuItem = defaultMenuItem;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (typeof menuItem === "object" && defaultMenuItem.name === menuItem.name) {
|
|
||||||
currentMenuItem = Object.assign({}, defaultMenuItem, menuItem);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
toolbarResult.push(currentMenuItem);
|
|
||||||
});
|
|
||||||
return toolbarResult;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue