获取 json 布局不应保存 scroll

This commit is contained in:
Vanessa 2023-12-31 16:51:31 +08:00
parent 45bfec7d2f
commit ac269b4e1b
16 changed files with 74 additions and 83 deletions

View file

@ -144,7 +144,7 @@ const dialogArrow = (app: App, element: HTMLElement, event: KeyboardEvent) => {
openFileById({ openFileById({
app, app,
id: currentLiElement.getAttribute("data-node-id"), id: currentLiElement.getAttribute("data-node-id"),
action: [Constants.CB_GET_SCROLL] action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
}); });
} }
hideElements(["dialog"]); hideElements(["dialog"]);

View file

@ -176,7 +176,6 @@ export const initWindow = async (app: App) => {
/// #if !BROWSER /// #if !BROWSER
const winOnClose = (close = false) => { const winOnClose = (close = false) => {
exportLayout({ exportLayout({
reload: false,
cb() { cb() {
if (window.siyuan.config.appearance.closeButtonBehavior === 1 && !close) { if (window.siyuan.config.appearance.closeButtonBehavior === 1 && !close) {
// 最小化 // 最小化
@ -191,7 +190,6 @@ export const initWindow = async (app: App) => {
exitSiYuan(); exitSiYuan();
} }
}, },
onlyData: false,
errorExit: true errorExit: true
}); });
}; };

View file

@ -306,8 +306,6 @@ export const about = {
networkServeElement.addEventListener("change", () => { networkServeElement.addEventListener("change", () => {
fetchPost("/api/system/setNetworkServe", {networkServe: networkServeElement.checked}, () => { fetchPost("/api/system/setNetworkServe", {networkServe: networkServeElement.checked}, () => {
exportLayout({ exportLayout({
reload: false,
onlyData: false,
errorExit: true, errorExit: true,
cb: exitSiYuan cb: exitSiYuan
}); });
@ -323,9 +321,10 @@ export const about = {
googleAnalyticsElement.addEventListener("change", () => { googleAnalyticsElement.addEventListener("change", () => {
fetchPost("/api/system/setGoogleAnalytics", {googleAnalytics: googleAnalyticsElement.checked}, () => { fetchPost("/api/system/setGoogleAnalytics", {googleAnalytics: googleAnalyticsElement.checked}, () => {
exportLayout({ exportLayout({
reload: true,
onlyData: false,
errorExit: false, errorExit: false,
cb() {
window.location.reload();
}
}); });
}); });
}); });
@ -333,8 +332,6 @@ export const about = {
uploadErrLogElement.addEventListener("change", () => { uploadErrLogElement.addEventListener("change", () => {
fetchPost("/api/system/setUploadErrLog", {uploadErrLog: uploadErrLogElement.checked}, () => { fetchPost("/api/system/setUploadErrLog", {uploadErrLog: uploadErrLogElement.checked}, () => {
exportLayout({ exportLayout({
reload: false,
onlyData: false,
errorExit: true, errorExit: true,
cb: exitSiYuan cb: exitSiYuan
}); });
@ -369,9 +366,10 @@ export const about = {
proxyURL: `${window.siyuan.config.system.networkProxy.scheme}://${window.siyuan.config.system.networkProxy.host}:${window.siyuan.config.system.networkProxy.port}`, proxyURL: `${window.siyuan.config.system.networkProxy.scheme}://${window.siyuan.config.system.networkProxy.host}:${window.siyuan.config.system.networkProxy.port}`,
}).then(() => { }).then(() => {
exportLayout({ exportLayout({
reload: true,
onlyData: false,
errorExit: false, errorExit: false,
cb() {
window.location.reload();
},
}); });
}); });
/// #endif /// #endif

View file

@ -169,9 +169,10 @@ export const appearance = {
window.siyuan.config.appearance.themeDark !== response.data.themeDark window.siyuan.config.appearance.themeDark !== response.data.themeDark
)) { )) {
exportLayout({ exportLayout({
reload: true,
onlyData: false,
errorExit: false, errorExit: false,
cb() {
window.location.reload();
},
}); });
return; return;
} }
@ -180,8 +181,9 @@ export const appearance = {
(response.data.mode === 1 && OSTheme === "light") || (response.data.mode === 0 && OSTheme === "dark") (response.data.mode === 1 && OSTheme === "light") || (response.data.mode === 0 && OSTheme === "dark")
)) { )) {
exportLayout({ exportLayout({
reload: true, cb() {
onlyData: false, window.location.reload();
},
errorExit: false, errorExit: false,
}); });
return; return;
@ -215,8 +217,9 @@ export const appearance = {
}); });
appearance.element.querySelector("#appearanceRefresh").addEventListener("click", () => { appearance.element.querySelector("#appearanceRefresh").addEventListener("click", () => {
exportLayout({ exportLayout({
reload: true, cb() {
onlyData: false, window.location.reload();
},
errorExit: false, errorExit: false,
}); });
}); });
@ -235,8 +238,9 @@ export const appearance = {
onSetappearance(data: IAppearance) { onSetappearance(data: IAppearance) {
if (data.lang !== window.siyuan.config.appearance.lang) { if (data.lang !== window.siyuan.config.appearance.lang) {
exportLayout({ exportLayout({
reload: true, cb() {
onlyData: false, window.location.reload();
},
errorExit: false, errorExit: false,
}); });
return; return;

View file

@ -626,8 +626,9 @@ export const bazaar = {
}, response => { }, response => {
if (window.siyuan.config.appearance.themeJS && bazaarType === "themes") { if (window.siyuan.config.appearance.themeJS && bazaarType === "themes") {
exportLayout({ exportLayout({
reload: true, cb() {
onlyData: false, window.location.reload();
},
errorExit: false, errorExit: false,
}); });
return; return;
@ -686,8 +687,9 @@ export const bazaar = {
)) { )) {
if (window.siyuan.config.appearance.themeJS) { if (window.siyuan.config.appearance.themeJS) {
exportLayout({ exportLayout({
reload: true, cb() {
onlyData: false, window.location.reload();
},
errorExit: false, errorExit: false,
}); });
} else { } else {
@ -763,8 +765,9 @@ export const bazaar = {
(mode === 0 && window.siyuan.config.appearance.themeLight !== packageName)) && (mode === 0 && window.siyuan.config.appearance.themeLight !== packageName)) &&
window.siyuan.config.appearance.themeJS) { window.siyuan.config.appearance.themeJS) {
exportLayout({ exportLayout({
reload: true, cb() {
onlyData: false, window.location.reload();
},
errorExit: false, errorExit: false,
}); });
} else { } else {

View file

@ -259,8 +259,9 @@ export const keymap = {
bindEvent(app: App) { bindEvent(app: App) {
keymap.element.querySelector("#keymapRefreshBtn").addEventListener("click", () => { keymap.element.querySelector("#keymapRefreshBtn").addEventListener("click", () => {
exportLayout({ exportLayout({
reload: true, cb() {
onlyData: false, window.location.reload();
},
errorExit: false, errorExit: false,
}); });
}); });

View file

@ -263,8 +263,6 @@ export const transactionError = () => {
exitSiYuan(); exitSiYuan();
/// #else /// #else
exportLayout({ exportLayout({
reload: false,
onlyData: false,
errorExit: true, errorExit: true,
cb: exitSiYuan cb: exitSiYuan
}); });

View file

@ -117,10 +117,8 @@ export const initBar = (app: App) => {
break; break;
} else if (targetId === "barExit") { } else if (targetId === "barExit") {
exportLayout({ exportLayout({
reload: false,
onlyData: false,
errorExit: true, errorExit: true,
cb: exitSiYuan cb: exitSiYuan,
}); });
event.stopPropagation(); event.stopPropagation();
break; break;

View file

@ -220,25 +220,19 @@ export const saveLayout = () => {
}; };
export const exportLayout = (options: { export const exportLayout = (options: {
reload: boolean, cb: () => void,
cb?: () => void, errorExit: boolean
onlyData: boolean,
errorExit: boolean,
}) => { }) => {
if (isWindow()) { if (isWindow()) {
const layoutJSON: any = { const layoutJSON: any = {
layout: {}, layout: {},
}; };
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout); layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);
if (options.onlyData) { getAllModels().editor.forEach(item => {
return layoutJSON; saveScroll(item.editor.protyle)
} })
sessionStorage.setItem("layout", JSON.stringify(layoutJSON)); sessionStorage.setItem("layout", JSON.stringify(layoutJSON));
if (options.reload) { options.cb();
window.location.reload();
} else if (options.cb) {
options.cb();
}
return; return;
} }
const useElement = document.querySelector("#barDock use"); const useElement = document.querySelector("#barDock use");
@ -253,21 +247,29 @@ export const exportLayout = (options: {
right: dockToJSON(window.siyuan.layout.rightDock), right: dockToJSON(window.siyuan.layout.rightDock),
}; };
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout); layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);
if (options.onlyData) { getAllModels().editor.forEach(item => {
return layoutJSON; saveScroll(item.editor.protyle)
} })
fetchPost("/api/system/setUILayout", { fetchPost("/api/system/setUILayout", {
layout: layoutJSON, layout: layoutJSON,
errorExit: options.errorExit // 后台不接受该参数,用于请求发生错误时退出程序 errorExit: options.errorExit // 后台不接受该参数,用于请求发生错误时退出程序
}, () => { }, () => {
if (options.reload) { options.cb();
window.location.reload();
} else if (options.cb) {
options.cb();
}
}); });
}; };
export const getAllLayout = () => {
const layoutJSON: any = {
hideDock: document.querySelector("#barDock use").getAttribute("xlink:href") === "#iconDock",
layout: {},
bottom: dockToJSON(window.siyuan.layout.bottomDock),
left: dockToJSON(window.siyuan.layout.leftDock),
right: dockToJSON(window.siyuan.layout.rightDock),
};
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);
return layoutJSON;
}
const initInternalDock = (dockItem: IDockTab[]) => { const initInternalDock = (dockItem: IDockTab[]) => {
dockItem.forEach((existSubItem) => { dockItem.forEach((existSubItem) => {
if (existSubItem.hotkeyLangId) { if (existSubItem.hotkeyLangId) {
@ -537,7 +539,6 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, brea
json.mode = layout.editor.protyle.preview.element.classList.contains("fn__none") ? "wysiwyg" : "preview"; json.mode = layout.editor.protyle.preview.element.classList.contains("fn__none") ? "wysiwyg" : "preview";
json.action = layout.editor.protyle.block.showAll ? Constants.CB_GET_ALL : Constants.CB_GET_SCROLL; json.action = layout.editor.protyle.block.showAll ? Constants.CB_GET_ALL : Constants.CB_GET_SCROLL;
json.instance = "Editor"; json.instance = "Editor";
saveScroll(layout.editor.protyle);
} else if (layout instanceof Asset) { } else if (layout instanceof Asset) {
json.path = layout.path; json.path = layout.path;
if (layout.pdfObject) { if (layout.pdfObject) {

View file

@ -11,7 +11,7 @@ import {isInAndroid, isInIOS, isIPad, setStorageVal, writeText} from "../protyle
import {openCard} from "../card/openCard"; import {openCard} from "../card/openCard";
import {openSetting} from "../config"; import {openSetting} from "../config";
import {getAllDocks} from "../layout/getAll"; import {getAllDocks} from "../layout/getAll";
import {exportLayout} from "../layout/util"; import {exportLayout, getAllLayout} from "../layout/util";
import {getDockByType} from "../layout/tabUtil"; import {getDockByType} from "../layout/tabUtil";
import {exitSiYuan, lockScreen} from "../dialog/processSystem"; import {exitSiYuan, lockScreen} from "../dialog/processSystem";
import {showMessage} from "../dialog/message"; import {showMessage} from "../dialog/message";
@ -252,11 +252,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {
if (item.name === value) { if (item.name === value) {
saveDialog.destroy(); saveDialog.destroy();
confirmDialog(window.siyuan.languages.save, window.siyuan.languages.exportTplTip, () => { confirmDialog(window.siyuan.languages.save, window.siyuan.languages.exportTplTip, () => {
item.layout = exportLayout({ item.layout = getAllLayout();
reload: false,
onlyData: true,
errorExit: false,
});
setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]); setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]);
}); });
return true; return true;
@ -267,11 +263,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {
} }
window.siyuan.storage[Constants.LOCAL_LAYOUTS].push({ window.siyuan.storage[Constants.LOCAL_LAYOUTS].push({
name: value, name: value,
layout: exportLayout({ layout: getAllLayout()
reload: false,
onlyData: true,
errorExit: false,
})
}); });
setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]); setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]);
saveDialog.destroy(); saveDialog.destroy();
@ -427,10 +419,8 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {
icon: "iconQuit", icon: "iconQuit",
click: () => { click: () => {
exportLayout({ exportLayout({
reload: false,
onlyData: false,
errorExit: true, errorExit: true,
cb: exitSiYuan cb: exitSiYuan,
}); });
} }
}).element); }).element);

View file

@ -24,7 +24,7 @@ ${unicode2Emoji(item.icon || Constants.SIYUAN_IMAGE_FILE, "b3-list-item__graphic
element.firstElementChild.addEventListener("click", (event) => { element.firstElementChild.addEventListener("click", (event) => {
const liElement = hasClosestByClassName(event.target as HTMLElement, "b3-list-item"); const liElement = hasClosestByClassName(event.target as HTMLElement, "b3-list-item");
if (liElement) { if (liElement) {
openMobileFileById(app, liElement.dataset.nodeId, [Constants.CB_GET_SCROLL]); openMobileFileById(app, liElement.dataset.nodeId, [Constants.CB_GET_SCROLL, Constants.CB_GET_HL]);
} }
}); });
} }

View file

@ -180,7 +180,7 @@ export const initFramework = (app: App, isStart: boolean) => {
const localDoc = window.siyuan.storage[Constants.LOCAL_DOCINFO]; const localDoc = window.siyuan.storage[Constants.LOCAL_DOCINFO];
fetchPost("/api/block/checkBlockExist", {id: localDoc.id}, existResponse => { fetchPost("/api/block/checkBlockExist", {id: localDoc.id}, existResponse => {
if (existResponse.data) { if (existResponse.data) {
openMobileFileById(app, localDoc.id, [Constants.CB_GET_SCROLL]); openMobileFileById(app, localDoc.id, [Constants.CB_GET_SCROLL, Constants.CB_GET_HL]);
} else { } else {
fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => { fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => {
if (response.data.length !== 0) { if (response.data.length !== 0) {

View file

@ -395,7 +395,7 @@ const focusElementById = (protyle: IProtyle, action: string[], scrollAttr?: IScr
if (hasScrollTop) { if (hasScrollTop) {
protyle.contentElement.scrollTop = scrollAttr.scrollTop; protyle.contentElement.scrollTop = scrollAttr.scrollTop;
} }
if (action.includes(Constants.CB_GET_FOCUS) || action.includes(Constants.CB_GET_HL) || action.includes(Constants.CB_GET_FOCUSFIRST)) { if (action.includes(Constants.CB_GET_FOCUS) || action.includes(Constants.CB_GET_SCROLL) || action.includes(Constants.CB_GET_HL) || action.includes(Constants.CB_GET_FOCUSFIRST)) {
const contentRect = protyle.contentElement.getBoundingClientRect(); const contentRect = protyle.contentElement.getBoundingClientRect();
const focusRect = focusElement.getBoundingClientRect(); const focusRect = focusElement.getBoundingClientRect();
if (!hasScrollTop && (contentRect.top > focusRect.top || contentRect.bottom < focusRect.bottom)) { if (!hasScrollTop && (contentRect.top > focusRect.top || contentRect.bottom < focusRect.bottom)) {

View file

@ -139,8 +139,9 @@ export const initAssets = () => {
if (window.siyuan.config.appearance.themeJS) { if (window.siyuan.config.appearance.themeJS) {
/// #if !MOBILE /// #if !MOBILE
exportLayout({ exportLayout({
reload: true, cb() {
onlyData: false, window.location.reload();
},
errorExit: false, errorExit: false,
}); });
/// #else /// #else
@ -271,8 +272,9 @@ export const setMode = (modeElementValue: number) => {
window.siyuan.config.appearance.themeDark !== response.data.themeDark window.siyuan.config.appearance.themeDark !== response.data.themeDark
)) { )) {
exportLayout({ exportLayout({
reload: true, cb() {
onlyData: false, window.location.reload();
},
errorExit: false, errorExit: false,
}); });
return; return;
@ -282,8 +284,9 @@ export const setMode = (modeElementValue: number) => {
(response.data.mode === 1 && OSTheme === "light") || (response.data.mode === 0 && OSTheme === "dark") (response.data.mode === 1 && OSTheme === "light") || (response.data.mode === 0 && OSTheme === "dark")
)) { )) {
exportLayout({ exportLayout({
reload: true, cb() {
onlyData: false, window.location.reload();
},
errorExit: false, errorExit: false,
}); });
return; return;

View file

@ -24,14 +24,15 @@ export const processMessage = (response: IWebSocketData) => {
if ("reloadui" === response.cmd) { if ("reloadui" === response.cmd) {
if (response.data?.resetScroll) { if (response.data?.resetScroll) {
window.siyuan.storage[Constants.LOCAL_FILEPOSITION] = {}; window.siyuan.storage[Constants.LOCAL_FILEPOSITION] = {};
setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]); setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]);
} }
/// #if MOBILE /// #if MOBILE
window.location.reload(); window.location.reload();
/// #else /// #else
exportLayout({ exportLayout({
reload: true, cb() {
onlyData: false, window.location.reload();
},
errorExit: false, errorExit: false,
}); });
/// #endif /// #endif

View file

@ -16,8 +16,6 @@ export const onWindowsMsg = (ipcData: IWebSocketData) => {
break; break;
case "lockscreen": case "lockscreen":
exportLayout({ exportLayout({
reload: false,
onlyData: false,
errorExit: false, errorExit: false,
cb() { cb() {
fetchPost("/api/system/logoutAuth", {}, () => { fetchPost("/api/system/logoutAuth", {}, () => {
@ -29,8 +27,6 @@ export const onWindowsMsg = (ipcData: IWebSocketData) => {
case "lockscreenByMode": case "lockscreenByMode":
if (window.siyuan.config.system.lockScreenMode === 1) { if (window.siyuan.config.system.lockScreenMode === 1) {
exportLayout({ exportLayout({
reload: false,
onlyData: false,
errorExit: false, errorExit: false,
cb() { cb() {
fetchPost("/api/system/logoutAuth", {}, () => { fetchPost("/api/system/logoutAuth", {}, () => {