mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
This commit is contained in:
parent
40b9c62693
commit
e24522b75d
8 changed files with 62 additions and 62 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import {exportLayout, JSONToLayout, resetLayout, resizeTopBar} from "../layout/util";
|
import {exportLayout, JSONToLayout, resetLayout, resizeTopBar, saveLayout} from "../layout/util";
|
||||||
import {resizeTabs} from "../layout/tabUtil";
|
import {resizeTabs} from "../layout/tabUtil";
|
||||||
import {setStorageVal} from "../protyle/util/compatibility";
|
import {setStorageVal} from "../protyle/util/compatibility";
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
|
|
@ -172,19 +172,6 @@ const winOnMaxRestore = async () => {
|
||||||
/// #endif
|
/// #endif
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveUI = () => {
|
|
||||||
exportLayout({
|
|
||||||
reload: false,
|
|
||||||
onlyData: false,
|
|
||||||
errorExit: false
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const unbindSaveUI = () => {
|
|
||||||
window.removeEventListener("beforeunload", saveUI);
|
|
||||||
window.removeEventListener("pagehide", saveUI);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const initWindow = async (app: App) => {
|
export const initWindow = async (app: App) => {
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
const winOnClose = (close = false) => {
|
const winOnClose = (close = false) => {
|
||||||
|
|
@ -514,7 +501,5 @@ ${response.data.replace("%pages", "<span class=totalPages></span>").replace("%pa
|
||||||
if (!isWindow()) {
|
if (!isWindow()) {
|
||||||
document.querySelector(".toolbar").classList.add("toolbar--browser");
|
document.querySelector(".toolbar").classList.add("toolbar--browser");
|
||||||
}
|
}
|
||||||
window.addEventListener("beforeunload", saveUI, false);
|
|
||||||
window.addEventListener("pagehide", saveUI, false);
|
|
||||||
/// #endif
|
/// #endif
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
import {Layout} from "./index";
|
import {Layout} from "./index";
|
||||||
import {genUUID} from "../util/genID";
|
import {genUUID} from "../util/genID";
|
||||||
import {
|
import {
|
||||||
exportLayout,
|
|
||||||
getInstanceById,
|
getInstanceById,
|
||||||
getWndByLayout, JSONToCenter,
|
getWndByLayout, JSONToCenter,
|
||||||
newModelByInitData, pdfIsLoading,
|
newModelByInitData, pdfIsLoading, saveLayout,
|
||||||
setPanelFocus,
|
setPanelFocus,
|
||||||
switchWnd
|
switchWnd
|
||||||
} from "./util";
|
} from "./util";
|
||||||
|
|
@ -280,11 +279,7 @@ export class Wnd {
|
||||||
} else {
|
} else {
|
||||||
oldTab.parent.children.push(tempTab);
|
oldTab.parent.children.push(tempTab);
|
||||||
}
|
}
|
||||||
exportLayout({
|
saveLayout()
|
||||||
reload: false,
|
|
||||||
onlyData: false,
|
|
||||||
errorExit: false
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.element.addEventListener("dragenter", (event: DragEvent & { target: HTMLElement }) => {
|
this.element.addEventListener("dragenter", (event: DragEvent & { target: HTMLElement }) => {
|
||||||
|
|
@ -498,7 +493,7 @@ export class Wnd {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public addTab(tab: Tab, keepCursor = false, saveLayout = true) {
|
public addTab(tab: Tab, keepCursor = false, isSaveLayout = true) {
|
||||||
if (keepCursor) {
|
if (keepCursor) {
|
||||||
tab.headElement?.classList.remove("item--focus");
|
tab.headElement?.classList.remove("item--focus");
|
||||||
tab.panelElement.classList.add("fn__none");
|
tab.panelElement.classList.add("fn__none");
|
||||||
|
|
@ -566,12 +561,8 @@ export class Wnd {
|
||||||
setTabPosition();
|
setTabPosition();
|
||||||
setModelsHash();
|
setModelsHash();
|
||||||
/// #endif
|
/// #endif
|
||||||
if (saveLayout) {
|
if (isSaveLayout) {
|
||||||
exportLayout({
|
saveLayout();
|
||||||
reload: false,
|
|
||||||
onlyData: false,
|
|
||||||
errorExit: false
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -773,7 +764,7 @@ export class Wnd {
|
||||||
item.panelElement.remove();
|
item.panelElement.remove();
|
||||||
this.destroyModel(item.model);
|
this.destroyModel(item.model);
|
||||||
this.children.splice(index, 1);
|
this.children.splice(index, 1);
|
||||||
resizeTabs();
|
resizeTabs(item.headElement ? true : false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -789,7 +780,7 @@ export class Wnd {
|
||||||
/// #endif
|
/// #endif
|
||||||
const wnd = new Wnd(this.app);
|
const wnd = new Wnd(this.app);
|
||||||
window.siyuan.layout.centerLayout.addWnd(wnd);
|
window.siyuan.layout.centerLayout.addWnd(wnd);
|
||||||
wnd.addTab(newCenterEmptyTab(this.app));
|
wnd.addTab(newCenterEmptyTab(this.app), false, false);
|
||||||
setTitle(window.siyuan.languages.siyuanNote);
|
setTitle(window.siyuan.languages.siyuanNote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -720,7 +720,7 @@ export class Dock {
|
||||||
this.element.classList.remove("fn__none");
|
this.element.classList.remove("fn__none");
|
||||||
}
|
}
|
||||||
if (data[0].show) {
|
if (data[0].show) {
|
||||||
this.toggleModel(data[0].type, true);
|
this.toggleModel(data[0].type, true, false, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import {Tab} from "./Tab";
|
import {Tab} from "./Tab";
|
||||||
import {exportLayout, getInstanceById, newModelByInitData} from "./util";
|
import {exportLayout, getInstanceById, newModelByInitData, saveLayout} from "./util";
|
||||||
import {getAllModels, getAllTabs} from "./getAll";
|
import {getAllModels, getAllTabs} from "./getAll";
|
||||||
import {hideAllElements, hideElements} from "../protyle/ui/hideElements";
|
import {hideAllElements, hideElements} from "../protyle/ui/hideElements";
|
||||||
import {pdfResize} from "../asset/renderAssets";
|
import {pdfResize} from "../asset/renderAssets";
|
||||||
|
|
@ -84,7 +84,7 @@ export const switchTabByIndex = (index: number) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
let resizeTimeout: number;
|
let resizeTimeout: number;
|
||||||
export const resizeTabs = (setLayout = true) => {
|
export const resizeTabs = (isSaveLayout = true) => {
|
||||||
clearTimeout(resizeTimeout);
|
clearTimeout(resizeTimeout);
|
||||||
// .layout .fn__flex-shrink {width .15s cubic-bezier(0, 0, .2, 1) 0ms} 时需要再次计算 padding
|
// .layout .fn__flex-shrink {width .15s cubic-bezier(0, 0, .2, 1) 0ms} 时需要再次计算 padding
|
||||||
// PDF 避免分屏多次调用后,页码跳转到1 https://github.com/siyuan-note/siyuan/issues/5646
|
// PDF 避免分屏多次调用后,页码跳转到1 https://github.com/siyuan-note/siyuan/issues/5646
|
||||||
|
|
@ -117,12 +117,8 @@ export const resizeTabs = (setLayout = true) => {
|
||||||
});
|
});
|
||||||
pdfResize();
|
pdfResize();
|
||||||
hideAllElements(["gutter"]);
|
hideAllElements(["gutter"]);
|
||||||
if (setLayout) {
|
if (isSaveLayout) {
|
||||||
exportLayout({
|
saveLayout();
|
||||||
reload: false,
|
|
||||||
onlyData: false,
|
|
||||||
errorExit: false
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}, 200);
|
}, 200);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,47 @@ export const resetLayout = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let saveCount = 0;
|
||||||
|
export const saveLayout = () => {
|
||||||
|
const breakObj = {}
|
||||||
|
let layoutJSON: any = {};
|
||||||
|
if (isWindow()) {
|
||||||
|
layoutJSON = {
|
||||||
|
layout: {},
|
||||||
|
};
|
||||||
|
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout, breakObj);
|
||||||
|
} else {
|
||||||
|
const useElement = document.querySelector("#barDock use");
|
||||||
|
if (useElement) {
|
||||||
|
layoutJSON = {
|
||||||
|
hideDock: useElement.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, breakObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(breakObj).length > 0 && saveCount < 10) {
|
||||||
|
saveCount++;
|
||||||
|
setTimeout(() => {
|
||||||
|
saveLayout();
|
||||||
|
}, Constants.TIMEOUT_LOAD);
|
||||||
|
} else {
|
||||||
|
saveCount = 0;
|
||||||
|
if (isWindow()) {
|
||||||
|
sessionStorage.setItem("layout", JSON.stringify(layoutJSON));
|
||||||
|
} else {
|
||||||
|
fetchPost("/api/system/setUILayout", {
|
||||||
|
layout: layoutJSON,
|
||||||
|
errorExit: false // 后台不接受该参数,用于请求发生错误时退出程序
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const exportLayout = (options: {
|
export const exportLayout = (options: {
|
||||||
reload: boolean,
|
reload: boolean,
|
||||||
cb?: () => void,
|
cb?: () => void,
|
||||||
|
|
@ -439,7 +480,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
|
||||||
resizeTopBar();
|
resizeTopBar();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => {
|
export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, breakObj?: IObject) => {
|
||||||
if (layout instanceof Layout) {
|
if (layout instanceof Layout) {
|
||||||
json.direction = layout.direction;
|
json.direction = layout.direction;
|
||||||
if (layout.parent) {
|
if (layout.parent) {
|
||||||
|
|
@ -482,6 +523,9 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => {
|
||||||
}
|
}
|
||||||
json.instance = "Tab";
|
json.instance = "Tab";
|
||||||
} else if (layout instanceof Editor) {
|
} else if (layout instanceof Editor) {
|
||||||
|
if (!layout.editor.protyle.notebookId && breakObj) {
|
||||||
|
breakObj.editor = "true";
|
||||||
|
}
|
||||||
json.notebookId = layout.editor.protyle.notebookId;
|
json.notebookId = layout.editor.protyle.notebookId;
|
||||||
json.blockId = layout.editor.protyle.block.id;
|
json.blockId = layout.editor.protyle.block.id;
|
||||||
json.rootId = layout.editor.protyle.block.rootID;
|
json.rootId = layout.editor.protyle.block.rootID;
|
||||||
|
|
@ -555,13 +599,13 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => {
|
||||||
layout.children.forEach((item: Layout | Wnd | Tab) => {
|
layout.children.forEach((item: Layout | Wnd | Tab) => {
|
||||||
const itemJSON = {};
|
const itemJSON = {};
|
||||||
json.children.push(itemJSON);
|
json.children.push(itemJSON);
|
||||||
layoutToJSON(item, itemJSON);
|
layoutToJSON(item, itemJSON, breakObj);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (layout instanceof Tab) {
|
} else if (layout instanceof Tab) {
|
||||||
if (layout.model) {
|
if (layout.model) {
|
||||||
json.children = {};
|
json.children = {};
|
||||||
layoutToJSON(layout.model, json.children);
|
layoutToJSON(layout.model, json.children, breakObj);
|
||||||
} else if (layout.headElement) {
|
} else if (layout.headElement) {
|
||||||
// 当前页签没有激活时编辑器没有初始化
|
// 当前页签没有激活时编辑器没有初始化
|
||||||
json.children = JSON.parse(layout.headElement.getAttribute("data-initdata") || "{}");
|
json.children = JSON.parse(layout.headElement.getAttribute("data-initdata") || "{}");
|
||||||
|
|
|
||||||
|
|
@ -303,7 +303,6 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fetchPost("/api/system/setUILayout", {layout: item.layout}, () => {
|
fetchPost("/api/system/setUILayout", {layout: item.layout}, () => {
|
||||||
unbindSaveUI();
|
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import {fetchSyncPost} from "../util/fetch";
|
||||||
import {App} from "../index";
|
import {App} from "../index";
|
||||||
import {Plugin} from "./index";
|
import {Plugin} from "./index";
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
import {exportLayout, resizeTopBar} from "../layout/util";
|
import {exportLayout, resizeTopBar, saveLayout} from "../layout/util";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {API} from "./API";
|
import {API} from "./API";
|
||||||
import {getFrontend, isMobile, isWindow} from "../util/functions";
|
import {getFrontend, isMobile, isWindow} from "../util/functions";
|
||||||
|
|
@ -80,13 +80,6 @@ export const loadPlugin = async (app: App, item: IPluginData) => {
|
||||||
styleElement.textContent = item.css;
|
styleElement.textContent = item.css;
|
||||||
document.head.append(styleElement);
|
document.head.append(styleElement);
|
||||||
afterLoadPlugin(plugin);
|
afterLoadPlugin(plugin);
|
||||||
/// #if !MOBILE
|
|
||||||
exportLayout({
|
|
||||||
reload: false,
|
|
||||||
onlyData: false,
|
|
||||||
errorExit: false
|
|
||||||
});
|
|
||||||
/// #endif
|
|
||||||
return plugin;
|
return plugin;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import {App} from "../index";
|
import {App} from "../index";
|
||||||
import {Plugin} from "../plugin";
|
import {Plugin} from "../plugin";
|
||||||
import {getAllModels} from "../layout/getAll";
|
import {getAllModels} from "../layout/getAll";
|
||||||
import {exportLayout, resizeTopBar} from "../layout/util";
|
import {exportLayout, resizeTopBar, saveLayout} from "../layout/util";
|
||||||
import {Constants} from "../constants";
|
import {Constants} from "../constants";
|
||||||
|
|
||||||
export const uninstall = (app: App, name: string) => {
|
export const uninstall = (app: App, name: string) => {
|
||||||
|
|
@ -51,14 +51,6 @@ export const uninstall = (app: App, name: string) => {
|
||||||
});
|
});
|
||||||
// rm plugin
|
// rm plugin
|
||||||
app.plugins.splice(index, 1);
|
app.plugins.splice(index, 1);
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
exportLayout({
|
|
||||||
reload: false,
|
|
||||||
onlyData: false,
|
|
||||||
errorExit: false
|
|
||||||
});
|
|
||||||
}, Constants.TIMEOUT_LOAD); // 移除页签时切换到新的文档页签,需等待新页签初始化完成,才有 editor.protyle.block 等数据
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue