Vanessa 2024-10-23 15:47:36 +08:00
parent 9f0552bc72
commit 814a4ec3ac
7 changed files with 52 additions and 33 deletions

View file

@ -46,7 +46,7 @@ const selectOpenTab = () => {
/// #if MOBILE /// #if MOBILE
if (window.siyuan.mobile.editor?.protyle) { if (window.siyuan.mobile.editor?.protyle) {
openDock("file"); openDock("file");
window.siyuan.mobile.files.selectItem(window.siyuan.mobile.editor.protyle.notebookId, window.siyuan.mobile.editor.protyle.path); window.siyuan.mobile.docks.file.selectItem(window.siyuan.mobile.editor.protyle.notebookId, window.siyuan.mobile.editor.protyle.path);
} }
/// #else /// #else
const dockFile = getDockByType("file"); const dockFile = getDockByType("file");

View file

@ -71,7 +71,7 @@ export const reloadSync = (
} }
} }
setNoteBook(() => { setNoteBook(() => {
window.siyuan.mobile.files.init(false); window.siyuan.mobile.docks.file.init(false);
}); });
/// #else /// #else
const allModels = getAllModels(); const allModels = getAllModels();
@ -215,7 +215,7 @@ export const setDefRefCount = (data: {
let liElement; let liElement;
/// #if MOBILE /// #if MOBILE
liElement = window.siyuan.mobile.files.element.querySelector(`li[data-node-id="${data.rootID}"]`); liElement = window.siyuan.mobile.docks.file.element.querySelector(`li[data-node-id="${data.rootID}"]`);
/// #else /// #else
liElement = (getDockByType("file").data.file as Files).element.querySelector(`li[data-node-id="${data.rootID}"]`); liElement = (getDockByType("file").data.file as Files).element.querySelector(`li[data-node-id="${data.rootID}"]`);
/// #endif /// #endif

View file

@ -190,7 +190,7 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
liElement.parentElement.setAttribute("data-sortmode", sort.toString()); liElement.parentElement.setAttribute("data-sortmode", sort.toString());
let files; let files;
/// #if MOBILE /// #if MOBILE
files = window.siyuan.mobile.files; files = window.siyuan.mobile.docks.file;
/// #else /// #else
files = (getDockByType("file").data["file"] as Files); files = (getDockByType("file").data["file"] as Files);
/// #endif /// #endif
@ -671,7 +671,7 @@ export const genImportMenu = (notebookId: string, pathString: string) => {
const reloadDocTree = () => { const reloadDocTree = () => {
let files; let files;
/// #if MOBILE /// #if MOBILE
files = window.siyuan.mobile.files; files = window.siyuan.mobile.docks.file;
/// #else /// #else
files = (getDockByType("file").data["file"] as Files); files = (getDockByType("file").data["file"] as Files);
/// #endif /// #endif

View file

@ -47,7 +47,16 @@ class App {
backStack: [], backStack: [],
dialogs: [], dialogs: [],
blockPanels: [], blockPanels: [],
mobile: {}, mobile: {
docks: {
outline: null,
file: null,
bookmark: null,
tag: null,
backlink: null,
inbox: null,
}
},
ws: new Model({ ws: new Model({
app: this, app: this,
id: genUUID(), id: genUUID(),
@ -149,7 +158,7 @@ const siyuanApp = new App();
// https://github.com/siyuan-note/siyuan/issues/8441 // https://github.com/siyuan-note/siyuan/issues/8441
window.reconnectWebSocket = () => { window.reconnectWebSocket = () => {
window.siyuan.ws.send("ping", {}); window.siyuan.ws.send("ping", {});
window.siyuan.mobile.files.send("ping", {}); window.siyuan.mobile.docks.file.send("ping", {});
window.siyuan.mobile.editor.protyle.ws.send("ping", {}); window.siyuan.mobile.editor.protyle.ws.send("ping", {});
window.siyuan.mobile.popEditor.protyle.ws.send("ping", {}); window.siyuan.mobile.popEditor.protyle.ws.send("ping", {});
}; };

View file

@ -62,11 +62,6 @@ export const initFramework = (app: App, isStart: boolean) => {
renderSnippet(); renderSnippet();
initKeyboardToolbar(); initKeyboardToolbar();
const sidebarElement = document.getElementById("sidebar"); const sidebarElement = document.getElementById("sidebar");
let outline: MobileOutline;
let backlink: MobileBacklinks;
let bookmark: MobileBookmarks;
let inbox: Inbox;
let tag: MobileTags;
// 不能使用 getEventName否则点击返回会展开右侧栏 // 不能使用 getEventName否则点击返回会展开右侧栏
const firstToolbarElement = sidebarElement.querySelector(".toolbar--border"); const firstToolbarElement = sidebarElement.querySelector(".toolbar--border");
firstToolbarElement.addEventListener("click", (event: MouseEvent) => { firstToolbarElement.addEventListener("click", (event: MouseEvent) => {
@ -99,31 +94,31 @@ export const initFramework = (app: App, isStart: boolean) => {
const tabPanelElement = sidebarElement.lastElementChild.querySelector(`[data-type="${itemType.replace("-tab", "")}"]`); const tabPanelElement = sidebarElement.lastElementChild.querySelector(`[data-type="${itemType.replace("-tab", "")}"]`);
if (itemType === type) { if (itemType === type) {
if (type === "sidebar-outline-tab") { if (type === "sidebar-outline-tab") {
if (!outline) { if (!window.siyuan.mobile.docks.outline) {
outline = new MobileOutline(app); window.siyuan.mobile.docks.outline = new MobileOutline(app);
} else { } else {
outline.update(); window.siyuan.mobile.docks.outline.update();
} }
} else if (type === "sidebar-backlink-tab") { } else if (type === "sidebar-backlink-tab") {
if (!backlink) { if (!window.siyuan.mobile.docks.backlink) {
backlink = new MobileBacklinks(app); window.siyuan.mobile.docks.backlink = new MobileBacklinks(app);
} else { } else {
backlink.update(); window.siyuan.mobile.docks.backlink.update();
} }
} else if (type === "sidebar-bookmark-tab") { } else if (type === "sidebar-bookmark-tab") {
if (!bookmark) { if (!window.siyuan.mobile.docks.bookmark) {
bookmark = new MobileBookmarks(app); window.siyuan.mobile.docks.bookmark = new MobileBookmarks(app);
} else { } else {
bookmark.update(); window.siyuan.mobile.docks.bookmark.update();
} }
} else if (type === "sidebar-tag-tab") { } else if (type === "sidebar-tag-tab") {
if (!tag) { if (!window.siyuan.mobile.docks.tag) {
tag = new MobileTags(app); window.siyuan.mobile.docks.tag = new MobileTags(app);
} else { } else {
tag.update(); window.siyuan.mobile.docks.tag.update();
} }
} else if (type === "sidebar-inbox-tab" && !inbox) { } else if (type === "sidebar-inbox-tab" && !window.siyuan.mobile.docks.inbox) {
inbox = new Inbox(app, document.querySelector('#sidebar [data-type="sidebar-inbox"]')); window.siyuan.mobile.docks.inbox = new Inbox(app, document.querySelector('#sidebar [data-type="sidebar-inbox"]'));
} else if (type === "sidebar-plugin-tab") { } else if (type === "sidebar-plugin-tab") {
if (!custom) { if (!custom) {
tabPanelElement.innerHTML = `<div class="b3-list--empty">${window.siyuan.languages.emptyContent}</div>`; tabPanelElement.innerHTML = `<div class="b3-list--empty">${window.siyuan.languages.emptyContent}</div>`;
@ -140,20 +135,20 @@ export const initFramework = (app: App, isStart: boolean) => {
} }
}); });
}); });
window.siyuan.mobile.files = new MobileFiles(app); window.siyuan.mobile.docks.files = new MobileFiles(app);
document.getElementById("toolbarFile").addEventListener("click", () => { document.getElementById("toolbarFile").addEventListener("click", () => {
hideKeyboardToolbar(); hideKeyboardToolbar();
activeBlur(); activeBlur();
sidebarElement.style.transform = "translateX(0px)"; sidebarElement.style.transform = "translateX(0px)";
const type = sidebarElement.querySelector(".toolbar--border .toolbar__icon--active").getAttribute("data-type"); const type = sidebarElement.querySelector(".toolbar--border .toolbar__icon--active").getAttribute("data-type");
if (type === "sidebar-outline-tab") { if (type === "sidebar-outline-tab") {
outline.update(); window.siyuan.mobile.docks.outline.update();
} else if (type === "sidebar-backlink-tab") { } else if (type === "sidebar-backlink-tab") {
backlink.update(); window.siyuan.mobile.docks.backlink.update();
} else if (type === "sidebar-bookmark-tab") { } else if (type === "sidebar-bookmark-tab") {
bookmark.update(); window.siyuan.mobile.docks.bookmark.update();
} else if (type === "sidebar-tag-tab") { } else if (type === "sidebar-tag-tab") {
tag.update(); window.siyuan.mobile.docks.tag.update();
} }
}); });
// 用 touchstart 会导致键盘不收起 // 用 touchstart 会导致键盘不收起

View file

@ -166,6 +166,14 @@ openTab = (options: {
}; };
/// #endif /// #endif
const getModelByDockType = (type: TDock | string) => {
/// #if MOBILE
return window.siyuan.mobile.docks[type];
/// #else
return getDockByType(type).data[type];
/// #endif
}
export const API = { export const API = {
adaptHotkey: updateHotkeyTip, adaptHotkey: updateHotkeyTip,
confirm: confirmDialog, confirm: confirmDialog,
@ -176,7 +184,7 @@ export const API = {
fetchGet, fetchGet,
getFrontend, getFrontend,
getBackend, getBackend,
getDockByType, getModelByDockType,
openTab, openTab,
openWindow, openWindow,
openMobileFileById, openMobileFileById,

View file

@ -376,7 +376,14 @@ interface ISiyuan {
mobile?: { mobile?: {
editor?: import("../protyle").Protyle editor?: import("../protyle").Protyle
popEditor?: import("../protyle").Protyle popEditor?: import("../protyle").Protyle
files?: import("../mobile/dock/MobileFiles").MobileFiles docks?: {
outline: import("../mobile/dock/MobileOutline").MobileOutline | null,
file: import("../mobile/dock/MobileFiles").MobileFiles | null,
bookmark: import("../mobile/dock/MobileBookmarks").MobileBookmarks | null,
tag: import("../mobile/dock/MobileTags").MobileTags | null,
backlink: import("../mobile/dock/MobileBacklinks").MobileBacklinks | null,
inbox: import("../layout/dock/Inbox").Inbox | null,
} & { [key: string]: import("../layout/Model").Model | boolean };
}, },
user?: { user?: {
userId: string userId: string