2022-05-26 15:18:53 +08:00
|
|
|
|
import {hasClosestByClassName} from "../protyle/util/hasClosest";
|
2022-10-02 20:56:48 +08:00
|
|
|
|
import {Protyle} from "../protyle";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {genUUID} from "../util/genID";
|
|
|
|
|
|
import {setPosition} from "../util/setPosition";
|
|
|
|
|
|
import {hideElements} from "../protyle/ui/hideElements";
|
|
|
|
|
|
import {Constants} from "../constants";
|
2023-02-06 21:50:28 +08:00
|
|
|
|
/// #if !BROWSER
|
|
|
|
|
|
import {openNewWindowById} from "../window/openNewWindow";
|
|
|
|
|
|
/// #endif
|
2023-05-22 22:19:38 +08:00
|
|
|
|
/// #if !MOBILE
|
|
|
|
|
|
import {moveResize} from "../dialog/moveResize";
|
2024-05-29 10:53:35 +08:00
|
|
|
|
import {openFileById} from "../editor/util";
|
2023-05-22 22:19:38 +08:00
|
|
|
|
/// #endif
|
2023-02-07 11:58:24 +08:00
|
|
|
|
import {fetchPost} from "../util/fetch";
|
|
|
|
|
|
import {showMessage} from "../dialog/message";
|
2023-05-18 19:27:21 +08:00
|
|
|
|
import {App} from "../index";
|
2023-08-18 10:57:28 +08:00
|
|
|
|
import {isMobile} from "../util/functions";
|
2023-09-13 12:05:57 +08:00
|
|
|
|
import {resize} from "../protyle/util/resize";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
|
|
|
|
|
export class BlockPanel {
|
|
|
|
|
|
public element: HTMLElement;
|
|
|
|
|
|
public targetElement: HTMLElement;
|
|
|
|
|
|
public nodeIds: string[];
|
|
|
|
|
|
public defIds: string[] = [];
|
|
|
|
|
|
public id: string;
|
2023-05-18 19:27:21 +08:00
|
|
|
|
private app: App;
|
2023-05-19 20:39:32 +08:00
|
|
|
|
public x: number;
|
|
|
|
|
|
public y: number;
|
2023-05-19 20:27:14 +08:00
|
|
|
|
private isBacklink: boolean;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
public editors: Protyle[] = [];
|
|
|
|
|
|
|
2023-05-19 20:27:14 +08:00
|
|
|
|
// x,y 和 targetElement 二选一必传
|
2022-05-26 15:18:53 +08:00
|
|
|
|
constructor(options: {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
app: App,
|
2023-05-19 20:27:14 +08:00
|
|
|
|
targetElement?: HTMLElement,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
nodeIds?: string[],
|
|
|
|
|
|
defIds?: string[],
|
2023-05-19 20:27:14 +08:00
|
|
|
|
isBacklink: boolean,
|
|
|
|
|
|
x?: number,
|
|
|
|
|
|
y?: number
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}) {
|
|
|
|
|
|
this.id = genUUID();
|
|
|
|
|
|
this.targetElement = options.targetElement;
|
|
|
|
|
|
this.nodeIds = options.nodeIds;
|
|
|
|
|
|
this.defIds = options.defIds || [];
|
2023-05-18 19:27:21 +08:00
|
|
|
|
this.app = options.app;
|
2023-05-19 20:27:14 +08:00
|
|
|
|
this.x = options.x;
|
|
|
|
|
|
this.y = options.y;
|
|
|
|
|
|
this.isBacklink = options.isBacklink;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
|
|
|
|
|
this.element = document.createElement("div");
|
2023-09-02 11:13:47 +08:00
|
|
|
|
this.element.classList.add("block__popover");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
|
|
|
|
|
const parentElement = hasClosestByClassName(this.targetElement, "block__popover", true);
|
|
|
|
|
|
let level = 1;
|
|
|
|
|
|
if (parentElement) {
|
|
|
|
|
|
this.element.setAttribute("data-oid", parentElement.getAttribute("data-oid"));
|
|
|
|
|
|
level = parseInt(parentElement.getAttribute("data-level")) + 1;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.element.setAttribute("data-oid", this.nodeIds[0]);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 移除同层级其他更高级的 block popover
|
|
|
|
|
|
this.element.setAttribute("data-level", level.toString());
|
|
|
|
|
|
for (let i = 0; i < window.siyuan.blockPanels.length; i++) {
|
|
|
|
|
|
const item = window.siyuan.blockPanels[i];
|
|
|
|
|
|
if (item.element.getAttribute("data-pin") === "false" &&
|
|
|
|
|
|
item.targetElement && parseInt(item.element.getAttribute("data-level")) >= level) {
|
|
|
|
|
|
item.destroy();
|
|
|
|
|
|
i--;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
document.body.insertAdjacentElement("beforeend", this.element);
|
|
|
|
|
|
|
2023-05-19 20:27:14 +08:00
|
|
|
|
if (this.targetElement) {
|
|
|
|
|
|
this.targetElement.style.cursor = "wait";
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
|
|
|
|
|
this.element.setAttribute("data-pin", "false");
|
|
|
|
|
|
this.element.addEventListener("dblclick", (event) => {
|
|
|
|
|
|
const target = event.target as HTMLElement;
|
2022-10-12 10:15:03 +08:00
|
|
|
|
const iconsElement = hasClosestByClassName(target, "block__icons");
|
|
|
|
|
|
if (iconsElement) {
|
|
|
|
|
|
const pingElement = iconsElement.querySelector('[data-type="pin"]');
|
2023-12-05 22:38:28 +08:00
|
|
|
|
if (this.element.getAttribute("data-pin") === "true") {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
pingElement.setAttribute("aria-label", window.siyuan.languages.pin);
|
2023-12-05 22:38:28 +08:00
|
|
|
|
pingElement.querySelector("use").setAttribute("xlink:href", "#iconPin");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.element.setAttribute("data-pin", "false");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
pingElement.setAttribute("aria-label", window.siyuan.languages.unpin);
|
2023-12-05 22:38:28 +08:00
|
|
|
|
pingElement.querySelector("use").setAttribute("xlink:href", "#iconUnpin");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.element.setAttribute("data-pin", "true");
|
|
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
this.element.addEventListener("click", (event) => {
|
2023-05-22 11:33:06 +08:00
|
|
|
|
if (this.element && window.siyuan.blockPanels.length > 1) {
|
2023-09-02 11:13:47 +08:00
|
|
|
|
this.element.style.zIndex = (++window.siyuan.zIndex).toString();
|
2023-05-22 11:33:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
let target = event.target as HTMLElement;
|
|
|
|
|
|
while (target && !target.isEqualNode(this.element)) {
|
|
|
|
|
|
if (target.classList.contains("block__icon") || target.classList.contains("block__logo")) {
|
|
|
|
|
|
const type = target.getAttribute("data-type");
|
2023-05-19 20:27:14 +08:00
|
|
|
|
if (type === "close") {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.destroy();
|
|
|
|
|
|
} else if (type === "pin") {
|
2023-12-05 22:38:28 +08:00
|
|
|
|
if (this.element.getAttribute("data-pin") === "true") {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
target.setAttribute("aria-label", window.siyuan.languages.pin);
|
2023-12-05 22:38:28 +08:00
|
|
|
|
target.querySelector("use").setAttribute("xlink:href", "#iconPin");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.element.setAttribute("data-pin", "false");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
target.setAttribute("aria-label", window.siyuan.languages.unpin);
|
2023-12-05 22:38:28 +08:00
|
|
|
|
target.querySelector("use").setAttribute("xlink:href", "#iconUnpin");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.element.setAttribute("data-pin", "true");
|
|
|
|
|
|
}
|
2023-02-06 21:50:28 +08:00
|
|
|
|
} else if (type === "open") {
|
|
|
|
|
|
/// #if !BROWSER
|
2023-02-06 21:54:26 +08:00
|
|
|
|
openNewWindowById(this.nodeIds[0]);
|
2023-02-06 21:50:28 +08:00
|
|
|
|
/// #endif
|
2024-05-27 22:06:35 +08:00
|
|
|
|
} else if (type === "stickTab") {
|
2024-05-29 10:53:35 +08:00
|
|
|
|
/// #if !BROWSER
|
2024-05-27 22:06:35 +08:00
|
|
|
|
openFileById({
|
|
|
|
|
|
app: options.app,
|
|
|
|
|
|
id: this.nodeIds[0],
|
2024-09-21 11:06:19 +08:00
|
|
|
|
action: this.editors[0].protyle.block.rootID !== this.nodeIds[0] ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_CONTEXT],
|
2024-05-27 22:06:35 +08:00
|
|
|
|
});
|
2024-05-29 10:53:35 +08:00
|
|
|
|
/// #endif
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
target = target.parentElement;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2023-05-26 17:03:35 +08:00
|
|
|
|
/// #if !MOBILE
|
2023-05-22 11:33:06 +08:00
|
|
|
|
moveResize(this.element, (type: string) => {
|
|
|
|
|
|
if (type !== "move") {
|
|
|
|
|
|
this.editors.forEach(item => {
|
2023-09-13 12:05:57 +08:00
|
|
|
|
resize(item.protyle);
|
2023-05-22 11:33:06 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
const pinElement = this.element.firstElementChild.querySelector('[data-type="pin"]');
|
|
|
|
|
|
pinElement.setAttribute("aria-label", window.siyuan.languages.unpin);
|
2023-12-05 22:38:28 +08:00
|
|
|
|
pinElement.querySelector("use").setAttribute("xlink:href", "#iconUnpin");
|
2023-05-22 11:33:06 +08:00
|
|
|
|
this.element.setAttribute("data-pin", "true");
|
2023-05-22 22:30:01 +08:00
|
|
|
|
});
|
2023-05-22 22:19:38 +08:00
|
|
|
|
/// #endif
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.render();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-18 23:46:08 +08:00
|
|
|
|
private initProtyle(editorElement: HTMLElement, afterCB?: () => void) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const index = parseInt(editorElement.getAttribute("data-index"));
|
2023-04-09 09:31:42 +08:00
|
|
|
|
fetchPost("/api/block/getBlockInfo", {id: this.nodeIds[index]}, (response) => {
|
2023-02-07 11:58:24 +08:00
|
|
|
|
if (response.code === 3) {
|
|
|
|
|
|
showMessage(response.msg);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-05-19 20:27:14 +08:00
|
|
|
|
if (!this.targetElement && typeof this.x === "undefined" && typeof this.y === "undefined") {
|
2023-03-06 09:28:18 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-02-07 11:58:24 +08:00
|
|
|
|
const action = [];
|
|
|
|
|
|
if (response.data.rootID !== this.nodeIds[index]) {
|
|
|
|
|
|
action.push(Constants.CB_GET_ALL);
|
2023-09-02 00:21:57 +08:00
|
|
|
|
} else {
|
2023-09-17 22:26:30 +08:00
|
|
|
|
action.push(Constants.CB_GET_CONTEXT);
|
2024-05-01 16:37:49 +08:00
|
|
|
|
// 不需要高亮 https://github.com/siyuan-note/siyuan/issues/11160#issuecomment-2084652764
|
2023-02-07 11:58:24 +08:00
|
|
|
|
}
|
2023-09-02 00:21:57 +08:00
|
|
|
|
|
2023-05-19 20:27:14 +08:00
|
|
|
|
if (this.isBacklink) {
|
2023-02-07 11:58:24 +08:00
|
|
|
|
action.push(Constants.CB_GET_BACKLINK);
|
|
|
|
|
|
}
|
2023-05-18 19:27:21 +08:00
|
|
|
|
const editor = new Protyle(this.app, editorElement, {
|
2023-02-07 11:58:24 +08:00
|
|
|
|
blockId: this.nodeIds[index],
|
|
|
|
|
|
defId: this.defIds[index] || this.defIds[0] || "",
|
|
|
|
|
|
action,
|
|
|
|
|
|
render: {
|
|
|
|
|
|
scroll: true,
|
|
|
|
|
|
gutter: true,
|
|
|
|
|
|
breadcrumbDocName: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
typewriterMode: false,
|
|
|
|
|
|
after: (editor) => {
|
|
|
|
|
|
if (response.data.rootID !== this.nodeIds[index]) {
|
2023-07-05 00:51:10 +08:00
|
|
|
|
editor.protyle.breadcrumb.element.parentElement.lastElementChild.classList.remove("fn__none");
|
2023-02-07 11:58:24 +08:00
|
|
|
|
}
|
2023-07-18 23:46:08 +08:00
|
|
|
|
if (afterCB) {
|
|
|
|
|
|
afterCB();
|
|
|
|
|
|
}
|
2023-08-18 10:57:28 +08:00
|
|
|
|
// https://ld246.com/article/1653639418266
|
|
|
|
|
|
if (editor.protyle.element.nextElementSibling || editor.protyle.element.previousElementSibling) {
|
|
|
|
|
|
editor.protyle.element.style.minHeight = Math.min(30 + editor.protyle.wysiwyg.element.clientHeight, window.innerHeight / 3) + "px";
|
|
|
|
|
|
}
|
|
|
|
|
|
// 由于 afterCB 中高度的设定,需在之后再进行设定
|
|
|
|
|
|
// 49 = 16(上图标)+16(下图标)+8(padding)+9(底部距离)
|
|
|
|
|
|
editor.protyle.scroll.element.parentElement.setAttribute("style", `--b3-dynamicscroll-width:${Math.min(editor.protyle.contentElement.clientHeight - 49, 200)}px;${isMobile() ? "" : "right:10px"}`);
|
2023-02-07 11:58:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
this.editors.push(editor);
|
2023-02-07 13:59:04 +08:00
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public destroy() {
|
|
|
|
|
|
window.siyuan.blockPanels.find((item, index) => {
|
|
|
|
|
|
if (item.id === this.id) {
|
|
|
|
|
|
window.siyuan.blockPanels.splice(index, 1);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (this.editors.length > 0) {
|
|
|
|
|
|
this.editors.forEach(item => {
|
2023-05-09 10:14:35 +08:00
|
|
|
|
// https://github.com/siyuan-note/siyuan/issues/8199
|
|
|
|
|
|
hideElements(["util"], item.protyle);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
item.destroy();
|
|
|
|
|
|
});
|
|
|
|
|
|
this.editors = [];
|
|
|
|
|
|
}
|
2024-02-24 21:38:25 +08:00
|
|
|
|
const level = parseInt(this.element.dataset.level);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.element.remove();
|
|
|
|
|
|
this.element = undefined;
|
|
|
|
|
|
this.targetElement = undefined;
|
|
|
|
|
|
// 移除弹出上使用右键菜单
|
2024-02-25 22:28:35 +08:00
|
|
|
|
const menuLevel = parseInt(window.siyuan.menus.menu.element.dataset.from);
|
2024-02-24 21:38:25 +08:00
|
|
|
|
if (window.siyuan.menus.menu.element.dataset.from !== "app" && menuLevel && menuLevel >= level) {
|
2023-12-19 11:16:38 +08:00
|
|
|
|
// https://github.com/siyuan-note/siyuan/issues/9854 右键菜单不是从浮窗中弹出的则不进行移除
|
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private render() {
|
2023-03-07 09:12:28 +08:00
|
|
|
|
if (!document.body.contains(this.element)) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.destroy();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-02-06 21:54:26 +08:00
|
|
|
|
let openHTML = "";
|
2023-02-06 21:50:28 +08:00
|
|
|
|
/// #if !BROWSER
|
|
|
|
|
|
if (this.nodeIds.length === 1) {
|
2024-09-21 11:06:19 +08:00
|
|
|
|
openHTML = `<span data-type="stickTab" class="block__icon block__icon--show b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.openBy}"><svg><use xlink:href="#iconOpen"></use></svg></span>
|
2024-05-27 22:06:35 +08:00
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
|
<span data-type="open" class="block__icon block__icon--show b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.openByNewWindow}"><svg><use xlink:href="#iconOpenWindow"></use></svg></span>
|
2023-02-06 21:54:26 +08:00
|
|
|
|
<span class="fn__space"></span>`;
|
2023-02-06 21:50:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
/// #endif
|
2023-04-21 09:51:04 +08:00
|
|
|
|
let html = `<div class="block__icons block__icons--menu">
|
2023-05-22 11:33:06 +08:00
|
|
|
|
<span class="fn__space fn__flex-1 resize__move"></span>${openHTML}
|
|
|
|
|
|
<span data-type="pin" class="block__icon block__icon--show b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.pin}"><svg><use xlink:href="#iconPin"></use></svg></span>
|
2022-05-26 15:18:53 +08:00
|
|
|
|
<span class="fn__space"></span>
|
2023-05-22 11:33:06 +08:00
|
|
|
|
<span data-type="close" class="block__icon block__icon--show b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.close}"><svg style="width: 10px"><use xlink:href="#iconClose"></use></svg></span>
|
2022-05-26 15:18:53 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="block__content">`;
|
|
|
|
|
|
if (this.nodeIds.length === 0) {
|
|
|
|
|
|
html += `<div class="ft__smaller ft__smaller ft__secondary b3-form__space--small" contenteditable="false">${window.siyuan.languages.refExpired}</div>`;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.nodeIds.forEach((item, index) => {
|
|
|
|
|
|
html += `<div class="block__edit fn__flex-1 protyle" data-index="${index}"></div>`;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (html) {
|
2023-05-22 11:33:06 +08:00
|
|
|
|
html += '</div><div class="resize__rd"></div><div class="resize__ld"></div><div class="resize__lt"></div><div class="resize__rt"></div><div class="resize__r"></div><div class="resize__d"></div><div class="resize__t"></div><div class="resize__l"></div>';
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
this.element.innerHTML = html;
|
|
|
|
|
|
const observer = new IntersectionObserver((e) => {
|
|
|
|
|
|
e.forEach(item => {
|
|
|
|
|
|
if (item.isIntersecting && item.target.innerHTML === "") {
|
|
|
|
|
|
this.initProtyle(item.target as HTMLElement);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}, {
|
|
|
|
|
|
threshold: 0,
|
|
|
|
|
|
});
|
|
|
|
|
|
this.element.querySelectorAll(".block__edit").forEach((item: HTMLElement, index) => {
|
|
|
|
|
|
if (index < 5) {
|
2023-07-18 23:46:08 +08:00
|
|
|
|
this.initProtyle(item, index === 0 ? () => {
|
2024-04-15 23:28:06 +08:00
|
|
|
|
if (!document.contains(this.element)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-07-18 23:46:08 +08:00
|
|
|
|
let targetRect;
|
|
|
|
|
|
if (this.targetElement && this.targetElement.classList.contains("protyle-wysiwyg__embed")) {
|
|
|
|
|
|
targetRect = this.targetElement.getBoundingClientRect();
|
|
|
|
|
|
// 嵌入块过长时,单击弹出的悬浮窗位置居下 https://ld246.com/article/1634292738717
|
|
|
|
|
|
let top = targetRect.top;
|
|
|
|
|
|
const contentElement = hasClosestByClassName(this.targetElement, "protyle-content", true);
|
|
|
|
|
|
if (contentElement) {
|
|
|
|
|
|
const contentRectTop = contentElement.getBoundingClientRect().top;
|
|
|
|
|
|
if (targetRect.top < contentRectTop) {
|
|
|
|
|
|
top = contentRectTop;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 单击嵌入块悬浮窗的位置最好是覆盖嵌入块
|
2023-08-18 10:57:28 +08:00
|
|
|
|
// 防止图片撑高后悬浮窗显示不下,只能设置高度
|
|
|
|
|
|
this.element.style.height = Math.min(window.innerHeight - Constants.SIZE_TOOLBAR_HEIGHT, targetRect.height + 42) + "px";
|
|
|
|
|
|
setPosition(this.element, targetRect.left, Math.max(top - 42, Constants.SIZE_TOOLBAR_HEIGHT), -42, 0);
|
2023-07-18 23:46:08 +08:00
|
|
|
|
} else if (this.targetElement) {
|
|
|
|
|
|
if (this.targetElement.classList.contains("pdf__rect")) {
|
|
|
|
|
|
targetRect = this.targetElement.firstElementChild.getBoundingClientRect();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
targetRect = this.targetElement.getBoundingClientRect();
|
|
|
|
|
|
}
|
2023-07-26 13:18:25 +08:00
|
|
|
|
// 下部位置大的话就置于下部 https://ld246.com/article/1690333302147
|
|
|
|
|
|
if (window.innerHeight - targetRect.bottom - 4 > targetRect.top + 12) {
|
|
|
|
|
|
this.element.style.maxHeight = Math.floor(window.innerHeight - targetRect.bottom - 12) + "px";
|
|
|
|
|
|
}
|
2023-07-18 23:46:08 +08:00
|
|
|
|
// 靠边不宜拖拽 https://github.com/siyuan-note/siyuan/issues/2937
|
|
|
|
|
|
setPosition(this.element, targetRect.left, targetRect.bottom + 4, targetRect.height + 12, 8);
|
|
|
|
|
|
} else if (typeof this.x === "number" && typeof this.y === "number") {
|
|
|
|
|
|
setPosition(this.element, this.x, this.y);
|
2023-09-07 22:50:46 +08:00
|
|
|
|
this.element.style.maxHeight = Math.floor(window.innerHeight - Math.max(this.y, Constants.SIZE_TOOLBAR_HEIGHT) - 12) + "px";
|
2023-07-18 23:46:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
const elementRect = this.element.getBoundingClientRect();
|
2023-08-18 10:57:28 +08:00
|
|
|
|
if (this.targetElement && !this.targetElement.classList.contains("protyle-wysiwyg__embed")) {
|
|
|
|
|
|
if (elementRect.top < targetRect.top) {
|
|
|
|
|
|
this.element.style.maxHeight = Math.floor(targetRect.top - elementRect.top - 8) + "px";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.element.style.maxHeight = Math.floor(window.innerHeight - elementRect.top - 8) + "px";
|
|
|
|
|
|
}
|
2023-07-18 23:46:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
this.element.classList.add("block__popover--open");
|
2023-09-07 22:17:26 +08:00
|
|
|
|
this.element.style.zIndex = (++window.siyuan.zIndex).toString();
|
2023-07-18 23:46:08 +08:00
|
|
|
|
} : undefined);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
observer.observe(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2023-05-19 20:27:14 +08:00
|
|
|
|
if (this.targetElement) {
|
|
|
|
|
|
this.targetElement.style.cursor = "";
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|