2022-08-23 11:55:40 +08:00
|
|
|
import {Constants} from "../../constants";
|
|
|
|
|
import {hideElements} from "../../protyle/ui/hideElements";
|
|
|
|
|
import {setEditMode} from "../../protyle/util/setEditMode";
|
|
|
|
|
import {fetchPost} from "../../util/fetch";
|
|
|
|
|
import {zoomOut} from "../../menus/protyle";
|
|
|
|
|
import {processRender} from "../../protyle/util/processCode";
|
|
|
|
|
import {highlightRender} from "../../protyle/markdown/highlightRender";
|
|
|
|
|
import {blockRender} from "../../protyle/markdown/blockRender";
|
2022-10-22 12:06:59 +08:00
|
|
|
import {disabledForeverProtyle, disabledProtyle, enableProtyle} from "../../protyle/util/onGet";
|
2023-01-01 15:18:32 +08:00
|
|
|
import {setStorageVal} from "../../protyle/util/compatibility";
|
2022-08-23 11:55:40 +08:00
|
|
|
|
|
|
|
|
const forwardStack: IBackStack[] = [];
|
|
|
|
|
|
|
|
|
|
const focusStack = (backStack: IBackStack) => {
|
|
|
|
|
const protyle = window.siyuan.mobileEditor.protyle;
|
2022-12-31 22:14:42 +08:00
|
|
|
window.siyuan.storage[Constants.LOCAL_DOCINFO] = {
|
2022-08-23 11:55:40 +08:00
|
|
|
id: backStack.id,
|
|
|
|
|
action: backStack.callback,
|
2022-12-31 22:14:42 +08:00
|
|
|
};
|
2023-01-01 15:18:32 +08:00
|
|
|
setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
|
2022-08-23 11:55:40 +08:00
|
|
|
hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle);
|
|
|
|
|
if (protyle.contentElement.classList.contains("fn__none")) {
|
|
|
|
|
setEditMode(protyle, "wysiwyg");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const startEndId = backStack.endId.split(Constants.ZWSP);
|
|
|
|
|
if (startEndId[0] === protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id") &&
|
|
|
|
|
startEndId[1] === protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id")) {
|
|
|
|
|
window.siyuan.mobileEditor.protyle.contentElement.scrollTo({
|
|
|
|
|
top: backStack.scrollTop,
|
|
|
|
|
behavior: "smooth"
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (backStack.id !== protyle.block.rootID) {
|
|
|
|
|
fetchPost("/api/block/getDocInfo", {
|
|
|
|
|
id: backStack.id,
|
|
|
|
|
}, (response) => {
|
|
|
|
|
(document.getElementById("toolbarName") as HTMLInputElement).value = response.data.name === "Untitled" ? "" : response.data.name;
|
2022-09-01 22:20:43 +08:00
|
|
|
protyle.background.render(response.data.ial, protyle.block.rootID);
|
2022-08-23 11:55:40 +08:00
|
|
|
protyle.wysiwyg.renderCustom(response.data.ial);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (backStack.isZoom) {
|
|
|
|
|
fetchPost("/api/block/checkBlockExist", {id: backStack.id}, existResponse => {
|
|
|
|
|
if (existResponse.data) {
|
|
|
|
|
zoomOut(protyle, backStack.id, undefined, false, () => {
|
|
|
|
|
protyle.contentElement.scrollTop = backStack.scrollTop;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fetchPost("/api/filetree/getDoc", {
|
|
|
|
|
id: backStack.id,
|
|
|
|
|
startID: startEndId[0],
|
|
|
|
|
endID: startEndId[1],
|
|
|
|
|
}, getResponse => {
|
2022-08-31 20:03:50 +08:00
|
|
|
protyle.block.parentID = getResponse.data.parentID;
|
|
|
|
|
protyle.block.parent2ID = getResponse.data.parent2ID;
|
|
|
|
|
protyle.block.rootID = getResponse.data.rootID;
|
2022-08-23 11:55:40 +08:00
|
|
|
protyle.block.showAll = false;
|
2022-08-31 20:03:50 +08:00
|
|
|
protyle.block.mode = getResponse.data.mode;
|
|
|
|
|
protyle.block.blockCount = getResponse.data.blockCount;
|
|
|
|
|
protyle.block.id = getResponse.data.id;
|
|
|
|
|
protyle.block.action = backStack.callback;
|
|
|
|
|
protyle.wysiwyg.element.setAttribute("data-doc-type", getResponse.data.type);
|
2022-08-23 11:55:40 +08:00
|
|
|
protyle.wysiwyg.element.innerHTML = getResponse.data.content;
|
|
|
|
|
processRender(protyle.wysiwyg.element);
|
|
|
|
|
highlightRender(protyle.wysiwyg.element);
|
2022-11-07 17:17:14 +08:00
|
|
|
blockRender(protyle, protyle.wysiwyg.element, backStack.scrollTop);
|
2022-10-22 12:06:59 +08:00
|
|
|
if (getResponse.data.isSyncing) {
|
|
|
|
|
disabledForeverProtyle(protyle);
|
2022-08-23 11:55:40 +08:00
|
|
|
} else {
|
2022-10-22 12:06:59 +08:00
|
|
|
if (protyle.disabled) {
|
|
|
|
|
disabledProtyle(protyle);
|
|
|
|
|
} else {
|
|
|
|
|
enableProtyle(protyle);
|
|
|
|
|
}
|
2022-08-23 11:55:40 +08:00
|
|
|
}
|
|
|
|
|
protyle.contentElement.scrollTop = backStack.scrollTop;
|
2022-08-31 01:14:45 +08:00
|
|
|
window.siyuan.mobileEditor.protyle.breadcrumb?.render(protyle);
|
2022-08-23 11:55:40 +08:00
|
|
|
});
|
2022-08-24 14:47:16 +08:00
|
|
|
};
|
2022-08-23 11:55:40 +08:00
|
|
|
|
|
|
|
|
export const pushBack = () => {
|
|
|
|
|
const protyle = window.siyuan.mobileEditor.protyle;
|
|
|
|
|
window.siyuan.backStack.push({
|
|
|
|
|
id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,
|
|
|
|
|
endId: protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id") + Constants.ZWSP + protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),
|
|
|
|
|
scrollTop: protyle.contentElement.scrollTop,
|
|
|
|
|
callback: protyle.block.action,
|
|
|
|
|
isZoom: protyle.block.showAll
|
|
|
|
|
});
|
2022-08-24 14:47:16 +08:00
|
|
|
};
|
2022-08-23 11:55:40 +08:00
|
|
|
|
|
|
|
|
export const goForward = () => {
|
|
|
|
|
if (window.JSAndroid && forwardStack.length < 2) {
|
|
|
|
|
window.JSAndroid.returnDesktop();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (forwardStack.length < 2) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-08-24 14:47:16 +08:00
|
|
|
window.siyuan.backStack.push(forwardStack.pop());
|
|
|
|
|
focusStack(forwardStack[forwardStack.length - 1]);
|
|
|
|
|
};
|
2022-08-23 11:55:40 +08:00
|
|
|
|
|
|
|
|
export const goBack = () => {
|
|
|
|
|
if (window.JSAndroid && window.siyuan.backStack.length < 1) {
|
|
|
|
|
window.JSAndroid.returnDesktop();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (window.siyuan.backStack.length < 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const protyle = window.siyuan.mobileEditor.protyle;
|
|
|
|
|
if (forwardStack.length === 0) {
|
|
|
|
|
forwardStack.push({
|
|
|
|
|
id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,
|
|
|
|
|
endId: protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id") + Constants.ZWSP + protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),
|
|
|
|
|
scrollTop: protyle.contentElement.scrollTop,
|
|
|
|
|
callback: protyle.block.action,
|
|
|
|
|
isZoom: protyle.block.showAll
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
const item = window.siyuan.backStack.pop();
|
|
|
|
|
forwardStack.push(item);
|
2022-08-24 14:47:16 +08:00
|
|
|
focusStack(item);
|
2022-08-23 11:55:40 +08:00
|
|
|
};
|