Skip to content

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

:heavy_plus_sign: fix https://github.com/siyuan-note/siyuan/issues/9452

Vanessa33dfa0de4e6c
diff --git a/app/src/plugin/EventBus.ts b/app/src/plugin/EventBus.ts
index 86a0051bbd..09e2a956c3 100644
--- a/app/src/plugin/EventBus.ts
+++ b/app/src/plugin/EventBus.ts
@@ -20,7 +20,7 @@ export class EventBus<DetailType = any> {
}
emit(type: TEventBus, detail?: DetailType) {
- return this.eventTarget.dispatchEvent(new CustomEvent(type, {detail}));
+ return this.eventTarget.dispatchEvent(new CustomEvent(type, {detail, cancelable: true}));
}
}
diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts
index 6a1fefeedc..1cb1cbed8a 100644
--- a/app/src/protyle/util/paste.ts
+++ b/app/src/protyle/util/paste.ts
@@ -125,10 +125,10 @@ export const pasteText = (protyle: IProtyle, textPlain: string, nodeElement: Ele
export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEvent) & { target: HTMLElement }) => {
event.stopPropagation();
event.preventDefault();
- let textHTML;
- let textPlain;
- let siyuanHTML;
- let files;
+ let textHTML: string;
+ let textPlain: string;
+ let siyuanHTML: string;
+ let files: FileList | DataTransferItemList;
if ("clipboardData" in event) {
textHTML = event.clipboardData.getData("text/html");
textPlain = event.clipboardData.getData("text/plain");
@@ -194,6 +194,37 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
textHTML = Lute.Sanitize(textHTML);
}
+ if (protyle && protyle.app && protyle.app.plugins) {
+ for (let i = 0; i < protyle.app.plugins.length; i++) {
+ const response: IObject & { files: FileList } = await new Promise((resolve) => {
+ const emitResult = protyle.app.plugins[i].eventBus.emit("paste", {
+ protyle,
+ resolve,
+ textHTML,
+ textPlain,
+ siyuanHTML,
+ files
+ });
+ if (emitResult) {
+ resolve(undefined);
+ }
+ });
+
+ if (response?.textHTML) {
+ textHTML = response.textHTML;
+ }
+ if (response?.textPlain) {
+ textPlain = response.textPlain;
+ }
+ if (response?.siyuanHTML) {
+ siyuanHTML = response.siyuanHTML;
+ }
+ if (response?.files) {
+ files = response.files as FileList;
+ }
+ }
+ }
+
const nodeElement = hasClosestBlock(event.target);
if (!nodeElement) {
if (files && files.length > 0) {
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index 99c2458667..db6f3cb37a 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -49,6 +49,7 @@ type TEventBus = "ws-main" |
"open-menu-blockref" | "open-menu-fileannotationref" | "open-menu-tag" | "open-menu-link" | "open-menu-image" |
"open-menu-av" | "open-menu-content" | "open-menu-breadcrumbmore" | "open-menu-doctree" |
"open-siyuan-url-plugin" | "open-siyuan-url-block" |
+ "paste" |
"input-search" |
"loaded-protyle" | "loaded-protyle-dynamic" |
"destroy-protyle"