mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-28 19:26:09 +01:00
This commit is contained in:
parent
19b7e3aad6
commit
a6a9dee8b9
1 changed files with 34 additions and 2 deletions
|
|
@ -4,7 +4,12 @@ import {hasClosestByAttribute, hasClosestByClassName} from "../protyle/util/hasC
|
|||
import * as dayjs from "dayjs";
|
||||
import {writeText} from "../protyle/util/compatibility";
|
||||
import {getAllModels} from "../layout/getAll";
|
||||
/// #if !BROWSER
|
||||
import {NativeImage} from "electron";
|
||||
import {getCurrentWindow} from "@electron/remote";
|
||||
/// #endif
|
||||
import {focusByRange} from "../protyle/util/selection";
|
||||
import {Constants} from "../constants";
|
||||
|
||||
const rectAnno = (config: any, pdf: any, element: HTMLElement) => {
|
||||
const rectAnnoElement = config.toolbar.rectAnno;
|
||||
|
|
@ -161,8 +166,35 @@ export const initAnno = (file: string, element: HTMLElement, annoId: string, pdf
|
|||
processed = true;
|
||||
break;
|
||||
} else if (type === "copy") {
|
||||
writeText(`<<${pdf.appConfig.file.replace(location.origin, "").substr(1)}/${rectElement.getAttribute(
|
||||
"data-node-id")} "${rectElement.getAttribute("data-content")}">>`);
|
||||
const id = rectElement.getAttribute("data-node-id");
|
||||
const text = rectElement.getAttribute("data-content")
|
||||
if (rectElement.childElementCount === 1) {
|
||||
/// #if !BROWSER
|
||||
const rect = rectElement.firstElementChild.getBoundingClientRect();
|
||||
getCurrentWindow().webContents.capturePage({
|
||||
x: Math.floor(rect.x),
|
||||
y: Math.floor(rect.y),
|
||||
width: Math.floor(rect.width) + 2,
|
||||
height: Math.floor(rect.height) + 2
|
||||
}).then((image: NativeImage) => {
|
||||
fetch(image.toDataURL()).then((response) => {
|
||||
return response.blob()
|
||||
}).then((blob) => {
|
||||
const formData = new FormData();
|
||||
const imageName = text + ".png";
|
||||
formData.append("file[]", blob, imageName);
|
||||
fetchPost(Constants.UPLOAD_ADDRESS, formData, (response) => {
|
||||
writeText(`<<${pdf.appConfig.file.replace(location.origin, "").substr(1)}/${id} "${text}">>
|
||||
`);
|
||||
});
|
||||
});
|
||||
});
|
||||
/// #else
|
||||
writeText(`<<${pdf.appConfig.file.replace(location.origin, "").substr(1)}/${id} "${text}">>`);
|
||||
/// #endif
|
||||
} else {
|
||||
writeText(`<<${pdf.appConfig.file.replace(location.origin, "").substr(1)}/${id} "${text}">>`);
|
||||
}
|
||||
hideToolbar(element);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue