diff --git a/app/src/emoji/index.ts b/app/src/emoji/index.ts index cc151e67e..5bb289458 100644 --- a/app/src/emoji/index.ts +++ b/app/src/emoji/index.ts @@ -430,9 +430,9 @@ export const updateFileTreeEmoji = (unicode: string, id: string, icon = "iconFil const updateFileEmoji = (unicode: string, id: string) => { /// #if MOBILE - if (window.siyuan.mobileEditor.protyle.block.rootID === id) { - window.siyuan.mobileEditor.protyle.background.ial.icon = unicode; - window.siyuan.mobileEditor.protyle.background.render(window.siyuan.mobileEditor.protyle.background.ial, window.siyuan.mobileEditor.protyle.block.rootID); + if (window.siyuan.mobile.editor.protyle.block.rootID === id) { + window.siyuan.mobile.editor.protyle.background.ial.icon = unicode; + window.siyuan.mobile.editor.protyle.background.render(window.siyuan.mobile.editor.protyle.background.ial, window.siyuan.mobile.editor.protyle.block.rootID); } /// #else getAllModels().editor.find(item => { diff --git a/app/src/menus/navigation.ts b/app/src/menus/navigation.ts index 5ef5fccc7..503f2ed0c 100644 --- a/app/src/menus/navigation.ts +++ b/app/src/menus/navigation.ts @@ -23,6 +23,8 @@ import {Constants} from "../constants"; import {newFile} from "../util/newFile"; import {hasClosestByTag} from "../protyle/util/hasClosest"; import {deleteFiles} from "../editor/deleteFile"; +import {getDockByType} from "../layout/util"; +import {Files} from "../layout/dock/Files"; const initMultiMenu = (selectItemElements: NodeListOf) => { const fileItemElement = Array.from(selectItemElements).find(item => { @@ -172,7 +174,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement: window.siyuan.menus.menu.remove(); const fileElement = hasClosestByTag(liElement, "DIV"); if (!fileElement) { - return window.siyuan.menus.menu; + return window.siyuan.menus.menu; } if (!liElement.classList.contains("b3-list-item--focus")) { fileElement.querySelectorAll(".b3-list-item--focus").forEach(item => { @@ -385,7 +387,14 @@ const genImportMenu = (notebookId: string, pathString: string) => { formData.append("file", event.target.files[0]); formData.append("notebook", notebookId); formData.append("toPath", pathString); - fetchPost("/api/import/importSY", formData); + fetchPost("/api/import/importSY", formData, () => { + /// #if MOBILE + window.siyuan.mobile.files.selectItem(notebookId, pathString); + /// #else + (getDockByType("file").data["file"] as Files).selectItem(notebookId, pathString) + /// #endif + window.siyuan.menus.menu.remove(); + }); }); } }, diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index b317ee646..7563bf7f0 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -456,7 +456,7 @@ export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushB return; } } - if (window.siyuan.mobileEditor) { + if (window.siyuan.mobile.editor) { window.siyuan.storage[Constants.LOCAL_DOCINFO] = { id, action: id === protyle.block.rootID ? [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT] : [Constants.CB_GET_ALL] diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.ts index c2e2fc642..a22eb1e1a 100644 --- a/app/src/mobile/editor.ts +++ b/app/src/mobile/editor.ts @@ -17,13 +17,13 @@ import {setStorageVal} from "../protyle/util/compatibility"; export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) => { window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id, action}; setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]); - if (window.siyuan.mobileEditor) { - hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle); - if (window.siyuan.mobileEditor.protyle.contentElement.classList.contains("fn__none")) { - setEditMode(window.siyuan.mobileEditor.protyle, "wysiwyg"); + if (window.siyuan.mobile.editor) { + hideElements(["toolbar", "hint", "util"], window.siyuan.mobile.editor.protyle); + if (window.siyuan.mobile.editor.protyle.contentElement.classList.contains("fn__none")) { + setEditMode(window.siyuan.mobile.editor.protyle, "wysiwyg"); } let blockElement; - Array.from(window.siyuan.mobileEditor.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${id}"]`)).find((item: HTMLElement) => { + Array.from(window.siyuan.mobile.editor.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${id}"]`)).find((item: HTMLElement) => { if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) { blockElement = item; return true; @@ -32,7 +32,7 @@ export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) = if (blockElement) { pushBack(); focusBlock(blockElement); - scrollCenter(window.siyuan.mobileEditor.protyle, blockElement, true); + scrollCenter(window.siyuan.mobile.editor.protyle, blockElement, true); closePanel(); return; } @@ -44,20 +44,20 @@ export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) = lockFile(data.data); return; } - if (window.siyuan.mobileEditor) { + if (window.siyuan.mobile.editor) { pushBack(); - addLoading(window.siyuan.mobileEditor.protyle); + addLoading(window.siyuan.mobile.editor.protyle); fetchPost("/api/filetree/getDoc", { id, size: action.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks, mode: action.includes(Constants.CB_GET_CONTEXT) ? 3 : 0, }, getResponse => { - onGet(getResponse, window.siyuan.mobileEditor.protyle, action); - window.siyuan.mobileEditor.protyle.breadcrumb?.render(window.siyuan.mobileEditor.protyle); + onGet(getResponse, window.siyuan.mobile.editor.protyle, action); + window.siyuan.mobile.editor.protyle.breadcrumb?.render(window.siyuan.mobile.editor.protyle); }); - window.siyuan.mobileEditor.protyle.undo.clear(); + window.siyuan.mobile.editor.protyle.undo.clear(); } else { - window.siyuan.mobileEditor = new Protyle(document.getElementById("editor"), { + window.siyuan.mobile.editor = new Protyle(document.getElementById("editor"), { blockId: id, action, render: { diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts index 2055c8150..8b113f497 100644 --- a/app/src/mobile/index.ts +++ b/app/src/mobile/index.ts @@ -29,6 +29,7 @@ class App { backStack: [], dialogs: [], blockPanels: [], + mobile: {}, menus: new Menus(), ws: new Model({ id: genUUID(), diff --git a/app/src/mobile/settings/appearance.ts b/app/src/mobile/settings/appearance.ts index ce089712b..454558040 100644 --- a/app/src/mobile/settings/appearance.ts +++ b/app/src/mobile/settings/appearance.ts @@ -57,7 +57,7 @@ export const initAppearance = (modelElement: HTMLElement, modelMainElement: HTML window.siyuan.config.editor.fontSize = parseInt(event.target.value); fetchPost("/api/setting/setEditor", window.siyuan.config.editor, (response) => { window.siyuan.config.editor = response.data; - reloadProtyle(window.siyuan.mobileEditor.protyle); + reloadProtyle(window.siyuan.mobile.editor.protyle); setInlineStyle(); }); }); diff --git a/app/src/mobile/util/MobileBackFoward.ts b/app/src/mobile/util/MobileBackFoward.ts index 1a54222ca..f7a2a67ae 100644 --- a/app/src/mobile/util/MobileBackFoward.ts +++ b/app/src/mobile/util/MobileBackFoward.ts @@ -12,13 +12,13 @@ import {setStorageVal} from "../../protyle/util/compatibility"; const forwardStack: IBackStack[] = []; const focusStack = (backStack: IBackStack) => { - const protyle = window.siyuan.mobileEditor.protyle; + const protyle = window.siyuan.mobile.editor.protyle; window.siyuan.storage[Constants.LOCAL_DOCINFO] = { id: backStack.id, action: backStack.callback, }; setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]); - hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle); + hideElements(["toolbar", "hint", "util"], window.siyuan.mobile.editor.protyle); if (protyle.contentElement.classList.contains("fn__none")) { setEditMode(protyle, "wysiwyg"); } @@ -26,7 +26,7 @@ const focusStack = (backStack: IBackStack) => { const startEndId = backStack.endId.split(Constants.ZWSP); if (startEndId[0] === protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id") && startEndId[1] === protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id")) { - window.siyuan.mobileEditor.protyle.contentElement.scrollTo({ + window.siyuan.mobile.editor.protyle.contentElement.scrollTo({ top: backStack.scrollTop, behavior: "smooth" }); @@ -81,12 +81,12 @@ const focusStack = (backStack: IBackStack) => { } } protyle.contentElement.scrollTop = backStack.scrollTop; - window.siyuan.mobileEditor.protyle.breadcrumb?.render(protyle); + window.siyuan.mobile.editor.protyle.breadcrumb?.render(protyle); }); }; export const pushBack = () => { - const protyle = window.siyuan.mobileEditor.protyle; + const protyle = window.siyuan.mobile.editor.protyle; window.siyuan.backStack.push({ id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID, endId: protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id") + Constants.ZWSP + protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"), @@ -116,7 +116,7 @@ export const goBack = () => { if (window.siyuan.backStack.length < 1) { return; } - const protyle = window.siyuan.mobileEditor.protyle; + const protyle = window.siyuan.mobile.editor.protyle; if (forwardStack.length === 0) { forwardStack.push({ id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID, diff --git a/app/src/mobile/util/MobileBacklinks.ts b/app/src/mobile/util/MobileBacklinks.ts index 66f596b8f..d2de31593 100644 --- a/app/src/mobile/util/MobileBacklinks.ts +++ b/app/src/mobile/util/MobileBacklinks.ts @@ -106,7 +106,7 @@ export class MobileBacklinks { public update() { fetchPost("/api/ref/getBacklink", { - id: window.siyuan.mobileEditor.protyle.block.id, + id: window.siyuan.mobile.editor.protyle.block.id, beforeLen: this.beforeLen, k: "", mk: "", diff --git a/app/src/mobile/util/MobileFiles.ts b/app/src/mobile/util/MobileFiles.ts index 7a650b77b..41c0cac2a 100644 --- a/app/src/mobile/util/MobileFiles.ts +++ b/app/src/mobile/util/MobileFiles.ts @@ -99,8 +99,8 @@ export class MobileFiles extends Model { event.preventDefault(); break; } else if (type === "focus") { - if (window.siyuan.mobileEditor) { - this.selectItem(window.siyuan.mobileEditor.protyle.notebookId, window.siyuan.mobileEditor.protyle.path); + if (window.siyuan.mobile.editor) { + this.selectItem(window.siyuan.mobile.editor.protyle.notebookId, window.siyuan.mobile.editor.protyle.path); } event.preventDefault(); break; diff --git a/app/src/mobile/util/MobileOutline.ts b/app/src/mobile/util/MobileOutline.ts index 77447daeb..2c9dda780 100644 --- a/app/src/mobile/util/MobileOutline.ts +++ b/app/src/mobile/util/MobileOutline.ts @@ -49,7 +49,7 @@ export class MobileOutline { public update() { fetchPost("/api/outline/getDocOutline", { - id: window.siyuan.mobileEditor.protyle.block.rootID, + id: window.siyuan.mobile.editor.protyle.block.rootID, }, response => { let currentId; let currentElement = this.element.querySelector(".b3-list-item--focus"); @@ -57,7 +57,7 @@ export class MobileOutline { currentId = currentElement.getAttribute("data-node-id"); } - const blockId = window.siyuan.mobileEditor.protyle.block.rootID; + const blockId = window.siyuan.mobile.editor.protyle.block.rootID; if (this.openNodes[blockId]) { this.openNodes[blockId] = this.tree.getExpandIds(); } diff --git a/app/src/mobile/util/initFramework.ts b/app/src/mobile/util/initFramework.ts index f70db127d..f93c43a32 100644 --- a/app/src/mobile/util/initFramework.ts +++ b/app/src/mobile/util/initFramework.ts @@ -73,7 +73,7 @@ export const initFramework = () => { } }); }); - new MobileFiles(); + window.siyuan.mobile.files = new MobileFiles(); document.getElementById("toolbarFile").addEventListener("click", () => { sidebarElement.style.left = "0"; document.querySelector(".scrim").classList.remove("fn__none"); @@ -110,11 +110,11 @@ export const initFramework = () => { window.siyuan.config.editor.readOnly = isReadonly; fetchPost("/api/setting/setEditor", window.siyuan.config.editor, () => { if (!isReadonly) { - enableProtyle(window.siyuan.mobileEditor.protyle); + enableProtyle(window.siyuan.mobile.editor.protyle); inputElement.readOnly = false; editIconElement.setAttribute("xlink:href", "#iconEdit"); } else { - disabledProtyle(window.siyuan.mobileEditor.protyle); + disabledProtyle(window.siyuan.mobile.editor.protyle); inputElement.readOnly = true; editIconElement.setAttribute("xlink:href", "#iconPreview"); } @@ -169,7 +169,7 @@ const initEditorName = () => { hideKeyboardToolbar(); }); inputElement.addEventListener("blur", () => { - if (window.siyuan.config.readonly || window.siyuan.config.editor.readOnly || window.siyuan.mobileEditor.protyle.disabled) { + if (window.siyuan.config.readonly || window.siyuan.config.editor.readOnly || window.siyuan.mobile.editor.protyle.disabled) { return; } if (!validateName(inputElement.value)) { @@ -178,8 +178,8 @@ const initEditorName = () => { } fetchPost("/api/filetree/renameDoc", { - notebook: window.siyuan.mobileEditor.protyle.notebookId, - path: window.siyuan.mobileEditor.protyle.path, + notebook: window.siyuan.mobile.editor.protyle.notebookId, + path: window.siyuan.mobile.editor.protyle.path, title: inputElement.value, }); }); diff --git a/app/src/mobile/util/search.ts b/app/src/mobile/util/search.ts index 6df65a197..7fe9a2165 100644 --- a/app/src/mobile/util/search.ts +++ b/app/src/mobile/util/search.ts @@ -75,8 +75,8 @@ export const popSearch = (modelElement: HTMLElement, modelMainElement: HTMLEleme while (target && !target.isEqualNode(searchElement)) { if (target.classList.contains("b3-list-item")) { const id = target.getAttribute("data-id"); - if (window.siyuan.mobileEditor.protyle) { - preventScroll(window.siyuan.mobileEditor.protyle); + if (window.siyuan.mobile.editor.protyle) { + preventScroll(window.siyuan.mobile.editor.protyle); } fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { openMobileFileById(id,foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]); diff --git a/app/src/mobile/util/setEmpty.ts b/app/src/mobile/util/setEmpty.ts index 5268155d1..1b68ab274 100644 --- a/app/src/mobile/util/setEmpty.ts +++ b/app/src/mobile/util/setEmpty.ts @@ -20,8 +20,8 @@ export const setEmpty = () => { ${window.siyuan.languages.help} `; document.getElementById("emptyNewFile").addEventListener(getEventName(), () => { - if (window.siyuan.mobileEditor) { - newFile(window.siyuan.mobileEditor.protyle.notebookId, window.siyuan.mobileEditor.protyle.path, true); + if (window.siyuan.mobile.editor) { + newFile(window.siyuan.mobile.editor.protyle.notebookId, window.siyuan.mobile.editor.protyle.path, true); } else { window.siyuan.notebooks.find(item => { if (item.closed) { diff --git a/app/src/mobile/util/showKeyboardToolbar.ts b/app/src/mobile/util/showKeyboardToolbar.ts index 50d65f9f3..345298c45 100644 --- a/app/src/mobile/util/showKeyboardToolbar.ts +++ b/app/src/mobile/util/showKeyboardToolbar.ts @@ -8,8 +8,8 @@ import {focusByRange, getSelectionPosition} from "../../protyle/util/selection"; export const showKeyboardToolbar = (bottom = 0) => { if (getSelection().rangeCount > 0) { const range = getSelection().getRangeAt(0); - if (!window.siyuan.mobileEditor || - !window.siyuan.mobileEditor.protyle.wysiwyg.element.contains(range.startContainer)) { + if (!window.siyuan.mobile.editor || + !window.siyuan.mobile.editor.protyle.wysiwyg.element.contains(range.startContainer)) { return; } } else { @@ -23,7 +23,7 @@ export const showKeyboardToolbar = (bottom = 0) => { toolbarElement.style.bottom = bottom + "px"; setTimeout(() => { - const contentElement = window.siyuan.mobileEditor.protyle.contentElement; + const contentElement = window.siyuan.mobile.editor.protyle.contentElement; const cursorTop = getSelectionPosition(contentElement).top - contentElement.getBoundingClientRect().top; if (cursorTop < window.innerHeight - 96) { return; @@ -46,16 +46,16 @@ export const initKeyboardToolbar = () => { toolbarElement.addEventListener("click", (event) => { const target = event.target as HTMLElement; const buttonElement = hasClosestByMatchTag(target, "BUTTON"); - if (!buttonElement || !window.siyuan.mobileEditor) { + if (!buttonElement || !window.siyuan.mobile.editor) { return; } - if (window.siyuan.mobileEditor.protyle.disabled) { + if (window.siyuan.mobile.editor.protyle.disabled) { return; } event.preventDefault(); event.stopPropagation(); const type = buttonElement.getAttribute("data-type"); - const protyle = window.siyuan.mobileEditor.protyle; + const protyle = window.siyuan.mobile.editor.protyle; if (type === "undo") { protyle.undo.undo(protyle); return; diff --git a/app/src/mobile/util/touch.ts b/app/src/mobile/util/touch.ts index 54fb006b8..ec853b6ab 100644 --- a/app/src/mobile/util/touch.ts +++ b/app/src/mobile/util/touch.ts @@ -6,7 +6,7 @@ let xDiff: number; let yDiff: number; export const handleTouchEnd = () => { - if (window.siyuan.mobileEditor) { + if (window.siyuan.mobile.editor) { document.querySelectorAll(".protyle-breadcrumb__bar--hide").forEach(item => { item.classList.remove("protyle-breadcrumb__bar--hide"); }); diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index 4b969fe69..63ef2880d 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -52,8 +52,8 @@ interface Window { } interface IWorkspace { - path:string - closed:boolean + path: string + closed: boolean } interface ICard { @@ -171,7 +171,10 @@ interface ISiyuan { notebooks?: INotebook[], emojis?: IEmoji[], backStack?: IBackStack[], - mobileEditor?: import("../protyle").Protyle, // mobile + mobile?: { + editor?: import("../protyle").Protyle + files?: import("../mobile/util/MobileFiles").MobileFiles + }, user?: { userId: string userName: string