mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 08:30:12 +01:00
This commit is contained in:
parent
dc7f763054
commit
5cce04da49
6 changed files with 47 additions and 32 deletions
|
|
@ -22,7 +22,7 @@ export const initBlockPopover = (app: App) => {
|
||||||
if (aElement) {
|
if (aElement) {
|
||||||
let tip = aElement.getAttribute("aria-label") || aElement.getAttribute("data-inline-memo-content");
|
let tip = aElement.getAttribute("aria-label") || aElement.getAttribute("data-inline-memo-content");
|
||||||
if (aElement.classList.contains("av__celltext")) {
|
if (aElement.classList.contains("av__celltext")) {
|
||||||
if (aElement.offsetWidth > aElement.parentElement.clientWidth - 11) {
|
if (aElement.offsetWidth > aElement.parentElement.clientWidth - 5) { // 只能减左边 padding,换行时字体会穿透到右侧 padding
|
||||||
if (aElement.querySelector(".av__cellicon")) {
|
if (aElement.querySelector(".av__cellicon")) {
|
||||||
tip = `${aElement.firstChild.textContent} → ${aElement.lastChild.textContent}`;
|
tip = `${aElement.firstChild.textContent} → ${aElement.lastChild.textContent}`;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,8 @@ export class Menus {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let target = event.target as HTMLElement;
|
let target = event.target as HTMLElement;
|
||||||
while (target && !target.parentElement.isEqualNode(document.querySelector("body"))) {
|
while (target && target.parentElement // ⌃⇥ 后点击会为空
|
||||||
|
&& !target.parentElement.isEqualNode(document.querySelector("body"))) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const dataType = target.getAttribute("data-type");
|
const dataType = target.getAttribute("data-type");
|
||||||
if (dataType === "tab-header") {
|
if (dataType === "tab-header") {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import {unicode2Emoji} from "../../../emoji";
|
||||||
import {focusBlock} from "../../util/selection";
|
import {focusBlock} from "../../util/selection";
|
||||||
import {isMac} from "../../util/compatibility";
|
import {isMac} from "../../util/compatibility";
|
||||||
import {hasClosestByClassName} from "../../util/hasClosest";
|
import {hasClosestByClassName} from "../../util/hasClosest";
|
||||||
|
import {stickyRow} from "./row";
|
||||||
|
|
||||||
export const avRender = (element: Element, protyle: IProtyle, cb?: () => void) => {
|
export const avRender = (element: Element, protyle: IProtyle, cb?: () => void) => {
|
||||||
let avElements: Element[] = [];
|
let avElements: Element[] = [];
|
||||||
|
|
@ -240,12 +241,19 @@ ${cell.color ? `color:${cell.color};` : ""}">${text}</div>`;
|
||||||
if (left) {
|
if (left) {
|
||||||
e.querySelector(".av__scroll").scrollLeft = left;
|
e.querySelector(".av__scroll").scrollLeft = left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const editRect = protyle.contentElement.getBoundingClientRect();
|
||||||
if (headerTransform) {
|
if (headerTransform) {
|
||||||
(e.querySelector(".av__row--header") as HTMLElement).style.transform = headerTransform;
|
(e.querySelector(".av__row--header") as HTMLElement).style.transform = headerTransform;
|
||||||
|
} else {
|
||||||
|
stickyRow(e, editRect, "top");
|
||||||
}
|
}
|
||||||
if (footerTransform) {
|
if (footerTransform) {
|
||||||
(e.querySelector(".av__row--footer") as HTMLElement).style.transform = footerTransform;
|
(e.querySelector(".av__row--footer") as HTMLElement).style.transform = footerTransform;
|
||||||
|
} else {
|
||||||
|
stickyRow(e, editRect, "bottom");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectCellId) {
|
if (selectCellId) {
|
||||||
const newCellElement = e.querySelector(`.av__row[data-id="${selectCellId.split(Constants.ZWSP)[0]}"] .av__cell[data-col-id="${selectCellId.split(Constants.ZWSP)[1]}"]`);
|
const newCellElement = e.querySelector(`.av__row[data-id="${selectCellId.split(Constants.ZWSP)[0]}"] .av__cell[data-col-id="${selectCellId.split(Constants.ZWSP)[1]}"]`);
|
||||||
if (newCellElement) {
|
if (newCellElement) {
|
||||||
|
|
|
||||||
|
|
@ -89,3 +89,30 @@ export const insertAttrViewBlockAnimation = (blockElement: Element, size: number
|
||||||
});
|
});
|
||||||
previousElement.insertAdjacentHTML("afterend", html);
|
previousElement.insertAdjacentHTML("afterend", html);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const stickyRow = (blockElement: HTMLElement, elementRect: DOMRect, status: "top" | "bottom" | "all") => {
|
||||||
|
const scrollRect = blockElement.querySelector(".av__scroll").getBoundingClientRect();
|
||||||
|
const headerElement = blockElement.querySelector(".av__row--header") as HTMLElement;
|
||||||
|
if (headerElement && (status === "top" || status === "all")) {
|
||||||
|
const distance = Math.floor(elementRect.top - scrollRect.top);
|
||||||
|
if (distance > 0 && distance < scrollRect.height) {
|
||||||
|
headerElement.style.transform = `translateY(${distance}px)`;
|
||||||
|
} else {
|
||||||
|
headerElement.style.transform = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const footerElement = blockElement.querySelector(".av__row--footer") as HTMLElement;
|
||||||
|
if (footerElement && (status === "bottom" || status === "all")) {
|
||||||
|
if (footerElement.querySelector(".av__calc--ashow")) {
|
||||||
|
const distance = Math.ceil(elementRect.bottom - footerElement.parentElement.getBoundingClientRect().bottom);
|
||||||
|
if (distance < 0 && -distance < scrollRect.height) {
|
||||||
|
footerElement.style.transform = `translateY(${distance}px)`;
|
||||||
|
} else {
|
||||||
|
footerElement.style.transform = "";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
footerElement.style.transform = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import {fetchPost} from "../../util/fetch";
|
||||||
import {onGet} from "../util/onGet";
|
import {onGet} from "../util/onGet";
|
||||||
import {isMobile} from "../../util/functions";
|
import {isMobile} from "../../util/functions";
|
||||||
import {hasClosestBlock, hasClosestByClassName} from "../util/hasClosest";
|
import {hasClosestBlock, hasClosestByClassName} from "../util/hasClosest";
|
||||||
|
import {stickyRow} from "../render/av/row";
|
||||||
|
|
||||||
let getIndexTimeout: number;
|
let getIndexTimeout: number;
|
||||||
export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
|
export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
|
||||||
|
|
@ -24,29 +25,7 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
|
||||||
if (item.dataset.render !== "true") {
|
if (item.dataset.render !== "true") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const scrollRect = item.querySelector(".av__scroll").getBoundingClientRect();
|
stickyRow(item, elementRect, "all");
|
||||||
const headerElement = item.querySelector(".av__row--header") as HTMLElement;
|
|
||||||
if (headerElement) {
|
|
||||||
const distance = Math.floor(elementRect.top - scrollRect.top);
|
|
||||||
if (distance > 0 && distance < scrollRect.height) {
|
|
||||||
headerElement.style.transform = `translateY(${distance}px)`;
|
|
||||||
} else {
|
|
||||||
headerElement.style.transform = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const footerElement = item.querySelector(".av__row--footer") as HTMLElement;
|
|
||||||
if (footerElement) {
|
|
||||||
if (footerElement.querySelector(".av__calc--ashow")) {
|
|
||||||
const distance = Math.ceil(elementRect.bottom - footerElement.parentElement.getBoundingClientRect().bottom);
|
|
||||||
if (distance < 0 && -distance < scrollRect.height) {
|
|
||||||
footerElement.style.transform = `translateY(${distance}px)`;
|
|
||||||
} else {
|
|
||||||
footerElement.style.transform = "";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
footerElement.style.transform = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!protyle.element.classList.contains("block__edit") && !isMobile()) {
|
if (!protyle.element.classList.contains("block__edit") && !isMobile()) {
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ import {removeSearchMark} from "../toolbar/util";
|
||||||
import {activeBlur, hideKeyboardToolbar} from "../../mobile/util/keyboardToolbar";
|
import {activeBlur, hideKeyboardToolbar} from "../../mobile/util/keyboardToolbar";
|
||||||
import {commonClick} from "./commonClick";
|
import {commonClick} from "./commonClick";
|
||||||
import {avClick, avContextmenu, updateAVName} from "../render/av/action";
|
import {avClick, avContextmenu, updateAVName} from "../render/av/action";
|
||||||
import {updateHeader} from "../render/av/row";
|
import {stickyRow, updateHeader} from "../render/av/row";
|
||||||
|
|
||||||
export class WYSIWYG {
|
export class WYSIWYG {
|
||||||
public lastHTMLs: { [key: string]: string } = {};
|
public lastHTMLs: { [key: string]: string } = {};
|
||||||
|
|
@ -382,14 +382,14 @@ export class WYSIWYG {
|
||||||
const oldWidth = dragElement.clientWidth;
|
const oldWidth = dragElement.clientWidth;
|
||||||
const dragColId = dragElement.getAttribute("data-col-id");
|
const dragColId = dragElement.getAttribute("data-col-id");
|
||||||
let newWidth: string;
|
let newWidth: string;
|
||||||
|
const scrollElement = nodeElement.querySelector(".av__scroll");
|
||||||
|
const contentRect = protyle.contentElement.getBoundingClientRect()
|
||||||
documentSelf.onmousemove = (moveEvent: MouseEvent) => {
|
documentSelf.onmousemove = (moveEvent: MouseEvent) => {
|
||||||
newWidth = Math.max(oldWidth + (moveEvent.clientX - event.clientX), 58) + "px";
|
newWidth = Math.max(oldWidth + (moveEvent.clientX - event.clientX), 58) + "px";
|
||||||
const scrollElement = hasClosestByClassName(dragElement, "av__scroll");
|
scrollElement.querySelectorAll(".av__row, .av__row--footer").forEach(item => {
|
||||||
if (scrollElement) {
|
(item.querySelector(`[data-col-id="${dragColId}"]`) as HTMLElement).style.width = newWidth;
|
||||||
scrollElement.querySelectorAll(".av__row, .av__row--footer").forEach(item => {
|
});
|
||||||
(item.querySelector(`[data-col-id="${dragColId}"]`) as HTMLElement).style.width = newWidth;
|
stickyRow(nodeElement, contentRect, "bottom");
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
documentSelf.onmouseup = () => {
|
documentSelf.onmouseup = () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue