This commit is contained in:
Vanessa 2023-06-01 20:50:49 +08:00
parent fd0893d8d8
commit 6806392b41
57 changed files with 271 additions and 360 deletions

View file

@ -4,10 +4,9 @@ import {fetchPost} from "../../util/fetch";
import {onGet} from "../util/onGet";
import {isMobile} from "../../util/functions";
import {hasClosestBlock, hasClosestByClassName} from "../util/hasClosest";
import {App} from "../../index";
let getIndexTimeout: number;
export const scrollEvent = (app: App, protyle: IProtyle, element: HTMLElement) => {
export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
let elementRect = element.getBoundingClientRect();
element.addEventListener("scroll", () => {
if (!protyle.toolbar.element.classList.contains("fn__none")) {
@ -75,7 +74,6 @@ export const scrollEvent = (app: App, protyle: IProtyle, element: HTMLElement) =
data: getResponse,
protyle,
action: [Constants.CB_GET_BEFORE, Constants.CB_GET_UNCHANGEID],
app
});
});
}
@ -92,7 +90,6 @@ export const scrollEvent = (app: App, protyle: IProtyle, element: HTMLElement) =
data: getResponse,
protyle,
action: [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID],
app
});
});
}

View file

@ -5,7 +5,6 @@ import {updateHotkeyTip} from "../util/compatibility";
import {hasClosestByClassName} from "../util/hasClosest";
import {goEnd, goHome} from "../wysiwyg/commonHotkey";
import {isMobile} from "../../util/functions";
import {App} from "../../index";
export class Scroll {
public element: HTMLElement;
@ -14,7 +13,7 @@ export class Scroll {
public lastScrollTop: number;
public keepLazyLoad: boolean; // 保持加载内容
constructor(protyle: IProtyle, app: App) {
constructor(protyle: IProtyle) {
this.parentElement = document.createElement("div");
this.parentElement.classList.add("protyle-scroll");
if (!isMobile()) {
@ -42,25 +41,25 @@ export class Scroll {
});
/// #if BROWSER
this.inputElement.addEventListener("change", () => {
this.setIndex(protyle, app);
this.setIndex(protyle);
});
this.inputElement.addEventListener("touchend", () => {
this.setIndex(protyle, app);
this.setIndex(protyle);
});
/// #endif
this.parentElement.addEventListener("click", (event) => {
const target = event.target as HTMLElement;
if (hasClosestByClassName(target, "protyle-scroll__up")) {
goHome(protyle, app);
goHome(protyle);
} else if (hasClosestByClassName(target, "protyle-scroll__down")) {
goEnd(protyle, app);
goEnd(protyle);
} else if (target.classList.contains("b3-slider")) {
this.setIndex(protyle, app);
this.setIndex(protyle);
}
});
}
private setIndex(protyle: IProtyle, app: App) {
private setIndex(protyle: IProtyle) {
if (protyle.wysiwyg.element.getAttribute("data-top")) {
return;
}
@ -75,7 +74,6 @@ export class Scroll {
data: getResponse,
protyle,
action: [Constants.CB_GET_FOCUSFIRST, Constants.CB_GET_UNCHANGEID],
app
});
});
}

View file

@ -3,7 +3,6 @@ import {getSelectionOffset} from "../util/selection";
import {fetchPost} from "../../util/fetch";
import {onGet} from "../util/onGet";
import {Constants} from "../../constants";
import {App} from "../../index";
export const saveScroll = (protyle: IProtyle, getObject = false) => {
if (!protyle.wysiwyg.element.firstElementChild || window.siyuan.config.readonly) {
@ -46,7 +45,6 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {
};
export const getDocByScroll = (options: {
app: App,
protyle: IProtyle,
scrollAttr: IScrollAttr,
mergedOptions?: IOptions,
@ -75,7 +73,6 @@ export const getDocByScroll = (options: {
protyle: options.protyle,
action: actions,
scrollAttr: options.scrollAttr,
app: options.app
});
if (options.cb) {
options.cb();
@ -94,7 +91,6 @@ export const getDocByScroll = (options: {
protyle: options.protyle,
action: actions,
scrollAttr: options.scrollAttr,
app: options.app
});
if (options.cb) {
options.cb();