Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Dec 12, 2023
1 parent 20d27a9 commit 2b3b784
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 25 deletions.
3 changes: 2 additions & 1 deletion app/src/boot/globalEvent/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {initTabMenu} from "../../menus/tab";
import {getInstanceById} from "../../layout/util";
import {Tab} from "../../layout/Tab";
import {hideTooltip} from "../../dialog/tooltip";
import {checkFold, openFileById} from "../../editor/util";
import {openFileById} from "../../editor/util";
import {checkFold} from "../../util/noRelyPCFunction";

export const initWindowEvent = (app: App) => {
document.body.addEventListener("mouseleave", () => {
Expand Down
3 changes: 2 additions & 1 deletion app/src/boot/globalEvent/searchKeydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from "path";
/// #endif
import {matchHotKey} from "../../protyle/util/hotKey";
import {fetchPost} from "../../util/fetch";
import {checkFold, openFileById} from "../../editor/util";
import {openFileById} from "../../editor/util";
import {Constants} from "../../constants";
import {newFileByName} from "../../util/newFile";
import {App} from "../../index";
Expand All @@ -15,6 +15,7 @@ import {showFileInFolder} from "../../util/pathName";
import {assetInputEvent, renderPreview, toggleAssetHistory} from "../../search/assets";
import {initSearchMenu} from "../../menus/search";
import {writeText} from "../../protyle/util/compatibility";
import {checkFold} from "../../util/noRelyPCFunction";

export const searchKeydown = (app: App, event: KeyboardEvent) => {
if (getSelection().rangeCount === 0) {
Expand Down
3 changes: 2 additions & 1 deletion app/src/boot/onGetConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {appearance} from "../config/appearance";
import {fetchPost, fetchSyncPost} from "../util/fetch";
import {addGA, initAssets, setInlineStyle} from "../util/assets";
import {renderSnippet} from "../config/util/snippets";
import {checkFold, openFile, openFileById} from "../editor/util";
import {openFile, openFileById} from "../editor/util";
import {focusByRange} from "../protyle/util/selection";
import {exitSiYuan} from "../dialog/processSystem";
import {isWindow} from "../util/functions";
Expand All @@ -28,6 +28,7 @@ import {App} from "../index";
import {initWindowEvent} from "./globalEvent/event";
import {sendGlobalShortcut} from "./globalEvent/keydown";
import {closeWindow} from "../window/closeWin";
import {checkFold} from "../util/noRelyPCFunction";

const matchKeymap = (keymap: Record<string, IKeymapItem>, key1: "general" | "editor", key2?: "general" | "insert" | "heading" | "list" | "table") => {
if (key1 === "general") {
Expand Down
9 changes: 0 additions & 9 deletions app/src/editor/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ import {App} from "../index";
import {newCardModel} from "../card/newCardTab";
import {preventScroll} from "../protyle/scroll/preventScroll";

export const checkFold = (id: string, cb: (zoomIn: boolean, action: string[]) => void) => {
if (!id) {
return;
}
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
cb(foldResponse.data, foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
});
};

export const openFileById = async (options: {
app: App,
id: string,
Expand Down
3 changes: 2 additions & 1 deletion app/src/layout/dock/Bookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import {setPanelFocus} from "../util";
import {getDockByType} from "../tabUtil";
import {fetchPost} from "../../util/fetch";
import {updateHotkeyTip} from "../../protyle/util/compatibility";
import {checkFold, openFileById} from "../../editor/util";
import {openFileById} from "../../editor/util";
import {hasClosestByClassName} from "../../protyle/util/hasClosest";
import {openBookmarkMenu} from "../../menus/bookmark";
import {App} from "../../index";
import {Constants} from "../../constants";
import {checkFold} from "../../util/noRelyPCFunction";

export class Bookmark extends Model {
private openNodes: string[];
Expand Down
3 changes: 2 additions & 1 deletion app/src/layout/dock/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import {addScript} from "../../protyle/util/addScript";
import {BlockPanel} from "../../block/Panel";
import {fullscreen} from "../../protyle/breadcrumb/action";
import {fetchPost} from "../../util/fetch";
import {checkFold, isCurrentEditor, openFileById} from "../../editor/util";
import {isCurrentEditor, openFileById} from "../../editor/util";
import {updateHotkeyTip} from "../../protyle/util/compatibility";
import {openGlobalSearch} from "../../search/util";
import {App} from "../../index";
import {checkFold} from "../../util/noRelyPCFunction";

declare const vis: any;

Expand Down
3 changes: 2 additions & 1 deletion app/src/layout/dock/Outline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import {fetchPost} from "../../util/fetch";
import {getAllModels} from "../getAll";
import {hasClosestBlock, hasClosestByClassName, hasTopClosestByClassName} from "../../protyle/util/hasClosest";
import {updateHotkeyTip} from "../../protyle/util/compatibility";
import {checkFold, openFileById} from "../../editor/util";
import {openFileById} from "../../editor/util";
import {Constants} from "../../constants";
import {escapeHtml} from "../../util/escape";
import {unicode2Emoji} from "../../emoji";
import {onGet} from "../../protyle/util/onGet";
import {getPreviousBlock} from "../../protyle/wysiwyg/getBlock";
import {App} from "../../index";
import {checkFold} from "../../util/noRelyPCFunction";

export class Outline extends Model {
public tree: Tree;
Expand Down
4 changes: 2 additions & 2 deletions app/src/menus/protyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {onGet} from "../protyle/util/onGet";
import {getAllModels} from "../layout/getAll";
import {pasteAsPlainText, pasteEscaped, pasteText} from "../protyle/util/paste";
/// #if !MOBILE
import {checkFold, openFileById, updateBacklinkGraph} from "../editor/util";
import {openFileById, updateBacklinkGraph} from "../editor/util";
import {openGlobalSearch} from "../search/util";
import {openNewWindowById} from "../window/openNewWindow";
/// #endif
Expand All @@ -45,7 +45,7 @@ import {pushBack} from "../mobile/util/MobileBackFoward";
import {copyPNG, exportAsset} from "./util";
import {removeInlineType} from "../protyle/toolbar/util";
import {alignImgCenter, alignImgLeft} from "../protyle/wysiwyg/commonHotkey";
import {renameTag} from "../util/noRelyPCFunction";
import {checkFold, renameTag} from "../util/noRelyPCFunction";
import {hideElements} from "../protyle/ui/hideElements";
import {emitOpenMenu} from "../plugin/EventBus";
import {openMobileFileById} from "../mobile/editor";
Expand Down
3 changes: 2 additions & 1 deletion app/src/menus/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import * as path from "path";
/// #endif
import {fetchPost} from "../util/fetch";
import {getAssetName, pathPosix, showFileInFolder} from "../util/pathName";
import {checkFold, openFileById} from "../editor/util";
import {openFileById} from "../editor/util";
import {Constants} from "../constants";
import {openNewWindowById} from "../window/openNewWindow";
import {MenuItem} from "./Menu";
import {App} from "../index";
import {isInAndroid, updateHotkeyTip} from "../protyle/util/compatibility";
import {checkFold} from "../util/noRelyPCFunction";

export const exportAsset = (src: string) => {
/// #if !BROWSER
Expand Down
2 changes: 1 addition & 1 deletion app/src/mobile/dock/MobileBookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {hasClosestByClassName} from "../../protyle/util/hasClosest";
import {openMobileFileById} from "../editor";
import {openBookmarkMenu} from "../../menus/bookmark";
import {App} from "../../index";
import {checkFold} from "../../editor/util";
import {checkFold} from "../../util/noRelyPCFunction";

export class MobileBookmarks {
public element: HTMLElement;
Expand Down
2 changes: 1 addition & 1 deletion app/src/mobile/dock/MobileOutline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {Constants} from "../../constants";
import {getEventName} from "../../protyle/util/compatibility";
import {App} from "../../index";
import {closePanel} from "../util/closePanel";
import {checkFold} from "../../editor/util";
import {checkFold} from "../../util/noRelyPCFunction";

export class MobileOutline {
private tree: Tree;
Expand Down
2 changes: 1 addition & 1 deletion app/src/mobile/menu/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
renderPreview,
} from "../../search/assets";
import {addClearButton} from "../../util/addClearButton";
import {checkFold} from "../../editor/util";
import {checkFold} from "../../util/noRelyPCFunction";

const replace = (element: Element, config: ISearchOption, isAll: boolean) => {
if (config.method === 1 || config.method === 2) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/mobile/util/initFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {syncGuide} from "../../sync/syncGuide";
import {Inbox} from "../../layout/dock/Inbox";
import {App} from "../../index";
import {setTitle} from "../../dialog/processSystem";
import {checkFold} from "../../editor/util";
import {checkFold} from "../../util/noRelyPCFunction";

export const initFramework = (app: App, isStart: boolean) => {
setInlineStyle();
Expand Down
3 changes: 2 additions & 1 deletion app/src/protyle/wysiwyg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import {blockRender} from "../render/blockRender";
/// #if !MOBILE
import {getAllModels} from "../../layout/getAll";
import {pushBack} from "../../util/backForward";
import {checkFold, openAsset, openBy, openFileById} from "../../editor/util";
import {openAsset, openBy, openFileById} from "../../editor/util";
import {openGlobalSearch} from "../../search/util";
/// #else
import {popSearch} from "../../mobile/menu/search";
Expand All @@ -80,6 +80,7 @@ import {stickyRow, updateHeader} from "../render/av/row";
import {showColMenu} from "../render/av/col";
import {openViewMenu} from "../render/av/view";
import {avRender} from "../render/av/render";
import {checkFold} from "../../util/noRelyPCFunction";

export class WYSIWYG {
public lastHTMLs: { [key: string]: string } = {};
Expand Down
3 changes: 2 additions & 1 deletion app/src/protyle/wysiwyg/keydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {newFileContentBySelect, rename, replaceFileName} from "../../editor/rena
import {insertEmptyBlock, jumpToParentNext} from "../../block/util";
import {isLocalPath, pathPosix} from "../../util/pathName";
/// #if !MOBILE
import {checkFold, openBy, openFileById} from "../../editor/util";
import {openBy, openFileById} from "../../editor/util";
/// #endif
import {
alignImgCenter, alignImgLeft,
Expand Down Expand Up @@ -68,6 +68,7 @@ import {escapeHtml} from "../../util/escape";
import {insertHTML} from "../util/insertHTML";
import {removeSearchMark} from "../toolbar/util";
import {avKeydown} from "../render/av/keydown";
import {checkFold} from "../../util/noRelyPCFunction";

export const getContentByInlineHTML = (range: Range, cb: (content: string) => void) => {
let html = "";
Expand Down
3 changes: 2 additions & 1 deletion app/src/search/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as path from "path";
import {Constants} from "../constants";
import {escapeAriaLabel, escapeGreat, escapeHtml} from "../util/escape";
import {fetchPost} from "../util/fetch";
import {checkFold, openFile, openFileById} from "../editor/util";
import {openFile, openFileById} from "../editor/util";
import {showMessage} from "../dialog/message";
import {reloadProtyle} from "../protyle/util/reload";
import {MenuItem} from "../menus/Menu";
Expand Down Expand Up @@ -40,6 +40,7 @@ import {
import {resize} from "../protyle/util/resize";
import {Menu} from "../plugin/Menu";
import {addClearButton} from "../util/addClearButton";
import {checkFold} from "../util/noRelyPCFunction";

export const toggleReplaceHistory = (searchElement: Element) => {
const list = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS];
Expand Down
10 changes: 10 additions & 0 deletions app/src/util/noRelyPCFunction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Dialog} from "../dialog";
import {fetchPost} from "./fetch";
import {isMobile} from "./functions";
import {Constants} from "../constants";

// 需独立出来,否则移动端引用的时候会引入 pc 端大量无用代码
export const renameTag = (labelName: string) => {
Expand Down Expand Up @@ -31,3 +32,12 @@ export const renameTag = (labelName: string) => {
export const getWorkspaceName = () => {
return window.siyuan.config.system.workspaceDir.replace(/^.*[\\\/]/, "");
};

export const checkFold = (id: string, cb: (zoomIn: boolean, action: string[]) => void) => {
if (!id) {
return;
}
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
cb(foldResponse.data, foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
});
};

0 comments on commit 2b3b784

Please sign in to comment.