Vanessa 2024-11-11 12:52:02 +08:00
parent 6b6ce37ca2
commit 76141021d0
16 changed files with 67 additions and 45 deletions

View file

@ -699,6 +699,40 @@ export abstract class Constants {
public static readonly SIYUAN_RENDER_CODE_LANGUAGES: string[] = [
"abc", "plantuml", "mermaid", "flowchart", "echarts", "mindmap", "graphviz", "math"
];
public static readonly PROTYLE_TOOLBAR: string[] = isMobile() ? [
"block-ref",
"a",
"|",
"text",
"strong",
"em",
"u",
"clear",
"|",
"code",
"tag",
"inline-math",
"inline-memo",
] : [
"block-ref",
"a",
"|",
"text",
"strong",
"em",
"u",
"s",
"mark",
"sup",
"sub",
"clear",
"|",
"code",
"kbd",
"tag",
"inline-math",
"inline-memo",
]
// Google Analytics 事件
public static readonly ANALYTICS_EVT_ON_GET_CONFIG: string = "siyuan.onGetConfig";

View file

@ -9,6 +9,7 @@ import {getFrontend, isMobile, isWindow} from "../util/functions";
import {Constants} from "../constants";
import {uninstall} from "./uninstall";
import {setStorageVal} from "../protyle/util/compatibility";
import { getAllEditor } from "../layout/getAll";
const requireFunc = (key: string) => {
const modules = {
@ -85,6 +86,9 @@ export const loadPlugin = async (app: App, item: IPluginData) => {
document.head.append(styleElement);
afterLoadPlugin(plugin);
saveLayout();
getAllEditor().forEach(editor => {
editor.protyle.toolbar.update(editor.protyle);
});
return plugin;
};

View file

@ -6,6 +6,7 @@ import {resizeTopBar} from "../layout/util";
/// #endif
import {Constants} from "../constants";
import {setStorageVal} from "../protyle/util/compatibility";
import {getAllEditor} from "../layout/getAll";
export const uninstall = (app: App, name: string, isUninstall = false) => {
app.plugins.find((plugin: Plugin, index) => {
@ -61,6 +62,10 @@ export const uninstall = (app: App, name: string, isUninstall = false) => {
});
// rm plugin
app.plugins.splice(index, 1);
// rm protyle toolbar
getAllEditor().forEach(editor => {
editor.protyle.toolbar.update(editor.protyle);
});
return true;
}
});

View file

@ -77,6 +77,18 @@ export class Toolbar {
});
}
public update(protyle: IProtyle) {
this.element.innerHTML = "";
protyle.options.toolbar = toolbarKeyToMenu(Constants.PROTYLE_TOOLBAR);
protyle.app.plugins.forEach(item => {
protyle.options.toolbar = toolbarKeyToMenu(item.updateProtyleToolbar(protyle.options.toolbar));
});
protyle.options.toolbar.forEach((menuItem: IMenuItem) => {
const itemElement = this.genItem(protyle, menuItem);
this.element.appendChild(itemElement);
});
}
public render(protyle: IProtyle, range: Range, event?: KeyboardEvent) {
this.range = range;
let nodeElement = hasClosestBlock(range.startContainer);

View file

@ -87,40 +87,7 @@ export class Options {
},
mode: "both",
},
toolbar: isMobile() ? [
"block-ref",
"a",
"|",
"text",
"strong",
"em",
"u",
"clear",
"|",
"code",
"tag",
"inline-math",
"inline-memo",
] : [
"block-ref",
"a",
"|",
"text",
"strong",
"em",
"u",
"s",
"mark",
"sup",
"sub",
"clear",
"|",
"code",
"kbd",
"tag",
"inline-math",
"inline-memo",
],
toolbar: Constants.PROTYLE_TOOLBAR,
typewriterMode: false,
upload: {
max: 1024 * 1024 * 1024 * 4,