mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-08 17:58:50 +01:00
This commit is contained in:
parent
8c35440a77
commit
74b4a00a2f
42 changed files with 426 additions and 270 deletions
|
|
@ -4,9 +4,10 @@ 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 = (protyle: IProtyle, element: HTMLElement) => {
|
||||
export const scrollEvent = (app: App, protyle: IProtyle, element: HTMLElement) => {
|
||||
let elementRect = element.getBoundingClientRect();
|
||||
element.addEventListener("scroll", () => {
|
||||
if (!protyle.toolbar.element.classList.contains("fn__none")) {
|
||||
|
|
@ -70,7 +71,12 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
|
|||
}, getResponse => {
|
||||
protyle.contentElement.style.overflow = "";
|
||||
protyle.contentElement.style.width = "";
|
||||
onGet(getResponse, protyle, [Constants.CB_GET_BEFORE, Constants.CB_GET_UNCHANGEID]);
|
||||
onGet({
|
||||
data: getResponse,
|
||||
protyle,
|
||||
action: [Constants.CB_GET_BEFORE, Constants.CB_GET_UNCHANGEID],
|
||||
app
|
||||
});
|
||||
});
|
||||
}
|
||||
} else if ((element.scrollTop > element.scrollHeight - element.clientHeight * 1.8) &&
|
||||
|
|
@ -82,7 +88,12 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
|
|||
mode: 2,
|
||||
size: window.siyuan.config.editor.dynamicLoadBlocks,
|
||||
}, getResponse => {
|
||||
onGet(getResponse, protyle, [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID]);
|
||||
onGet({
|
||||
data: getResponse,
|
||||
protyle,
|
||||
action: [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID],
|
||||
app
|
||||
});
|
||||
});
|
||||
}
|
||||
protyle.scroll.lastScrollTop = Math.max(element.scrollTop, 0);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ 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;
|
||||
|
|
@ -13,7 +14,7 @@ export class Scroll {
|
|||
public lastScrollTop: number;
|
||||
public keepLazyLoad: boolean; // 保持加载内容
|
||||
|
||||
constructor(protyle: IProtyle) {
|
||||
constructor(protyle: IProtyle, app: App) {
|
||||
this.parentElement = document.createElement("div");
|
||||
this.parentElement.classList.add("protyle-scroll");
|
||||
if (!isMobile()) {
|
||||
|
|
@ -41,25 +42,25 @@ export class Scroll {
|
|||
});
|
||||
/// #if BROWSER
|
||||
this.inputElement.addEventListener("change", () => {
|
||||
this.setIndex(protyle);
|
||||
this.setIndex(protyle, app);
|
||||
});
|
||||
this.inputElement.addEventListener("touchend", () => {
|
||||
this.setIndex(protyle);
|
||||
this.setIndex(protyle, app);
|
||||
});
|
||||
/// #endif
|
||||
this.parentElement.addEventListener("click", (event) => {
|
||||
const target = event.target as HTMLElement;
|
||||
if (hasClosestByClassName(target, "protyle-scroll__up")) {
|
||||
goHome(protyle);
|
||||
goHome(protyle, app);
|
||||
} else if (hasClosestByClassName(target, "protyle-scroll__down")) {
|
||||
goEnd(protyle);
|
||||
goEnd(protyle, app);
|
||||
} else if (target.classList.contains("b3-slider")) {
|
||||
this.setIndex(protyle);
|
||||
this.setIndex(protyle, app);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private setIndex(protyle: IProtyle) {
|
||||
private setIndex(protyle: IProtyle, app: App) {
|
||||
if (protyle.wysiwyg.element.getAttribute("data-top")) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -70,7 +71,12 @@ export class Scroll {
|
|||
mode: 0,
|
||||
size: window.siyuan.config.editor.dynamicLoadBlocks,
|
||||
}, getResponse => {
|
||||
onGet(getResponse, protyle, [Constants.CB_GET_FOCUSFIRST, Constants.CB_GET_UNCHANGEID]);
|
||||
onGet({
|
||||
data: getResponse,
|
||||
protyle,
|
||||
action: [Constants.CB_GET_FOCUSFIRST, Constants.CB_GET_UNCHANGEID],
|
||||
app
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ 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) {
|
||||
|
|
@ -45,6 +46,7 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {
|
|||
};
|
||||
|
||||
export const getDocByScroll = (options: {
|
||||
app: App,
|
||||
protyle: IProtyle,
|
||||
scrollAttr: IScrollAttr,
|
||||
mergedOptions?: IOptions,
|
||||
|
|
@ -68,7 +70,13 @@ export const getDocByScroll = (options: {
|
|||
}, response => {
|
||||
actions.push(Constants.CB_GET_ALL);
|
||||
options.protyle.breadcrumb?.toggleExit(false);
|
||||
onGet(response, options.protyle, actions, options.scrollAttr);
|
||||
onGet({
|
||||
data: response,
|
||||
protyle: options.protyle,
|
||||
action: actions,
|
||||
scrollAttr: options.scrollAttr,
|
||||
app: options.app
|
||||
});
|
||||
if (options.cb) {
|
||||
options.cb();
|
||||
}
|
||||
|
|
@ -81,7 +89,13 @@ export const getDocByScroll = (options: {
|
|||
endID: options.scrollAttr.endId,
|
||||
}, response => {
|
||||
options.protyle.breadcrumb?.toggleExit(true);
|
||||
onGet(response, options.protyle, actions, options.scrollAttr);
|
||||
onGet({
|
||||
data: response,
|
||||
protyle: options.protyle,
|
||||
action: actions,
|
||||
scrollAttr: options.scrollAttr,
|
||||
app: options.app
|
||||
});
|
||||
if (options.cb) {
|
||||
options.cb();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue