Vanessa 2024-11-21 00:22:20 +08:00
parent 028e3118c4
commit c0b68b1e5e
5 changed files with 121 additions and 96 deletions

View file

@ -1,6 +1,7 @@
import {fetchPost} from "../../util/fetch";
import {fetchPost, fetchSyncPost} from "../../util/fetch";
import {Constants} from "../../constants";
import {focusByRange, focusByWbr} from "../util/selection";
import {writeText} from "../util/compatibility";
export const previewTemplate = (pathString: string, element: Element, parentId: string) => {
if (!pathString) {
@ -213,3 +214,34 @@ export const toolbarKeyToMenu = (toolbar: Array<string | IMenuItem>) => {
});
return toolbarResult;
};
export const copyTextByType = async (ids: string[],
type: "ref" | "blockEmbed" | "protocol" | "protocolMd" | "hPath" | "id") => {
let text = "";
for (let i = 0; i < ids.length; i++) {
const id = ids[i];
if (ids.length > 1) {
text += "* ";
}
if (type === "ref") {
const response = await fetchSyncPost("/api/block/getRefText", {id});
text += `((${id} '${response.data}'))`;
} else if (type === "blockEmbed") {
text += `{{select * from blocks where id='${id}'}}`;
} else if (type === "protocol") {
text += `siyuan://blocks/${id}`;
} else if (type === "protocolMd") {
const response = await fetchSyncPost("/api/block/getRefText", {id});
text += `[${response.data}](siyuan://blocks/${id})`;
} else if (type === "hPath") {
const response = await fetchSyncPost("/api/filetree/getHPathByID", {id});
text += response.data;
} else if (type === "id") {
text += id;
}
if (ids.length > 1 && i !== ids.length - 1) {
text += "\n";
}
}
writeText(text);
}