Vanessa 2023-10-25 17:06:19 +08:00
parent 5047d414e3
commit b2e72fd9ab
34 changed files with 645 additions and 365 deletions

View file

@ -3,8 +3,7 @@ import {genUUID} from "../util/genID";
import {
getInstanceById,
getWndByLayout, JSONToCenter,
newCenterEmptyTab, newModelByInitData, pdfIsLoading,
resizeTabs,
newModelByInitData, pdfIsLoading,
setPanelFocus,
switchWnd
} from "./util";
@ -37,6 +36,7 @@ import {App} from "../index";
import {unicode2Emoji} from "../emoji";
import {closeWindow} from "../window/closeWin";
import {setTitle} from "../dialog/processSystem";
import {newCenterEmptyTab, resizeTabs} from "./tabUtil";
export class Wnd {
private app: App;
@ -745,6 +745,7 @@ export class Wnd {
});
if (latestHeadElement && !closeAll) {
this.switchTab(latestHeadElement, true, true, false);
this.showHeading();
}
}
if (animate) {

View file

@ -1,7 +1,8 @@
import {Tab} from "../Tab";
import {Model} from "../Model";
import {Tree} from "../../util/Tree";
import {getDockByType, setPanelFocus} from "../util";
import {setPanelFocus} from "../util";
import {getDockByType} from "../tabUtil";
import {fetchPost} from "../../util/fetch";
import {Constants} from "../../constants";
import {updateHotkeyTip} from "../../protyle/util/compatibility";

View file

@ -1,7 +1,8 @@
import {Tab} from "../Tab";
import {Model} from "../Model";
import {Tree} from "../../util/Tree";
import {getDockByType, setPanelFocus} from "../util";
import {setPanelFocus} from "../util";
import {getDockByType} from "../tabUtil";
import {fetchPost} from "../../util/fetch";
import {updateHotkeyTip} from "../../protyle/util/compatibility";
import {openFileById} from "../../editor/util";

View file

@ -1,7 +1,8 @@
import {escapeHtml} from "../../util/escape";
import {Tab} from "../Tab";
import {Model} from "../Model";
import {getDockByType, getInstanceById, setPanelFocus} from "../util";
import {getInstanceById, setPanelFocus} from "../util";
import {getDockByType} from "../tabUtil";
import {Constants} from "../../constants";
import {getDisplayName, pathPosix, setNoteBook} from "../../util/pathName";
import {newFile} from "../../util/newFile";

View file

@ -1,5 +1,6 @@
import {Tab} from "../Tab";
import {getDockByType, setPanelFocus} from "../util";
import {setPanelFocus} from "../util";
import {getDockByType} from "../tabUtil";
import {Model} from "../Model";
import {Constants} from "../../constants";
import {addScript} from "../../protyle/util/addScript";

View file

@ -1,6 +1,7 @@
/// #if !MOBILE
import {Tab} from "../Tab";
import {getDockByType, setPanelFocus} from "../util";
import {setPanelFocus} from "../util";
import {getDockByType} from "../tabUtil";
/// #endif
import {fetchPost} from "../../util/fetch";
import {updateHotkeyTip} from "../../protyle/util/compatibility";

View file

@ -1,7 +1,8 @@
import {Tab} from "../Tab";
import {Model} from "../Model";
import {Tree} from "../../util/Tree";
import {getDockByType, getInstanceById, setPanelFocus} from "../util";
import {getInstanceById, setPanelFocus} from "../util";
import {getDockByType} from "../tabUtil";
import {fetchPost} from "../../util/fetch";
import {getAllModels} from "../getAll";
import {hasClosestBlock, hasClosestByClassName, hasTopClosestByClassName} from "../../protyle/util/hasClosest";

View file

@ -1,7 +1,8 @@
import {Tab} from "../Tab";
import {Model} from "../Model";
import {Tree} from "../../util/Tree";
import {getDockByType, setPanelFocus} from "../util";
import {setPanelFocus} from "../util";
import {getDockByType} from "../tabUtil";
import {fetchPost} from "../../util/fetch";
import {updateHotkeyTip} from "../../protyle/util/compatibility";
import {openGlobalSearch} from "../../search/util";

View file

@ -9,7 +9,8 @@ import {Bookmark} from "./Bookmark";
import {Tag} from "./Tag";
import {Graph} from "./Graph";
import {Model} from "../Model";
import {getDockByType, resizeTabs, setPanelFocus} from "../util";
import {setPanelFocus} from "../util";
import {getDockByType, resizeTabs} from "../tabUtil";
import {Inbox} from "./Inbox";
import {Protyle} from "../../protyle";
import {Backlink} from "./Backlink";

View file

@ -2,7 +2,8 @@ import {getAllModels} from "../getAll";
import {Tab} from "../Tab";
import {Graph} from "./Graph";
import {Outline} from "./Outline";
import {getInstanceById, getWndByLayout, resizeTabs, switchWnd} from "../util";
import {getInstanceById, getWndByLayout, switchWnd} from "../util";
import {resizeTabs} from "../tabUtil";
import {Backlink} from "./Backlink";
import {App} from "../../index";
import {Wnd} from "../Wnd";

View file

@ -1,6 +1,7 @@
import {Wnd} from "./Wnd";
import {genUUID} from "../util/genID";
import {addResize, resizeTabs} from "./util";
import {addResize} from "./util";
import {resizeTabs} from "./tabUtil";
/// #if MOBILE
// 检测移动端是否引入了桌面端的代码
console.error("Need remove unused code");

View file

@ -1,5 +1,5 @@
/// #if !MOBILE
import {getDockByType} from "./util";
import {getDockByType} from "./tabUtil";
import {hasClosestByClassName} from "../protyle/util/hasClosest";
import {fetchPost} from "../util/fetch";
import {mountHelp} from "../util/mount";

364
app/src/layout/tabUtil.ts Normal file
View file

@ -0,0 +1,364 @@
import {Tab} from "./Tab";
import {getInstanceById, newModelByInitData} from "./util";
import {getAllModels, getAllTabs} from "./getAll";
import {hideAllElements, hideElements} from "../protyle/ui/hideElements";
import {pdfResize} from "../asset/renderAssets";
import {App} from "../index";
import {Model} from "./Model";
import {Editor} from "../editor";
import {saveScroll} from "../protyle/scroll/saveScroll";
import {Asset} from "../asset";
import {Graph} from "./dock/Graph";
import {Files} from "./dock/Files";
import {Outline} from "./dock/Outline";
import {Backlink} from "./dock/Backlink";
import {Bookmark} from "./dock/Bookmark";
import {Tag} from "./dock/Tag";
import {Search} from "../search";
import {Custom} from "./dock/Custom";
import {newCardModel} from "../card/newCardTab";
import {updateHotkeyTip} from "../protyle/util/compatibility";
import {openSearch} from "../search/spread";
import {openRecentDocs} from "../business/openRecentDocs";
import {openHistory} from "../history/history";
import {newFile} from "../util/newFile";
import {mountHelp, newNotebook} from "../util/mount";
export const getActiveTab = (wndActive = true) => {
const activeTabElement = document.querySelector(".layout__wnd--active .item--focus");
let tab;
if (activeTabElement) {
tab = getInstanceById(activeTabElement.getAttribute("data-id")) as Tab;
}
if (!tab && !wndActive) {
getAllTabs().find(item => {
if (item.headElement?.classList.contains("item--focus")) {
tab = item;
}
});
}
return tab;
};
export const switchTabByIndex = (index: number) => {
const activeDockIcoElement = document.querySelector(".dock .dock__item--activefocus");
if (activeDockIcoElement) {
let indexElement = activeDockIcoElement.parentElement.children[index]
if (index === -1) {
// 最后一个
indexElement = activeDockIcoElement.parentElement.lastElementChild
if (!indexElement.getAttribute("data-type")) {
indexElement = indexElement.previousElementSibling
}
} else if (index === -2) {
// 上一个
indexElement = activeDockIcoElement.previousElementSibling
} else if (index === -3) {
// 下一个
indexElement = activeDockIcoElement.nextElementSibling
}
const type = indexElement?.getAttribute("data-type")
if (type) {
getDockByType(type)?.toggleModel(type, true, false);
}
return;
}
const tab = getActiveTab(false);
if (tab) {
let indexElement = tab.parent.headersElement.children[index]
if (index === -1) {
// 最后一个
indexElement = tab.parent.headersElement.lastElementChild
} else if (index === -2) {
// 上一个
indexElement = tab.headElement.previousElementSibling
} else if (index === -3) {
// 下一个
indexElement = tab.headElement.nextElementSibling
}
if (indexElement) {
tab.parent.switchTab(indexElement as HTMLElement, true);
tab.parent.showHeading();
}
}
}
let resizeTimeout: number;
export const resizeTabs = () => {
clearTimeout(resizeTimeout);
// .layout .fn__flex-shrink {width .15s cubic-bezier(0, 0, .2, 1) 0ms} 时需要再次计算 padding
// PDF 避免分屏多次调用后页码跳转到1 https://github.com/siyuan-note/siyuan/issues/5646
resizeTimeout = window.setTimeout(() => {
const models = getAllModels();
models.editor.forEach((item) => {
if (item.editor && item.editor.protyle &&
item.element.parentElement && !item.element.classList.contains("fn__none")) {
item.editor.resize();
}
});
// https://github.com/siyuan-note/siyuan/issues/6250
models.backlink.forEach(item => {
const mTreeElement = item.element.querySelector(".backlinkMList") as HTMLElement;
if (mTreeElement.style.height && mTreeElement.style.height !== "0px" && item.element.clientHeight !== 0) {
mTreeElement.style.height = (item.element.clientHeight - mTreeElement.previousElementSibling.clientHeight * 2) + "px";
}
item.editors.forEach(editorItem => {
hideElements(["gutter"], editorItem.protyle);
editorItem.resize();
});
});
models.search.forEach(item => {
item.edit.resize();
});
models.custom.forEach(item => {
if (item.resize) {
item.resize();
}
});
pdfResize();
hideAllElements(["gutter"]);
}, 200);
};
export const getDockByType = (type: string) => {
if (!window.siyuan.layout.leftDock) {
return undefined;
}
if (window.siyuan.layout.leftDock.data[type]) {
return window.siyuan.layout.leftDock;
}
if (window.siyuan.layout.rightDock.data[type]) {
return window.siyuan.layout.rightDock;
}
if (window.siyuan.layout.bottomDock.data[type]) {
return window.siyuan.layout.bottomDock;
}
};
export const newCenterEmptyTab = (app: App) => {
return new Tab({
panel: `<div class="layout__empty b3-list">
<div class="${!window.siyuan.config.readonly ? " fn__none" : ""}">
<div class="config-about__logo">
<img src="/stage/icon.png">
${window.siyuan.languages.siyuanNote}
</div>
<div class="b3-label__text">${window.siyuan.languages.slogan}</div>
</div>
<div class="fn__hr"></div>
<div class="b3-list-item" id="editorEmptySearch">
<svg class="b3-list-item__graphic"><use xlink:href="#iconSearch"></use></svg>
<span>${window.siyuan.languages.search}</span>
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.globalSearch.custom)}</span>
</div>
<div id="editorEmptyRecent" class="b3-list-item">
<svg class="b3-list-item__graphic"><use xlink:href="#iconList"></use></svg>
<span>${window.siyuan.languages.recentDocs}</span>
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.recentDocs.custom)}</span>
</div>
<div id="editorEmptyHistory" class="b3-list-item${window.siyuan.config.readonly ? " fn__none" : ""}">
<svg class="b3-list-item__graphic"><use xlink:href="#iconHistory"></use></svg>
<span>${window.siyuan.languages.dataHistory}</span>
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.dataHistory.custom)}</span>
</div>
<div class="b3-list-item${window.siyuan.config.readonly ? " fn__none" : ""}" id="editorEmptyFile">
<svg class="b3-list-item__graphic"><use xlink:href="#iconFile"></use></svg>
<span>${window.siyuan.languages.newFile}</span>
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.newFile.custom)}</span>
</div>
<div class="b3-list-item${window.siyuan.config.readonly ? " fn__none" : ""}" id="editorEmptyNewNotebook">
<svg class="b3-list-item__graphic"><use xlink:href="#iconFilesRoot"></use></svg>
<span>${window.siyuan.languages.newNotebook}</span>
</div>
<div class="b3-list-item" id="editorEmptyHelp">
<svg class="b3-list-item__graphic"><use xlink:href="#iconHelp"></use></svg>
<span>${window.siyuan.languages.help}</span>
</div>
</div>`,
callback(tab: Tab) {
tab.panelElement.addEventListener("click", (event) => {
let target = event.target as HTMLElement;
while (target && !target.isEqualNode(tab.panelElement)) {
if (target.id === "editorEmptySearch") {
openSearch({
app,
hotkey: window.siyuan.config.keymap.general.globalSearch.custom,
});
event.stopPropagation();
event.preventDefault();
break;
} else if (target.id === "editorEmptyRecent") {
const openRecentDocsDialog = window.siyuan.dialogs.find(item => {
if (item.element.getAttribute("data-key") === window.siyuan.config.keymap.general.recentDocs.custom) {
return true;
}
});
if (openRecentDocsDialog) {
hideElements(["dialog"]);
return;
}
openRecentDocs();
event.stopPropagation();
event.preventDefault();
break;
} else if (target.id === "editorEmptyHistory") {
openHistory(app);
event.stopPropagation();
event.preventDefault();
break;
} else if (target.id === "editorEmptyFile") {
newFile({
app,
useSavePath: true
});
event.stopPropagation();
event.preventDefault();
break;
} else if (target.id === "editorEmptyNewNotebook") {
newNotebook();
event.stopPropagation();
event.preventDefault();
break;
} else if (target.id === "editorEmptyHelp") {
mountHelp();
event.stopPropagation();
event.preventDefault();
break;
}
target = target.parentElement;
}
});
}
});
};
export const copyTab = (app: App, tab: Tab) => {
return new Tab({
icon: tab.icon,
docIcon: tab.docIcon,
title: tab.title,
callback(newTab: Tab) {
let model: Model;
if (tab.model instanceof Editor) {
model = new Editor({
app,
tab: newTab,
blockId: tab.model.editor.protyle.block.id,
scrollAttr: saveScroll(tab.model.editor.protyle, true)
});
} else if (tab.model instanceof Asset) {
model = new Asset({
app,
tab: newTab,
path: tab.model.path
});
} else if (tab.model instanceof Graph) {
model = new Graph({
app,
tab: newTab,
blockId: tab.model.blockId,
rootId: tab.model.rootId,
type: tab.model.type,
});
} else if (tab.model instanceof Files) {
model = new Files({
app,
tab: newTab
});
} else if (tab.model instanceof Outline) {
model = new Outline({
app,
tab: newTab,
blockId: tab.model.blockId,
type: tab.model.type,
isPreview: tab.model.isPreview
});
} else if (tab.model instanceof Backlink) {
model = new Backlink({
app,
tab: newTab,
blockId: tab.model.blockId,
rootId: tab.model.rootId,
type: tab.model.type
});
} else if (tab.model instanceof Bookmark) {
model = new Bookmark(app, newTab);
} else if (tab.model instanceof Tag) {
model = new Tag(app, newTab);
} else if (tab.model instanceof Search) {
model = new Search({
app,
tab: newTab,
config: tab.model.config
});
} else if (tab.model instanceof Custom) {
const custom = tab.model as Custom;
if (custom.type === "siyuan-card") {
model = newCardModel({
app,
tab: newTab,
data: custom.data
});
} else {
app.plugins.find(item => {
if (item.models[custom.type]) {
model = item.models[custom.type]({
tab: newTab,
data: custom.data
});
return true;
}
});
}
} else if (!tab.model && tab.headElement) {
const initData = JSON.parse(tab.headElement.getAttribute("data-initdata") || "{}");
if (initData) {
// 历史数据兼容 2023-05-24
if (initData.scrollAttr) {
initData.scrollAttr.rootId = initData.rootId;
}
model = newModelByInitData(app, newTab, initData);
}
}
newTab.addModel(model);
}
});
};
export const closeTabByType = async (tab: Tab, type: "closeOthers" | "closeAll" | "other", tabs?: Tab[]) => {
if (type === "closeOthers") {
for (let index = 0; index < tab.parent.children.length; index++) {
if (tab.parent.children[index].id !== tab.id && !tab.parent.children[index].headElement.classList.contains("item--pin")) {
tab.parent.children[index].parent.removeTab(tab.parent.children[index].id, true, true, false);
}
}
if (!tab.headElement.parentElement.querySelector(".item--focus")) {
tab.parent.switchTab(tab.headElement, true);
}
return
}
if (type === "closeAll") {
for (let index = 0; index < tab.parent.children.length; index++) {
if (!tab.parent.children[index].headElement.classList.contains("item--pin")) {
await tab.parent.children[index].parent.removeTab(tab.parent.children[index].id, true);
}
}
if (tab.parent.children[0].headElement.parentElement) {
tab.parent.children[0].parent.switchTab(tab.parent.children[0].headElement, true);
}
return;
}
if (tabs.length > 0) {
for (let index = 0; index < tabs.length; index++) {
if (!tabs[index].headElement.classList.contains("item--pin")) {
await tabs[index].parent.removeTab(tabs[index].id);
}
}
if (tab.headElement.parentElement && !tab.headElement.parentElement.querySelector(".item--focus")) {
tab.parent.switchTab(tab.headElement, true);
} else if (tab.parent.children[0].headElement.parentElement) {
tab.parent.children[0].parent.switchTab(tab.parent.children[0].headElement, true);
}
return;
}
}

View file

@ -1,29 +1,24 @@
import {Layout} from "./index";
import {Wnd} from "./Wnd";
import {mountHelp, newNotebook} from "../util/mount";
import {Tab} from "./Tab";
import {Model} from "./Model";
import {Graph} from "./dock/Graph";
import {Editor} from "../editor";
import {Files} from "./dock/Files";
import {newFile} from "../util/newFile";
import {Outline} from "./dock/Outline";
import {Bookmark} from "./dock/Bookmark";
import {updateHotkeyTip} from "../protyle/util/compatibility";
import {Tag} from "./dock/Tag";
import {getAllModels, getAllTabs} from "./getAll";
import {Asset} from "../asset";
import {Search} from "../search";
import {Dock} from "./dock";
import {focusByOffset, focusByRange, getSelectionOffset} from "../protyle/util/selection";
import {hideAllElements, hideElements} from "../protyle/ui/hideElements";
import {hideElements} from "../protyle/ui/hideElements";
import {fetchPost} from "../util/fetch";
import {hasClosestBlock, hasClosestByClassName} from "../protyle/util/hasClosest";
import {getContenteditableElement} from "../protyle/wysiwyg/getBlock";
import {Constants} from "../constants";
import {openSearch} from "../search/spread";
import {saveScroll} from "../protyle/scroll/saveScroll";
import {pdfResize} from "../asset/renderAssets";
import {Backlink} from "./dock/Backlink";
import {openFileById} from "../editor/util";
import {isWindow} from "../util/functions";
@ -32,13 +27,12 @@ import {setTabPosition} from "../window/setHeader";
/// #endif
import {showMessage} from "../dialog/message";
import {getIdZoomInByPath} from "../util/pathName";
import {openHistory} from "../history/history";
import {Custom} from "./dock/Custom";
import {newCardModel} from "../card/newCardTab";
import {openRecentDocs} from "../business/openRecentDocs";
import {App} from "../index";
import {afterLoadPlugin} from "../plugin/loader";
import {setTitle} from "../dialog/processSystem";
import {newCenterEmptyTab, resizeTabs} from "./tabUtil";
export const setPanelFocus = (element: Element) => {
if (element.getAttribute("data-type") === "wnd") {
@ -76,21 +70,6 @@ export const setPanelFocus = (element: Element) => {
}
};
export const getDockByType = (type: string) => {
if (!window.siyuan.layout.leftDock) {
return undefined;
}
if (window.siyuan.layout.leftDock.data[type]) {
return window.siyuan.layout.leftDock;
}
if (window.siyuan.layout.rightDock.data[type]) {
return window.siyuan.layout.rightDock;
}
if (window.siyuan.layout.bottomDock.data[type]) {
return window.siyuan.layout.bottomDock;
}
};
export const switchWnd = (newWnd: Wnd, targetWnd: Wnd) => {
// DOM 移动后 range 会变化
const rangeDatas: {
@ -449,7 +428,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
tab.parent.switchTab(item, false, false);
});
}
resizeTopbar();
resizeTopBar();
};
export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, dropEditScroll = false) => {
@ -587,7 +566,7 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, drop
}
};
export const resizeTopbar = () => {
export const resizeTopBar = () => {
const toolbarElement = document.querySelector("#toolbar");
if (!toolbarElement) {
return;
@ -647,136 +626,6 @@ export const resizeTopbar = () => {
});
};
let resizeTimeout: number;
export const resizeTabs = () => {
clearTimeout(resizeTimeout);
// .layout .fn__flex-shrink {width .15s cubic-bezier(0, 0, .2, 1) 0ms} 时需要再次计算 padding
// PDF 避免分屏多次调用后页码跳转到1 https://github.com/siyuan-note/siyuan/issues/5646
resizeTimeout = window.setTimeout(() => {
const models = getAllModels();
models.editor.forEach((item) => {
if (item.editor && item.editor.protyle &&
item.element.parentElement && !item.element.classList.contains("fn__none")) {
item.editor.resize();
}
});
// https://github.com/siyuan-note/siyuan/issues/6250
models.backlink.forEach(item => {
const mTreeElement = item.element.querySelector(".backlinkMList") as HTMLElement;
if (mTreeElement.style.height && mTreeElement.style.height !== "0px" && item.element.clientHeight !== 0) {
mTreeElement.style.height = (item.element.clientHeight - mTreeElement.previousElementSibling.clientHeight * 2) + "px";
}
item.editors.forEach(editorItem => {
hideElements(["gutter"], editorItem.protyle);
editorItem.resize();
});
});
models.search.forEach(item => {
item.edit.resize();
});
models.custom.forEach(item => {
if (item.resize) {
item.resize();
}
});
pdfResize();
hideAllElements(["gutter"]);
}, 200);
};
export const copyTab = (app: App, tab: Tab) => {
return new Tab({
icon: tab.icon,
docIcon: tab.docIcon,
title: tab.title,
callback(newTab: Tab) {
let model: Model;
if (tab.model instanceof Editor) {
model = new Editor({
app,
tab: newTab,
blockId: tab.model.editor.protyle.block.id,
scrollAttr: saveScroll(tab.model.editor.protyle, true)
});
} else if (tab.model instanceof Asset) {
model = new Asset({
app,
tab: newTab,
path: tab.model.path
});
} else if (tab.model instanceof Graph) {
model = new Graph({
app,
tab: newTab,
blockId: tab.model.blockId,
rootId: tab.model.rootId,
type: tab.model.type,
});
} else if (tab.model instanceof Files) {
model = new Files({
app,
tab: newTab
});
} else if (tab.model instanceof Outline) {
model = new Outline({
app,
tab: newTab,
blockId: tab.model.blockId,
type: tab.model.type,
isPreview: tab.model.isPreview
});
} else if (tab.model instanceof Backlink) {
model = new Backlink({
app,
tab: newTab,
blockId: tab.model.blockId,
rootId: tab.model.rootId,
type: tab.model.type
});
} else if (tab.model instanceof Bookmark) {
model = new Bookmark(app, newTab);
} else if (tab.model instanceof Tag) {
model = new Tag(app, newTab);
} else if (tab.model instanceof Search) {
model = new Search({
app,
tab: newTab,
config: tab.model.config
});
} else if (tab.model instanceof Custom) {
const custom = tab.model as Custom;
if (custom.type === "siyuan-card") {
model = newCardModel({
app,
tab: newTab,
data: custom.data
});
} else {
app.plugins.find(item => {
if (item.models[custom.type]) {
model = item.models[custom.type]({
tab: newTab,
data: custom.data
});
return true;
}
});
}
} else if (!tab.model && tab.headElement) {
const initData = JSON.parse(tab.headElement.getAttribute("data-initdata") || "{}");
if (initData) {
// 历史数据兼容 2023-05-24
if (initData.scrollAttr) {
initData.scrollAttr.rootId = initData.rootId;
}
model = newModelByInitData(app, newTab, initData);
}
}
newTab.addModel(model);
}
});
};
export const newModelByInitData = (app: App, tab: Tab, json: any) => {
let model: Model;
if (json.instance === "Custom") {
@ -959,100 +808,3 @@ export const addResize = (obj: Layout | Wnd) => {
obj.element.insertAdjacentElement("beforebegin", resizeElement);
resizeWnd(resizeElement, obj.resize);
};
export const newCenterEmptyTab = (app: App) => {
return new Tab({
panel: `<div class="layout__empty b3-list">
<div class="${!window.siyuan.config.readonly ? " fn__none" : ""}">
<div class="config-about__logo">
<img src="/stage/icon.png">
${window.siyuan.languages.siyuanNote}
</div>
<div class="b3-label__text">${window.siyuan.languages.slogan}</div>
</div>
<div class="fn__hr"></div>
<div class="b3-list-item" id="editorEmptySearch">
<svg class="b3-list-item__graphic"><use xlink:href="#iconSearch"></use></svg>
<span>${window.siyuan.languages.search}</span>
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.globalSearch.custom)}</span>
</div>
<div id="editorEmptyRecent" class="b3-list-item">
<svg class="b3-list-item__graphic"><use xlink:href="#iconList"></use></svg>
<span>${window.siyuan.languages.recentDocs}</span>
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.recentDocs.custom)}</span>
</div>
<div id="editorEmptyHistory" class="b3-list-item${window.siyuan.config.readonly ? " fn__none" : ""}">
<svg class="b3-list-item__graphic"><use xlink:href="#iconHistory"></use></svg>
<span>${window.siyuan.languages.dataHistory}</span>
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.dataHistory.custom)}</span>
</div>
<div class="b3-list-item${window.siyuan.config.readonly ? " fn__none" : ""}" id="editorEmptyFile">
<svg class="b3-list-item__graphic"><use xlink:href="#iconFile"></use></svg>
<span>${window.siyuan.languages.newFile}</span>
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.newFile.custom)}</span>
</div>
<div class="b3-list-item${window.siyuan.config.readonly ? " fn__none" : ""}" id="editorEmptyNewNotebook">
<svg class="b3-list-item__graphic"><use xlink:href="#iconFilesRoot"></use></svg>
<span>${window.siyuan.languages.newNotebook}</span>
</div>
<div class="b3-list-item" id="editorEmptyHelp">
<svg class="b3-list-item__graphic"><use xlink:href="#iconHelp"></use></svg>
<span>${window.siyuan.languages.help}</span>
</div>
</div>`,
callback(tab: Tab) {
tab.panelElement.addEventListener("click", (event) => {
let target = event.target as HTMLElement;
while (target && !target.isEqualNode(tab.panelElement)) {
if (target.id === "editorEmptySearch") {
openSearch({
app,
hotkey: window.siyuan.config.keymap.general.globalSearch.custom,
});
event.stopPropagation();
event.preventDefault();
break;
} else if (target.id === "editorEmptyRecent") {
const openRecentDocsDialog = window.siyuan.dialogs.find(item => {
if (item.element.getAttribute("data-key") === window.siyuan.config.keymap.general.recentDocs.custom) {
return true;
}
});
if (openRecentDocsDialog) {
hideElements(["dialog"]);
return;
}
openRecentDocs();
event.stopPropagation();
event.preventDefault();
break;
} else if (target.id === "editorEmptyHistory") {
openHistory(app);
event.stopPropagation();
event.preventDefault();
break;
} else if (target.id === "editorEmptyFile") {
newFile({
app,
useSavePath: true
});
event.stopPropagation();
event.preventDefault();
break;
} else if (target.id === "editorEmptyNewNotebook") {
newNotebook();
event.stopPropagation();
event.preventDefault();
break;
} else if (target.id === "editorEmptyHelp") {
mountHelp();
event.stopPropagation();
event.preventDefault();
break;
}
target = target.parentElement;
}
});
}
});
};