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

View file

@ -1,3 +1,4 @@
/// #if !MOBILE
import {getAllDocks} from "./getAll"; import {getAllDocks} from "./getAll";
import {updateHotkeyTip} from "../protyle/util/compatibility"; import {updateHotkeyTip} from "../protyle/util/compatibility";
import {exportLayout, getDockByType, resizeTabs} from "./util"; import {exportLayout, getDockByType, resizeTabs} from "./util";
@ -7,9 +8,10 @@ import {mountHelp} from "../util/mount";
/// #if !BROWSER /// #if !BROWSER
import {getCurrentWindow} from "@electron/remote"; import {getCurrentWindow} from "@electron/remote";
/// #endif /// #endif
import {isMobile} from "../util/functions"; /// #endif
export const initStatus = () => { export const initStatus = () => {
/// #if !MOBILE
const allDocks = getAllDocks(); const allDocks = getAllDocks();
let menuHTML = ""; let menuHTML = "";
allDocks.forEach(item => { allDocks.forEach(item => {
@ -124,10 +126,12 @@ export const initStatus = () => {
if (window.siyuan.config.appearance.hideStatusBar) { if (window.siyuan.config.appearance.hideStatusBar) {
document.getElementById("status").classList.add("fn__none"); document.getElementById("status").classList.add("fn__none");
} }
/// #endif
}; };
export const countSelectWord = (range: Range) => { 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; return;
} }
const selectText = range.toString(); const selectText = range.toString();
@ -142,10 +146,12 @@ export const countSelectWord = (range: Range) => {
} else { } else {
document.querySelector("#status .status__counter").innerHTML = ""; document.querySelector("#status .status__counter").innerHTML = "";
} }
/// #endif
}; };
export const countBlockWord = (ids: string[]) => { 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; return;
} }
if (ids.length > 0) { if (ids.length > 0) {
@ -159,5 +165,6 @@ export const countBlockWord = (ids: string[]) => {
} else { } else {
document.querySelector("#status .status__counter").innerHTML = ""; 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 {fetchPost} from "../util/fetch";
import {hideMessage, showMessage} from "../dialog/message"; import {hideMessage, showMessage} from "../dialog/message";
import {Dialog} from "../dialog"; import {Dialog} from "../dialog";
import {getAllModels} from "../layout/getAll";
import {focusBlock, focusByRange, getEditorRange} from "../protyle/util/selection"; import {focusBlock, focusByRange, getEditorRange} from "../protyle/util/selection";
import {setPosition} from "../util/setPosition"; import {setPosition} from "../util/setPosition";
import {updateTransaction} from "../protyle/wysiwyg/transaction"; import {updateTransaction} from "../protyle/wysiwyg/transaction";
/// #if !MOBILE
import {getAllModels} from "../layout/getAll";
import {Bookmark} from "../layout/dock/Bookmark"; import {Bookmark} from "../layout/dock/Bookmark";
import {openAsset, openBy} from "../editor/util";
/// #endif
import {rename} from "../editor/rename"; import {rename} from "../editor/rename";
import {deleteFile, openAsset, openBy} from "../editor/util";
import {matchHotKey} from "../protyle/util/hotKey"; import {matchHotKey} from "../protyle/util/hotKey";
import * as dayjs from "dayjs"; import * as dayjs from "dayjs";
import {Constants} from "../constants"; import {Constants} from "../constants";
import {deleteFile} from "../editor/deleteFile";
const bindAttrInput = (inputElement: HTMLInputElement, confirmElement: Element) => { const bindAttrInput = (inputElement: HTMLInputElement, confirmElement: Element) => {
inputElement.addEventListener("keydown", (event) => { inputElement.addEventListener("keydown", (event) => {
@ -315,7 +318,7 @@ export const openFileAttr = (attrs: IObject, id: string, focusName = "bookmark")
if (errorTip) { if (errorTip) {
showMessage(errorTip.substr(0, errorTip.length - 2) + " " + window.siyuan.languages.invalid); showMessage(errorTip.substr(0, errorTip.length - 2) + " " + window.siyuan.languages.invalid);
} }
if (!isMobile()) { /// #if !MOBILE
getAllModels().editor.forEach(item => { getAllModels().editor.forEach(item => {
if (item.editor.protyle.block.rootID === id) { if (item.editor.protyle.block.rootID === id) {
const refElement = item.editor.protyle.title.element.querySelector(".protyle-attr--refcount"); 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); item.editor.protyle.wysiwyg.renderCustom(attrsResult);
} }
}); });
}
fetchPost("/api/attr/resetBlockAttrs", {id, attrs: attrsResult}, () => { fetchPost("/api/attr/resetBlockAttrs", {id, attrs: attrsResult}, () => {
if (attrsResult.bookmark !== attrs.bookmark) { if (attrsResult.bookmark !== attrs.bookmark) {
const bookmark = getDockByType("bookmark").data.bookmark; const bookmark = getDockByType("bookmark").data.bookmark;
@ -335,6 +337,7 @@ export const openFileAttr = (attrs: IObject, id: string, focusName = "bookmark")
} }
} }
}); });
/// #endif
dialog.destroy(); dialog.destroy();
}); });
dialog.element.querySelectorAll(".b3-text-field").forEach((item: HTMLInputElement) => { 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); const escapeHTML = Lute.EscapeHTMLStr(item.value);
nodeElement.setAttribute(name, escapeHTML); nodeElement.setAttribute(name, escapeHTML);
if (name === "bookmark") { if (name === "bookmark") {
if (escapeHTML !== response.data.bookmark && !isMobile()) { /// #if !MOBILE
if (escapeHTML !== response.data.bookmark) {
const bookmark = getDockByType("bookmark").data.bookmark; const bookmark = getDockByType("bookmark").data.bookmark;
if (bookmark instanceof Bookmark) { if (bookmark instanceof Bookmark) {
setTimeout(() => { setTimeout(() => {
@ -516,6 +520,7 @@ export const openAttr = (nodeElement: Element, protyle: IProtyle, focusName = "b
}, 219); }, 219);
} }
} }
/// #endif
nodeAttrHTML += `<div class="protyle-attr--bookmark">${escapeHTML}</div>`; nodeAttrHTML += `<div class="protyle-attr--bookmark">${escapeHTML}</div>`;
} else if (name === "name") { } else if (name === "name") {
nodeAttrHTML += `<div class="protyle-attr--name"><svg><use xlink:href="#iconN"></use></svg>${escapeHTML}</div>`; 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.endsWith(".pdf") && !src.startsWith("file://"))) (src.endsWith(".pdf") && !src.startsWith("file://")))
) { ) {
/// #if !MOBILE
submenu.push({ submenu.push({
label: window.siyuan.languages.insertRight, label: window.siyuan.languages.insertRight,
accelerator: "Click", accelerator: "Click",
@ -722,6 +728,7 @@ export const openMenu = (src: string, onlyMenu = false) => {
openAsset(src.trim(), parseInt(getSearch("page", src)), "right"); openAsset(src.trim(), parseInt(getSearch("page", src)), "right");
} }
}); });
/// #endif
/// #if !BROWSER /// #if !BROWSER
submenu.push({ submenu.push({
label: window.siyuan.languages.useDefault, label: window.siyuan.languages.useDefault,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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