Vanessa 2024-01-06 20:41:02 +08:00
parent 013b06dcce
commit 473df4b185
6 changed files with 35 additions and 7 deletions

View file

@ -40,6 +40,7 @@ import {avRender} from "./render/av/render";
import {focusBlock, getEditorRange} from "./util/selection";
import {hasClosestBlock} from "./util/hasClosest";
import {setStorageVal} from "./util/compatibility";
import {merge} from "./util/merge";
export class Protyle {
@ -52,9 +53,14 @@ export class Protyle {
*/
constructor(app: App, id: HTMLElement, options?: IOptions) {
this.version = Constants.SIYUAN_VERSION;
const getOptions = new Options(options);
let pluginsOptions: IOptions = options;
app.plugins.forEach(item => {
if (item.protyleOptions) {
pluginsOptions = merge(pluginsOptions, item.protyleOptions);
}
})
const getOptions = new Options(pluginsOptions);
const mergedOptions = getOptions.merge();
this.protyle = {
getInstance: () => this,
app,

View file

@ -1,5 +1,6 @@
import {getEventName} from "../util/compatibility";
import {updateHotkeyTip} from "../util/compatibility";
import {Constants} from "../../constants";
export class ToolbarItem {
public element: HTMLElement;
@ -17,7 +18,11 @@ export class ToolbarItem {
}
this.element.addEventListener(getEventName(), (event) => {
event.preventDefault();
protyle.toolbar.setInlineMark(protyle, menuItem.name, "toolbar");
if (Constants.INLINE_TYPE.includes(menuItem.name)) {
protyle.toolbar.setInlineMark(protyle, menuItem.name, "toolbar");
} else if (menuItem.click) {
menuItem.click(protyle.getInstance());
}
});
}
}

View file

@ -229,6 +229,9 @@ export class Toolbar {
case "a":
menuItemObj = new Link(protyle, menuItem);
break;
default:
menuItemObj = new ToolbarItem(protyle, menuItem);
break;
}
if (!menuItemObj) {
return;

View file

@ -1288,8 +1288,10 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
findToolbar = true;
if (["a", "block-ref", "inline-math", "inline-memo", "text"].includes(menuItem.name)) {
protyle.toolbar.element.querySelector(`[data-type="${menuItem.name}"]`).dispatchEvent(new CustomEvent("click"));
} else {
} else if (Constants.INLINE_TYPE.includes(menuItem.name)) {
protyle.toolbar.setInlineMark(protyle, menuItem.name, "range");
} else if (menuItem.click) {
menuItem.click(protyle.getInstance());
}
return true;
}