Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Nov 7, 2024
1 parent dc15256 commit 97c4878
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 117 deletions.
4 changes: 4 additions & 0 deletions app/src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ export class Plugin {
}));
};

public updateProtyleToolbar(toolbar: Array<string | IMenuItem>) {
return toolbar;
}

set protyleOptions(options: IProtyleOptions) {
this.protyleOptionsValue = options;
}
Expand Down
6 changes: 4 additions & 2 deletions app/src/protyle/toolbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {insertEmptyBlock} from "../../block/util";
import {matchHotKey} from "../util/hotKey";
import {hideElements} from "../ui/hideElements";
import {electronUndo} from "../undo";
import {previewTemplate} from "./util";
import {previewTemplate, toolbarKeyToMenu} from "./util";
import {hideMessage, showMessage} from "../../dialog/message";
import {InlineMath} from "./InlineMath";
import {InlineMemo} from "./InlineMemo";
Expand Down Expand Up @@ -68,7 +68,9 @@ export class Toolbar {
this.subElement.className = "protyle-util fn__none";
/// #endif
this.toolbarHeight = 29;

protyle.app.plugins.forEach(item => {
options.toolbar = toolbarKeyToMenu(item.updateProtyleToolbar(options.toolbar));
});
options.toolbar.forEach((menuItem: IMenuItem) => {
const itemElement = this.genItem(protyle, menuItem);
this.element.appendChild(itemElement);
Expand Down
118 changes: 118 additions & 0 deletions app/src/protyle/toolbar/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
117 changes: 2 additions & 115 deletions app/src/protyle/util/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Constants} from "../../constants";
import {merge} from "./merge";
import {hintEmbed, hintRef, hintSlash, hintTag} from "../hint/extend";
import {isMobile} from "../../util/functions";
import {toolbarKeyToMenu} from "../toolbar/util";

export class Options {
public options: IProtyleOptions;
Expand Down Expand Up @@ -152,120 +153,6 @@ export class Options {
}

private mergeToolbar(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;
return toolbarKeyToMenu(toolbar);
}
}

0 comments on commit 97c4878

Please sign in to comment.