Vanessa 2025-01-11 21:25:51 +08:00
parent 32ca803eb4
commit 78839671e8
4 changed files with 32 additions and 19 deletions

View file

@ -12,6 +12,12 @@
background-color: var(--b3-list-hover);
}
&.dragover,
&.dragover__top,
&.dragover__bottom {
cursor: copy;
}
&.dragover::after {
background-color: var(--b3-theme-primary-lightest);
position: absolute;

View file

@ -8,27 +8,10 @@ import {hideAllElements} from "../../protyle/ui/hideElements";
import {isWindow} from "../../util/functions";
import {writeText} from "../../protyle/util/compatibility";
import {showMessage} from "../../dialog/message";
import {cancelDrag} from "./dragover";
export const globalClick = (event: MouseEvent & { target: HTMLElement }) => {
const ghostElement = document.getElementById("dragGhost");
if (ghostElement) {
if (ghostElement.dataset.ghostType === "dock") {
ghostElement.parentElement.querySelectorAll(".dock__item").forEach((item: HTMLElement) => {
item.style.opacity = "";
});
document.querySelector("#dockMoveItem")?.remove();
} else {
const startElement = ghostElement.parentElement.querySelector(`[data-node-id="${ghostElement.getAttribute("data-node-id")}"]`) as HTMLElement;
if (startElement) {
startElement.style.opacity = "";
}
ghostElement.parentElement.querySelectorAll(".dragover__top, .dragover__bottom, .dragover, .dragover__current").forEach((item: HTMLElement) => {
item.classList.remove("dragover__top", "dragover__bottom", "dragover", "dragover__current");
item.style.opacity = "";
});
}
ghostElement.remove();
}
cancelDrag();
if (!window.siyuan.menus.menu.element.contains(event.target) && !hasClosestByAttribute(event.target, "data-menu", "true")) {
if (getSelection().rangeCount > 0 && window.siyuan.menus.menu.element.contains(getSelection().getRangeAt(0).startContainer) &&
window.siyuan.menus.menu.element.contains(document.activeElement)) {

View file

@ -0,0 +1,22 @@
export const cancelDrag = () => {
const ghostElement = document.getElementById("dragGhost");
if (ghostElement) {
if (ghostElement.dataset.ghostType === "dock") {
ghostElement.parentElement.querySelectorAll(".dock__item").forEach((item: HTMLElement) => {
item.style.opacity = "";
});
document.querySelector("#dockMoveItem")?.remove();
} else {
const startElement = ghostElement.parentElement.querySelector(`[data-node-id="${ghostElement.getAttribute("data-node-id")}"]`) as HTMLElement;
if (startElement) {
startElement.style.opacity = "";
}
ghostElement.parentElement.querySelectorAll(".dragover__top, .dragover__bottom, .dragover, .dragover__current").forEach((item: HTMLElement) => {
item.classList.remove("dragover__top", "dragover__bottom", "dragover", "dragover__current");
item.style.opacity = "";
});
}
ghostElement.remove();
document.onmousemove = null;
}
}

View file

@ -74,6 +74,7 @@ import {globalCommand} from "./command/global";
import {duplicateCompletely} from "../../protyle/render/av/action";
import {copyTextByType} from "../../protyle/toolbar/util";
import {onlyProtyleCommand} from "./command/protyle";
import {cancelDrag} from "./dragover";
const switchDialogEvent = (app: App, event: MouseEvent) => {
event.preventDefault();
@ -1395,6 +1396,7 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
}
if (event.key === "Escape" && !event.isComposing) {
cancelDrag();
const imgPreviewElement = document.querySelector(".protyle-img");
if (imgPreviewElement) {
imgPreviewElement.remove();