mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
This commit is contained in:
parent
b0377a168b
commit
dab5377a4b
7 changed files with 50 additions and 20 deletions
|
|
@ -3,11 +3,11 @@ import {fetchPost} from "../util/fetch";
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
import {getAllModels} from "../layout/getAll";
|
import {getAllModels} from "../layout/getAll";
|
||||||
import {ipcRenderer} from "electron";
|
import {ipcRenderer} from "electron";
|
||||||
|
import {exportLayout} from "../layout/util";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {showMessage} from "./message";
|
import {showMessage} from "./message";
|
||||||
import {Dialog} from "./index";
|
import {Dialog} from "./index";
|
||||||
import {isMobile} from "../util/functions";
|
import {isMobile} from "../util/functions";
|
||||||
import {exportLayout} from "../layout/util";
|
|
||||||
|
|
||||||
export const lockFile = (id: string) => {
|
export const lockFile = (id: string) => {
|
||||||
const html = `<div class="b3-dialog__scrim"></div>
|
const html = `<div class="b3-dialog__scrim"></div>
|
||||||
|
|
@ -134,9 +134,13 @@ export const transactionError = (data: { code: number, data: string }) => {
|
||||||
});
|
});
|
||||||
const btnsElement = dialog.element.querySelectorAll(".b3-button");
|
const btnsElement = dialog.element.querySelectorAll(".b3-button");
|
||||||
btnsElement[0].addEventListener("click", () => {
|
btnsElement[0].addEventListener("click", () => {
|
||||||
|
/// #if MOBILE
|
||||||
|
exitSiYuan();
|
||||||
|
/// #else
|
||||||
exportLayout(false, () => {
|
exportLayout(false, () => {
|
||||||
exitSiYuan();
|
exitSiYuan();
|
||||||
});
|
});
|
||||||
|
/// #endif
|
||||||
});
|
});
|
||||||
btnsElement[1].addEventListener("click", () => {
|
btnsElement[1].addEventListener("click", () => {
|
||||||
fetchPost("/api/filetree/refreshFiletree", {});
|
fetchPost("/api/filetree/refreshFiletree", {});
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,9 @@ import {addEmoji, filterEmoji, lazyLoadEmoji, unicode2Emoji} from "../../emoji";
|
||||||
import {escapeHtml} from "../../util/escape";
|
import {escapeHtml} from "../../util/escape";
|
||||||
import {blockRender} from "../markdown/blockRender";
|
import {blockRender} from "../markdown/blockRender";
|
||||||
import {uploadFiles} from "../upload";
|
import {uploadFiles} from "../upload";
|
||||||
|
/// #if !MOBILE
|
||||||
import {openFileById} from "../../editor/util";
|
import {openFileById} from "../../editor/util";
|
||||||
import {isMobile} from "../../util/functions";
|
/// #endif
|
||||||
import {openMobileFileById} from "../../mobile/editor";
|
import {openMobileFileById} from "../../mobile/editor";
|
||||||
import {getIconByType} from "../../editor/getIcon";
|
import {getIconByType} from "../../editor/getIcon";
|
||||||
|
|
||||||
|
|
@ -497,15 +498,15 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
||||||
md: ""
|
md: ""
|
||||||
}, () => {
|
}, () => {
|
||||||
insertHTML(genEmptyBlock(false, false, `<span data-type="block-ref" data-id="${newSubDocId}" data-subtype="d">Untitled</span>`), protyle);
|
insertHTML(genEmptyBlock(false, false, `<span data-type="block-ref" data-id="${newSubDocId}" data-subtype="d">Untitled</span>`), protyle);
|
||||||
if (isMobile()) {
|
/// #if MOBILE
|
||||||
openMobileFileById(newSubDocId, true);
|
openMobileFileById(newSubDocId, true);
|
||||||
} else {
|
/// #else
|
||||||
openFileById({
|
openFileById({
|
||||||
id: newSubDocId,
|
id: newSubDocId,
|
||||||
hasContext: true,
|
hasContext: true,
|
||||||
action: [Constants.CB_GET_HL]
|
action: [Constants.CB_GET_HL]
|
||||||
});
|
});
|
||||||
}
|
/// #endif
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
} else if (Constants.INLINE_TYPE.includes(value)) {
|
} else if (Constants.INLINE_TYPE.includes(value)) {
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,14 @@ import {getSearch, isMobile} from "../../util/functions";
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
import {shell} from "electron";
|
import {shell} from "electron";
|
||||||
/// #endif
|
/// #endif
|
||||||
|
/// #if !MOBILE
|
||||||
|
import {openAsset, openBy} from "../../editor/util";
|
||||||
|
/// #endif
|
||||||
import {fetchPost} from "../../util/fetch";
|
import {fetchPost} from "../../util/fetch";
|
||||||
import {processRender} from "../util/processCode";
|
import {processRender} from "../util/processCode";
|
||||||
import {highlightRender} from "../markdown/highlightRender";
|
import {highlightRender} from "../markdown/highlightRender";
|
||||||
import {speechRender} from "../markdown/speechRender";
|
import {speechRender} from "../markdown/speechRender";
|
||||||
import {mediaRender} from "../markdown/mediaRender";
|
import {mediaRender} from "../markdown/mediaRender";
|
||||||
import {openAsset, openBy} from "../../editor/util";
|
|
||||||
|
|
||||||
export class Preview {
|
export class Preview {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
@ -46,6 +48,7 @@ export class Preview {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (isLocalPath(linkAddress)) {
|
if (isLocalPath(linkAddress)) {
|
||||||
|
/// #if !MOBILE
|
||||||
if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname((linkAddress.split("?page")[0])))) {
|
if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname((linkAddress.split("?page")[0])))) {
|
||||||
openAsset(linkAddress.split("?page")[0], parseInt(getSearch("page", linkAddress)));
|
openAsset(linkAddress.split("?page")[0], parseInt(getSearch("page", linkAddress)));
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -53,6 +56,7 @@ export class Preview {
|
||||||
openBy(linkAddress, "folder");
|
openBy(linkAddress, "folder");
|
||||||
/// #endif
|
/// #endif
|
||||||
}
|
}
|
||||||
|
/// #endif
|
||||||
} else {
|
} else {
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
shell.openExternal(linkAddress).catch((e) => {
|
shell.openExternal(linkAddress).catch((e) => {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,9 @@ import {processRender} from "./processCode";
|
||||||
import {highlightRender} from "../markdown/highlightRender";
|
import {highlightRender} from "../markdown/highlightRender";
|
||||||
import {blockRender} from "../markdown/blockRender";
|
import {blockRender} from "../markdown/blockRender";
|
||||||
import {highlightById} from "../../util/highlightById";
|
import {highlightById} from "../../util/highlightById";
|
||||||
|
/// #if !MOBILE
|
||||||
import {pushBack} from "../../util/backForward";
|
import {pushBack} from "../../util/backForward";
|
||||||
|
/// #endif
|
||||||
import {focusBlock} from "./selection";
|
import {focusBlock} from "./selection";
|
||||||
import {hasClosestByAttribute, hasClosestByClassName} from "./hasClosest";
|
import {hasClosestByAttribute, hasClosestByClassName} from "./hasClosest";
|
||||||
import {preventScroll} from "../scroll/preventScroll";
|
import {preventScroll} from "../scroll/preventScroll";
|
||||||
|
|
@ -144,9 +146,11 @@ const setHTML = (options: { content: string, action?: string[] }, protyle: IProt
|
||||||
if (options.action.includes(Constants.CB_GET_HL)) {
|
if (options.action.includes(Constants.CB_GET_HL)) {
|
||||||
preventScroll(protyle); // 搜索页签滚动会导致再次请求
|
preventScroll(protyle); // 搜索页签滚动会导致再次请求
|
||||||
const hlElement = highlightById(protyle, protyle.block.id, true);
|
const hlElement = highlightById(protyle, protyle.block.id, true);
|
||||||
|
/// #if !MOBILE
|
||||||
if (hlElement && !options.action.includes(Constants.CB_GET_UNUNDO)) {
|
if (hlElement && !options.action.includes(Constants.CB_GET_UNUNDO)) {
|
||||||
pushBack(protyle, undefined, hlElement);
|
pushBack(protyle, undefined, hlElement);
|
||||||
}
|
}
|
||||||
|
/// #endif
|
||||||
} else if (options.action.includes(Constants.CB_GET_FOCUS)) {
|
} else if (options.action.includes(Constants.CB_GET_FOCUS)) {
|
||||||
let focusElement: Element;
|
let focusElement: Element;
|
||||||
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${protyle.block.id}"]`)).find((item: HTMLElement) => {
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${protyle.block.id}"]`)).find((item: HTMLElement) => {
|
||||||
|
|
@ -161,9 +165,11 @@ const setHTML = (options: { content: string, action?: string[] }, protyle: IProt
|
||||||
}
|
}
|
||||||
if (focusElement && !protyle.wysiwyg.element.firstElementChild.isSameNode(focusElement)) {
|
if (focusElement && !protyle.wysiwyg.element.firstElementChild.isSameNode(focusElement)) {
|
||||||
focusBlock(focusElement);
|
focusBlock(focusElement);
|
||||||
|
/// #if !MOBILE
|
||||||
if (!options.action.includes(Constants.CB_GET_UNUNDO)) {
|
if (!options.action.includes(Constants.CB_GET_UNUNDO)) {
|
||||||
pushBack(protyle, undefined, focusElement);
|
pushBack(protyle, undefined, focusElement);
|
||||||
}
|
}
|
||||||
|
/// #endif
|
||||||
focusElement.scrollIntoView();
|
focusElement.scrollIntoView();
|
||||||
// 减少抖动 https://ld246.com/article/1654263598088
|
// 减少抖动 https://ld246.com/article/1654263598088
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
@ -171,16 +177,20 @@ const setHTML = (options: { content: string, action?: string[] }, protyle: IProt
|
||||||
}, Constants.TIMEOUT_BLOCKLOAD);
|
}, Constants.TIMEOUT_BLOCKLOAD);
|
||||||
} else {
|
} else {
|
||||||
focusBlock(protyle.wysiwyg.element.firstElementChild);
|
focusBlock(protyle.wysiwyg.element.firstElementChild);
|
||||||
|
/// #if !MOBILE
|
||||||
if (!options.action.includes(Constants.CB_GET_UNUNDO)) {
|
if (!options.action.includes(Constants.CB_GET_UNUNDO)) {
|
||||||
pushBack(protyle, undefined, protyle.wysiwyg.element.firstElementChild);
|
pushBack(protyle, undefined, protyle.wysiwyg.element.firstElementChild);
|
||||||
}
|
}
|
||||||
|
/// #endif
|
||||||
}
|
}
|
||||||
} else if (options.action.includes(Constants.CB_GET_FOCUSFIRST)) {
|
} else if (options.action.includes(Constants.CB_GET_FOCUSFIRST)) {
|
||||||
// settimeout 时间需短一点,否则定位后快速滚动无效
|
// settimeout 时间需短一点,否则定位后快速滚动无效
|
||||||
preventScroll(protyle, 8, 256);
|
preventScroll(protyle, 8, 256);
|
||||||
protyle.contentElement.scrollTop = 8;
|
protyle.contentElement.scrollTop = 8;
|
||||||
focusBlock(protyle.wysiwyg.element.firstElementChild);
|
focusBlock(protyle.wysiwyg.element.firstElementChild);
|
||||||
|
/// #if !MOBILE
|
||||||
pushBack(protyle, undefined, protyle.wysiwyg.element.firstElementChild);
|
pushBack(protyle, undefined, protyle.wysiwyg.element.firstElementChild);
|
||||||
|
/// #endif
|
||||||
}
|
}
|
||||||
if (protyle.disabled) {
|
if (protyle.disabled) {
|
||||||
disabledProtyle(protyle);
|
disabledProtyle(protyle);
|
||||||
|
|
|
||||||
|
|
@ -42,12 +42,12 @@ import {keydown} from "./keydown";
|
||||||
import {openMobileFileById} from "../../mobile/editor";
|
import {openMobileFileById} from "../../mobile/editor";
|
||||||
import {removeBlock} from "./remove";
|
import {removeBlock} from "./remove";
|
||||||
import {highlightRender} from "../markdown/highlightRender";
|
import {highlightRender} from "../markdown/highlightRender";
|
||||||
import {getAllModels} from "../../layout/getAll";
|
|
||||||
import {setPosition} from "../../util/setPosition";
|
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";
|
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
|
import {getAllModels} from "../../layout/getAll";
|
||||||
|
import {pushBack} from "../../util/backForward";
|
||||||
import {openAsset, openBy, openFileById} from "../../editor/util";
|
import {openAsset, openBy, openFileById} from "../../editor/util";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {BlockPanel} from "../../block/Panel";
|
import {BlockPanel} from "../../block/Panel";
|
||||||
|
|
@ -157,6 +157,7 @@ export class WYSIWYG {
|
||||||
}
|
}
|
||||||
nodeElement = tempElement;
|
nodeElement = tempElement;
|
||||||
}
|
}
|
||||||
|
/// #if !MOBILE
|
||||||
if (protyle.model) {
|
if (protyle.model) {
|
||||||
getAllModels().outline.forEach(item => {
|
getAllModels().outline.forEach(item => {
|
||||||
if (item.blockId === protyle.block.rootID) {
|
if (item.blockId === protyle.block.rootID) {
|
||||||
|
|
@ -173,6 +174,7 @@ export class WYSIWYG {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/// #endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private bindEvent(protyle: IProtyle) {
|
private bindEvent(protyle: IProtyle) {
|
||||||
|
|
@ -1381,6 +1383,7 @@ export class WYSIWYG {
|
||||||
}
|
}
|
||||||
/// #endif
|
/// #endif
|
||||||
});
|
});
|
||||||
|
/// #if !MOBILE
|
||||||
if (protyle.model) {
|
if (protyle.model) {
|
||||||
// 打开双链需记录到后退中 https://github.com/siyuan-note/insider/issues/801
|
// 打开双链需记录到后退中 https://github.com/siyuan-note/insider/issues/801
|
||||||
let blockElement: HTMLElement | false;
|
let blockElement: HTMLElement | false;
|
||||||
|
|
@ -1393,6 +1396,7 @@ export class WYSIWYG {
|
||||||
pushBack(protyle, getEditorRange(this.element), blockElement);
|
pushBack(protyle, getEditorRange(this.element), blockElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// #endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1726,7 +1730,9 @@ export class WYSIWYG {
|
||||||
if (!protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select")) {
|
if (!protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select")) {
|
||||||
countSelectWord(newRange);
|
countSelectWord(newRange);
|
||||||
}
|
}
|
||||||
|
/// #if !MOBILE
|
||||||
pushBack(protyle, newRange);
|
pushBack(protyle, newRange);
|
||||||
|
/// #endif
|
||||||
}, isMobile() ? 520 : 0); // Android 双击慢了出不来
|
}, isMobile() ? 520 : 0); // Android 双击慢了出不来
|
||||||
|
|
||||||
protyle.toolbar.isNewEmptyInline = false;
|
protyle.toolbar.isNewEmptyInline = false;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,9 @@ import {lockFile} from "../../dialog/processSystem";
|
||||||
import {setFold} from "../../menus/protyle";
|
import {setFold} from "../../menus/protyle";
|
||||||
import {addLoading} from "../ui/initUI";
|
import {addLoading} from "../ui/initUI";
|
||||||
import {onGet} from "../util/onGet";
|
import {onGet} from "../util/onGet";
|
||||||
|
/// #if !MOBILE
|
||||||
import {getAllModels} from "../../layout/getAll";
|
import {getAllModels} from "../../layout/getAll";
|
||||||
|
/// #endif
|
||||||
import {removeFoldHeading} from "../util/heading";
|
import {removeFoldHeading} from "../util/heading";
|
||||||
import {genEmptyElement, genSBElement} from "../../block/util";
|
import {genEmptyElement, genSBElement} from "../../block/util";
|
||||||
import {hideElements} from "../ui/hideElements";
|
import {hideElements} from "../ui/hideElements";
|
||||||
|
|
@ -311,6 +313,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
|
||||||
endOffset: range.endOffset,
|
endOffset: range.endOffset,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
/// #if !MOBILE
|
||||||
if (!updateElement) {
|
if (!updateElement) {
|
||||||
// 打开两个相同的文档 A、A1,从 A 拖拽块 B 到 A1,在后续 ws 处理中,无法获取到拖拽出去的 B
|
// 打开两个相同的文档 A、A1,从 A 拖拽块 B 到 A1,在后续 ws 处理中,无法获取到拖拽出去的 B
|
||||||
getAllModels().editor.forEach(editor => {
|
getAllModels().editor.forEach(editor => {
|
||||||
|
|
@ -320,6 +323,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/// #endif
|
||||||
if (operation.previousID) {
|
if (operation.previousID) {
|
||||||
let beforeElement: Element;
|
let beforeElement: Element;
|
||||||
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.previousID}"]`)).find(item => {
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.previousID}"]`)).find(item => {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import {hideMessage, showMessage} from "../dialog/message";
|
import {hideMessage, showMessage} from "../dialog/message";
|
||||||
|
/// #if !MOBILE
|
||||||
import {exportLayout} from "../layout/util";
|
import {exportLayout} from "../layout/util";
|
||||||
import {isMobile} from "./functions";
|
/// #endif
|
||||||
|
|
||||||
export const processMessage = (response: IWebSocketData) => {
|
export const processMessage = (response: IWebSocketData) => {
|
||||||
if ("msg" === response.cmd) {
|
if ("msg" === response.cmd) {
|
||||||
|
|
@ -19,11 +20,11 @@ export const processMessage = (response: IWebSocketData) => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ("reloadui" === response.cmd) {
|
if ("reloadui" === response.cmd) {
|
||||||
if (isMobile()) {
|
/// #if MOBILE
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
} else {
|
/// #else
|
||||||
exportLayout(true);
|
exportLayout(true);
|
||||||
}
|
/// #endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue