mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-26 11:28:49 +01:00
This commit is contained in:
parent
4047f95016
commit
33dfa0de4e
3 changed files with 37 additions and 5 deletions
|
|
@ -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}));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
1
app/src/types/index.d.ts
vendored
1
app/src/types/index.d.ts
vendored
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue