mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
This commit is contained in:
parent
1475fd9747
commit
99f9a0d5f0
3 changed files with 45 additions and 62 deletions
|
|
@ -55,7 +55,6 @@ export class Gutter {
|
||||||
event.dataTransfer.setDragImage(protyle.wysiwyg.element.querySelector(`[data-node-id="${selectIds[0]}"]`), 0, 0);
|
event.dataTransfer.setDragImage(protyle.wysiwyg.element.querySelector(`[data-node-id="${selectIds[0]}"]`), 0, 0);
|
||||||
}
|
}
|
||||||
event.target.style.opacity = "0.1";
|
event.target.style.opacity = "0.1";
|
||||||
event.dataTransfer.effectAllowed = "move";
|
|
||||||
window.siyuan.dragElement = event.target;
|
window.siyuan.dragElement = event.target;
|
||||||
window.siyuan.dragElement.setAttribute("data-selected-ids", selectIds.toString());
|
window.siyuan.dragElement.setAttribute("data-selected-ids", selectIds.toString());
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -604,73 +604,56 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const targetElement = editorElement.querySelector(".dragover__bottom") || editorElement.querySelector(".dragover__top") || editorElement.querySelector(".dragover__left") || editorElement.querySelector(".dragover__right");
|
const targetElement = editorElement.querySelector(".dragover__bottom") || editorElement.querySelector(".dragover__top") || editorElement.querySelector(".dragover__left") || editorElement.querySelector(".dragover__right");
|
||||||
const isBacklink = window.siyuan.dragElement?.getAttribute("data-treetype") === "backlink";
|
if (window.siyuan.dragElement && (
|
||||||
if (window.siyuan.dragElement && (event.altKey || event.shiftKey) && isBacklink) {
|
|
||||||
focusByRange(document.caretRangeFromPoint(event.clientX, event.clientY));
|
|
||||||
const sourceId = window.siyuan.dragElement.getAttribute("data-node-id");
|
|
||||||
if (event.altKey) {
|
|
||||||
fetchPost("/api/block/getRefText", {id: sourceId}, (response) => {
|
|
||||||
insertHTML(`((${sourceId} '${response.data}'))`, protyle);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
insertHTML(protyle.lute.SpinBlockDOM(`{{select * from blocks where id='${sourceId}'}}`), protyle);
|
|
||||||
blockRender(protyle, protyle.wysiwyg.element);
|
|
||||||
}
|
|
||||||
} else if (window.siyuan.dragElement && targetElement && (
|
|
||||||
window.siyuan.dragElement.parentElement.classList.contains("protyle-gutters") ||
|
window.siyuan.dragElement.parentElement.classList.contains("protyle-gutters") ||
|
||||||
isBacklink ||
|
|
||||||
window.siyuan.dragElement.getAttribute("data-type") === "NodeListItem")) {
|
window.siyuan.dragElement.getAttribute("data-type") === "NodeListItem")) {
|
||||||
// gutter 或反链面板拖拽
|
// gutter 或反链面板拖拽
|
||||||
const sourceId = window.siyuan.dragElement.getAttribute("data-node-id");
|
const sourceElements: Element[] = [];
|
||||||
let sourceElements: Element[] = [];
|
const selectedIdsData = window.siyuan.dragElement.getAttribute("data-selected-ids");
|
||||||
if (isBacklink) {
|
const selectedIds = selectedIdsData ? selectedIdsData.split(",") : [window.siyuan.dragElement.getAttribute("data-node-id")];
|
||||||
let sourceElement = document.createElement("div");
|
selectedIds.forEach(item => {
|
||||||
const domHTML = await fetchSyncPost("/api/block/getBlockDOM", {id: sourceId});
|
const selectElement = window.siyuan.dragElement.parentElement.parentElement.querySelector(`.protyle-wysiwyg [data-node-id="${item}"]`);
|
||||||
sourceElement.innerHTML = domHTML.data.dom;
|
if (selectElement) {
|
||||||
sourceElement = sourceElement.firstElementChild as HTMLDivElement;
|
sourceElements.push(selectElement);
|
||||||
processRender(sourceElement);
|
}
|
||||||
highlightRender(sourceElement);
|
});
|
||||||
blockRender(protyle, sourceElement);
|
|
||||||
sourceElements = [sourceElement];
|
|
||||||
} else {
|
|
||||||
const selectedIdsData = window.siyuan.dragElement.getAttribute("data-selected-ids");
|
|
||||||
const selectedIds = selectedIdsData ? selectedIdsData.split(",") : [window.siyuan.dragElement.getAttribute("data-node-id")];
|
|
||||||
selectedIds.forEach(item => {
|
|
||||||
const selectElement = window.siyuan.dragElement.parentElement.parentElement.querySelector(`.protyle-wysiwyg [data-node-id="${item}"]`);
|
|
||||||
if (selectElement) {
|
|
||||||
sourceElements.push(selectElement);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
sourceElements.forEach(item => {
|
sourceElements.forEach(item => {
|
||||||
item.classList.remove("protyle-wysiwyg--select", "protyle-wysiwyg--hl");
|
item.classList.remove("protyle-wysiwyg--select", "protyle-wysiwyg--hl");
|
||||||
});
|
});
|
||||||
const targetClass = targetElement.className.split(" ");
|
if (event.altKey) {
|
||||||
targetElement.classList.remove("dragover__bottom", "dragover__top", "dragover__left", "dragover__right", "protyle-wysiwyg--select");
|
focusByRange(document.caretRangeFromPoint(event.clientX, event.clientY));
|
||||||
if (targetElement.parentElement.getAttribute("data-type") === "NodeSuperBlock" &&
|
let html = ''
|
||||||
targetElement.parentElement.getAttribute("data-sb-layout") === "col") {
|
for (let i = 0; i < selectedIds.length; i++) {
|
||||||
if (targetClass.includes("dragover__left") || targetClass.includes("dragover__right")) {
|
const response = await fetchSyncPost("/api/block/getRefText", {id: selectedIds[i]});
|
||||||
dragSame(protyle, sourceElements, targetElement, targetClass.includes("dragover__right"));
|
html += `((${selectedIds[i]} '${response.data}')) `
|
||||||
} else {
|
|
||||||
dragSb(protyle, sourceElements, targetElement, targetClass.includes("dragover__bottom"), "row");
|
|
||||||
}
|
}
|
||||||
} else {
|
insertHTML(html, protyle);
|
||||||
if (targetClass.includes("dragover__left") || targetClass.includes("dragover__right")) {
|
} else if (event.shiftKey) {
|
||||||
dragSb(protyle, sourceElements, targetElement, targetClass.includes("dragover__right"), "col");
|
focusByRange(document.caretRangeFromPoint(event.clientX, event.clientY));
|
||||||
|
let html = ''
|
||||||
|
selectedIds.forEach(item => {
|
||||||
|
html += `{{select * from blocks where id='${item}'}}\n`
|
||||||
|
})
|
||||||
|
insertHTML(protyle.lute.SpinBlockDOM(html), protyle);
|
||||||
|
blockRender(protyle, protyle.wysiwyg.element);
|
||||||
|
} else if (targetElement) {
|
||||||
|
const targetClass = targetElement.className.split(" ");
|
||||||
|
targetElement.classList.remove("dragover__bottom", "dragover__top", "dragover__left", "dragover__right", "protyle-wysiwyg--select");
|
||||||
|
if (targetElement.parentElement.getAttribute("data-type") === "NodeSuperBlock" &&
|
||||||
|
targetElement.parentElement.getAttribute("data-sb-layout") === "col") {
|
||||||
|
if (targetClass.includes("dragover__left") || targetClass.includes("dragover__right")) {
|
||||||
|
dragSame(protyle, sourceElements, targetElement, targetClass.includes("dragover__right"));
|
||||||
|
} else {
|
||||||
|
dragSb(protyle, sourceElements, targetElement, targetClass.includes("dragover__bottom"), "row");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
dragSame(protyle, sourceElements, targetElement, targetClass.includes("dragover__bottom"));
|
if (targetClass.includes("dragover__left") || targetClass.includes("dragover__right")) {
|
||||||
|
dragSb(protyle, sourceElements, targetElement, targetClass.includes("dragover__right"), "col");
|
||||||
|
} else {
|
||||||
|
dragSame(protyle, sourceElements, targetElement, targetClass.includes("dragover__bottom"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// #if !MOBILE
|
|
||||||
if (isBacklink) {
|
|
||||||
setTimeout(() => {
|
|
||||||
// 等待 drag transaction
|
|
||||||
getAllModels().backlink.forEach(item => {
|
|
||||||
item.refresh();
|
|
||||||
});
|
|
||||||
}, 200);
|
|
||||||
}
|
|
||||||
/// #endif
|
|
||||||
} else if (window.siyuan.dragElement && window.siyuan.dragElement.getAttribute("data-type") === "navigation-file" && targetElement) {
|
} else if (window.siyuan.dragElement && window.siyuan.dragElement.getAttribute("data-type") === "navigation-file" && targetElement) {
|
||||||
// 文件树拖拽
|
// 文件树拖拽
|
||||||
fetchPost("/api/filetree/doc2Heading", {
|
fetchPost("/api/filetree/doc2Heading", {
|
||||||
|
|
@ -729,7 +712,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
if (!window.siyuan.dragElement) {
|
if (!window.siyuan.dragElement) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((event.shiftKey || event.altKey) && window.siyuan.dragElement.getAttribute("data-treetype") === "backlink") {
|
if (event.shiftKey || event.altKey) {
|
||||||
const targetElement = hasClosestBlock(event.target);
|
const targetElement = hasClosestBlock(event.target);
|
||||||
if (targetElement) {
|
if (targetElement) {
|
||||||
targetElement.classList.remove("dragover__top", "protyle-wysiwyg--select", "dragover__bottom", "dragover__left", "dragover__right");
|
targetElement.classList.remove("dragover__top", "protyle-wysiwyg--select", "dragover__bottom", "dragover__left", "dragover__right");
|
||||||
|
|
@ -777,9 +760,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
|
|
||||||
if (window.siyuan.dragElement.parentElement.classList.contains("protyle-gutters") ||
|
if (window.siyuan.dragElement.parentElement.classList.contains("protyle-gutters") ||
|
||||||
// 列表项之前的点
|
// 列表项之前的点
|
||||||
window.siyuan.dragElement.getAttribute("data-type") === "NodeListItem" ||
|
window.siyuan.dragElement.getAttribute("data-type") === "NodeListItem") {
|
||||||
// 反向链接
|
|
||||||
window.siyuan.dragElement.getAttribute("data-treetype") === "backlink") {
|
|
||||||
// gutter 文档内拖拽限制
|
// gutter 文档内拖拽限制
|
||||||
// 排除自己及子孙
|
// 排除自己及子孙
|
||||||
const selectedIdsData = window.siyuan.dragElement.getAttribute("data-selected-ids");
|
const selectedIdsData = window.siyuan.dragElement.getAttribute("data-selected-ids");
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,9 @@ import {onGet} from "./onGet";
|
||||||
import {saveScroll} from "../scroll/saveScroll";
|
import {saveScroll} from "../scroll/saveScroll";
|
||||||
|
|
||||||
export const reloadProtyle = (protyle:IProtyle) => {
|
export const reloadProtyle = (protyle:IProtyle) => {
|
||||||
|
if (protyle.options.backlinkData) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (window.siyuan.config.editor.displayBookmarkIcon) {
|
if (window.siyuan.config.editor.displayBookmarkIcon) {
|
||||||
protyle.wysiwyg.element.classList.add("protyle-wysiwyg--attr");
|
protyle.wysiwyg.element.classList.add("protyle-wysiwyg--attr");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue