mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-14 19:18:06 +01:00
This commit is contained in:
parent
ce520f71fd
commit
1569435890
2 changed files with 66 additions and 7 deletions
|
|
@ -11,6 +11,8 @@ import {exportAsset} from "../../../menus/util";
|
|||
import {setPosition} from "../../../util/setPosition";
|
||||
import {previewImage} from "../../preview/image";
|
||||
import {genAVValueHTML} from "./blockAttr";
|
||||
import {hideMessage, showMessage} from "../../../dialog/message";
|
||||
import {fetchPost} from "../../../util/fetch";
|
||||
|
||||
export const bindAssetEvent = (options: {
|
||||
protyle: IProtyle,
|
||||
|
|
@ -323,3 +325,43 @@ export const addAssetLink = (protyle: IProtyle, data: IAV, cellElements: HTMLEle
|
|||
h: rect.height,
|
||||
});
|
||||
};
|
||||
|
||||
export const dragUpload = (files: string[], protyle: IProtyle, cellElement: HTMLElement, avID: string) => {
|
||||
const msgId = showMessage(window.siyuan.languages.uploading, 0);
|
||||
fetchPost("/api/asset/insertLocalAssets", {
|
||||
assetPaths: files,
|
||||
isUpload: true,
|
||||
id: protyle.block.rootID
|
||||
}, (response) => {
|
||||
hideMessage(msgId);
|
||||
const addUpdateValue: IAVCellAssetValue[] = []
|
||||
Object.keys(response.data.succMap).forEach(key => {
|
||||
const type = pathPosix().extname(key).toLowerCase();
|
||||
const name = key.substring(0, key.length - type.length)
|
||||
if (Constants.SIYUAN_ASSETS_IMAGE.includes(type)) {
|
||||
addUpdateValue.push({
|
||||
type: "image",
|
||||
name,
|
||||
content: response.data.succMap[key],
|
||||
})
|
||||
} else {
|
||||
addUpdateValue.push({
|
||||
type: "file",
|
||||
name,
|
||||
content: response.data.succMap[key],
|
||||
})
|
||||
}
|
||||
})
|
||||
fetchPost("/api/av/renderAttributeView", {
|
||||
id: avID,
|
||||
}, (response) => {
|
||||
updateAssetCell({
|
||||
protyle,
|
||||
data: response.data as IAV,
|
||||
cellElements: [cellElement],
|
||||
type: "addUpdate",
|
||||
addUpdateValue
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import {insertHTML} from "./insertHTML";
|
|||
import {isBrowser} from "../../util/functions";
|
||||
import {hideElements} from "../ui/hideElements";
|
||||
import {insertAttrViewBlockAnimation} from "../render/av/row";
|
||||
import {dragUpload} from "../render/av/asset";
|
||||
|
||||
const moveToNew = (protyle: IProtyle, sourceElements: Element[], targetElement: Element, newSourceElement: Element,
|
||||
isSameDoc: boolean, isBottom: boolean, isCopy: boolean) => {
|
||||
|
|
@ -988,15 +989,31 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
targetElement.classList.remove("dragover__bottom", "dragover__top", "dragover__left", "dragover__right");
|
||||
} else if (!window.siyuan.dragElement && (event.dataTransfer.types[0] === "Files" || event.dataTransfer.types.includes("text/html"))) {
|
||||
// 外部文件拖入编辑器中或者编辑器内选中文字拖拽
|
||||
focusByRange(getRangeByPoint(event.clientX, event.clientY));
|
||||
if (event.dataTransfer.types[0] === "Files" && !isBrowser()) {
|
||||
const files: string[] = [];
|
||||
for (let i = 0; i < event.dataTransfer.files.length; i++) {
|
||||
files.push(event.dataTransfer.files[i].path);
|
||||
// https://github.com/siyuan-note/siyuan/issues/9544
|
||||
const avElement = hasClosestByClassName(event.target, 'av')
|
||||
if (!avElement) {
|
||||
focusByRange(getRangeByPoint(event.clientX, event.clientY));
|
||||
if (event.dataTransfer.types[0] === "Files" && !isBrowser()) {
|
||||
const files: string[] = [];
|
||||
for (let i = 0; i < event.dataTransfer.files.length; i++) {
|
||||
files.push(event.dataTransfer.files[i].path);
|
||||
}
|
||||
uploadLocalFiles(files, protyle, !event.altKey);
|
||||
} else {
|
||||
paste(protyle, event);
|
||||
}
|
||||
uploadLocalFiles(files, protyle, !event.altKey);
|
||||
} else {
|
||||
paste(protyle, event);
|
||||
const cellElement = hasClosestByClassName(event.target, 'av__cell')
|
||||
if (cellElement) {
|
||||
const cellType = avElement.querySelector(`.av__row--header [data-col-id="${cellElement.dataset.colId}"]`)?.getAttribute("data-dtype")
|
||||
if (cellType === "mAsset" && event.dataTransfer.types[0] === "Files" && !isBrowser()) {
|
||||
const files: string[] = [];
|
||||
for (let i = 0; i < event.dataTransfer.files.length; i++) {
|
||||
files.push(event.dataTransfer.files[i].path);
|
||||
}
|
||||
dragUpload(files, protyle, cellElement, avElement.dataset.avId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (window.siyuan.dragElement) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue