mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-06 16:58:49 +01:00
This commit is contained in:
parent
a00af1bd6c
commit
ed3f2af467
16 changed files with 63 additions and 50 deletions
|
|
@ -430,9 +430,9 @@ export const updateFileTreeEmoji = (unicode: string, id: string, icon = "iconFil
|
|||
|
||||
const updateFileEmoji = (unicode: string, id: string) => {
|
||||
/// #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, window.siyuan.mobileEditor.protyle.block.rootID);
|
||||
if (window.siyuan.mobile.editor.protyle.block.rootID === id) {
|
||||
window.siyuan.mobile.editor.protyle.background.ial.icon = unicode;
|
||||
window.siyuan.mobile.editor.protyle.background.render(window.siyuan.mobile.editor.protyle.background.ial, window.siyuan.mobile.editor.protyle.block.rootID);
|
||||
}
|
||||
/// #else
|
||||
getAllModels().editor.find(item => {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ import {Constants} from "../constants";
|
|||
import {newFile} from "../util/newFile";
|
||||
import {hasClosestByTag} from "../protyle/util/hasClosest";
|
||||
import {deleteFiles} from "../editor/deleteFile";
|
||||
import {getDockByType} from "../layout/util";
|
||||
import {Files} from "../layout/dock/Files";
|
||||
|
||||
const initMultiMenu = (selectItemElements: NodeListOf<Element>) => {
|
||||
const fileItemElement = Array.from(selectItemElements).find(item => {
|
||||
|
|
@ -172,7 +174,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
|
|||
window.siyuan.menus.menu.remove();
|
||||
const fileElement = hasClosestByTag(liElement, "DIV");
|
||||
if (!fileElement) {
|
||||
return window.siyuan.menus.menu;
|
||||
return window.siyuan.menus.menu;
|
||||
}
|
||||
if (!liElement.classList.contains("b3-list-item--focus")) {
|
||||
fileElement.querySelectorAll(".b3-list-item--focus").forEach(item => {
|
||||
|
|
@ -385,7 +387,14 @@ const genImportMenu = (notebookId: string, pathString: string) => {
|
|||
formData.append("file", event.target.files[0]);
|
||||
formData.append("notebook", notebookId);
|
||||
formData.append("toPath", pathString);
|
||||
fetchPost("/api/import/importSY", formData);
|
||||
fetchPost("/api/import/importSY", formData, () => {
|
||||
/// #if MOBILE
|
||||
window.siyuan.mobile.files.selectItem(notebookId, pathString);
|
||||
/// #else
|
||||
(getDockByType("file").data["file"] as Files).selectItem(notebookId, pathString)
|
||||
/// #endif
|
||||
window.siyuan.menus.menu.remove();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -456,7 +456,7 @@ export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushB
|
|||
return;
|
||||
}
|
||||
}
|
||||
if (window.siyuan.mobileEditor) {
|
||||
if (window.siyuan.mobile.editor) {
|
||||
window.siyuan.storage[Constants.LOCAL_DOCINFO] = {
|
||||
id,
|
||||
action: id === protyle.block.rootID ? [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT] : [Constants.CB_GET_ALL]
|
||||
|
|
|
|||
|
|
@ -17,13 +17,13 @@ import {setStorageVal} from "../protyle/util/compatibility";
|
|||
export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) => {
|
||||
window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id, action};
|
||||
setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
|
||||
if (window.siyuan.mobileEditor) {
|
||||
hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle);
|
||||
if (window.siyuan.mobileEditor.protyle.contentElement.classList.contains("fn__none")) {
|
||||
setEditMode(window.siyuan.mobileEditor.protyle, "wysiwyg");
|
||||
if (window.siyuan.mobile.editor) {
|
||||
hideElements(["toolbar", "hint", "util"], window.siyuan.mobile.editor.protyle);
|
||||
if (window.siyuan.mobile.editor.protyle.contentElement.classList.contains("fn__none")) {
|
||||
setEditMode(window.siyuan.mobile.editor.protyle, "wysiwyg");
|
||||
}
|
||||
let blockElement;
|
||||
Array.from(window.siyuan.mobileEditor.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${id}"]`)).find((item: HTMLElement) => {
|
||||
Array.from(window.siyuan.mobile.editor.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${id}"]`)).find((item: HTMLElement) => {
|
||||
if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) {
|
||||
blockElement = item;
|
||||
return true;
|
||||
|
|
@ -32,7 +32,7 @@ export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) =
|
|||
if (blockElement) {
|
||||
pushBack();
|
||||
focusBlock(blockElement);
|
||||
scrollCenter(window.siyuan.mobileEditor.protyle, blockElement, true);
|
||||
scrollCenter(window.siyuan.mobile.editor.protyle, blockElement, true);
|
||||
closePanel();
|
||||
return;
|
||||
}
|
||||
|
|
@ -44,20 +44,20 @@ export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) =
|
|||
lockFile(data.data);
|
||||
return;
|
||||
}
|
||||
if (window.siyuan.mobileEditor) {
|
||||
if (window.siyuan.mobile.editor) {
|
||||
pushBack();
|
||||
addLoading(window.siyuan.mobileEditor.protyle);
|
||||
addLoading(window.siyuan.mobile.editor.protyle);
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id,
|
||||
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.mobileEditor.protyle, action);
|
||||
window.siyuan.mobileEditor.protyle.breadcrumb?.render(window.siyuan.mobileEditor.protyle);
|
||||
onGet(getResponse, window.siyuan.mobile.editor.protyle, action);
|
||||
window.siyuan.mobile.editor.protyle.breadcrumb?.render(window.siyuan.mobile.editor.protyle);
|
||||
});
|
||||
window.siyuan.mobileEditor.protyle.undo.clear();
|
||||
window.siyuan.mobile.editor.protyle.undo.clear();
|
||||
} else {
|
||||
window.siyuan.mobileEditor = new Protyle(document.getElementById("editor"), {
|
||||
window.siyuan.mobile.editor = new Protyle(document.getElementById("editor"), {
|
||||
blockId: id,
|
||||
action,
|
||||
render: {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ class App {
|
|||
backStack: [],
|
||||
dialogs: [],
|
||||
blockPanels: [],
|
||||
mobile: {},
|
||||
menus: new Menus(),
|
||||
ws: new Model({
|
||||
id: genUUID(),
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ export const initAppearance = (modelElement: HTMLElement, modelMainElement: HTML
|
|||
window.siyuan.config.editor.fontSize = parseInt(event.target.value);
|
||||
fetchPost("/api/setting/setEditor", window.siyuan.config.editor, (response) => {
|
||||
window.siyuan.config.editor = response.data;
|
||||
reloadProtyle(window.siyuan.mobileEditor.protyle);
|
||||
reloadProtyle(window.siyuan.mobile.editor.protyle);
|
||||
setInlineStyle();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@ import {setStorageVal} from "../../protyle/util/compatibility";
|
|||
const forwardStack: IBackStack[] = [];
|
||||
|
||||
const focusStack = (backStack: IBackStack) => {
|
||||
const protyle = window.siyuan.mobileEditor.protyle;
|
||||
const protyle = window.siyuan.mobile.editor.protyle;
|
||||
window.siyuan.storage[Constants.LOCAL_DOCINFO] = {
|
||||
id: backStack.id,
|
||||
action: backStack.callback,
|
||||
};
|
||||
setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
|
||||
hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle);
|
||||
hideElements(["toolbar", "hint", "util"], window.siyuan.mobile.editor.protyle);
|
||||
if (protyle.contentElement.classList.contains("fn__none")) {
|
||||
setEditMode(protyle, "wysiwyg");
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ const focusStack = (backStack: IBackStack) => {
|
|||
const startEndId = backStack.endId.split(Constants.ZWSP);
|
||||
if (startEndId[0] === protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id") &&
|
||||
startEndId[1] === protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id")) {
|
||||
window.siyuan.mobileEditor.protyle.contentElement.scrollTo({
|
||||
window.siyuan.mobile.editor.protyle.contentElement.scrollTo({
|
||||
top: backStack.scrollTop,
|
||||
behavior: "smooth"
|
||||
});
|
||||
|
|
@ -81,12 +81,12 @@ const focusStack = (backStack: IBackStack) => {
|
|||
}
|
||||
}
|
||||
protyle.contentElement.scrollTop = backStack.scrollTop;
|
||||
window.siyuan.mobileEditor.protyle.breadcrumb?.render(protyle);
|
||||
window.siyuan.mobile.editor.protyle.breadcrumb?.render(protyle);
|
||||
});
|
||||
};
|
||||
|
||||
export const pushBack = () => {
|
||||
const protyle = window.siyuan.mobileEditor.protyle;
|
||||
const protyle = window.siyuan.mobile.editor.protyle;
|
||||
window.siyuan.backStack.push({
|
||||
id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,
|
||||
endId: protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id") + Constants.ZWSP + protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),
|
||||
|
|
@ -116,7 +116,7 @@ export const goBack = () => {
|
|||
if (window.siyuan.backStack.length < 1) {
|
||||
return;
|
||||
}
|
||||
const protyle = window.siyuan.mobileEditor.protyle;
|
||||
const protyle = window.siyuan.mobile.editor.protyle;
|
||||
if (forwardStack.length === 0) {
|
||||
forwardStack.push({
|
||||
id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ export class MobileBacklinks {
|
|||
|
||||
public update() {
|
||||
fetchPost("/api/ref/getBacklink", {
|
||||
id: window.siyuan.mobileEditor.protyle.block.id,
|
||||
id: window.siyuan.mobile.editor.protyle.block.id,
|
||||
beforeLen: this.beforeLen,
|
||||
k: "",
|
||||
mk: "",
|
||||
|
|
|
|||
|
|
@ -99,8 +99,8 @@ export class MobileFiles extends Model {
|
|||
event.preventDefault();
|
||||
break;
|
||||
} else if (type === "focus") {
|
||||
if (window.siyuan.mobileEditor) {
|
||||
this.selectItem(window.siyuan.mobileEditor.protyle.notebookId, window.siyuan.mobileEditor.protyle.path);
|
||||
if (window.siyuan.mobile.editor) {
|
||||
this.selectItem(window.siyuan.mobile.editor.protyle.notebookId, window.siyuan.mobile.editor.protyle.path);
|
||||
}
|
||||
event.preventDefault();
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ export class MobileOutline {
|
|||
|
||||
public update() {
|
||||
fetchPost("/api/outline/getDocOutline", {
|
||||
id: window.siyuan.mobileEditor.protyle.block.rootID,
|
||||
id: window.siyuan.mobile.editor.protyle.block.rootID,
|
||||
}, response => {
|
||||
let currentId;
|
||||
let currentElement = this.element.querySelector(".b3-list-item--focus");
|
||||
|
|
@ -57,7 +57,7 @@ export class MobileOutline {
|
|||
currentId = currentElement.getAttribute("data-node-id");
|
||||
}
|
||||
|
||||
const blockId = window.siyuan.mobileEditor.protyle.block.rootID;
|
||||
const blockId = window.siyuan.mobile.editor.protyle.block.rootID;
|
||||
if (this.openNodes[blockId]) {
|
||||
this.openNodes[blockId] = this.tree.getExpandIds();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ export const initFramework = () => {
|
|||
}
|
||||
});
|
||||
});
|
||||
new MobileFiles();
|
||||
window.siyuan.mobile.files = new MobileFiles();
|
||||
document.getElementById("toolbarFile").addEventListener("click", () => {
|
||||
sidebarElement.style.left = "0";
|
||||
document.querySelector(".scrim").classList.remove("fn__none");
|
||||
|
|
@ -110,11 +110,11 @@ export const initFramework = () => {
|
|||
window.siyuan.config.editor.readOnly = isReadonly;
|
||||
fetchPost("/api/setting/setEditor", window.siyuan.config.editor, () => {
|
||||
if (!isReadonly) {
|
||||
enableProtyle(window.siyuan.mobileEditor.protyle);
|
||||
enableProtyle(window.siyuan.mobile.editor.protyle);
|
||||
inputElement.readOnly = false;
|
||||
editIconElement.setAttribute("xlink:href", "#iconEdit");
|
||||
} else {
|
||||
disabledProtyle(window.siyuan.mobileEditor.protyle);
|
||||
disabledProtyle(window.siyuan.mobile.editor.protyle);
|
||||
inputElement.readOnly = true;
|
||||
editIconElement.setAttribute("xlink:href", "#iconPreview");
|
||||
}
|
||||
|
|
@ -169,7 +169,7 @@ const initEditorName = () => {
|
|||
hideKeyboardToolbar();
|
||||
});
|
||||
inputElement.addEventListener("blur", () => {
|
||||
if (window.siyuan.config.readonly || window.siyuan.config.editor.readOnly || window.siyuan.mobileEditor.protyle.disabled) {
|
||||
if (window.siyuan.config.readonly || window.siyuan.config.editor.readOnly || window.siyuan.mobile.editor.protyle.disabled) {
|
||||
return;
|
||||
}
|
||||
if (!validateName(inputElement.value)) {
|
||||
|
|
@ -178,8 +178,8 @@ const initEditorName = () => {
|
|||
}
|
||||
|
||||
fetchPost("/api/filetree/renameDoc", {
|
||||
notebook: window.siyuan.mobileEditor.protyle.notebookId,
|
||||
path: window.siyuan.mobileEditor.protyle.path,
|
||||
notebook: window.siyuan.mobile.editor.protyle.notebookId,
|
||||
path: window.siyuan.mobile.editor.protyle.path,
|
||||
title: inputElement.value,
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -75,8 +75,8 @@ export const popSearch = (modelElement: HTMLElement, modelMainElement: HTMLEleme
|
|||
while (target && !target.isEqualNode(searchElement)) {
|
||||
if (target.classList.contains("b3-list-item")) {
|
||||
const id = target.getAttribute("data-id");
|
||||
if (window.siyuan.mobileEditor.protyle) {
|
||||
preventScroll(window.siyuan.mobileEditor.protyle);
|
||||
if (window.siyuan.mobile.editor.protyle) {
|
||||
preventScroll(window.siyuan.mobile.editor.protyle);
|
||||
}
|
||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||
openMobileFileById(id,foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ export const setEmpty = () => {
|
|||
<svg class="b3-list-item__graphic"><use xlink:href="#iconHelp"></use></svg><span class="b3-list-item__text">${window.siyuan.languages.help}</span>
|
||||
</div>`;
|
||||
document.getElementById("emptyNewFile").addEventListener(getEventName(), () => {
|
||||
if (window.siyuan.mobileEditor) {
|
||||
newFile(window.siyuan.mobileEditor.protyle.notebookId, window.siyuan.mobileEditor.protyle.path, true);
|
||||
if (window.siyuan.mobile.editor) {
|
||||
newFile(window.siyuan.mobile.editor.protyle.notebookId, window.siyuan.mobile.editor.protyle.path, true);
|
||||
} else {
|
||||
window.siyuan.notebooks.find(item => {
|
||||
if (item.closed) {
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import {focusByRange, getSelectionPosition} from "../../protyle/util/selection";
|
|||
export const showKeyboardToolbar = (bottom = 0) => {
|
||||
if (getSelection().rangeCount > 0) {
|
||||
const range = getSelection().getRangeAt(0);
|
||||
if (!window.siyuan.mobileEditor ||
|
||||
!window.siyuan.mobileEditor.protyle.wysiwyg.element.contains(range.startContainer)) {
|
||||
if (!window.siyuan.mobile.editor ||
|
||||
!window.siyuan.mobile.editor.protyle.wysiwyg.element.contains(range.startContainer)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -23,7 +23,7 @@ export const showKeyboardToolbar = (bottom = 0) => {
|
|||
toolbarElement.style.bottom = bottom + "px";
|
||||
|
||||
setTimeout(() => {
|
||||
const contentElement = window.siyuan.mobileEditor.protyle.contentElement;
|
||||
const contentElement = window.siyuan.mobile.editor.protyle.contentElement;
|
||||
const cursorTop = getSelectionPosition(contentElement).top - contentElement.getBoundingClientRect().top;
|
||||
if (cursorTop < window.innerHeight - 96) {
|
||||
return;
|
||||
|
|
@ -46,16 +46,16 @@ export const initKeyboardToolbar = () => {
|
|||
toolbarElement.addEventListener("click", (event) => {
|
||||
const target = event.target as HTMLElement;
|
||||
const buttonElement = hasClosestByMatchTag(target, "BUTTON");
|
||||
if (!buttonElement || !window.siyuan.mobileEditor) {
|
||||
if (!buttonElement || !window.siyuan.mobile.editor) {
|
||||
return;
|
||||
}
|
||||
if (window.siyuan.mobileEditor.protyle.disabled) {
|
||||
if (window.siyuan.mobile.editor.protyle.disabled) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const type = buttonElement.getAttribute("data-type");
|
||||
const protyle = window.siyuan.mobileEditor.protyle;
|
||||
const protyle = window.siyuan.mobile.editor.protyle;
|
||||
if (type === "undo") {
|
||||
protyle.undo.undo(protyle);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ let xDiff: number;
|
|||
let yDiff: number;
|
||||
|
||||
export const handleTouchEnd = () => {
|
||||
if (window.siyuan.mobileEditor) {
|
||||
if (window.siyuan.mobile.editor) {
|
||||
document.querySelectorAll(".protyle-breadcrumb__bar--hide").forEach(item => {
|
||||
item.classList.remove("protyle-breadcrumb__bar--hide");
|
||||
});
|
||||
|
|
|
|||
9
app/src/types/index.d.ts
vendored
9
app/src/types/index.d.ts
vendored
|
|
@ -52,8 +52,8 @@ interface Window {
|
|||
}
|
||||
|
||||
interface IWorkspace {
|
||||
path:string
|
||||
closed:boolean
|
||||
path: string
|
||||
closed: boolean
|
||||
}
|
||||
|
||||
interface ICard {
|
||||
|
|
@ -171,7 +171,10 @@ interface ISiyuan {
|
|||
notebooks?: INotebook[],
|
||||
emojis?: IEmoji[],
|
||||
backStack?: IBackStack[],
|
||||
mobileEditor?: import("../protyle").Protyle, // mobile
|
||||
mobile?: {
|
||||
editor?: import("../protyle").Protyle
|
||||
files?: import("../mobile/util/MobileFiles").MobileFiles
|
||||
},
|
||||
user?: {
|
||||
userId: string
|
||||
userName: string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue