Vanessa 2023-06-01 14:56:21 +08:00
parent 8c35440a77
commit 74b4a00a2f
42 changed files with 426 additions and 270 deletions

View file

@ -58,7 +58,7 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_
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.mobile.editor.protyle, action);
onGet({data: getResponse, protyle: window.siyuan.mobile.editor.protyle, action, app});
window.siyuan.mobile.editor.protyle.breadcrumb?.render(window.siyuan.mobile.editor.protyle);
});
window.siyuan.mobile.editor.protyle.undo.clear();

View file

@ -96,13 +96,13 @@ class App {
handleTouchEnd(this, event);
}, false);
});
promiseTransactions();
promiseTransactions(this);
}
}
const siyuanApp = new App();
window.goBack = goBack;
window.goBack = goBack.apply(siyuanApp);
window.showKeyboardToolbar = (height) => {
document.getElementById("keyboardToolbar").setAttribute("data-keyboardheight", (height ? height : window.innerHeight / 2 - 42).toString());
showKeyboardToolbar();

View file

@ -144,7 +144,7 @@ export const initRightMenu = (app: App) => {
event.stopPropagation();
break;
} else if (target.id === "menuEditor") {
initEditor();
initEditor(app);
event.preventDefault();
event.stopPropagation();
break;

View file

@ -16,7 +16,7 @@ import {reloadProtyle} from "../../protyle/util/reload";
import {activeBlur, hideKeyboardToolbar} from "../util/keyboardToolbar";
import {App} from "../../index";
const replace = (element: Element, config: ISearchOption, isAll: boolean) => {
const replace = (app: App,element: Element, config: ISearchOption, isAll: boolean) => {
if (config.method === 1 || config.method === 2) {
showMessage(window.siyuan.languages._kernel[132]);
return;
@ -60,7 +60,7 @@ const replace = (element: Element, config: ISearchOption, isAll: boolean) => {
if (ids.length > 1) {
return;
}
reloadProtyle(window.siyuan.mobile.editor.protyle, false);
reloadProtyle(window.siyuan.mobile.editor.protyle, app, false);
if (currentLiElement.nextElementSibling) {
currentLiElement.nextElementSibling.classList.add("b3-list-item--focus");
@ -478,12 +478,12 @@ const initSearchEvent = (app: App, element: Element, config: ISearchOption) => {
event.preventDefault();
break;
} else if (type === "replace-all") {
replace(element, config, true);
replace(app, element, config, true);
event.stopPropagation();
event.preventDefault();
break;
} else if (type === "replace") {
replace(element, config, false);
replace(app, element, config, false);
event.stopPropagation();
event.preventDefault();
break;

View file

@ -3,8 +3,9 @@ import {fetchPost} from "../../util/fetch";
import {reloadProtyle} from "../../protyle/util/reload";
import {setInlineStyle} from "../../util/assets";
import {confirmDialog} from "../../dialog/confirmDialog";
import {App} from "../../index";
const setEditor = (modelMainElement: Element) => {
const setEditor = (app: App, modelMainElement: Element) => {
let dynamicLoadBlocks = parseInt((modelMainElement.querySelector("#dynamicLoadBlocks") as HTMLInputElement).value);
if (48 > dynamicLoadBlocks) {
dynamicLoadBlocks = 48;
@ -40,12 +41,12 @@ const setEditor = (modelMainElement: Element) => {
window.siyuan.config.editor.historyRetentionDays = parseInt((modelMainElement.querySelector("#historyRetentionDays") as HTMLInputElement).value);
fetchPost("/api/setting/setEditor", window.siyuan.config.editor, response => {
window.siyuan.config.editor = response.data;
reloadProtyle(window.siyuan.mobile.editor.protyle, false);
reloadProtyle(window.siyuan.mobile.editor.protyle, app, false);
setInlineStyle();
});
};
export const initEditor = () => {
export const initEditor = (app: App) => {
openModel({
title: window.siyuan.languages.editor,
icon: "iconEdit",
@ -230,12 +231,12 @@ export const initEditor = () => {
modelMainElement.querySelectorAll("input.b3-switch, select.b3-select, input.b3-slider").forEach((item) => {
item.addEventListener("change", () => {
setEditor(modelMainElement);
setEditor(app, modelMainElement);
});
});
modelMainElement.querySelectorAll("textarea.b3-text-field, input.b3-text-field, input.b3-slider").forEach((item) => {
item.addEventListener("blur", () => {
setEditor(modelMainElement);
setEditor(app, modelMainElement);
});
});
modelMainElement.querySelectorAll("input.b3-slider").forEach((item) => {

View file

@ -11,10 +11,11 @@ import {setStorageVal} from "../../protyle/util/compatibility";
import {closePanel} from "./closePanel";
import {showMessage} from "../../dialog/message";
import {getCurrentEditor} from "../editor";
import {App} from "../../index";
const forwardStack: IBackStack[] = [];
const focusStack = (backStack: IBackStack) => {
const focusStack = (backStack: IBackStack, app: App) => {
const protyle = getCurrentEditor().protyle;
window.siyuan.storage[Constants.LOCAL_DOCINFO] = {
id: backStack.id,
@ -50,8 +51,14 @@ const focusStack = (backStack: IBackStack) => {
if (backStack.zoomId !== protyle.block.id) {
fetchPost("/api/block/checkBlockExist", {id: backStack.id}, existResponse => {
if (existResponse.data) {
zoomOut(protyle, backStack.id, undefined, false, () => {
protyle.contentElement.scrollTop = backStack.scrollTop;
zoomOut({
app,
protyle,
id: backStack.id,
isPushBack: false,
callback: () => {
protyle.contentElement.scrollTop = backStack.scrollTop;
}
});
}
});
@ -104,7 +111,7 @@ export const pushBack = () => {
});
};
export const goForward = () => {
export const goForward = (app: App) => {
if (window.siyuan.menus.menu.element.classList.contains("b3-menu--fullscreen") &&
!window.siyuan.menus.menu.element.classList.contains("fn__none")) {
window.siyuan.menus.menu.element.dispatchEvent(new CustomEvent("click", {detail: "back"}));
@ -123,10 +130,10 @@ export const goForward = () => {
return;
}
window.siyuan.backStack.push(forwardStack.pop());
focusStack(forwardStack[forwardStack.length - 1]);
focusStack(forwardStack[forwardStack.length - 1], app);
};
export const goBack = () => {
export const goBack = (app: App) => {
const editor = getCurrentEditor();
if (window.siyuan.menus.menu.element.classList.contains("b3-menu--fullscreen") &&
!window.siyuan.menus.menu.element.classList.contains("fn__none")) {
@ -174,5 +181,5 @@ export const goBack = () => {
}
const item = window.siyuan.backStack.pop();
forwardStack.push(item);
focusStack(item);
focusStack(item, app);
};

View file

@ -23,7 +23,7 @@ import {App} from "../../index";
export const initFramework = (app: App) => {
setInlineStyle();
renderSnippet();
initKeyboardToolbar();
initKeyboardToolbar(app);
const sidebarElement = document.getElementById("sidebar");
let outline: MobileOutline;
let backlink: MobileBacklinks;

View file

@ -4,6 +4,7 @@ import {moveToDown, moveToUp} from "../../protyle/wysiwyg/move";
import {Constants} from "../../constants";
import {focusByRange, getSelectionPosition} from "../../protyle/util/selection";
import {getCurrentEditor} from "../editor";
import {App} from "../../index";
let renderKeyboardToolbarTimeout: number;
let showUtil = false;
@ -327,7 +328,7 @@ export const activeBlur = () => {
(document.activeElement as HTMLElement).blur();
};
export const initKeyboardToolbar = () => {
export const initKeyboardToolbar = (app: App) => {
let preventRender = false;
document.addEventListener("selectionchange", () => {
if (!preventRender) {
@ -416,10 +417,10 @@ export const initKeyboardToolbar = () => {
return;
}
if (type === "undo") {
protyle.undo.undo(protyle);
protyle.undo.undo(app, protyle);
return;
} else if (type === "redo") {
protyle.undo.redo(protyle);
protyle.undo.redo(app, protyle);
return;
}
if (getSelection().rangeCount === 0) {
@ -475,7 +476,7 @@ export const initKeyboardToolbar = () => {
}
return;
} else if (type === "more") {
protyle.breadcrumb.showMenu(protyle, {
protyle.breadcrumb.showMenu(app, protyle, {
x: 0,
y: 0
});