2022-05-26 15:18:53 +08:00
|
|
|
import {Constants} from "../../constants";
|
|
|
|
|
import {closePanel} from "./closePanel";
|
|
|
|
|
import {openMobileFileById} from "../editor";
|
|
|
|
|
import {validateName} from "../../editor/rename";
|
|
|
|
|
import {getEventName} from "../../protyle/util/compatibility";
|
|
|
|
|
import {mountHelp} from "../../util/mount";
|
|
|
|
|
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";
|
|
|
|
|
import {disabledProtyle, enableProtyle} from "../../protyle/util/onGet";
|
|
|
|
|
import {getOpenNotebookCount} from "../../util/pathName";
|
|
|
|
|
import {popMenu} from "./menu";
|
|
|
|
|
import {MobileFiles} from "./MobileFiles";
|
|
|
|
|
import {MobileOutline} from "./MobileOutline";
|
|
|
|
|
import {hasTopClosestByTag} from "../../protyle/util/hasClosest";
|
|
|
|
|
import {MobileBacklinks} from "./MobileBacklinks";
|
2022-07-31 10:56:03 +08:00
|
|
|
import {MobileBookmarks} from "./MobileBookmarks";
|
|
|
|
|
import {MobileTags} from "./MobileTags";
|
2022-10-08 14:31:34 +08:00
|
|
|
import {hideKeyboardToolbar, initKeyboardToolbar} from "./showKeyboardToolbar";
|
2023-01-16 21:33:50 +08:00
|
|
|
import {getSearch} from "../../util/functions";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
|
|
|
export const initFramework = () => {
|
|
|
|
|
setInlineStyle();
|
2022-10-12 09:23:25 +08:00
|
|
|
renderSnippet();
|
2022-10-06 17:30:43 +08:00
|
|
|
initKeyboardToolbar();
|
2022-05-26 15:18:53 +08:00
|
|
|
const scrimElement = document.querySelector(".scrim");
|
|
|
|
|
const sidebarElement = document.getElementById("sidebar");
|
|
|
|
|
let outline: MobileOutline;
|
|
|
|
|
let backlink: MobileBacklinks;
|
2022-07-31 18:22:03 +08:00
|
|
|
let bookmark: MobileBookmarks;
|
|
|
|
|
let tag: MobileTags;
|
2022-05-26 15:18:53 +08:00
|
|
|
sidebarElement.querySelector(".toolbar--border").addEventListener(getEventName(), (event: Event & { target: Element }) => {
|
|
|
|
|
const svgElement = hasTopClosestByTag(event.target, "svg");
|
|
|
|
|
if (!svgElement || svgElement.classList.contains("toolbar__icon--active")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const type = svgElement.getAttribute("data-type");
|
|
|
|
|
sidebarElement.querySelectorAll(".toolbar--border svg").forEach(item => {
|
|
|
|
|
const itemType = item.getAttribute("data-type");
|
|
|
|
|
if (itemType === type) {
|
|
|
|
|
if (type === "sidebar-outline-tab") {
|
|
|
|
|
if (!outline) {
|
|
|
|
|
outline = new MobileOutline();
|
|
|
|
|
} else {
|
|
|
|
|
outline.update();
|
|
|
|
|
}
|
|
|
|
|
} else if (type === "sidebar-backlink-tab") {
|
|
|
|
|
if (!backlink) {
|
|
|
|
|
backlink = new MobileBacklinks();
|
|
|
|
|
} else {
|
|
|
|
|
backlink.update();
|
|
|
|
|
}
|
2022-07-31 10:56:03 +08:00
|
|
|
} else if (type === "sidebar-bookmark-tab") {
|
|
|
|
|
if (!backlink) {
|
|
|
|
|
bookmark = new MobileBookmarks();
|
|
|
|
|
} else {
|
|
|
|
|
backlink.update();
|
|
|
|
|
}
|
|
|
|
|
} else if (type === "sidebar-tag-tab") {
|
|
|
|
|
if (!backlink) {
|
|
|
|
|
tag = new MobileTags();
|
|
|
|
|
} else {
|
2022-07-31 17:12:55 +08:00
|
|
|
tag.update();
|
2022-07-31 10:56:03 +08:00
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
svgElement.classList.add("toolbar__icon--active");
|
|
|
|
|
sidebarElement.lastElementChild.querySelector(`[data-type="${itemType.replace("-tab", "")}"]`).classList.remove("fn__none");
|
|
|
|
|
} else {
|
|
|
|
|
item.classList.remove("toolbar__icon--active");
|
|
|
|
|
sidebarElement.lastElementChild.querySelector(`[data-type="${itemType.replace("-tab", "")}"]`).classList.add("fn__none");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
new MobileFiles();
|
2022-10-08 14:31:34 +08:00
|
|
|
document.getElementById("toolbarFile").addEventListener("click", () => {
|
2022-05-26 15:18:53 +08:00
|
|
|
sidebarElement.style.left = "0";
|
|
|
|
|
document.querySelector(".scrim").classList.remove("fn__none");
|
|
|
|
|
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();
|
|
|
|
|
});
|
|
|
|
|
const editElement = document.getElementById("toolbarEdit");
|
|
|
|
|
if (window.siyuan.config.readonly) {
|
|
|
|
|
editElement.classList.add("fn__none");
|
2022-10-17 09:49:59 +08:00
|
|
|
}
|
|
|
|
|
const inputElement = document.getElementById("toolbarName") as HTMLInputElement;
|
|
|
|
|
const editIconElement = editElement.querySelector("use");
|
|
|
|
|
if (window.siyuan.config.readonly || window.siyuan.config.editor.readOnly) {
|
|
|
|
|
inputElement.readOnly = true;
|
2022-12-10 14:47:47 +08:00
|
|
|
editIconElement.setAttribute("xlink:href", "#iconPreview");
|
2022-05-26 15:18:53 +08:00
|
|
|
} else {
|
2022-10-17 09:49:59 +08:00
|
|
|
inputElement.readOnly = false;
|
2022-12-10 14:47:47 +08:00
|
|
|
editIconElement.setAttribute("xlink:href", "#iconEdit");
|
2022-10-17 09:49:59 +08:00
|
|
|
}
|
|
|
|
|
editElement.addEventListener(getEventName(), () => {
|
2022-12-10 14:47:47 +08:00
|
|
|
const isReadonly = editIconElement.getAttribute("xlink:href") === "#iconEdit";
|
2022-10-17 09:49:59 +08:00
|
|
|
window.siyuan.config.editor.readOnly = isReadonly;
|
|
|
|
|
fetchPost("/api/setting/setEditor", window.siyuan.config.editor, () => {
|
|
|
|
|
if (!isReadonly) {
|
2022-05-26 15:18:53 +08:00
|
|
|
enableProtyle(window.siyuan.mobileEditor.protyle);
|
|
|
|
|
inputElement.readOnly = false;
|
2022-12-10 14:47:47 +08:00
|
|
|
editIconElement.setAttribute("xlink:href", "#iconEdit");
|
2022-05-26 15:18:53 +08:00
|
|
|
} else {
|
|
|
|
|
disabledProtyle(window.siyuan.mobileEditor.protyle);
|
|
|
|
|
inputElement.readOnly = true;
|
2022-12-10 14:47:47 +08:00
|
|
|
editIconElement.setAttribute("xlink:href", "#iconPreview");
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
2022-10-19 21:47:47 +08:00
|
|
|
});
|
2022-10-17 09:49:59 +08:00
|
|
|
});
|
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
scrimElement.addEventListener(getEventName(), () => {
|
|
|
|
|
closePanel();
|
|
|
|
|
});
|
|
|
|
|
document.getElementById("modelClose").addEventListener(getEventName(), () => {
|
|
|
|
|
closePanel();
|
|
|
|
|
});
|
|
|
|
|
initEditorName();
|
|
|
|
|
if (getOpenNotebookCount() > 0) {
|
2023-01-17 00:23:21 +08:00
|
|
|
const openId = getSearch("id");
|
2023-01-16 23:54:47 +08:00
|
|
|
if (openId !== null) {
|
|
|
|
|
openMobileFileById(openId,
|
2023-01-17 00:23:21 +08:00
|
|
|
getSearch("focus") === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
|
2023-01-16 21:33:50 +08:00
|
|
|
} else {
|
|
|
|
|
const localDoc = window.siyuan.storage[Constants.LOCAL_DOCINFO];
|
|
|
|
|
fetchPost("/api/block/checkBlockExist", {id: localDoc.id}, existResponse => {
|
|
|
|
|
if (existResponse.data) {
|
|
|
|
|
openMobileFileById(localDoc.id, localDoc.action);
|
|
|
|
|
} else {
|
|
|
|
|
fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => {
|
|
|
|
|
if (response.data.length !== 0) {
|
|
|
|
|
openMobileFileById(response.data[0].id, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
|
|
|
|
} else {
|
|
|
|
|
setEmpty();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
} else {
|
|
|
|
|
setEmpty();
|
|
|
|
|
}
|
|
|
|
|
if (window.siyuan.config.newbie) {
|
|
|
|
|
mountHelp();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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-10-08 14:31:34 +08:00
|
|
|
inputElement.addEventListener("focus", () => {
|
2022-10-17 09:49:59 +08:00
|
|
|
hideKeyboardToolbar();
|
2022-10-08 14:31:34 +08:00
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
inputElement.addEventListener("blur", () => {
|
2022-10-25 00:23:42 +08:00
|
|
|
if (window.siyuan.config.readonly || window.siyuan.config.editor.readOnly || window.siyuan.mobileEditor.protyle.disabled) {
|
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", {
|
|
|
|
|
notebook: window.siyuan.mobileEditor.protyle.notebookId,
|
|
|
|
|
path: window.siyuan.mobileEditor.protyle.path,
|
|
|
|
|
title: inputElement.value,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|