This commit is contained in:
Vanessa 2023-05-22 22:19:38 +08:00
parent 0d1868fe3a
commit 2c7a58d3b9
3 changed files with 22 additions and 38 deletions

View file

@ -8,11 +8,13 @@ import {Constants} from "../constants";
/// #if !BROWSER
import {openNewWindowById} from "../window/openNewWindow";
/// #endif
/// #if !MOBILE
import {moveResize} from "../dialog/moveResize";
/// #endif
import {disabledProtyle} from "../protyle/util/onGet";
import {fetchPost} from "../util/fetch";
import {showMessage} from "../dialog/message";
import {App} from "../index";
import {moveResize} from "../dialog/moveResize";
export class BlockPanel {
public element: HTMLElement;
@ -127,6 +129,7 @@ export class BlockPanel {
target = target.parentElement;
}
});
/// if !MOBILE
moveResize(this.element, (type: string) => {
if (type !== "move") {
this.editors.forEach(item => {
@ -138,6 +141,7 @@ export class BlockPanel {
pinElement.setAttribute("aria-label", window.siyuan.languages.unpin);
this.element.setAttribute("data-pin", "true");
})
/// #endif
this.render();
}

View file

@ -1,6 +1,8 @@
import {genUUID} from "../util/genID";
import {isMobile} from "../util/functions";
/// if !MOBILE
import {moveResize} from "./moveResize";
/// #endif
import {isMobile} from "../util/functions";
export class Dialog {
private destroyCallback: (options?: IObject) => void;

View file

@ -26,6 +26,9 @@ import {blockRender} from "../markdown/blockRender";
/// #if !BROWSER
import {openBy} from "../../editor/util";
/// #endif
/// if !MOBILE
import {moveResize} from "../../dialog/moveResize";
/// #endif
import {fetchPost} from "../../util/fetch";
import {isArrayEqual, isMobile} from "../../util/functions";
import * as dayjs from "dayjs";
@ -889,8 +892,10 @@ export class Toolbar {
this.subElement.style.padding = "0";
}
this.subElement.innerHTML = `<div ${(isPin && this.subElement.firstElementChild.getAttribute("data-drag") === "true") ? 'data-drag="true"' : ""}><div class="block__icons block__icons--menu fn__flex">
${title}
<span class="fn__flex-1 fn__space"></span>
<span class="fn__flex-1 resize__move">
${title}
</span>
<span class="fn__space"></span>
<button data-type="refresh" class="block__icon block__icon--show b3-tooltips b3-tooltips__nw${(isPin && !this.subElement.querySelector('[data-type="refresh"]').classList.contains("block__icon--active")) ? "" : " block__icon--active"}${types.includes("NodeBlockQueryEmbed") ? " fn__none" : ""}" aria-label="${window.siyuan.languages.refresh}"><svg><use xlink:href="#iconRefresh"></use></svg></button>
<span class="fn__space"></span>
<button data-type="before" class="block__icon block__icon--show b3-tooltips b3-tooltips__nw${protyle.disabled ? " fn__none" : ""}" aria-label="${window.siyuan.languages["insert-before"]}"><svg><use xlink:href="#iconBefore"></use></svg></button>
@ -1008,41 +1013,14 @@ export class Toolbar {
});
}, Constants.TIMEOUT_LOAD);
};
headerElement.addEventListener("mousedown", (event: MouseEvent) => {
if (hasClosestByClassName(event.target as HTMLElement, "block__icon")) {
return;
}
event.stopPropagation();
const documentSelf = document;
this.subElement.style.userSelect = "none";
const x = event.clientX - parseInt(this.subElement.style.left);
const y = event.clientY - parseInt(this.subElement.style.top);
documentSelf.onmousemove = (moveEvent: MouseEvent) => {
let positionX = moveEvent.clientX - x;
let positionY = moveEvent.clientY - y;
if (positionX > window.innerWidth - this.subElement.clientWidth) {
positionX = window.innerWidth - this.subElement.clientWidth;
}
if (positionY > window.innerHeight - this.subElement.clientHeight) {
positionY = window.innerHeight - this.subElement.clientHeight;
}
this.subElement.style.left = Math.max(positionX, 0) + "px";
this.subElement.style.top = Math.max(positionY, Constants.SIZE_TOOLBAR_HEIGHT) + "px";
this.subElement.firstElementChild.setAttribute("data-drag", "true");
};
documentSelf.onmouseup = () => {
const pinElement = headerElement.querySelector('[data-type="pin"]');
pinElement.classList.add("block__icon--active");
pinElement.setAttribute("aria-label", window.siyuan.languages.unpin);
this.subElement.style.userSelect = "auto";
documentSelf.onmousemove = null;
documentSelf.onmouseup = null;
documentSelf.ondragstart = null;
documentSelf.onselectstart = null;
documentSelf.onselect = null;
};
return;
/// if !MOBILE
moveResize(this.subElement, () => {
const pinElement = headerElement.querySelector('[data-type="pin"]');
pinElement.classList.add("block__icon--active");
pinElement.setAttribute("aria-label", window.siyuan.languages.unpin);
this.subElement.firstElementChild.setAttribute("data-drag", "true");
});
/// #endif
const textElement = this.subElement.querySelector(".b3-text-field") as HTMLTextAreaElement;
if (types.includes("NodeHTMLBlock")) {
textElement.value = Lute.UnEscapeHTMLStr(renderElement.querySelector("protyle-html").getAttribute("data-content") || "");