Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/10090

Vanessa473df4b185b7
diff --git a/app/src/plugin/index.ts b/app/src/plugin/index.ts
index 512b88241e..9cf7babac6 100644
--- a/app/src/plugin/index.ts
+++ b/app/src/plugin/index.ts
@@ -56,6 +56,7 @@ export class Plugin {
/// #endif
}
} = {};
+ private protyleOptionsValue: IOptions;
constructor(options: {
app: App,
@@ -307,4 +308,12 @@ export class Plugin {
defIds: options.defIds,
}));
};
+
+ set protyleOptions(options: IOptions) {
+ this.protyleOptionsValue = options;
+ }
+
+ get protyleOptions() {
+ return this.protyleOptionsValue;
+ }
}
diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts
index 5195f48bc2..7c5b61c9dd 100644
--- a/app/src/protyle/index.ts
+++ b/app/src/protyle/index.ts
@@ -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,
diff --git a/app/src/protyle/toolbar/ToolbarItem.ts b/app/src/protyle/toolbar/ToolbarItem.ts
index f5847ba467..11e8a8db21 100644
--- a/app/src/protyle/toolbar/ToolbarItem.ts
+++ b/app/src/protyle/toolbar/ToolbarItem.ts
@@ -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());
+ }
});
}
}
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index 4564ac22a6..ce2fbb239e 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -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;
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index 87671c386e..93d1577c71 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -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;
}
diff --git a/app/src/types/protyle.d.ts b/app/src/types/protyle.d.ts
index 32cfd703b8..5d70e57fe4 100644
--- a/app/src/types/protyle.d.ts
+++ b/app/src/types/protyle.d.ts
@@ -303,15 +303,18 @@ interface IUpload {
interface IMenuItem {
/** 唯一标示 */
name: string;
+ /** 提示 */
+ tip?: string;
+ /** 语言 key */
lang?: string;
/** svg 图标 */
icon?: string;
- /** 提示 */
- tip?: string;
/** 快捷键 */
hotkey?: string;
- /** 插入编辑器中的后缀 */
+ /** 提示的位置 */
tipPosition?: string;
+
+ click?(protyle: import("../protyle").Protyle): void;
}
/** @link https://ld246.com/article/1549638745630#options-preview-markdown */