import {Tab} from "./Tab"; import {getInstanceById, newModelByInitData, saveLayout} 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 {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 {isIPad, 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"; import {Constants} from "../constants"; 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; if (!indexElement) { indexElement = activeDockIcoElement.parentElement.lastElementChild; if (indexElement.classList.contains("dock__item--pin")) { indexElement = indexElement.previousElementSibling; } } } else if (index === -3) { // 下一个 indexElement = activeDockIcoElement.nextElementSibling; if (!indexElement || indexElement.classList.contains("dock__item--pin")) { indexElement = activeDockIcoElement.parentElement.firstElementChild; } } 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; if (!indexElement) { indexElement = tab.headElement.parentElement.lastElementChild; } } else if (index === -3) { // 下一个 indexElement = tab.headElement.nextElementSibling; if (!indexElement) { indexElement = tab.headElement.parentElement.firstElementChild; } } if (indexElement) { tab.parent.switchTab(indexElement as HTMLElement, true); tab.parent.showHeading(); } } }; let resizeTimeout: number; export const resizeTabs = (isSaveLayout = true) => { 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 => { if (item.element.querySelector("#searchUnRefPanel").classList.contains("fn__none")) { item.editors.edit.resize(); } else { item.editors.unRefEdit.resize(); } }); models.custom.forEach(item => { if (item.resize) { item.resize(); } }); pdfResize(); hideAllElements(["gutter"]); if (isSaveLayout) { saveLayout(); } }, 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: `