Vanessa 2022-06-29 15:36:44 +08:00
parent ec34dcca19
commit 0200e6eed5
12 changed files with 221 additions and 190 deletions

View file

@ -0,0 +1,27 @@
import {fetchPost} from "../util/fetch";
import {getDisplayName} from "../util/pathName";
import {confirmDialog} from "../dialog/confirmDialog";
export const deleteFile = (notebookId: string, pathString: string, name: string) => {
if (window.siyuan.config.fileTree.removeDocWithoutConfirm) {
fetchPost("/api/filetree/removeDoc", {
notebook: notebookId,
path: pathString
});
return;
}
fetchPost("/api/block/getDocInfo", {
id: getDisplayName(pathString, true, true)
}, (response) => {
let tip = `${window.siyuan.languages.confirmDelete} <b>${name}</b>?`;
if (response.data.subFileCount > 0) {
tip = `${window.siyuan.languages.confirmDelete} <b>${name}</b> ${window.siyuan.languages.andSubFile.replace("x", response.data.subFileCount)}?`;
}
confirmDialog(window.siyuan.languages.delete, tip, () => {
fetchPost("/api/filetree/removeDoc", {
notebook: notebookId,
path: pathString
});
});
});
};

View file

@ -457,27 +457,3 @@ export const openBy = (url: string, type: "folder" | "app") => {
}
/// #endif
};
export const deleteFile = (notebookId: string, pathString: string, name: string) => {
if (window.siyuan.config.fileTree.removeDocWithoutConfirm) {
fetchPost("/api/filetree/removeDoc", {
notebook: notebookId,
path: pathString
});
return;
}
fetchPost("/api/block/getDocInfo", {
id: getDisplayName(pathString, true, true)
}, (response) => {
let tip = `${window.siyuan.languages.confirmDelete} <b>${name}</b>?`;
if (response.data.subFileCount > 0) {
tip = `${window.siyuan.languages.confirmDelete} <b>${name}</b> ${window.siyuan.languages.andSubFile.replace("x", response.data.subFileCount)}?`;
}
confirmDialog(window.siyuan.languages.delete, tip, () => {
fetchPost("/api/filetree/removeDoc", {
notebook: notebookId,
path: pathString
});
});
});
};

View file

@ -3,9 +3,11 @@ import {setPosition} from "../util/setPosition";
import {fetchPost} from "../util/fetch";
import {hasClosestByClassName} from "../protyle/util/hasClosest";
import {Constants} from "../constants";
import {getDockByType} from "../layout/util";
import {Files} from "../layout/dock/Files";
/// #if !MOBILE
import {getDockByType} from "../layout/util";
import {getAllModels} from "../layout/getAll";
/// #endif
import {getEventName} from "../protyle/util/compatibility";
import {setNoteBook} from "../util/pathName";
@ -392,26 +394,25 @@ ${unicode2Emoji(emoji.unicode)}</button>`;
};
export const updateOutlineEmoji = (unicode: string) => {
if (isMobile()) {
return;
}
/// #if !MOBILE
getAllModels().outline.forEach(model => {
model.headerElement.nextElementSibling.firstElementChild.innerHTML = unicode2Emoji(unicode || Constants.SIYUAN_IMAGE_FILE);
});
/// #endif
};
export const updateFileTreeEmoji = (unicode: string, id: string, icon = "iconFile") => {
let emojiElement;
if (isMobile()) {
/// #if MOBILE
emojiElement = document.querySelector(`#sidebar [data-type="sidebar-file"] [data-node-id="${id}"] .b3-list-item__icon`);
} else {
/// #else
const files = getDockByType("file").data.file as Files;
if (icon === "iconFile") {
emojiElement = files.element.querySelector(`[data-node-id="${id}"] .b3-list-item__icon`);
} else {
emojiElement = files.element.querySelector(`[data-node-id="${id}"] .b3-list-item__icon`) || files.element.querySelector(`[data-url="${id}"] .b3-list-item__icon`) || files.closeElement.querySelector(`[data-url="${id}"] .b3-list-item__icon`);
}
}
/// #endif
if (emojiElement) {
emojiElement.innerHTML = unicode2Emoji(unicode || (icon === "iconFile" ? (emojiElement.previousElementSibling.classList.contains("fn__hidden") ? Constants.SIYUAN_IMAGE_FILE : Constants.SIYUAN_IMAGE_FOLDER) : Constants.SIYUAN_IMAGE_NOTE));
}
@ -421,12 +422,12 @@ export const updateFileTreeEmoji = (unicode: string, id: string, icon = "iconFil
};
const updateFileEmoji = (unicode: string, id: string) => {
if (isMobile()) {
/// #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, id);
}
} else {
/// #else
getAllModels().editor.find(item => {
if (item.editor.protyle.block.rootID === id) {
item.editor.protyle.background.ial.icon = unicode;
@ -435,5 +436,5 @@ const updateFileEmoji = (unicode: string, id: string) => {
return true;
}
});
}
/// #endif
};

View file

@ -1,3 +1,4 @@
/// #if !MOBILE
import {getAllDocks} from "./getAll";
import {updateHotkeyTip} from "../protyle/util/compatibility";
import {exportLayout, getDockByType, resizeTabs} from "./util";
@ -7,9 +8,10 @@ import {mountHelp} from "../util/mount";
/// #if !BROWSER
import {getCurrentWindow} from "@electron/remote";
/// #endif
import {isMobile} from "../util/functions";
/// #endif
export const initStatus = () => {
/// #if !MOBILE
const allDocks = getAllDocks();
let menuHTML = "";
allDocks.forEach(item => {
@ -124,10 +126,12 @@ export const initStatus = () => {
if (window.siyuan.config.appearance.hideStatusBar) {
document.getElementById("status").classList.add("fn__none");
}
/// #endif
};
export const countSelectWord = (range: Range) => {
if (isMobile() || document.getElementById("status").classList.contains("fn__none")) {
/// #if !MOBILE
if (document.getElementById("status").classList.contains("fn__none")) {
return;
}
const selectText = range.toString();
@ -142,10 +146,12 @@ export const countSelectWord = (range: Range) => {
} else {
document.querySelector("#status .status__counter").innerHTML = "";
}
/// #endif
};
export const countBlockWord = (ids: string[]) => {
if (isMobile() || document.getElementById("status").classList.contains("fn__none")) {
/// #if !MOBILE
if (document.getElementById("status").classList.contains("fn__none")) {
return;
}
if (ids.length > 0) {
@ -159,5 +165,6 @@ export const countBlockWord = (ids: string[]) => {
} else {
document.querySelector("#status .status__counter").innerHTML = "";
}
/// #endif
};

View file

@ -13,16 +13,19 @@ import {writeText} from "../protyle/util/compatibility";
import {fetchPost} from "../util/fetch";
import {hideMessage, showMessage} from "../dialog/message";
import {Dialog} from "../dialog";
import {getAllModels} from "../layout/getAll";
import {focusBlock, focusByRange, getEditorRange} from "../protyle/util/selection";
import {setPosition} from "../util/setPosition";
import {updateTransaction} from "../protyle/wysiwyg/transaction";
/// #if !MOBILE
import {getAllModels} from "../layout/getAll";
import {Bookmark} from "../layout/dock/Bookmark";
import {openAsset, openBy} from "../editor/util";
/// #endif
import {rename} from "../editor/rename";
import {deleteFile, openAsset, openBy} from "../editor/util";
import {matchHotKey} from "../protyle/util/hotKey";
import * as dayjs from "dayjs";
import {Constants} from "../constants";
import {deleteFile} from "../editor/deleteFile";
const bindAttrInput = (inputElement: HTMLInputElement, confirmElement: Element) => {
inputElement.addEventListener("keydown", (event) => {
@ -315,7 +318,7 @@ export const openFileAttr = (attrs: IObject, id: string, focusName = "bookmark")
if (errorTip) {
showMessage(errorTip.substr(0, errorTip.length - 2) + " " + window.siyuan.languages.invalid);
}
if (!isMobile()) {
/// #if !MOBILE
getAllModels().editor.forEach(item => {
if (item.editor.protyle.block.rootID === id) {
const refElement = item.editor.protyle.title.element.querySelector(".protyle-attr--refcount");
@ -326,7 +329,6 @@ export const openFileAttr = (attrs: IObject, id: string, focusName = "bookmark")
item.editor.protyle.wysiwyg.renderCustom(attrsResult);
}
});
}
fetchPost("/api/attr/resetBlockAttrs", {id, attrs: attrsResult}, () => {
if (attrsResult.bookmark !== attrs.bookmark) {
const bookmark = getDockByType("bookmark").data.bookmark;
@ -335,6 +337,7 @@ export const openFileAttr = (attrs: IObject, id: string, focusName = "bookmark")
}
}
});
/// #endif
dialog.destroy();
});
dialog.element.querySelectorAll(".b3-text-field").forEach((item: HTMLInputElement) => {
@ -508,7 +511,8 @@ export const openAttr = (nodeElement: Element, protyle: IProtyle, focusName = "b
const escapeHTML = Lute.EscapeHTMLStr(item.value);
nodeElement.setAttribute(name, escapeHTML);
if (name === "bookmark") {
if (escapeHTML !== response.data.bookmark && !isMobile()) {
/// #if !MOBILE
if (escapeHTML !== response.data.bookmark) {
const bookmark = getDockByType("bookmark").data.bookmark;
if (bookmark instanceof Bookmark) {
setTimeout(() => {
@ -516,6 +520,7 @@ export const openAttr = (nodeElement: Element, protyle: IProtyle, focusName = "b
}, 219);
}
}
/// #endif
nodeAttrHTML += `<div class="protyle-attr--bookmark">${escapeHTML}</div>`;
} else if (name === "name") {
nodeAttrHTML += `<div class="protyle-attr--name"><svg><use xlink:href="#iconN"></use></svg>${escapeHTML}</div>`;
@ -715,6 +720,7 @@ export const openMenu = (src: string, onlyMenu = false) => {
(!src.endsWith(".pdf") ||
(src.endsWith(".pdf") && !src.startsWith("file://")))
) {
/// #if !MOBILE
submenu.push({
label: window.siyuan.languages.insertRight,
accelerator: "Click",
@ -722,6 +728,7 @@ export const openMenu = (src: string, onlyMenu = false) => {
openAsset(src.trim(), parseInt(getSearch("page", src)), "right");
}
});
/// #endif
/// #if !BROWSER
submenu.push({
label: window.siyuan.languages.useDefault,

View file

@ -19,11 +19,10 @@ import {fetchPost} from "../util/fetch";
import {onGetnotebookconf} from "./onGetnotebookconf";
/// #if !MOBILE
import {openSearch} from "../search/spread";
import {openFileById} from "../editor/util";
/// #endif
import {confirmDialog} from "../dialog/confirmDialog";
import {isMobile} from "../util/functions";
import {Constants} from "../constants";
import {openFileById} from "../editor/util";
export const initNavigationMenu = (liElement: HTMLElement) => {
const notebookId = liElement.parentElement.getAttribute("data-url");
@ -180,6 +179,7 @@ export const initFileMenu = (notebookId: string, pathString: string, id: string,
/// #endif
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
}
/// #if !MOBILE
const openSubmenus: IMenu[] = [{
icon: "iconRight",
label: window.siyuan.languages.insertRight,
@ -227,12 +227,11 @@ export const initFileMenu = (notebookId: string, pathString: string, id: string,
});
}
/// #endif
if (!isMobile()) {
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.openBy,
submenu: openSubmenus,
}).element);
}
/// #endif
if (!window.siyuan.config.readonly) {
genImportMenu(notebookId, pathString);
}

View file

@ -26,13 +26,14 @@ import {clipboard} from "electron";
import {onGet} from "../protyle/util/onGet";
import {getAllModels} from "../layout/getAll";
import {pasteText} from "../protyle/util/paste";
/// #if !MOBILE
import {openFileById, updateBacklinkGraph} from "../editor/util";
/// #endif
import {isMobile} from "../util/functions";
import {removeFoldHeading} from "../protyle/util/heading";
import {lineNumberRender} from "../protyle/markdown/highlightRender";
import * as dayjs from "dayjs";
import {blockRender} from "../protyle/markdown/blockRender";
import {isLocalPath} from "../util/pathName";
export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
const nodeElement = hasClosestBlock(element);
@ -78,7 +79,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
window.siyuan.menus.menu.append(new MenuItem({
type: "separator"
}).element);
if (!isMobile()) {
/// #if !MOBILE
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.openBy,
accelerator: "⌘Click",
@ -126,7 +127,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
});
}
}).element);
}
/// #endif
let submenu: IMenu[] = [];
if (element.getAttribute("data-subtype") === "s") {
submenu.push({
@ -381,9 +382,11 @@ export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushB
return;
}
}
/// #if !MOBILE
if (protyle.model) {
updateBacklinkGraph(getAllModels(), protyle);
}
/// #endif
});
};

View file

@ -3,7 +3,6 @@ import {escapeHtml} from "../../util/escape";
import {Model} from "../../layout/Model";
import {Constants} from "../../constants";
import {getDisplayName, pathPosix, setNoteBook} from "../../util/pathName";
import {newFile} from "../../util/newFile";
import {initFileMenu, initNavigationMenu} from "../../menus/navigation";
import {showMessage} from "../../dialog/message";
import {fetchPost} from "../../util/fetch";
@ -14,6 +13,7 @@ import {newNotebook} from "../../util/mount";
import {setEmpty} from "./setEmpty";
import {confirmDialog} from "../../dialog/confirmDialog";
import {MenuItem} from "../../menus/Menu";
import {newFile} from "../../util/newFile";
export class MobileFiles extends Model {
public element: HTMLElement;

View file

@ -18,7 +18,7 @@ import {matchHotKey} from "../util/hotKey";
import {updateHotkeyTip, writeText} from "../util/compatibility";
import {setPanelFocus} from "../../layout/util";
import {escapeHtml} from "../../util/escape";
import {deleteFile, updatePanelByEditor} from "../../editor/util";
import {updatePanelByEditor} from "../../editor/util";
import * as dayjs from "dayjs";
import {setTitle} from "../../dialog/processSystem";
import {getNoContainerElement} from "../wysiwyg/getBlock";
@ -26,6 +26,7 @@ import {commonHotkey} from "../wysiwyg/commonHotkey";
import {setPosition} from "../../util/setPosition";
import {code160to32} from "../util/code160to32";
import {openBacklink, openGraph, openOutline} from "../../layout/dock/util";
import {deleteFile} from "../../editor/deleteFile";
export class Title {
public element: HTMLElement;

View file

@ -47,7 +47,9 @@ import {setPosition} from "../../util/setPosition";
import {openAttr} from "../../menus/commonMenuItem";
import {blockRender} from "../markdown/blockRender";
import {pushBack} from "../../util/backForward";
/// #if !MOBILE
import {openAsset, openBy, openFileById} from "../../editor/util";
/// #endif
import {BlockPanel} from "../../block/Panel";
import {isCtrl} from "../util/compatibility";
import {MenuItem} from "../../menus/Menu";
@ -1342,9 +1344,9 @@ export class WYSIWYG {
}
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
if (isMobile()) {
/// #if MOBILE
openMobileFileById(refBlockId, !foldResponse.data, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL]);
} else {
/// #else
if (window.siyuan.shiftIsPressed) {
openFileById({
id: refBlockId,
@ -1377,7 +1379,7 @@ export class WYSIWYG {
zoomIn: foldResponse.data
});
}
}
/// #endif
});
if (protyle.model) {
// 打开双链需记录到后退中 https://github.com/siyuan-note/insider/issues/801
@ -1400,14 +1402,13 @@ export class WYSIWYG {
event.preventDefault();
const fileIds = fileElement.getAttribute("data-id").split("/");
const linkAddress = `assets/${fileIds[1]}`;
if (isMobile()) {
/// #if MOBILE
if (typeof window.JSAndroid === "undefined") {
window.open(linkAddress);
} else {
window.JSAndroid.openExternal(linkAddress);
}
return;
}
/// #else
if (window.siyuan.ctrlIsPressed) {
openBy(linkAddress, "folder");
} else if (window.siyuan.shiftIsPressed) {
@ -1415,6 +1416,7 @@ export class WYSIWYG {
} else {
openAsset(linkAddress, fileIds[2], "right");
}
/// #endif
return;
}
@ -1422,7 +1424,7 @@ export class WYSIWYG {
event.stopPropagation();
event.preventDefault();
const linkAddress = aElement.getAttribute("data-href");
if (isMobile()) {
/// #if MOBILE
if (window.siyuan.config.system.container === "ios") {
window.location.href = linkAddress;
} else if (window.siyuan.config.system.container === "android" && window.JSAndroid) {
@ -1430,8 +1432,7 @@ export class WYSIWYG {
} else {
window.open(linkAddress);
}
return;
}
/// #else
if (isLocalPath(linkAddress)) {
const linkPathname = linkAddress.split("?page")[0];
if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname(linkPathname)) &&
@ -1474,6 +1475,7 @@ export class WYSIWYG {
}
/// #endif
}
/// #endif
return;
}
@ -1487,9 +1489,10 @@ export class WYSIWYG {
const embedItemElement = hasClosestByClassName(event.target, "protyle-wysiwyg__embed");
if (embedItemElement) {
const embedId = embedItemElement.getAttribute("data-id");
if (isMobile()) {
/// #if MOBILE
openMobileFileById(embedId, false, [Constants.CB_GET_ALL]);
} else if (window.siyuan.shiftIsPressed) {
/// #else
if (window.siyuan.shiftIsPressed) {
openFileById({
id: embedId,
position: "bottom",
@ -1519,6 +1522,7 @@ export class WYSIWYG {
nodeIds: [embedId],
}));
}
/// #endif
event.stopPropagation();
return;
}

View file

@ -24,7 +24,7 @@ import {goBack, goForward} from "./backForward";
import {onGet} from "../protyle/util/onGet";
import {getDisplayName, getNotebookName, movePathTo} from "./pathName";
import {confirmDialog} from "../dialog/confirmDialog";
import {deleteFile, openFileById} from "../editor/util";
import {openFileById} from "../editor/util";
import {getAllDocks, getAllModels, getAllTabs} from "../layout/getAll";
import {openGlobalSearch} from "../search/util";
import {getColIndex} from "../protyle/util/table";
@ -36,6 +36,7 @@ import {openHistory} from "./history";
import {needSubscribe} from "./needSubscribe";
import {Dialog} from "../dialog";
import {unicode2Emoji} from "../emoji";
import {deleteFile} from "../editor/deleteFile";
const getRightBlock = (element: HTMLElement, x: number, y: number) => {
let index = 1;

View file

@ -2,18 +2,20 @@ import {showMessage} from "../dialog/message";
import {getAllModels} from "../layout/getAll";
import {hasTopClosestByTag} from "../protyle/util/hasClosest";
import {getDockByType} from "../layout/util";
/// #if !MOBILE
import {Files} from "../layout/dock/Files";
import {openFileById} from "../editor/util";
/// #endif
import {fetchPost} from "./fetch";
import {getDisplayName, getOpenNotebookCount, pathPosix} from "./pathName";
import {openFileById} from "../editor/util";
import {Constants} from "../constants";
import {isMobile} from "./functions";
export const newFile = (notebookId?: string, currentPath?: string, open?: boolean) => {
if (getOpenNotebookCount() === 0) {
showMessage(window.siyuan.languages.newFileTip);
return;
}
/// #if !MOBILE
if (!notebookId) {
getAllModels().editor.find((item) => {
const currentElement = item.parent.headElement;
@ -39,6 +41,8 @@ export const newFile = (notebookId?: string, currentPath?: string, open?: boolea
}
}
}
}
/// #endif
if (!notebookId) {
window.siyuan.notebooks.find(item => {
if (!item.closed) {
@ -48,7 +52,6 @@ export const newFile = (notebookId?: string, currentPath?: string, open?: boolea
}
});
}
}
fetchPost("/api/filetree/getDocNameTemplate", {notebook: notebookId}, (data) => {
const id = Lute.NewNodeID();
fetchPost("/api/filetree/createDoc", {
@ -57,9 +60,11 @@ export const newFile = (notebookId?: string, currentPath?: string, open?: boolea
title: data.data.name || "Untitled",
md: "",
}, () => {
if (open && !isMobile()) {
/// #if !MOBILE
if (open) {
openFileById({id, hasContext: true, action: [Constants.CB_GET_HL]});
}
/// #endif
});
});
};