2022-05-26 15:18:53 +08:00
|
|
|
|
import {Constants} from "../../constants";
|
2023-04-20 12:26:12 +08:00
|
|
|
|
import {closeModel, closePanel} from "./closePanel";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {openMobileFileById} from "../editor";
|
|
|
|
|
|
import {validateName} from "../../editor/rename";
|
2023-09-12 10:22:04 +08:00
|
|
|
|
import {getEventName} from "../../protyle/util/compatibility";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {fetchPost} from "../../util/fetch";
|
2022-10-27 19:34:26 +08:00
|
|
|
|
import {setInlineStyle} from "../../util/assets";
|
|
|
|
|
|
import {renderSnippet} from "../../config/util/snippets";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {setEmpty} from "./setEmpty";
|
2023-04-19 18:50:15 +08:00
|
|
|
|
import {getIdZoomInByPath, getOpenNotebookCount} from "../../util/pathName";
|
2023-03-30 11:11:48 +08:00
|
|
|
|
import {popMenu} from "../menu";
|
2023-04-21 21:58:57 +08:00
|
|
|
|
import {MobileFiles} from "../dock/MobileFiles";
|
|
|
|
|
|
import {MobileOutline} from "../dock/MobileOutline";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {hasTopClosestByTag} from "../../protyle/util/hasClosest";
|
2023-04-21 21:58:57 +08:00
|
|
|
|
import {MobileBacklinks} from "../dock/MobileBacklinks";
|
|
|
|
|
|
import {MobileBookmarks} from "../dock/MobileBookmarks";
|
|
|
|
|
|
import {MobileTags} from "../dock/MobileTags";
|
2023-03-06 09:23:11 +08:00
|
|
|
|
import {activeBlur, hideKeyboardToolbar, initKeyboardToolbar} from "./keyboardToolbar";
|
2023-01-19 11:49:31 +08:00
|
|
|
|
import {syncGuide} from "../../sync/syncGuide";
|
2023-04-21 21:58:57 +08:00
|
|
|
|
import {Inbox} from "../../layout/dock/Inbox";
|
2023-05-15 13:54:30 +08:00
|
|
|
|
import {App} from "../../index";
|
2023-11-22 16:47:41 +08:00
|
|
|
|
import {setTitle} from "../../dialog/processSystem";
|
2023-12-12 12:09:31 +08:00
|
|
|
|
import {checkFold} from "../../util/noRelyPCFunction";
|
2023-12-21 11:24:53 +08:00
|
|
|
|
import {MobileCustom} from "../dock/MobileCustom";
|
|
|
|
|
|
import {Menu} from "../../plugin/Menu";
|
|
|
|
|
|
import {showMessage} from "../../dialog/message";
|
|
|
|
|
|
|
|
|
|
|
|
let custom: MobileCustom;
|
|
|
|
|
|
const openDockMenu = (app: App) => {
|
|
|
|
|
|
const menu = new Menu("dockMobileMenu");
|
|
|
|
|
|
if (menu.isOpen) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
app.plugins.forEach((plugin) => {
|
|
|
|
|
|
Object.keys(plugin.docks).forEach((dockId) => {
|
|
|
|
|
|
menu.addItem({
|
|
|
|
|
|
label: plugin.docks[dockId].config.title,
|
|
|
|
|
|
icon: plugin.docks[dockId].config.icon,
|
|
|
|
|
|
click() {
|
|
|
|
|
|
if (custom?.type === dockId) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (custom) {
|
2023-12-26 14:41:25 +08:00
|
|
|
|
if (custom.destroy) {
|
|
|
|
|
|
custom.destroy();
|
|
|
|
|
|
}
|
2023-12-21 11:24:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
custom = plugin.docks[dockId].mobileModel(document.querySelector('#sidebar [data-type="sidebar-plugin"]'));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-12-25 21:31:32 +08:00
|
|
|
|
});
|
2023-12-21 11:24:53 +08:00
|
|
|
|
});
|
|
|
|
|
|
});
|
2024-08-10 19:00:50 +08:00
|
|
|
|
menu.fullscreen();
|
2023-12-21 11:24:53 +08:00
|
|
|
|
if (menu.element.lastElementChild.innerHTML === "") {
|
2023-12-21 11:35:07 +08:00
|
|
|
|
showMessage(window.siyuan.languages._kernel[122]);
|
2023-12-21 11:24:53 +08:00
|
|
|
|
}
|
2023-12-25 21:31:32 +08:00
|
|
|
|
};
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
2023-11-22 16:18:32 +08:00
|
|
|
|
export const initFramework = (app: App, isStart: boolean) => {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
setInlineStyle();
|
2022-10-12 09:23:25 +08:00
|
|
|
|
renderSnippet();
|
2023-06-01 20:50:49 +08:00
|
|
|
|
initKeyboardToolbar();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const sidebarElement = document.getElementById("sidebar");
|
|
|
|
|
|
let outline: MobileOutline;
|
|
|
|
|
|
let backlink: MobileBacklinks;
|
2022-07-31 18:22:03 +08:00
|
|
|
|
let bookmark: MobileBookmarks;
|
2023-04-21 21:58:57 +08:00
|
|
|
|
let inbox: Inbox;
|
2022-07-31 18:22:03 +08:00
|
|
|
|
let tag: MobileTags;
|
2023-03-19 14:19:42 +08:00
|
|
|
|
// 不能使用 getEventName,否则点击返回会展开右侧栏
|
2023-03-25 17:13:36 +08:00
|
|
|
|
const firstToolbarElement = sidebarElement.querySelector(".toolbar--border");
|
2024-05-06 00:17:42 +08:00
|
|
|
|
firstToolbarElement.addEventListener("click", (event: MouseEvent) => {
|
|
|
|
|
|
const target = event.target as HTMLElement;
|
|
|
|
|
|
let svgElement: HTMLElement;
|
|
|
|
|
|
if (typeof event.detail === "string") {
|
|
|
|
|
|
svgElement = firstToolbarElement.querySelector(`svg[data-type="sidebar-${event.detail}-tab"]`) as HTMLElement;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
svgElement = hasTopClosestByTag(target, "svg") as HTMLElement;
|
|
|
|
|
|
}
|
2023-12-21 11:24:53 +08:00
|
|
|
|
if (!svgElement) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const type = svgElement.getAttribute("data-type");
|
2023-12-21 11:24:53 +08:00
|
|
|
|
if (svgElement.classList.contains("toolbar__icon--active")) {
|
|
|
|
|
|
if (type === "sidebar-plugin-tab") {
|
|
|
|
|
|
openDockMenu(app);
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-03-17 11:35:08 +08:00
|
|
|
|
if (!type) {
|
|
|
|
|
|
closePanel();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-03-25 16:56:56 +08:00
|
|
|
|
firstToolbarElement.querySelectorAll(".toolbar__icon").forEach(item => {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const itemType = item.getAttribute("data-type");
|
2023-03-25 16:56:56 +08:00
|
|
|
|
if (!itemType) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-12-21 11:24:53 +08:00
|
|
|
|
const tabPanelElement = sidebarElement.lastElementChild.querySelector(`[data-type="${itemType.replace("-tab", "")}"]`);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (itemType === type) {
|
|
|
|
|
|
if (type === "sidebar-outline-tab") {
|
|
|
|
|
|
if (!outline) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
outline = new MobileOutline(app);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
outline.update();
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (type === "sidebar-backlink-tab") {
|
|
|
|
|
|
if (!backlink) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
backlink = new MobileBacklinks(app);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
backlink.update();
|
|
|
|
|
|
}
|
2022-07-31 10:56:03 +08:00
|
|
|
|
} else if (type === "sidebar-bookmark-tab") {
|
2023-03-25 16:56:56 +08:00
|
|
|
|
if (!bookmark) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
bookmark = new MobileBookmarks(app);
|
2022-07-31 10:56:03 +08:00
|
|
|
|
} else {
|
2023-05-22 22:08:01 +08:00
|
|
|
|
bookmark.update();
|
2022-07-31 10:56:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else if (type === "sidebar-tag-tab") {
|
2023-03-25 16:56:56 +08:00
|
|
|
|
if (!tag) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
tag = new MobileTags(app);
|
2022-07-31 10:56:03 +08:00
|
|
|
|
} else {
|
2022-07-31 17:12:55 +08:00
|
|
|
|
tag.update();
|
2022-07-31 10:56:03 +08:00
|
|
|
|
}
|
2023-04-21 21:58:57 +08:00
|
|
|
|
} else if (type === "sidebar-inbox-tab" && !inbox) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
inbox = new Inbox(app, document.querySelector('#sidebar [data-type="sidebar-inbox"]'));
|
2023-12-21 11:24:53 +08:00
|
|
|
|
} else if (type === "sidebar-plugin-tab") {
|
|
|
|
|
|
if (!custom) {
|
|
|
|
|
|
tabPanelElement.innerHTML = `<div class="b3-list--empty">${window.siyuan.languages.emptyContent}</div>`;
|
|
|
|
|
|
openDockMenu(app);
|
|
|
|
|
|
} else if (custom.update) {
|
|
|
|
|
|
custom.update();
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
svgElement.classList.add("toolbar__icon--active");
|
2023-12-21 11:24:53 +08:00
|
|
|
|
tabPanelElement.classList.remove("fn__none");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
item.classList.remove("toolbar__icon--active");
|
2023-12-21 11:24:53 +08:00
|
|
|
|
tabPanelElement.classList.add("fn__none");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2023-05-18 19:27:21 +08:00
|
|
|
|
window.siyuan.mobile.files = new MobileFiles(app);
|
2023-03-03 10:39:58 +08:00
|
|
|
|
document.getElementById("toolbarFile").addEventListener("click", () => {
|
2023-03-01 12:06:46 +08:00
|
|
|
|
hideKeyboardToolbar();
|
2023-03-06 09:23:11 +08:00
|
|
|
|
activeBlur();
|
2023-04-07 09:06:30 +08:00
|
|
|
|
sidebarElement.style.transform = "translateX(0px)";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const type = sidebarElement.querySelector(".toolbar--border .toolbar__icon--active").getAttribute("data-type");
|
|
|
|
|
|
if (type === "sidebar-outline-tab") {
|
|
|
|
|
|
outline.update();
|
|
|
|
|
|
} else if (type === "sidebar-backlink-tab") {
|
|
|
|
|
|
backlink.update();
|
2022-07-31 10:56:03 +08:00
|
|
|
|
} else if (type === "sidebar-bookmark-tab") {
|
|
|
|
|
|
bookmark.update();
|
|
|
|
|
|
} else if (type === "sidebar-tag-tab") {
|
|
|
|
|
|
tag.update();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2022-10-08 14:31:34 +08:00
|
|
|
|
// 用 touchstart 会导致键盘不收起
|
|
|
|
|
|
document.getElementById("toolbarMore").addEventListener("click", () => {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
popMenu();
|
|
|
|
|
|
});
|
2023-03-05 15:08:25 +08:00
|
|
|
|
document.getElementById("toolbarSync").addEventListener(getEventName(), () => {
|
2023-05-15 13:54:30 +08:00
|
|
|
|
syncGuide(app);
|
2023-03-05 15:08:25 +08:00
|
|
|
|
});
|
2023-03-23 10:16:40 +08:00
|
|
|
|
document.getElementById("modelClose").addEventListener("click", () => {
|
2023-04-20 12:26:12 +08:00
|
|
|
|
closeModel();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
|
initEditorName();
|
2023-01-20 11:24:11 +08:00
|
|
|
|
if (getOpenNotebookCount() > 0) {
|
2023-03-19 23:20:31 +08:00
|
|
|
|
if (window.JSAndroid && window.openFileByURL(window.JSAndroid.getBlockURL())) {
|
|
|
|
|
|
return;
|
2023-01-20 11:24:11 +08:00
|
|
|
|
}
|
2023-04-19 18:50:15 +08:00
|
|
|
|
const idZoomIn = getIdZoomInByPath();
|
|
|
|
|
|
if (idZoomIn.id) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openMobileFileById(app, idZoomIn.id,
|
2024-01-01 01:21:30 +08:00
|
|
|
|
idZoomIn.isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
|
2023-01-20 11:24:11 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-11-17 23:14:16 +08:00
|
|
|
|
if (window.siyuan.config.fileTree.closeTabsOnStart && isStart) {
|
|
|
|
|
|
setEmpty(app);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-01-20 11:24:11 +08:00
|
|
|
|
const localDoc = window.siyuan.storage[Constants.LOCAL_DOCINFO];
|
|
|
|
|
|
fetchPost("/api/block/checkBlockExist", {id: localDoc.id}, existResponse => {
|
|
|
|
|
|
if (existResponse.data) {
|
2023-12-31 16:51:31 +08:00
|
|
|
|
openMobileFileById(app, localDoc.id, [Constants.CB_GET_SCROLL, Constants.CB_GET_HL]);
|
2023-01-20 11:24:11 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => {
|
|
|
|
|
|
if (response.data.length !== 0) {
|
2023-12-09 22:58:33 +08:00
|
|
|
|
checkFold(response.data[0].id, (zoomIn) => {
|
|
|
|
|
|
openMobileFileById(app, response.data[0].id, zoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
|
|
|
|
|
|
});
|
2023-01-20 11:24:11 +08:00
|
|
|
|
} else {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
setEmpty(app);
|
2023-01-20 11:24:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2023-01-24 20:33:13 +08:00
|
|
|
|
return;
|
2023-01-20 11:24:11 +08:00
|
|
|
|
}
|
2023-05-18 19:27:21 +08:00
|
|
|
|
setEmpty(app);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const initEditorName = () => {
|
|
|
|
|
|
const inputElement = document.getElementById("toolbarName") as HTMLInputElement;
|
2022-06-18 23:02:21 +08:00
|
|
|
|
inputElement.setAttribute("placeholder", window.siyuan.languages._kernel[16]);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
inputElement.addEventListener("blur", () => {
|
2023-09-09 14:54:05 +08:00
|
|
|
|
if (inputElement.getAttribute("readonly") === "readonly") {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!validateName(inputElement.value)) {
|
2022-10-22 17:37:41 +08:00
|
|
|
|
inputElement.value = inputElement.value.substring(0, Constants.SIZE_TITLE);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fetchPost("/api/filetree/renameDoc", {
|
2023-01-19 20:31:14 +08:00
|
|
|
|
notebook: window.siyuan.mobile.editor.protyle.notebookId,
|
|
|
|
|
|
path: window.siyuan.mobile.editor.protyle.path,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
title: inputElement.value,
|
|
|
|
|
|
});
|
2023-11-22 16:47:41 +08:00
|
|
|
|
setTitle(inputElement.value);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
|
};
|