mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
♻️ https://github.com/siyuan-note/siyuan/issues/5066 click block menu
This commit is contained in:
parent
61ab0ffd68
commit
54022ed92a
70 changed files with 604 additions and 350 deletions
|
|
@ -13,6 +13,7 @@ import {webViewerPageNumberChanged} from "./pdf/app";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {fetchPost} from "../util/fetch";
|
import {fetchPost} from "../util/fetch";
|
||||||
import {setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
|
import {setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
export class Asset extends Model {
|
export class Asset extends Model {
|
||||||
public path: string;
|
public path: string;
|
||||||
|
|
@ -21,8 +22,8 @@ export class Asset extends Model {
|
||||||
private pdfPage: number;
|
private pdfPage: number;
|
||||||
public pdfObject: any;
|
public pdfObject: any;
|
||||||
|
|
||||||
constructor(options: { tab: Tab, path: string, page?: number | string }) {
|
constructor(options: { app: App, tab: Tab, path: string, page?: number | string }) {
|
||||||
super({id: options.tab.id});
|
super({app: options.app, id: options.tab.id});
|
||||||
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
|
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
|
||||||
options.tab.headElement.classList.add("item--unupdate");
|
options.tab.headElement.classList.add("item--unupdate");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import {openNewWindowById} from "../window/openNewWindow";
|
||||||
import {disabledProtyle} from "../protyle/util/onGet";
|
import {disabledProtyle} from "../protyle/util/onGet";
|
||||||
import {fetchPost} from "../util/fetch";
|
import {fetchPost} from "../util/fetch";
|
||||||
import {showMessage} from "../dialog/message";
|
import {showMessage} from "../dialog/message";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
export class BlockPanel {
|
export class BlockPanel {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
@ -19,11 +20,13 @@ export class BlockPanel {
|
||||||
public defIds: string[] = [];
|
public defIds: string[] = [];
|
||||||
public id: string;
|
public id: string;
|
||||||
private stmt: string;
|
private stmt: string;
|
||||||
|
private app: App;
|
||||||
public editors: Protyle[] = [];
|
public editors: Protyle[] = [];
|
||||||
public esc: () => void;
|
public esc: () => void;
|
||||||
|
|
||||||
// stmt 非空且 id 为空为查询嵌入
|
// stmt 非空且 id 为空为查询嵌入
|
||||||
constructor(options: {
|
constructor(options: {
|
||||||
|
app: App,
|
||||||
targetElement: HTMLElement,
|
targetElement: HTMLElement,
|
||||||
nodeIds?: string[],
|
nodeIds?: string[],
|
||||||
defIds?: string[],
|
defIds?: string[],
|
||||||
|
|
@ -36,6 +39,7 @@ export class BlockPanel {
|
||||||
this.nodeIds = options.nodeIds;
|
this.nodeIds = options.nodeIds;
|
||||||
this.defIds = options.defIds || [];
|
this.defIds = options.defIds || [];
|
||||||
this.esc = options.esc;
|
this.esc = options.esc;
|
||||||
|
this.app = options.app;
|
||||||
|
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.classList.add("block__popover", "block__popover--move", "block__popover--top");
|
this.element.classList.add("block__popover", "block__popover--move", "block__popover--top");
|
||||||
|
|
@ -259,7 +263,7 @@ export class BlockPanel {
|
||||||
this.targetElement.classList.contains("counter")) {
|
this.targetElement.classList.contains("counter")) {
|
||||||
action.push(Constants.CB_GET_BACKLINK);
|
action.push(Constants.CB_GET_BACKLINK);
|
||||||
}
|
}
|
||||||
const editor = new Protyle(editorElement, {
|
const editor = new Protyle(this.app, editorElement, {
|
||||||
blockId: this.nodeIds[index],
|
blockId: this.nodeIds[index],
|
||||||
defId: this.defIds[index] || this.defIds[0] || "",
|
defId: this.defIds[index] || this.defIds[0] || "",
|
||||||
action,
|
action,
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../
|
||||||
import {fetchSyncPost} from "../util/fetch";
|
import {fetchSyncPost} from "../util/fetch";
|
||||||
import {hideTooltip, showTooltip} from "../dialog/tooltip";
|
import {hideTooltip, showTooltip} from "../dialog/tooltip";
|
||||||
import {getIdFromSYProtocol} from "../util/pathName";
|
import {getIdFromSYProtocol} from "../util/pathName";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
let popoverTargetElement: HTMLElement;
|
let popoverTargetElement: HTMLElement;
|
||||||
export const initBlockPopover = () => {
|
export const initBlockPopover = (app: App) => {
|
||||||
let timeout: number;
|
let timeout: number;
|
||||||
let timeoutHide: number;
|
let timeoutHide: number;
|
||||||
// 编辑器内容块引用/backlinks/tag/bookmark/套娃中使用
|
// 编辑器内容块引用/backlinks/tag/bookmark/套娃中使用
|
||||||
|
|
@ -50,10 +51,10 @@ export const initBlockPopover = () => {
|
||||||
}
|
}
|
||||||
if (window.siyuan.ctrlIsPressed) {
|
if (window.siyuan.ctrlIsPressed) {
|
||||||
clearTimeout(timeoutHide);
|
clearTimeout(timeoutHide);
|
||||||
showPopover();
|
showPopover(app);
|
||||||
} else if (window.siyuan.shiftIsPressed) {
|
} else if (window.siyuan.shiftIsPressed) {
|
||||||
clearTimeout(timeoutHide);
|
clearTimeout(timeoutHide);
|
||||||
showPopover(true);
|
showPopover(app, true);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -73,7 +74,7 @@ export const initBlockPopover = () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
clearTimeout(timeoutHide);
|
clearTimeout(timeoutHide);
|
||||||
showPopover();
|
showPopover(app);
|
||||||
}, 620);
|
}, 620);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -177,7 +178,7 @@ const getTarget = (event: MouseEvent & { target: HTMLElement }, aElement: false
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const showPopover = async (showRef = false) => {
|
export const showPopover = async (app: App, showRef = false) => {
|
||||||
if (!popoverTargetElement) {
|
if (!popoverTargetElement) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -241,6 +242,7 @@ export const showPopover = async (showRef = false) => {
|
||||||
popoverTargetElement.parentElement.style.opacity !== "0.1" // 反向面板图标拖拽时不应该弹层
|
popoverTargetElement.parentElement.style.opacity !== "0.1" // 反向面板图标拖拽时不应该弹层
|
||||||
) {
|
) {
|
||||||
window.siyuan.blockPanels.push(new BlockPanel({
|
window.siyuan.blockPanels.push(new BlockPanel({
|
||||||
|
app,
|
||||||
targetElement: popoverTargetElement,
|
targetElement: popoverTargetElement,
|
||||||
nodeIds: ids,
|
nodeIds: ids,
|
||||||
defIds,
|
defIds,
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ const getRightBlock = (element: HTMLElement, x: number, y: number) => {
|
||||||
return nodeElement;
|
return nodeElement;
|
||||||
};
|
};
|
||||||
|
|
||||||
const switchDialogEvent = (event: MouseEvent, switchDialog: Dialog) => {
|
const switchDialogEvent = (app: App, event: MouseEvent, switchDialog: Dialog) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
let target = event.target as HTMLElement;
|
let target = event.target as HTMLElement;
|
||||||
while (!target.isSameNode(switchDialog.element)) {
|
while (!target.isSameNode(switchDialog.element)) {
|
||||||
|
|
@ -74,7 +74,7 @@ const switchDialogEvent = (event: MouseEvent, switchDialog: Dialog) => {
|
||||||
const currentType = target.getAttribute("data-type");
|
const currentType = target.getAttribute("data-type");
|
||||||
if (currentType) {
|
if (currentType) {
|
||||||
if (currentType === "riffCard") {
|
if (currentType === "riffCard") {
|
||||||
openCard();
|
openCard(app);
|
||||||
} else {
|
} else {
|
||||||
getDockByType(currentType).toggleModel(currentType, true);
|
getDockByType(currentType).toggleModel(currentType, true);
|
||||||
}
|
}
|
||||||
|
|
@ -270,10 +270,10 @@ export const globalShortcut = (app: App) => {
|
||||||
window.addEventListener("mouseup", (event) => {
|
window.addEventListener("mouseup", (event) => {
|
||||||
if (event.button === 3) {
|
if (event.button === 3) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
goBack();
|
goBack(app);
|
||||||
} else if (event.button === 4) {
|
} else if (event.button === 4) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
goForward();
|
goForward(app);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -367,7 +367,7 @@ export const globalShortcut = (app: App) => {
|
||||||
const currentType = currentLiElement.getAttribute("data-type");
|
const currentType = currentLiElement.getAttribute("data-type");
|
||||||
if (currentType) {
|
if (currentType) {
|
||||||
if (currentType === "riffCard") {
|
if (currentType === "riffCard") {
|
||||||
openCard();
|
openCard(app);
|
||||||
} else {
|
} else {
|
||||||
getDockByType(currentType).toggleModel(currentType, true);
|
getDockByType(currentType).toggleModel(currentType, true);
|
||||||
}
|
}
|
||||||
|
|
@ -425,7 +425,7 @@ export const globalShortcut = (app: App) => {
|
||||||
if (event.key === "Meta" || event.key === "Control" || event.ctrlKey || event.metaKey) {
|
if (event.key === "Meta" || event.key === "Control" || event.ctrlKey || event.metaKey) {
|
||||||
window.siyuan.ctrlIsPressed = true;
|
window.siyuan.ctrlIsPressed = true;
|
||||||
if (window.siyuan.config.editor.floatWindowMode === 1 && !event.repeat) {
|
if (window.siyuan.config.editor.floatWindowMode === 1 && !event.repeat) {
|
||||||
showPopover();
|
showPopover(app);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
window.siyuan.ctrlIsPressed = false;
|
window.siyuan.ctrlIsPressed = false;
|
||||||
|
|
@ -436,7 +436,7 @@ export const globalShortcut = (app: App) => {
|
||||||
if (event.key === "Shift") {
|
if (event.key === "Shift") {
|
||||||
window.siyuan.shiftIsPressed = true;
|
window.siyuan.shiftIsPressed = true;
|
||||||
if (!event.repeat) {
|
if (!event.repeat) {
|
||||||
showPopover(true);
|
showPopover(app,true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
window.siyuan.shiftIsPressed = false;
|
window.siyuan.shiftIsPressed = false;
|
||||||
|
|
@ -452,7 +452,7 @@ export const globalShortcut = (app: App) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switchDialog && event.ctrlKey && !event.metaKey && event.key.startsWith("Arrow")) {
|
if (switchDialog && event.ctrlKey && !event.metaKey && event.key.startsWith("Arrow")) {
|
||||||
dialogArrow(switchDialog.element, event);
|
dialogArrow(app, switchDialog.element, event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -525,11 +525,11 @@ export const globalShortcut = (app: App) => {
|
||||||
switchDialog.element.querySelector("input").focus();
|
switchDialog.element.querySelector("input").focus();
|
||||||
if (isMac()) {
|
if (isMac()) {
|
||||||
switchDialog.element.addEventListener("contextmenu", (event) => {
|
switchDialog.element.addEventListener("contextmenu", (event) => {
|
||||||
switchDialogEvent(event, switchDialog);
|
switchDialogEvent(app, event, switchDialog);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
switchDialog.element.addEventListener("click", (event) => {
|
switchDialog.element.addEventListener("click", (event) => {
|
||||||
switchDialogEvent(event, switchDialog);
|
switchDialogEvent(app, event, switchDialog);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -543,7 +543,7 @@ export const globalShortcut = (app: App) => {
|
||||||
});
|
});
|
||||||
if (openRecentDocsDialog) {
|
if (openRecentDocsDialog) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
dialogArrow(openRecentDocsDialog.element, event);
|
dialogArrow(app, openRecentDocsDialog.element, event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -611,7 +611,7 @@ export const globalShortcut = (app: App) => {
|
||||||
}
|
}
|
||||||
if (!isTabWindow && matchHotKey(window.siyuan.config.keymap.general.dataHistory.custom, event)) {
|
if (!isTabWindow && matchHotKey(window.siyuan.config.keymap.general.dataHistory.custom, event)) {
|
||||||
if (!window.siyuan.config.readonly) {
|
if (!window.siyuan.config.readonly) {
|
||||||
openHistory();
|
openHistory(app);
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
|
|
@ -639,7 +639,7 @@ export const globalShortcut = (app: App) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!isTabWindow && matchHotKey(window.siyuan.config.keymap.general.riffCard.custom, event)) {
|
if (!isTabWindow && matchHotKey(window.siyuan.config.keymap.general.riffCard.custom, event)) {
|
||||||
openCard();
|
openCard(app);
|
||||||
if (document.activeElement) {
|
if (document.activeElement) {
|
||||||
(document.activeElement as HTMLElement).blur();
|
(document.activeElement as HTMLElement).blur();
|
||||||
}
|
}
|
||||||
|
|
@ -653,7 +653,7 @@ export const globalShortcut = (app: App) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (matchHotKey(window.siyuan.config.keymap.general.newFile.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.general.newFile.custom, event)) {
|
||||||
newFile(undefined, undefined, undefined, true);
|
newFile(app, undefined, undefined, undefined, true);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -731,13 +731,13 @@ export const globalShortcut = (app: App) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchHotKey(window.siyuan.config.keymap.general.goForward.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.general.goForward.custom, event)) {
|
||||||
goForward();
|
goForward(app);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchHotKey(window.siyuan.config.keymap.general.goBack.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.general.goBack.custom, event)) {
|
||||||
goBack();
|
goBack(app);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -784,20 +784,20 @@ export const globalShortcut = (app: App) => {
|
||||||
if (matchHotKey(window.siyuan.config.keymap.general.stickSearch.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.general.stickSearch.custom, event)) {
|
||||||
if (getSelection().rangeCount > 0) {
|
if (getSelection().rangeCount > 0) {
|
||||||
const range = getSelection().getRangeAt(0);
|
const range = getSelection().getRangeAt(0);
|
||||||
openGlobalSearch(range.toString(), false);
|
openGlobalSearch(app, range.toString(), false);
|
||||||
} else {
|
} else {
|
||||||
openGlobalSearch("", false);
|
openGlobalSearch(app, "", false);
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editKeydown(event)) {
|
if (editKeydown(app, event)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 文件树的操作
|
// 文件树的操作
|
||||||
if (!isTabWindow && fileTreeKeydown(event)) {
|
if (!isTabWindow && fileTreeKeydown(app, event)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -817,9 +817,16 @@ export const globalShortcut = (app: App) => {
|
||||||
if (searchKey) {
|
if (searchKey) {
|
||||||
if (getSelection().rangeCount > 0) {
|
if (getSelection().rangeCount > 0) {
|
||||||
const range = getSelection().getRangeAt(0);
|
const range = getSelection().getRangeAt(0);
|
||||||
openSearch(searchKey, range.toString());
|
openSearch({
|
||||||
|
app,
|
||||||
|
hotkey: searchKey,
|
||||||
|
key: range.toString(),
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
openSearch(searchKey);
|
openSearch({
|
||||||
|
app,
|
||||||
|
hotkey: searchKey,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
|
|
@ -906,7 +913,7 @@ export const globalShortcut = (app: App) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const dialogArrow = (element: HTMLElement, event: KeyboardEvent) => {
|
const dialogArrow = (app: App, element: HTMLElement, event: KeyboardEvent) => {
|
||||||
let currentLiElement = element.querySelector(".b3-list-item--focus");
|
let currentLiElement = element.querySelector(".b3-list-item--focus");
|
||||||
if (currentLiElement) {
|
if (currentLiElement) {
|
||||||
currentLiElement.classList.remove("b3-list-item--focus");
|
currentLiElement.classList.remove("b3-list-item--focus");
|
||||||
|
|
@ -933,12 +940,13 @@ const dialogArrow = (element: HTMLElement, event: KeyboardEvent) => {
|
||||||
const currentType = currentLiElement.getAttribute("data-type");
|
const currentType = currentLiElement.getAttribute("data-type");
|
||||||
if (currentType) {
|
if (currentType) {
|
||||||
if (currentType === "riffCard") {
|
if (currentType === "riffCard") {
|
||||||
openCard();
|
openCard(app);
|
||||||
} else {
|
} else {
|
||||||
getDockByType(currentType).toggleModel(currentType, true);
|
getDockByType(currentType).toggleModel(currentType, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id: currentLiElement.getAttribute("data-node-id"),
|
id: currentLiElement.getAttribute("data-node-id"),
|
||||||
action: [Constants.CB_GET_SCROLL]
|
action: [Constants.CB_GET_SCROLL]
|
||||||
});
|
});
|
||||||
|
|
@ -967,7 +975,7 @@ const dialogArrow = (element: HTMLElement, event: KeyboardEvent) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const editKeydown = (event: KeyboardEvent) => {
|
const editKeydown = (app: App, event: KeyboardEvent) => {
|
||||||
const activeTabElement = document.querySelector(".layout__wnd--active .item--focus");
|
const activeTabElement = document.querySelector(".layout__wnd--active .item--focus");
|
||||||
let protyle: IProtyle;
|
let protyle: IProtyle;
|
||||||
if (activeTabElement) {
|
if (activeTabElement) {
|
||||||
|
|
@ -1004,16 +1012,25 @@ const editKeydown = (event: KeyboardEvent) => {
|
||||||
range = getSelection().getRangeAt(0);
|
range = getSelection().getRangeAt(0);
|
||||||
}
|
}
|
||||||
if (range && protyle.element.contains(range.startContainer)) {
|
if (range && protyle.element.contains(range.startContainer)) {
|
||||||
openSearch(searchKey, range.toString(), protyle.notebookId, protyle.path);
|
openSearch({
|
||||||
|
app,
|
||||||
|
hotkey: searchKey,
|
||||||
|
key: range.toString(),
|
||||||
|
notebookId: protyle.notebookId,
|
||||||
|
searchPath: protyle.path
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
openSearch(searchKey);
|
openSearch({
|
||||||
|
app,
|
||||||
|
hotkey: searchKey,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!isFileFocus && matchHotKey(window.siyuan.config.keymap.editor.general.spaceRepetition.custom, event)) {
|
if (!isFileFocus && matchHotKey(window.siyuan.config.keymap.editor.general.spaceRepetition.custom, event)) {
|
||||||
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: protyle.block.rootID}, (response) => {
|
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: protyle.block.rootID}, (response) => {
|
||||||
openCardByData(response.data, "doc", protyle.block.rootID, protyle.title.editElement.textContent || "Untitled");
|
openCardByData(app, response.data, "doc", protyle.block.rootID, protyle.title.editElement.textContent || "Untitled");
|
||||||
});
|
});
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -1088,7 +1105,7 @@ const editKeydown = (event: KeyboardEvent) => {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const fileTreeKeydown = (event: KeyboardEvent) => {
|
const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
|
||||||
const dockFile = getDockByType("file");
|
const dockFile = getDockByType("file");
|
||||||
if (!dockFile) {
|
if (!dockFile) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1135,11 +1152,11 @@ const fileTreeKeydown = (event: KeyboardEvent) => {
|
||||||
if (isFile) {
|
if (isFile) {
|
||||||
const id = liElements[0].getAttribute("data-node-id");
|
const id = liElements[0].getAttribute("data-node-id");
|
||||||
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: id}, (response) => {
|
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: id}, (response) => {
|
||||||
openCardByData(response.data, "doc", id, getDisplayName(liElements[0].getAttribute("data-name"), false, true));
|
openCardByData(app, response.data, "doc", id, getDisplayName(liElements[0].getAttribute("data-name"), false, true));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
fetchPost("/api/riff/getNotebookRiffDueCards", {notebook: notebookId}, (response) => {
|
fetchPost("/api/riff/getNotebookRiffDueCards", {notebook: notebookId}, (response) => {
|
||||||
openCardByData(response.data, "notebook", notebookId, getNotebookName(notebookId));
|
openCardByData(app, response.data, "notebook", notebookId, getNotebookName(notebookId));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1158,12 +1175,12 @@ const fileTreeKeydown = (event: KeyboardEvent) => {
|
||||||
if (matchHotKey("⌘/", event)) {
|
if (matchHotKey("⌘/", event)) {
|
||||||
const liRect = liElements[0].getBoundingClientRect();
|
const liRect = liElements[0].getBoundingClientRect();
|
||||||
if (isFile) {
|
if (isFile) {
|
||||||
initFileMenu(notebookId, pathString, liElements[0]).popup({
|
initFileMenu(app, notebookId, pathString, liElements[0]).popup({
|
||||||
x: liRect.right - 15,
|
x: liRect.right - 15,
|
||||||
y: liRect.top + 15
|
y: liRect.top + 15
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
initNavigationMenu(liElements[0] as HTMLElement).popup({x: liRect.right - 15, y: liRect.top + 15});
|
initNavigationMenu(app, liElements[0] as HTMLElement).popup({x: liRect.right - 15, y: liRect.top + 15});
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -1185,9 +1202,18 @@ const fileTreeKeydown = (event: KeyboardEvent) => {
|
||||||
if (searchKey) {
|
if (searchKey) {
|
||||||
window.siyuan.menus.menu.remove();
|
window.siyuan.menus.menu.remove();
|
||||||
if (isFile) {
|
if (isFile) {
|
||||||
openSearch(searchKey, undefined, notebookId, getDisplayName(pathString, false, true));
|
openSearch({
|
||||||
|
app,
|
||||||
|
hotkey: searchKey,
|
||||||
|
notebookId: notebookId,
|
||||||
|
searchPath: getDisplayName(pathString, false, true)
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
openSearch(searchKey, undefined, notebookId);
|
openSearch({
|
||||||
|
app,
|
||||||
|
hotkey: searchKey,
|
||||||
|
notebookId: notebookId,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -1363,7 +1389,7 @@ const fileTreeKeydown = (event: KeyboardEvent) => {
|
||||||
window.siyuan.menus.menu.remove();
|
window.siyuan.menus.menu.remove();
|
||||||
liElements.forEach(item => {
|
liElements.forEach(item => {
|
||||||
if (item.getAttribute("data-type") === "navigation-file") {
|
if (item.getAttribute("data-type") === "navigation-file") {
|
||||||
openFileById({id: item.getAttribute("data-node-id"), action: [Constants.CB_GET_FOCUS]});
|
openFileById({app, id: item.getAttribute("data-node-id"), action: [Constants.CB_GET_FOCUS]});
|
||||||
} else {
|
} else {
|
||||||
const itemTopULElement = hasTopClosestByTag(item, "UL");
|
const itemTopULElement = hasTopClosestByTag(item, "UL");
|
||||||
if (itemTopULElement) {
|
if (itemTopULElement) {
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ export const onGetConfig = (isStart: boolean, app: App) => {
|
||||||
initBar(app);
|
initBar(app);
|
||||||
setProxy();
|
setProxy();
|
||||||
initStatus();
|
initStatus();
|
||||||
initWindow();
|
initWindow(app);
|
||||||
appearance.onSetappearance(window.siyuan.config.appearance);
|
appearance.onSetappearance(window.siyuan.config.appearance);
|
||||||
initAssets();
|
initAssets();
|
||||||
renderSnippet();
|
renderSnippet();
|
||||||
|
|
@ -160,7 +160,7 @@ export const onGetConfig = (isStart: boolean, app: App) => {
|
||||||
addGA();
|
addGA();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initWindow = () => {
|
export const initWindow = (app: App) => {
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
const winOnFocus = () => {
|
const winOnFocus = () => {
|
||||||
if (getSelection().rangeCount > 0) {
|
if (getSelection().rangeCount > 0) {
|
||||||
|
|
@ -256,6 +256,7 @@ export const initWindow = () => {
|
||||||
fetchPost("/api/block/checkBlockExist", {id}, existResponse => {
|
fetchPost("/api/block/checkBlockExist", {id}, existResponse => {
|
||||||
if (existResponse.data) {
|
if (existResponse.data) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id,
|
id,
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
zoomIn: getSearch("focus", url) === "1"
|
zoomIn: getSearch("focus", url) === "1"
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import {viewCards} from "./viewCards";
|
||||||
import {Constants} from "../constants";
|
import {Constants} from "../constants";
|
||||||
import {escapeAttr, escapeHtml} from "../util/escape";
|
import {escapeAttr, escapeHtml} from "../util/escape";
|
||||||
import {transaction} from "../protyle/wysiwyg/transaction";
|
import {transaction} from "../protyle/wysiwyg/transaction";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
export const genCardItem = (item: ICardPackage) => {
|
export const genCardItem = (item: ICardPackage) => {
|
||||||
return `<li data-id="${item.id}" data-name="${escapeAttr(item.name)}" class="b3-list-item b3-list-item--narrow${isMobile() ? "" : " b3-list-item--hide-action"}">
|
return `<li data-id="${item.id}" data-name="${escapeAttr(item.name)}" class="b3-list-item b3-list-item--narrow${isMobile() ? "" : " b3-list-item--hide-action"}">
|
||||||
|
|
@ -34,7 +35,7 @@ export const genCardItem = (item: ICardPackage) => {
|
||||||
</li>`;
|
</li>`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const makeCard = (ids: string[]) => {
|
export const makeCard = (app: App, ids: string[]) => {
|
||||||
window.siyuan.dialogs.find(item => {
|
window.siyuan.dialogs.find(item => {
|
||||||
if (item.element.getAttribute("data-key") === "makeCard") {
|
if (item.element.getAttribute("data-key") === "makeCard") {
|
||||||
hideElements(["dialog"]);
|
hideElements(["dialog"]);
|
||||||
|
|
@ -122,14 +123,14 @@ export const makeCard = (ids: string[]) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
} else if (type === "view") {
|
} else if (type === "view") {
|
||||||
viewCards(target.parentElement.getAttribute("data-id"), target.parentElement.getAttribute("data-name"), "", (removeResponse) => {
|
viewCards(app, target.parentElement.getAttribute("data-id"), target.parentElement.getAttribute("data-name"), "", (removeResponse) => {
|
||||||
target.parentElement.outerHTML = genCardItem(removeResponse.data);
|
target.parentElement.outerHTML = genCardItem(removeResponse.data);
|
||||||
});
|
});
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
} else if (type === "viewall") {
|
} else if (type === "viewall") {
|
||||||
viewCards("", window.siyuan.languages.all, "");
|
viewCards(app, "", window.siyuan.languages.all, "");
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,10 @@ import {bindCardEvent, genCardHTML} from "./openCard";
|
||||||
import {fetchPost} from "../util/fetch";
|
import {fetchPost} from "../util/fetch";
|
||||||
import {Protyle} from "../protyle";
|
import {Protyle} from "../protyle";
|
||||||
import {setPanelFocus} from "../layout/util";
|
import {setPanelFocus} from "../layout/util";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
export const newCardModel = (options: {
|
export const newCardModel = (options: {
|
||||||
|
app: App,
|
||||||
tab: Tab,
|
tab: Tab,
|
||||||
data: {
|
data: {
|
||||||
cardType: TCardType,
|
cardType: TCardType,
|
||||||
|
|
@ -15,6 +17,7 @@ export const newCardModel = (options: {
|
||||||
}) => {
|
}) => {
|
||||||
let editor: Protyle;
|
let editor: Protyle;
|
||||||
const customObj = new Custom({
|
const customObj = new Custom({
|
||||||
|
app: options.app,
|
||||||
type: "siyuan-card",
|
type: "siyuan-card",
|
||||||
tab: options.tab,
|
tab: options.tab,
|
||||||
data: options.data,
|
data: options.data,
|
||||||
|
|
@ -33,6 +36,7 @@ export const newCardModel = (options: {
|
||||||
});
|
});
|
||||||
|
|
||||||
editor = bindCardEvent({
|
editor = bindCardEvent({
|
||||||
|
app: options.app,
|
||||||
element: this.element,
|
element: this.element,
|
||||||
id: this.data.id,
|
id: this.data.id,
|
||||||
title: this.data.title,
|
title: this.data.title,
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import {openFile} from "../editor/util";
|
||||||
import {newCardModel} from "./newCardTab";
|
import {newCardModel} from "./newCardTab";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {getDisplayName, movePathTo} from "../util/pathName";
|
import {getDisplayName, movePathTo} from "../util/pathName";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
export const genCardHTML = (options: {
|
export const genCardHTML = (options: {
|
||||||
id: string,
|
id: string,
|
||||||
|
|
@ -110,6 +111,7 @@ export const genCardHTML = (options: {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const bindCardEvent = (options: {
|
export const bindCardEvent = (options: {
|
||||||
|
app: App,
|
||||||
element: Element,
|
element: Element,
|
||||||
title?: string,
|
title?: string,
|
||||||
blocks: ICard[],
|
blocks: ICard[],
|
||||||
|
|
@ -118,7 +120,7 @@ export const bindCardEvent = (options: {
|
||||||
dialog?: Dialog,
|
dialog?: Dialog,
|
||||||
}) => {
|
}) => {
|
||||||
let index = 0;
|
let index = 0;
|
||||||
const editor = new Protyle(options.element.querySelector("[data-type='render']") as HTMLElement, {
|
const editor = new Protyle(options.app, options.element.querySelector("[data-type='render']") as HTMLElement, {
|
||||||
blockId: "",
|
blockId: "",
|
||||||
action: [Constants.CB_GET_ALL],
|
action: [Constants.CB_GET_ALL],
|
||||||
render: {
|
render: {
|
||||||
|
|
@ -205,6 +207,7 @@ export const bindCardEvent = (options: {
|
||||||
const sticktabElement = hasClosestByAttribute(target, "data-type", "sticktab");
|
const sticktabElement = hasClosestByAttribute(target, "data-type", "sticktab");
|
||||||
if (sticktabElement) {
|
if (sticktabElement) {
|
||||||
openFile({
|
openFile({
|
||||||
|
app: options.app,
|
||||||
position: "right",
|
position: "right",
|
||||||
custom: {
|
custom: {
|
||||||
icon: "iconRiffCard",
|
icon: "iconRiffCard",
|
||||||
|
|
@ -399,13 +402,13 @@ export const bindCardEvent = (options: {
|
||||||
return editor;
|
return editor;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const openCard = () => {
|
export const openCard = (app: App) => {
|
||||||
fetchPost("/api/riff/getRiffDueCards", {deckID: ""}, (cardsResponse) => {
|
fetchPost("/api/riff/getRiffDueCards", {deckID: ""}, (cardsResponse) => {
|
||||||
openCardByData(cardsResponse.data, "all");
|
openCardByData(app, cardsResponse.data, "all");
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const openCardByData = (cardsData: {
|
export const openCardByData = (app: App, cardsData: {
|
||||||
cards: ICard[],
|
cards: ICard[],
|
||||||
unreviewedCount: number
|
unreviewedCount: number
|
||||||
}, cardType: TCardType, id?: string, title?: string) => {
|
}, cardType: TCardType, id?: string, title?: string) => {
|
||||||
|
|
@ -435,6 +438,7 @@ export const openCardByData = (cardsData: {
|
||||||
(dialog.element.querySelector(".b3-dialog__scrim") as HTMLElement).style.backgroundColor = "var(--b3-theme-background)";
|
(dialog.element.querySelector(".b3-dialog__scrim") as HTMLElement).style.backgroundColor = "var(--b3-theme-background)";
|
||||||
(dialog.element.querySelector(".b3-dialog__container") as HTMLElement).style.maxWidth = "1024px";
|
(dialog.element.querySelector(".b3-dialog__container") as HTMLElement).style.maxWidth = "1024px";
|
||||||
const editor = bindCardEvent({
|
const editor = bindCardEvent({
|
||||||
|
app,
|
||||||
element: dialog.element,
|
element: dialog.element,
|
||||||
blocks: cardsData.cards,
|
blocks: cardsData.cards,
|
||||||
title,
|
title,
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,9 @@ import {unicode2Emoji} from "../emoji";
|
||||||
import {addLoading} from "../protyle/ui/initUI";
|
import {addLoading} from "../protyle/ui/initUI";
|
||||||
import {Constants} from "../constants";
|
import {Constants} from "../constants";
|
||||||
import {disabledProtyle, onGet} from "../protyle/util/onGet";
|
import {disabledProtyle, onGet} from "../protyle/util/onGet";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
export const viewCards = (deckID: string, title: string, deckType: "Tree" | "" | "Notebook", cb?: (response: IWebSocketData) => void) => {
|
export const viewCards = (app: App, deckID: string, title: string, deckType: "Tree" | "" | "Notebook", cb?: (response: IWebSocketData) => void) => {
|
||||||
let pageIndex = 1;
|
let pageIndex = 1;
|
||||||
let edit: Protyle;
|
let edit: Protyle;
|
||||||
fetchPost(`/api/riff/get${deckType}RiffCards`, {
|
fetchPost(`/api/riff/get${deckType}RiffCards`, {
|
||||||
|
|
@ -55,7 +56,7 @@ export const viewCards = (deckID: string, title: string, deckType: "Tree" | "" |
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (response.data.blocks.length > 0) {
|
if (response.data.blocks.length > 0) {
|
||||||
edit = new Protyle(dialog.element.querySelector("#cardPreview") as HTMLElement, {
|
edit = new Protyle(app, dialog.element.querySelector("#cardPreview") as HTMLElement, {
|
||||||
blockId: "",
|
blockId: "",
|
||||||
render: {
|
render: {
|
||||||
gutter: true,
|
gutter: true,
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import {reloadProtyle} from "../protyle/util/reload";
|
||||||
import {Tab} from "../layout/Tab";
|
import {Tab} from "../layout/Tab";
|
||||||
import {setEmpty} from "../mobile/util/setEmpty";
|
import {setEmpty} from "../mobile/util/setEmpty";
|
||||||
import {hideElements} from "../protyle/ui/hideElements";
|
import {hideElements} from "../protyle/ui/hideElements";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
const updateTitle = (rootID: string, tab: Tab) => {
|
const updateTitle = (rootID: string, tab: Tab) => {
|
||||||
fetchPost("/api/block/getDocInfo", {
|
fetchPost("/api/block/getDocInfo", {
|
||||||
|
|
@ -29,7 +30,7 @@ const updateTitle = (rootID: string, tab: Tab) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const reloadSync = (data: { upsertRootIDs: string[], removeRootIDs: string[] }) => {
|
export const reloadSync = (app: App, data: { upsertRootIDs: string[], removeRootIDs: string[] }) => {
|
||||||
hideMessage();
|
hideMessage();
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
if (window.siyuan.mobile.popEditor) {
|
if (window.siyuan.mobile.popEditor) {
|
||||||
|
|
@ -42,7 +43,7 @@ export const reloadSync = (data: { upsertRootIDs: string[], removeRootIDs: strin
|
||||||
}
|
}
|
||||||
if (window.siyuan.mobile.editor) {
|
if (window.siyuan.mobile.editor) {
|
||||||
if (data.removeRootIDs.includes(window.siyuan.mobile.editor.protyle.block.rootID)) {
|
if (data.removeRootIDs.includes(window.siyuan.mobile.editor.protyle.block.rootID)) {
|
||||||
setEmpty();
|
setEmpty(app);
|
||||||
} else {
|
} else {
|
||||||
reloadProtyle(window.siyuan.mobile.editor.protyle, false);
|
reloadProtyle(window.siyuan.mobile.editor.protyle, false);
|
||||||
fetchPost("/api/block/getDocInfo", {
|
fetchPost("/api/block/getDocInfo", {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import {getAllModels} from "../layout/getAll";
|
||||||
import {setModelsHash} from "../window/setHeader";
|
import {setModelsHash} from "../window/setHeader";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {countBlockWord} from "../layout/status";
|
import {countBlockWord} from "../layout/status";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
export class Editor extends Model {
|
export class Editor extends Model {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
@ -15,6 +16,7 @@ export class Editor extends Model {
|
||||||
public headElement: HTMLElement;
|
public headElement: HTMLElement;
|
||||||
|
|
||||||
constructor(options: {
|
constructor(options: {
|
||||||
|
app: App,
|
||||||
tab: Tab,
|
tab: Tab,
|
||||||
blockId: string,
|
blockId: string,
|
||||||
mode?: TEditorMode,
|
mode?: TEditorMode,
|
||||||
|
|
@ -22,6 +24,7 @@ export class Editor extends Model {
|
||||||
scrollAttr?: IScrollAttr
|
scrollAttr?: IScrollAttr
|
||||||
}) {
|
}) {
|
||||||
super({
|
super({
|
||||||
|
app: options.app,
|
||||||
id: options.tab.id,
|
id: options.tab.id,
|
||||||
});
|
});
|
||||||
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
|
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
|
||||||
|
|
@ -38,7 +41,7 @@ export class Editor extends Model {
|
||||||
mode?: TEditorMode,
|
mode?: TEditorMode,
|
||||||
scrollAttr?: IScrollAttr
|
scrollAttr?: IScrollAttr
|
||||||
}) {
|
}) {
|
||||||
this.editor = new Protyle(this.element, {
|
this.editor = new Protyle(this.app, this.element, {
|
||||||
action: options.action || [],
|
action: options.action || [],
|
||||||
blockId: options.blockId,
|
blockId: options.blockId,
|
||||||
mode: options.mode,
|
mode: options.mode,
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,10 @@ import {showMessage} from "../dialog/message";
|
||||||
import {objEquals} from "../util/functions";
|
import {objEquals} from "../util/functions";
|
||||||
import {resize} from "../protyle/util/resize";
|
import {resize} from "../protyle/util/resize";
|
||||||
import {Search} from "../search";
|
import {Search} from "../search";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
export const openFileById = async (options: {
|
export const openFileById = async (options: {
|
||||||
|
app: App,
|
||||||
id: string,
|
id: string,
|
||||||
position?: string,
|
position?: string,
|
||||||
mode?: TEditorMode,
|
mode?: TEditorMode,
|
||||||
|
|
@ -47,6 +49,7 @@ export const openFileById = async (options: {
|
||||||
options.removeCurrentTab = true;
|
options.removeCurrentTab = true;
|
||||||
}
|
}
|
||||||
openFile({
|
openFile({
|
||||||
|
app: options.app,
|
||||||
fileName: data.data.rootTitle,
|
fileName: data.data.rootTitle,
|
||||||
rootIcon: data.data.rootIcon,
|
rootIcon: data.data.rootIcon,
|
||||||
rootID: data.data.rootID,
|
rootID: data.data.rootID,
|
||||||
|
|
@ -62,12 +65,13 @@ export const openFileById = async (options: {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const openAsset = (assetPath: string, page: number | string, position?: string) => {
|
export const openAsset = (app: App, assetPath: string, page: number | string, position?: string) => {
|
||||||
const suffix = pathPosix().extname(assetPath.split("?page")[0]);
|
const suffix = pathPosix().extname(assetPath.split("?page")[0]);
|
||||||
if (!Constants.SIYUAN_ASSETS_EXTS.includes(suffix)) {
|
if (!Constants.SIYUAN_ASSETS_EXTS.includes(suffix)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
openFile({
|
openFile({
|
||||||
|
app,
|
||||||
assetPath,
|
assetPath,
|
||||||
page,
|
page,
|
||||||
position,
|
position,
|
||||||
|
|
@ -379,6 +383,7 @@ const newTab = (options: IOpenFileOptions) => {
|
||||||
title: getDisplayName(options.assetPath),
|
title: getDisplayName(options.assetPath),
|
||||||
callback(tab) {
|
callback(tab) {
|
||||||
tab.addModel(new Asset({
|
tab.addModel(new Asset({
|
||||||
|
app: options.app,
|
||||||
tab,
|
tab,
|
||||||
path: options.assetPath,
|
path: options.assetPath,
|
||||||
page: options.page,
|
page: options.page,
|
||||||
|
|
@ -405,6 +410,7 @@ const newTab = (options: IOpenFileOptions) => {
|
||||||
title: window.siyuan.languages.search,
|
title: window.siyuan.languages.search,
|
||||||
callback(tab) {
|
callback(tab) {
|
||||||
tab.addModel(new Search({
|
tab.addModel(new Search({
|
||||||
|
app: options.app,
|
||||||
tab,
|
tab,
|
||||||
config: options.searchData
|
config: options.searchData
|
||||||
}));
|
}));
|
||||||
|
|
@ -419,12 +425,14 @@ const newTab = (options: IOpenFileOptions) => {
|
||||||
let editor;
|
let editor;
|
||||||
if (options.zoomIn) {
|
if (options.zoomIn) {
|
||||||
editor = new Editor({
|
editor = new Editor({
|
||||||
|
app: options.app,
|
||||||
tab,
|
tab,
|
||||||
blockId: options.id,
|
blockId: options.id,
|
||||||
action: [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS],
|
action: [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS],
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
editor = new Editor({
|
editor = new Editor({
|
||||||
|
app: options.app,
|
||||||
tab,
|
tab,
|
||||||
blockId: options.id,
|
blockId: options.id,
|
||||||
mode: options.mode,
|
mode: options.mode,
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import {hasClosestByClassName} from "../protyle/util/hasClosest";
|
||||||
import {escapeHtml} from "../util/escape";
|
import {escapeHtml} from "../util/escape";
|
||||||
import * as dayjs from "dayjs";
|
import * as dayjs from "dayjs";
|
||||||
import {isMobile} from "../util/functions";
|
import {isMobile} from "../util/functions";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
const genItem = (data: [], data2?: { title: string, fileID: string }[]) => {
|
const genItem = (data: [], data2?: { title: string, fileID: string }[]) => {
|
||||||
if (!data || data.length === 0) {
|
if (!data || data.length === 0) {
|
||||||
|
|
@ -27,7 +28,7 @@ const genItem = (data: [], data2?: { title: string, fileID: string }[]) => {
|
||||||
|
|
||||||
let leftEditor: Protyle;
|
let leftEditor: Protyle;
|
||||||
let rightEditor: Protyle;
|
let rightEditor: Protyle;
|
||||||
const renderCompare = (element: HTMLElement) => {
|
const renderCompare = (app: App, element: HTMLElement) => {
|
||||||
const listElement = hasClosestByClassName(element, "history__diff");
|
const listElement = hasClosestByClassName(element, "history__diff");
|
||||||
if (!listElement) {
|
if (!listElement) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -35,7 +36,7 @@ const renderCompare = (element: HTMLElement) => {
|
||||||
const leftElement = listElement.nextElementSibling.firstElementChild;
|
const leftElement = listElement.nextElementSibling.firstElementChild;
|
||||||
const rightElement = listElement.nextElementSibling.lastElementChild;
|
const rightElement = listElement.nextElementSibling.lastElementChild;
|
||||||
if (!leftEditor) {
|
if (!leftEditor) {
|
||||||
leftEditor = new Protyle(leftElement.lastElementChild as HTMLElement, {
|
leftEditor = new Protyle(app, leftElement.lastElementChild as HTMLElement, {
|
||||||
blockId: "",
|
blockId: "",
|
||||||
action: [Constants.CB_GET_HISTORY],
|
action: [Constants.CB_GET_HISTORY],
|
||||||
render: {
|
render: {
|
||||||
|
|
@ -48,7 +49,7 @@ const renderCompare = (element: HTMLElement) => {
|
||||||
typewriterMode: false
|
typewriterMode: false
|
||||||
});
|
});
|
||||||
disabledProtyle(leftEditor.protyle);
|
disabledProtyle(leftEditor.protyle);
|
||||||
rightEditor = new Protyle(rightElement.lastElementChild as HTMLElement, {
|
rightEditor = new Protyle(app, rightElement.lastElementChild as HTMLElement, {
|
||||||
blockId: "",
|
blockId: "",
|
||||||
action: [Constants.CB_GET_HISTORY],
|
action: [Constants.CB_GET_HISTORY],
|
||||||
render: {
|
render: {
|
||||||
|
|
@ -98,7 +99,7 @@ const renderCompare = (element: HTMLElement) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const showDiff = (data: { id: string, time: string }[]) => {
|
export const showDiff = (app: App, data: { id: string, time: string }[]) => {
|
||||||
if (data.length !== 2) {
|
if (data.length !== 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +138,7 @@ export const showDiff = (data: { id: string, time: string }[]) => {
|
||||||
}
|
}
|
||||||
dialog.element.querySelector(".history__diff .b3-list-item--focus")?.classList.remove("b3-list-item--focus");
|
dialog.element.querySelector(".history__diff .b3-list-item--focus")?.classList.remove("b3-list-item--focus");
|
||||||
target.classList.add("b3-list-item--focus");
|
target.classList.add("b3-list-item--focus");
|
||||||
renderCompare(target);
|
renderCompare(app, target);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
|
|
@ -159,7 +160,7 @@ export const showDiff = (data: { id: string, time: string }[]) => {
|
||||||
genHTML(left, right, dialog, "left");
|
genHTML(left, right, dialog, "left");
|
||||||
};
|
};
|
||||||
|
|
||||||
const genHTML = (left: string, right: string, dialog: Dialog, direct:string) => {
|
const genHTML = (left: string, right: string, dialog: Dialog, direct: string) => {
|
||||||
leftEditor = undefined;
|
leftEditor = undefined;
|
||||||
rightEditor = undefined;
|
rightEditor = undefined;
|
||||||
const isPhone = isMobile();
|
const isPhone = isMobile();
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import {showDiff} from "./diff";
|
||||||
import {setStorageVal} from "../protyle/util/compatibility";
|
import {setStorageVal} from "../protyle/util/compatibility";
|
||||||
import {openModel} from "../mobile/menu/model";
|
import {openModel} from "../mobile/menu/model";
|
||||||
import {closeModel} from "../mobile/util/closePanel";
|
import {closeModel} from "../mobile/util/closePanel";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
let historyEditor: Protyle;
|
let historyEditor: Protyle;
|
||||||
|
|
||||||
|
|
@ -288,7 +289,7 @@ const renderRmNotebook = (element: HTMLElement) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const openHistory = () => {
|
export const openHistory = (app: App) => {
|
||||||
if (window.siyuan.config.readonly) {
|
if (window.siyuan.config.readonly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -403,7 +404,7 @@ export const openHistory = () => {
|
||||||
icon: "iconHistory",
|
icon: "iconHistory",
|
||||||
title: window.siyuan.languages.dataHistory,
|
title: window.siyuan.languages.dataHistory,
|
||||||
bindEvent(element) {
|
bindEvent(element) {
|
||||||
bindEvent(element.firstElementChild);
|
bindEvent(app, element.firstElementChild);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -415,11 +416,11 @@ export const openHistory = () => {
|
||||||
historyEditor = undefined;
|
historyEditor = undefined;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
bindEvent(dialog.element, dialog);
|
bindEvent(app, dialog.element, dialog);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const bindEvent = (element: Element, dialog?: Dialog) => {
|
const bindEvent = (app: App, element: Element, dialog?: Dialog) => {
|
||||||
const firstPanelElement = element.querySelector("#historyContainer [data-type=doc]") as HTMLElement;
|
const firstPanelElement = element.querySelector("#historyContainer [data-type=doc]") as HTMLElement;
|
||||||
firstPanelElement.querySelectorAll(".b3-select").forEach((itemElement) => {
|
firstPanelElement.querySelectorAll(".b3-select").forEach((itemElement) => {
|
||||||
itemElement.addEventListener("change", () => {
|
itemElement.addEventListener("change", () => {
|
||||||
|
|
@ -439,7 +440,7 @@ const bindEvent = (element: Element, dialog?: Dialog) => {
|
||||||
const assetElement = firstPanelElement.querySelector('.history__text[data-type="assetPanel"]');
|
const assetElement = firstPanelElement.querySelector('.history__text[data-type="assetPanel"]');
|
||||||
const mdElement = firstPanelElement.querySelector('.history__text[data-type="mdPanel"]') as HTMLTextAreaElement;
|
const mdElement = firstPanelElement.querySelector('.history__text[data-type="mdPanel"]') as HTMLTextAreaElement;
|
||||||
renderDoc(firstPanelElement, 1);
|
renderDoc(firstPanelElement, 1);
|
||||||
historyEditor = new Protyle(docElement, {
|
historyEditor = new Protyle(app, docElement, {
|
||||||
blockId: "",
|
blockId: "",
|
||||||
action: [Constants.CB_GET_HISTORY],
|
action: [Constants.CB_GET_HISTORY],
|
||||||
render: {
|
render: {
|
||||||
|
|
@ -750,7 +751,7 @@ const bindEvent = (element: Element, dialog?: Dialog) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
} else if (type === "compare" && !target.getAttribute("disabled")) {
|
} else if (type === "compare" && !target.getAttribute("disabled")) {
|
||||||
showDiff(JSON.parse(target.getAttribute("data-ids") || "[]"));
|
showDiff(app, JSON.parse(target.getAttribute("data-ids") || "[]"));
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ export class App {
|
||||||
ctrlIsPressed: false,
|
ctrlIsPressed: false,
|
||||||
altIsPressed: false,
|
altIsPressed: false,
|
||||||
ws: new Model({
|
ws: new Model({
|
||||||
|
app: this,
|
||||||
id: genUUID(),
|
id: genUUID(),
|
||||||
type: "main",
|
type: "main",
|
||||||
msgCallback: (data) => {
|
msgCallback: (data) => {
|
||||||
|
|
@ -60,7 +61,7 @@ export class App {
|
||||||
if (data) {
|
if (data) {
|
||||||
switch (data.cmd) {
|
switch (data.cmd) {
|
||||||
case "syncMergeResult":
|
case "syncMergeResult":
|
||||||
reloadSync(data.data);
|
reloadSync(this, data.data);
|
||||||
break;
|
break;
|
||||||
case "readonly":
|
case "readonly":
|
||||||
window.siyuan.config.editor.readOnly = data.data;
|
window.siyuan.config.editor.readOnly = data.data;
|
||||||
|
|
@ -135,10 +136,10 @@ export class App {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "createdailynote":
|
case "createdailynote":
|
||||||
openFileById({id: data.data.id, action: [Constants.CB_GET_FOCUS]});
|
openFileById({app: this, id: data.data.id, action: [Constants.CB_GET_FOCUS]});
|
||||||
break;
|
break;
|
||||||
case "openFileById":
|
case "openFileById":
|
||||||
openFileById({id: data.data.id, action: [Constants.CB_GET_FOCUS]});
|
openFileById({app: this, id: data.data.id, action: [Constants.CB_GET_FOCUS]});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -166,12 +167,12 @@ export class App {
|
||||||
getLocalStorage(() => {
|
getLocalStorage(() => {
|
||||||
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => {
|
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => {
|
||||||
window.siyuan.languages = lauguages;
|
window.siyuan.languages = lauguages;
|
||||||
window.siyuan.menus = new Menus(siyuanApp);
|
window.siyuan.menus = new Menus(this);
|
||||||
bootSync();
|
bootSync();
|
||||||
fetchPost("/api/setting/getCloudUser", {}, userResponse => {
|
fetchPost("/api/setting/getCloudUser", {}, userResponse => {
|
||||||
window.siyuan.user = userResponse.data;
|
window.siyuan.user = userResponse.data;
|
||||||
loadPlugins(siyuanApp);
|
loadPlugins(this);
|
||||||
onGetConfig(response.data.start, siyuanApp);
|
onGetConfig(response.data.start, this);
|
||||||
account.onSetaccount();
|
account.onSetaccount();
|
||||||
resizeDrag();
|
resizeDrag();
|
||||||
setTitle(window.siyuan.languages.siyuanNote);
|
setTitle(window.siyuan.languages.siyuanNote);
|
||||||
|
|
@ -181,7 +182,7 @@ export class App {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
setNoteBook();
|
setNoteBook();
|
||||||
initBlockPopover();
|
initBlockPopover(this);
|
||||||
promiseTransactions();
|
promiseTransactions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -192,6 +193,7 @@ window.openFileByURL = (openURL) => {
|
||||||
if (openURL && isSYProtocol(openURL)) {
|
if (openURL && isSYProtocol(openURL)) {
|
||||||
const isZoomIn = getSearch("focus", openURL) === "1";
|
const isZoomIn = getSearch("focus", openURL) === "1";
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: siyuanApp,
|
||||||
id: getIdFromSYProtocol(openURL),
|
id: getIdFromSYProtocol(openURL),
|
||||||
action: isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
zoomIn: isZoomIn
|
zoomIn: isZoomIn
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import {Tab} from "./Tab";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {processMessage} from "../util/processMessage";
|
import {processMessage} from "../util/processMessage";
|
||||||
import {kernelError, reloadSync} from "../dialog/processSystem";
|
import {kernelError, reloadSync} from "../dialog/processSystem";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
export class Model {
|
export class Model {
|
||||||
public ws: WebSocket;
|
public ws: WebSocket;
|
||||||
|
|
@ -14,13 +15,16 @@ export class Model {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
public parent: any;
|
public parent: any;
|
||||||
/// #endif
|
/// #endif
|
||||||
|
public app: App;
|
||||||
|
|
||||||
constructor(options: {
|
constructor(options: {
|
||||||
|
app: App,
|
||||||
id: string,
|
id: string,
|
||||||
type?: TWS,
|
type?: TWS,
|
||||||
callback?: () => void,
|
callback?: () => void,
|
||||||
msgCallback?: (data: IWebSocketData) => void
|
msgCallback?: (data: IWebSocketData) => void
|
||||||
}) {
|
}) {
|
||||||
|
this.app = options.app;
|
||||||
if (options.msgCallback) {
|
if (options.msgCallback) {
|
||||||
this.connect(options);
|
this.connect(options);
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +45,7 @@ export class Model {
|
||||||
const logElement = document.getElementById("errorLog");
|
const logElement = document.getElementById("errorLog");
|
||||||
if (logElement) {
|
if (logElement) {
|
||||||
// 内核中断后无法 catch fetch 请求错误,重连会导致无法执行 transactionsTimeout
|
// 内核中断后无法 catch fetch 请求错误,重连会导致无法执行 transactionsTimeout
|
||||||
reloadSync({upsertRootIDs: [], removeRootIDs: []});
|
reloadSync(this.app, {upsertRootIDs: [], removeRootIDs: []});
|
||||||
window.siyuan.dialogs.find(item =>{
|
window.siyuan.dialogs.find(item =>{
|
||||||
if (item.element.id === "errorLog") {
|
if (item.element.id === "errorLog") {
|
||||||
item.destroy();
|
item.destroy();
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ export class Wnd {
|
||||||
while (target && !target.isEqualNode(this.headersElement)) {
|
while (target && !target.isEqualNode(this.headersElement)) {
|
||||||
if (target.classList.contains("block__icon") && target.getAttribute("data-type") === "new") {
|
if (target.classList.contains("block__icon") && target.getAttribute("data-type") === "new") {
|
||||||
setPanelFocus(this.headersElement.parentElement.parentElement);
|
setPanelFocus(this.headersElement.parentElement.parentElement);
|
||||||
newFile(undefined, undefined, undefined, true);
|
newFile(app, undefined, undefined, undefined, true);
|
||||||
break;
|
break;
|
||||||
} else if (target.classList.contains("block__icon") && target.getAttribute("data-type") === "more") {
|
} else if (target.classList.contains("block__icon") && target.getAttribute("data-type") === "more") {
|
||||||
this.renderTabList(target);
|
this.renderTabList(target);
|
||||||
|
|
@ -211,6 +211,7 @@ export class Wnd {
|
||||||
event.dataTransfer.getData(Constants.SIYUAN_DROP_FILE).split(",").forEach(item => {
|
event.dataTransfer.getData(Constants.SIYUAN_DROP_FILE).split(",").forEach(item => {
|
||||||
if (item) {
|
if (item) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id: item,
|
id: item,
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
|
||||||
});
|
});
|
||||||
|
|
@ -435,6 +436,7 @@ export class Wnd {
|
||||||
if (initData) {
|
if (initData) {
|
||||||
const json = JSON.parse(initData);
|
const json = JSON.parse(initData);
|
||||||
currentTab.addModel(new Editor({
|
currentTab.addModel(new Editor({
|
||||||
|
app: this.app,
|
||||||
tab: currentTab,
|
tab: currentTab,
|
||||||
blockId: json.blockId,
|
blockId: json.blockId,
|
||||||
mode: json.mode,
|
mode: json.mode,
|
||||||
|
|
@ -476,6 +478,7 @@ export class Wnd {
|
||||||
scrollCenter(currentTab.model.editor.protyle, nodeElement, true);
|
scrollCenter(currentTab.model.editor.protyle, nodeElement, true);
|
||||||
} else {
|
} else {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: this.app,
|
||||||
id: keepCursorId,
|
id: keepCursorId,
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
||||||
});
|
});
|
||||||
|
|
@ -767,7 +770,7 @@ export class Wnd {
|
||||||
/// #endif
|
/// #endif
|
||||||
const wnd = new Wnd(this.app);
|
const wnd = new Wnd(this.app);
|
||||||
window.siyuan.layout.centerLayout.addWnd(wnd);
|
window.siyuan.layout.centerLayout.addWnd(wnd);
|
||||||
wnd.addTab(newCenterEmptyTab());
|
wnd.addTab(newCenterEmptyTab(this.app));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import {updateHotkeyTip} from "../../protyle/util/compatibility";
|
||||||
import {openFileById} from "../../editor/util";
|
import {openFileById} from "../../editor/util";
|
||||||
import {Protyle} from "../../protyle";
|
import {Protyle} from "../../protyle";
|
||||||
import {MenuItem} from "../../menus/Menu";
|
import {MenuItem} from "../../menus/Menu";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class Backlink extends Model {
|
export class Backlink extends Model {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
@ -32,12 +33,14 @@ export class Backlink extends Model {
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
constructor(options: {
|
constructor(options: {
|
||||||
|
app: App,
|
||||||
tab: Tab,
|
tab: Tab,
|
||||||
blockId: string,
|
blockId: string,
|
||||||
rootId?: string,
|
rootId?: string,
|
||||||
type: "pin" | "local"
|
type: "pin" | "local"
|
||||||
}) {
|
}) {
|
||||||
super({
|
super({
|
||||||
|
app: options.app,
|
||||||
id: options.tab.id,
|
id: options.tab.id,
|
||||||
callback() {
|
callback() {
|
||||||
if (this.type === "local") {
|
if (this.type === "local") {
|
||||||
|
|
@ -156,6 +159,7 @@ export class Backlink extends Model {
|
||||||
},
|
},
|
||||||
ctrlClick: (element) => {
|
ctrlClick: (element) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: options.app,
|
||||||
id: element.getAttribute("data-node-id"),
|
id: element.getAttribute("data-node-id"),
|
||||||
action: [Constants.CB_GET_CONTEXT]
|
action: [Constants.CB_GET_CONTEXT]
|
||||||
});
|
});
|
||||||
|
|
@ -163,6 +167,7 @@ export class Backlink extends Model {
|
||||||
},
|
},
|
||||||
altClick(element) {
|
altClick(element) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: options.app,
|
||||||
id: element.getAttribute("data-node-id"),
|
id: element.getAttribute("data-node-id"),
|
||||||
position: "right",
|
position: "right",
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
||||||
|
|
@ -171,6 +176,7 @@ export class Backlink extends Model {
|
||||||
},
|
},
|
||||||
shiftClick(element) {
|
shiftClick(element) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: options.app,
|
||||||
id: element.getAttribute("data-node-id"),
|
id: element.getAttribute("data-node-id"),
|
||||||
position: "bottom",
|
position: "bottom",
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
||||||
|
|
@ -193,6 +199,7 @@ export class Backlink extends Model {
|
||||||
},
|
},
|
||||||
ctrlClick(element) {
|
ctrlClick(element) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: options.app,
|
||||||
id: element.getAttribute("data-node-id"),
|
id: element.getAttribute("data-node-id"),
|
||||||
action: [Constants.CB_GET_CONTEXT]
|
action: [Constants.CB_GET_CONTEXT]
|
||||||
});
|
});
|
||||||
|
|
@ -200,6 +207,7 @@ export class Backlink extends Model {
|
||||||
},
|
},
|
||||||
altClick(element) {
|
altClick(element) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: options.app,
|
||||||
id: element.getAttribute("data-node-id"),
|
id: element.getAttribute("data-node-id"),
|
||||||
position: "right",
|
position: "right",
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
||||||
|
|
@ -208,6 +216,7 @@ export class Backlink extends Model {
|
||||||
},
|
},
|
||||||
shiftClick(element) {
|
shiftClick(element) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: options.app,
|
||||||
id: element.getAttribute("data-node-id"),
|
id: element.getAttribute("data-node-id"),
|
||||||
position: "bottom",
|
position: "bottom",
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
||||||
|
|
@ -431,7 +440,7 @@ export class Backlink extends Model {
|
||||||
editorElement.setAttribute("data-defid", this.blockId);
|
editorElement.setAttribute("data-defid", this.blockId);
|
||||||
editorElement.setAttribute("data-ismention", isMention ? "true" : "false");
|
editorElement.setAttribute("data-ismention", isMention ? "true" : "false");
|
||||||
liElement.after(editorElement);
|
liElement.after(editorElement);
|
||||||
const editor = new Protyle(editorElement, {
|
const editor = new Protyle(this.app, editorElement, {
|
||||||
blockId: docId,
|
blockId: docId,
|
||||||
backlinkData: isMention ? response.data.backmentions : response.data.backlinks,
|
backlinkData: isMention ? response.data.backmentions : response.data.backlinks,
|
||||||
render: {
|
render: {
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,16 @@ import {openFileById} from "../../editor/util";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
import {hasClosestByClassName} from "../../protyle/util/hasClosest";
|
import {hasClosestByClassName} from "../../protyle/util/hasClosest";
|
||||||
import {openBookmarkMenu} from "../../menus/bookmark";
|
import {openBookmarkMenu} from "../../menus/bookmark";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class Bookmark extends Model {
|
export class Bookmark extends Model {
|
||||||
private openNodes: string[];
|
private openNodes: string[];
|
||||||
public tree: Tree;
|
public tree: Tree;
|
||||||
private element: Element;
|
private element: Element;
|
||||||
|
|
||||||
constructor(tab: Tab) {
|
constructor(app: App, tab: Tab) {
|
||||||
super({
|
super({
|
||||||
|
app,
|
||||||
id: tab.id,
|
id: tab.id,
|
||||||
msgCallback(data) {
|
msgCallback(data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|
@ -85,6 +87,7 @@ export class Bookmark extends Model {
|
||||||
if (id) {
|
if (id) {
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id,
|
id,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
zoomIn: foldResponse.data
|
zoomIn: foldResponse.data
|
||||||
|
|
@ -97,6 +100,7 @@ export class Bookmark extends Model {
|
||||||
},
|
},
|
||||||
ctrlClick(element: HTMLElement) {
|
ctrlClick(element: HTMLElement) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id: element.getAttribute("data-node-id"),
|
id: element.getAttribute("data-node-id"),
|
||||||
keepCursor: true,
|
keepCursor: true,
|
||||||
action: [Constants.CB_GET_CONTEXT]
|
action: [Constants.CB_GET_CONTEXT]
|
||||||
|
|
@ -104,6 +108,7 @@ export class Bookmark extends Model {
|
||||||
},
|
},
|
||||||
altClick(element: HTMLElement) {
|
altClick(element: HTMLElement) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id: element.getAttribute("data-node-id"),
|
id: element.getAttribute("data-node-id"),
|
||||||
position: "right",
|
position: "right",
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
||||||
|
|
@ -111,6 +116,7 @@ export class Bookmark extends Model {
|
||||||
},
|
},
|
||||||
shiftClick(element: HTMLElement) {
|
shiftClick(element: HTMLElement) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id: element.getAttribute("data-node-id"),
|
id: element.getAttribute("data-node-id"),
|
||||||
position: "bottom",
|
position: "bottom",
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import {Tab} from "../Tab";
|
import {Tab} from "../Tab";
|
||||||
import {Model} from "../Model";
|
import {Model} from "../Model";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class Custom extends Model {
|
export class Custom extends Model {
|
||||||
public element: Element;
|
public element: Element;
|
||||||
|
|
@ -11,6 +12,7 @@ export class Custom extends Model {
|
||||||
public update: () => void;
|
public update: () => void;
|
||||||
|
|
||||||
constructor(options: {
|
constructor(options: {
|
||||||
|
app: App,
|
||||||
type: string,
|
type: string,
|
||||||
tab: Tab,
|
tab: Tab,
|
||||||
data: any,
|
data: any,
|
||||||
|
|
@ -19,7 +21,7 @@ export class Custom extends Model {
|
||||||
update?: () => void,
|
update?: () => void,
|
||||||
init: () => void
|
init: () => void
|
||||||
}) {
|
}) {
|
||||||
super({id: options.tab.id});
|
super({app: options.app, id: options.tab.id});
|
||||||
this.type = options.type;
|
this.type = options.type;
|
||||||
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
|
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
|
||||||
options.tab.headElement.classList.add("item--unupdate");
|
options.tab.headElement.classList.add("item--unupdate");
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import {updateHotkeyTip} from "../../protyle/util/compatibility";
|
||||||
import {openFileById} from "../../editor/util";
|
import {openFileById} from "../../editor/util";
|
||||||
import {hasClosestByAttribute, hasClosestByTag, hasTopClosestByTag} from "../../protyle/util/hasClosest";
|
import {hasClosestByAttribute, hasClosestByTag, hasTopClosestByTag} from "../../protyle/util/hasClosest";
|
||||||
import {isTouchDevice} from "../../util/functions";
|
import {isTouchDevice} from "../../util/functions";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class Files extends Model {
|
export class Files extends Model {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
@ -24,8 +25,9 @@ export class Files extends Model {
|
||||||
private actionsElement: HTMLElement;
|
private actionsElement: HTMLElement;
|
||||||
public closeElement: HTMLElement;
|
public closeElement: HTMLElement;
|
||||||
|
|
||||||
constructor(options: { tab: Tab }) {
|
constructor(options: { tab: Tab, app: App }) {
|
||||||
super({
|
super({
|
||||||
|
app: options.app,
|
||||||
type: "filetree",
|
type: "filetree",
|
||||||
id: options.tab.id,
|
id: options.tab.id,
|
||||||
msgCallback(data) {
|
msgCallback(data) {
|
||||||
|
|
@ -198,6 +200,7 @@ export class Files extends Model {
|
||||||
if (target.tagName === "LI" && !target.getAttribute("data-opening")) {
|
if (target.tagName === "LI" && !target.getAttribute("data-opening")) {
|
||||||
target.setAttribute("data-opening", "true");
|
target.setAttribute("data-opening", "true");
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: options.app,
|
||||||
removeCurrentTab: false,
|
removeCurrentTab: false,
|
||||||
id: target.getAttribute("data-node-id"),
|
id: target.getAttribute("data-node-id"),
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
|
||||||
|
|
@ -240,13 +243,16 @@ export class Files extends Model {
|
||||||
const pathString = target.parentElement.getAttribute("data-path");
|
const pathString = target.parentElement.getAttribute("data-path");
|
||||||
if (!window.siyuan.config.readonly) {
|
if (!window.siyuan.config.readonly) {
|
||||||
if (type === "new") {
|
if (type === "new") {
|
||||||
newFile(notebookId, pathString);
|
newFile(options.app, notebookId, pathString);
|
||||||
} else if (type === "more-root") {
|
} else if (type === "more-root") {
|
||||||
initNavigationMenu(target.parentElement).popup({x: event.clientX, y: event.clientY});
|
initNavigationMenu(options.app, target.parentElement).popup({
|
||||||
|
x: event.clientX,
|
||||||
|
y: event.clientY
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type === "more-file") {
|
if (type === "more-file") {
|
||||||
initFileMenu(notebookId, pathString, target.parentElement).popup({
|
initFileMenu(options.app, notebookId, pathString, target.parentElement).popup({
|
||||||
x: event.clientX,
|
x: event.clientX,
|
||||||
y: event.clientY
|
y: event.clientY
|
||||||
});
|
});
|
||||||
|
|
@ -267,6 +273,7 @@ export class Files extends Model {
|
||||||
target.setAttribute("data-opening", "true");
|
target.setAttribute("data-opening", "true");
|
||||||
if (event.altKey && !event.metaKey && !event.ctrlKey && !event.shiftKey) {
|
if (event.altKey && !event.metaKey && !event.ctrlKey && !event.shiftKey) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: options.app,
|
||||||
id: target.getAttribute("data-node-id"),
|
id: target.getAttribute("data-node-id"),
|
||||||
position: "right",
|
position: "right",
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
|
||||||
|
|
@ -276,6 +283,7 @@ export class Files extends Model {
|
||||||
});
|
});
|
||||||
} else if (!event.altKey && !event.metaKey && !event.ctrlKey && event.shiftKey) {
|
} else if (!event.altKey && !event.metaKey && !event.ctrlKey && event.shiftKey) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: options.app,
|
||||||
id: target.getAttribute("data-node-id"),
|
id: target.getAttribute("data-node-id"),
|
||||||
position: "bottom",
|
position: "bottom",
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
|
||||||
|
|
@ -286,6 +294,7 @@ export class Files extends Model {
|
||||||
} else if (window.siyuan.config.fileTree.openFilesUseCurrentTab &&
|
} else if (window.siyuan.config.fileTree.openFilesUseCurrentTab &&
|
||||||
event.altKey && (event.metaKey || event.ctrlKey) && !event.shiftKey) {
|
event.altKey && (event.metaKey || event.ctrlKey) && !event.shiftKey) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: options.app,
|
||||||
removeCurrentTab: false,
|
removeCurrentTab: false,
|
||||||
id: target.getAttribute("data-node-id"),
|
id: target.getAttribute("data-node-id"),
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
|
||||||
|
|
@ -295,6 +304,7 @@ export class Files extends Model {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: options.app,
|
||||||
id: target.getAttribute("data-node-id"),
|
id: target.getAttribute("data-node-id"),
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
|
||||||
afterOpen() {
|
afterOpen() {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import {fetchPost} from "../../util/fetch";
|
||||||
import {isCurrentEditor, openFileById} from "../../editor/util";
|
import {isCurrentEditor, openFileById} from "../../editor/util";
|
||||||
import {updateHotkeyTip} from "../../protyle/util/compatibility";
|
import {updateHotkeyTip} from "../../protyle/util/compatibility";
|
||||||
import {openGlobalSearch} from "../../search/util";
|
import {openGlobalSearch} from "../../search/util";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
declare const vis: any;
|
declare const vis: any;
|
||||||
|
|
||||||
|
|
@ -29,12 +30,14 @@ export class Graph extends Model {
|
||||||
public type: "local" | "pin" | "global";
|
public type: "local" | "pin" | "global";
|
||||||
|
|
||||||
constructor(options: {
|
constructor(options: {
|
||||||
|
app: App
|
||||||
tab: Tab
|
tab: Tab
|
||||||
blockId?: string
|
blockId?: string
|
||||||
rootId?: string
|
rootId?: string
|
||||||
type: "local" | "pin" | "global"
|
type: "local" | "pin" | "global"
|
||||||
}) {
|
}) {
|
||||||
super({
|
super({
|
||||||
|
app: options.app,
|
||||||
id: options.tab.id,
|
id: options.tab.id,
|
||||||
callback() {
|
callback() {
|
||||||
if (this.type === "local") {
|
if (this.type === "local") {
|
||||||
|
|
@ -635,28 +638,35 @@ export class Graph extends Model {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (node.type === "textmark tag") {
|
if (node.type === "textmark tag") {
|
||||||
openGlobalSearch(`#${node.id}#`, !window.siyuan.ctrlIsPressed);
|
openGlobalSearch(this.app, `#${node.id}#`, !window.siyuan.ctrlIsPressed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (window.siyuan.shiftIsPressed) {
|
if (window.siyuan.shiftIsPressed) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: this.app,
|
||||||
id: node.id,
|
id: node.id,
|
||||||
position: "bottom",
|
position: "bottom",
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
||||||
});
|
});
|
||||||
} else if (window.siyuan.altIsPressed) {
|
} else if (window.siyuan.altIsPressed) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: this.app,
|
||||||
id: node.id,
|
id: node.id,
|
||||||
position: "right",
|
position: "right",
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
||||||
});
|
});
|
||||||
} else if (window.siyuan.ctrlIsPressed) {
|
} else if (window.siyuan.ctrlIsPressed) {
|
||||||
window.siyuan.blockPanels.push(new BlockPanel({
|
window.siyuan.blockPanels.push(new BlockPanel({
|
||||||
|
app: this.app,
|
||||||
targetElement: this.inputElement,
|
targetElement: this.inputElement,
|
||||||
nodeIds: [node.id],
|
nodeIds: [node.id],
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
openFileById({id: node.id, action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]});
|
openFileById({
|
||||||
|
app: this.app,
|
||||||
|
id: node.id,
|
||||||
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import {MenuItem} from "../../menus/Menu";
|
||||||
import {confirmDialog} from "../../dialog/confirmDialog";
|
import {confirmDialog} from "../../dialog/confirmDialog";
|
||||||
import {replaceFileName} from "../../editor/rename";
|
import {replaceFileName} from "../../editor/rename";
|
||||||
import {getDisplayName, movePathTo, pathPosix} from "../../util/pathName";
|
import {getDisplayName, movePathTo, pathPosix} from "../../util/pathName";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class Inbox extends Model {
|
export class Inbox extends Model {
|
||||||
private element: Element;
|
private element: Element;
|
||||||
|
|
@ -18,8 +19,8 @@ export class Inbox extends Model {
|
||||||
private pageCount = 1;
|
private pageCount = 1;
|
||||||
private data: { [key: string]: IInbox } = {};
|
private data: { [key: string]: IInbox } = {};
|
||||||
|
|
||||||
constructor(tab: Tab | Element) {
|
constructor(app: App, tab: Tab | Element) {
|
||||||
super({id: tab.id});
|
super({app, id: tab.id});
|
||||||
if (tab instanceof Element) {
|
if (tab instanceof Element) {
|
||||||
this.element = tab;
|
this.element = tab;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import {escapeHtml} from "../../util/escape";
|
||||||
import {unicode2Emoji} from "../../emoji";
|
import {unicode2Emoji} from "../../emoji";
|
||||||
import {onGet} from "../../protyle/util/onGet";
|
import {onGet} from "../../protyle/util/onGet";
|
||||||
import {getPreviousBlock} from "../../protyle/wysiwyg/getBlock";
|
import {getPreviousBlock} from "../../protyle/wysiwyg/getBlock";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class Outline extends Model {
|
export class Outline extends Model {
|
||||||
public tree: Tree;
|
public tree: Tree;
|
||||||
|
|
@ -22,11 +23,13 @@ export class Outline extends Model {
|
||||||
private openNodes: { [key: string]: string[] } = {};
|
private openNodes: { [key: string]: string[] } = {};
|
||||||
|
|
||||||
constructor(options: {
|
constructor(options: {
|
||||||
|
app: App,
|
||||||
tab: Tab,
|
tab: Tab,
|
||||||
blockId: string,
|
blockId: string,
|
||||||
type: "pin" | "local"
|
type: "pin" | "local"
|
||||||
}) {
|
}) {
|
||||||
super({
|
super({
|
||||||
|
app: options.app,
|
||||||
id: options.tab.id,
|
id: options.tab.id,
|
||||||
callback() {
|
callback() {
|
||||||
if (this.type === "local") {
|
if (this.type === "local") {
|
||||||
|
|
@ -101,6 +104,7 @@ export class Outline extends Model {
|
||||||
const id = element.getAttribute("data-node-id");
|
const id = element.getAttribute("data-node-id");
|
||||||
fetchPost("/api/attr/getBlockAttrs", {id}, (attrResponse) => {
|
fetchPost("/api/attr/getBlockAttrs", {id}, (attrResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: options.app,
|
||||||
id,
|
id,
|
||||||
action: attrResponse.data["heading-fold"] === "1" ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_FOCUS, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML],
|
action: attrResponse.data["heading-fold"] === "1" ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_FOCUS, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML],
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,16 @@ import {MenuItem} from "../../menus/Menu";
|
||||||
import {confirmDialog} from "../../dialog/confirmDialog";
|
import {confirmDialog} from "../../dialog/confirmDialog";
|
||||||
import {escapeHtml} from "../../util/escape";
|
import {escapeHtml} from "../../util/escape";
|
||||||
import {renameTag} from "../../util/noRelyPCFunction";
|
import {renameTag} from "../../util/noRelyPCFunction";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class Tag extends Model {
|
export class Tag extends Model {
|
||||||
private openNodes: string[];
|
private openNodes: string[];
|
||||||
public tree: Tree;
|
public tree: Tree;
|
||||||
private element: Element;
|
private element: Element;
|
||||||
|
|
||||||
constructor(tab: Tab) {
|
constructor(app: App, tab: Tab) {
|
||||||
super({
|
super({
|
||||||
|
app,
|
||||||
id: tab.id,
|
id: tab.id,
|
||||||
msgCallback(data) {
|
msgCallback(data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|
@ -78,7 +80,7 @@ export class Tag extends Model {
|
||||||
element: this.element.lastElementChild as HTMLElement,
|
element: this.element.lastElementChild as HTMLElement,
|
||||||
data: null,
|
data: null,
|
||||||
click(element: HTMLElement) {
|
click(element: HTMLElement) {
|
||||||
openGlobalSearch(`#${element.getAttribute("data-label")}#`, !window.siyuan.ctrlIsPressed);
|
openGlobalSearch(app, `#${element.getAttribute("data-label")}#`, !window.siyuan.ctrlIsPressed);
|
||||||
},
|
},
|
||||||
rightClick: (element: HTMLElement, event: MouseEvent) => {
|
rightClick: (element: HTMLElement, event: MouseEvent) => {
|
||||||
const labelName = element.getAttribute("data-label");
|
const labelName = element.getAttribute("data-label");
|
||||||
|
|
|
||||||
|
|
@ -328,29 +328,30 @@ export class Dock {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "file":
|
case "file":
|
||||||
tab = new Tab({
|
tab = new Tab({
|
||||||
callback(tab: Tab) {
|
callback: (tab: Tab) => {
|
||||||
tab.addModel(new Files({tab}));
|
tab.addModel(new Files({tab, app: this.app}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "bookmark":
|
case "bookmark":
|
||||||
tab = new Tab({
|
tab = new Tab({
|
||||||
callback(tab: Tab) {
|
callback: (tab: Tab) => {
|
||||||
tab.addModel(new Bookmark(tab));
|
tab.addModel(new Bookmark(this.app, tab));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "tag":
|
case "tag":
|
||||||
tab = new Tab({
|
tab = new Tab({
|
||||||
callback(tab: Tab) {
|
callback: (tab: Tab) => {
|
||||||
tab.addModel(new Tag(tab));
|
tab.addModel(new Tag(this.app, tab));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "outline":
|
case "outline":
|
||||||
tab = new Tab({
|
tab = new Tab({
|
||||||
callback(tab: Tab) {
|
callback: (tab: Tab) => {
|
||||||
const outline = new Outline({
|
const outline = new Outline({
|
||||||
|
app: this.app,
|
||||||
type: "pin",
|
type: "pin",
|
||||||
tab,
|
tab,
|
||||||
blockId: editor?.protyle?.block?.rootID,
|
blockId: editor?.protyle?.block?.rootID,
|
||||||
|
|
@ -364,8 +365,9 @@ export class Dock {
|
||||||
break;
|
break;
|
||||||
case "graph":
|
case "graph":
|
||||||
tab = new Tab({
|
tab = new Tab({
|
||||||
callback(tab: Tab) {
|
callback: (tab: Tab) => {
|
||||||
tab.addModel(new Graph({
|
tab.addModel(new Graph({
|
||||||
|
app: this.app,
|
||||||
tab,
|
tab,
|
||||||
blockId: editor?.protyle?.block?.rootID,
|
blockId: editor?.protyle?.block?.rootID,
|
||||||
type: "pin"
|
type: "pin"
|
||||||
|
|
@ -375,8 +377,9 @@ export class Dock {
|
||||||
break;
|
break;
|
||||||
case "globalGraph":
|
case "globalGraph":
|
||||||
tab = new Tab({
|
tab = new Tab({
|
||||||
callback(tab: Tab) {
|
callback: (tab: Tab) => {
|
||||||
tab.addModel(new Graph({
|
tab.addModel(new Graph({
|
||||||
|
app: this.app,
|
||||||
tab,
|
tab,
|
||||||
type: "global"
|
type: "global"
|
||||||
}));
|
}));
|
||||||
|
|
@ -385,8 +388,9 @@ export class Dock {
|
||||||
break;
|
break;
|
||||||
case "backlink":
|
case "backlink":
|
||||||
tab = new Tab({
|
tab = new Tab({
|
||||||
callback(tab: Tab) {
|
callback: (tab: Tab) => {
|
||||||
tab.addModel(new Backlink({
|
tab.addModel(new Backlink({
|
||||||
|
app: this.app,
|
||||||
type: "pin",
|
type: "pin",
|
||||||
tab,
|
tab,
|
||||||
blockId: editor?.protyle?.block?.rootID,
|
blockId: editor?.protyle?.block?.rootID,
|
||||||
|
|
@ -396,8 +400,8 @@ export class Dock {
|
||||||
break;
|
break;
|
||||||
case "inbox":
|
case "inbox":
|
||||||
tab = new Tab({
|
tab = new Tab({
|
||||||
callback(tab: Tab) {
|
callback: (tab: Tab) => {
|
||||||
tab.addModel(new Inbox(tab));
|
tab.addModel(new Inbox(this.app, tab));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,9 @@ import {Graph} from "./Graph";
|
||||||
import {Outline} from "./Outline";
|
import {Outline} from "./Outline";
|
||||||
import {switchWnd} from "../util";
|
import {switchWnd} from "../util";
|
||||||
import {Backlink} from "./Backlink";
|
import {Backlink} from "./Backlink";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export const openBacklink = (protyle: IProtyle) => {
|
export const openBacklink = (app: App, protyle: IProtyle) => {
|
||||||
const backlink = getAllModels().backlink.find(item => {
|
const backlink = getAllModels().backlink.find(item => {
|
||||||
if (item.blockId === protyle.block.id && item.type === "local") {
|
if (item.blockId === protyle.block.id && item.type === "local") {
|
||||||
item.parent.parent.removeTab(item.parent.id);
|
item.parent.parent.removeTab(item.parent.id);
|
||||||
|
|
@ -21,6 +22,7 @@ export const openBacklink = (protyle: IProtyle) => {
|
||||||
title: protyle.title.editElement.textContent || "Untitled",
|
title: protyle.title.editElement.textContent || "Untitled",
|
||||||
callback(tab: Tab) {
|
callback(tab: Tab) {
|
||||||
tab.addModel(new Backlink({
|
tab.addModel(new Backlink({
|
||||||
|
app,
|
||||||
type: "local",
|
type: "local",
|
||||||
tab,
|
tab,
|
||||||
// 通过搜索打开的包含上下文,但不是缩放,因此需要传 rootID https://ld246.com/article/1666786639708
|
// 通过搜索打开的包含上下文,但不是缩放,因此需要传 rootID https://ld246.com/article/1666786639708
|
||||||
|
|
@ -32,7 +34,7 @@ export const openBacklink = (protyle: IProtyle) => {
|
||||||
newWnd.addTab(tab);
|
newWnd.addTab(tab);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const openGraph = (protyle: IProtyle) => {
|
export const openGraph = (app: App, protyle: IProtyle) => {
|
||||||
const graph = getAllModels().graph.find(item => {
|
const graph = getAllModels().graph.find(item => {
|
||||||
if (item.blockId === protyle.block.id && item.type === "local") {
|
if (item.blockId === protyle.block.id && item.type === "local") {
|
||||||
item.parent.parent.removeTab(item.parent.id);
|
item.parent.parent.removeTab(item.parent.id);
|
||||||
|
|
@ -48,6 +50,7 @@ export const openGraph = (protyle: IProtyle) => {
|
||||||
title: protyle.title.editElement.textContent || "Untitled",
|
title: protyle.title.editElement.textContent || "Untitled",
|
||||||
callback(tab: Tab) {
|
callback(tab: Tab) {
|
||||||
tab.addModel(new Graph({
|
tab.addModel(new Graph({
|
||||||
|
app,
|
||||||
type: "local",
|
type: "local",
|
||||||
tab,
|
tab,
|
||||||
blockId: protyle.block.id,
|
blockId: protyle.block.id,
|
||||||
|
|
@ -58,7 +61,7 @@ export const openGraph = (protyle: IProtyle) => {
|
||||||
wnd.addTab(tab);
|
wnd.addTab(tab);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const openOutline = (protyle: IProtyle) => {
|
export const openOutline = (app: App,protyle: IProtyle) => {
|
||||||
const outlinePanel = getAllModels().outline.find(item => {
|
const outlinePanel = getAllModels().outline.find(item => {
|
||||||
if (item.blockId === protyle.block.rootID && item.type === "local") {
|
if (item.blockId === protyle.block.rootID && item.type === "local") {
|
||||||
item.parent.parent.removeTab(item.parent.id);
|
item.parent.parent.removeTab(item.parent.id);
|
||||||
|
|
@ -74,6 +77,7 @@ export const openOutline = (protyle: IProtyle) => {
|
||||||
title: protyle.title.editElement.textContent || "Untitled",
|
title: protyle.title.editElement.textContent || "Untitled",
|
||||||
callback(tab: Tab) {
|
callback(tab: Tab) {
|
||||||
tab.addModel(new Outline({
|
tab.addModel(new Outline({
|
||||||
|
app,
|
||||||
type: "local",
|
type: "local",
|
||||||
tab,
|
tab,
|
||||||
blockId: protyle.block.rootID,
|
blockId: protyle.block.rootID,
|
||||||
|
|
|
||||||
|
|
@ -65,11 +65,11 @@ export const initBar = (app: App) => {
|
||||||
let target = event.target as HTMLElement;
|
let target = event.target as HTMLElement;
|
||||||
while (!target.classList.contains("toolbar")) {
|
while (!target.classList.contains("toolbar")) {
|
||||||
if (target.id === "barBack") {
|
if (target.id === "barBack") {
|
||||||
goBack();
|
goBack(app);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
} else if (target.id === "barForward") {
|
} else if (target.id === "barForward") {
|
||||||
goForward();
|
goForward(app);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
} else if (target.id === "barSync") {
|
} else if (target.id === "barSync") {
|
||||||
|
|
@ -128,7 +128,10 @@ export const initBar = (app: App) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
} else if (target.id === "barSearch") {
|
} else if (target.id === "barSearch") {
|
||||||
openSearch(window.siyuan.config.keymap.general.globalSearch.custom);
|
openSearch({
|
||||||
|
app,
|
||||||
|
hotkey: window.siyuan.config.keymap.general.globalSearch.custom
|
||||||
|
});
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
} else if (target.id === "barZoom") {
|
} else if (target.id === "barZoom") {
|
||||||
|
|
|
||||||
|
|
@ -324,7 +324,7 @@ export const JSONToCenter = (app: App, json: ILayoutJSON, layout?: Layout | Wnd
|
||||||
}
|
}
|
||||||
} else if (json.instance === "Tab") {
|
} else if (json.instance === "Tab") {
|
||||||
if (!json.title) {
|
if (!json.title) {
|
||||||
child = newCenterEmptyTab();
|
child = newCenterEmptyTab(app);
|
||||||
} else {
|
} else {
|
||||||
let title = json.title;
|
let title = json.title;
|
||||||
if (json.lang) {
|
if (json.lang) {
|
||||||
|
|
@ -358,25 +358,29 @@ export const JSONToCenter = (app: App, json: ILayoutJSON, layout?: Layout | Wnd
|
||||||
(layout as Tab).headElement.setAttribute("data-initdata", JSON.stringify(json));
|
(layout as Tab).headElement.setAttribute("data-initdata", JSON.stringify(json));
|
||||||
} else if (json.instance === "Asset") {
|
} else if (json.instance === "Asset") {
|
||||||
(layout as Tab).addModel(new Asset({
|
(layout as Tab).addModel(new Asset({
|
||||||
|
app,
|
||||||
tab: (layout as Tab),
|
tab: (layout as Tab),
|
||||||
path: json.path,
|
path: json.path,
|
||||||
page: json.page,
|
page: json.page,
|
||||||
}));
|
}));
|
||||||
} else if (json.instance === "Backlink") {
|
} else if (json.instance === "Backlink") {
|
||||||
(layout as Tab).addModel(new Backlink({
|
(layout as Tab).addModel(new Backlink({
|
||||||
|
app,
|
||||||
tab: (layout as Tab),
|
tab: (layout as Tab),
|
||||||
blockId: json.blockId,
|
blockId: json.blockId,
|
||||||
rootId: json.rootId,
|
rootId: json.rootId,
|
||||||
type: json.type as "pin" | "local",
|
type: json.type as "pin" | "local",
|
||||||
}));
|
}));
|
||||||
} else if (json.instance === "Bookmark") {
|
} else if (json.instance === "Bookmark") {
|
||||||
(layout as Tab).addModel(new Bookmark((layout as Tab)));
|
(layout as Tab).addModel(new Bookmark(app, (layout as Tab)));
|
||||||
} else if (json.instance === "Files") {
|
} else if (json.instance === "Files") {
|
||||||
(layout as Tab).addModel(new Files({
|
(layout as Tab).addModel(new Files({
|
||||||
|
app,
|
||||||
tab: (layout as Tab),
|
tab: (layout as Tab),
|
||||||
}));
|
}));
|
||||||
} else if (json.instance === "Graph") {
|
} else if (json.instance === "Graph") {
|
||||||
(layout as Tab).addModel(new Graph({
|
(layout as Tab).addModel(new Graph({
|
||||||
|
app,
|
||||||
tab: (layout as Tab),
|
tab: (layout as Tab),
|
||||||
blockId: json.blockId,
|
blockId: json.blockId,
|
||||||
rootId: json.rootId,
|
rootId: json.rootId,
|
||||||
|
|
@ -384,20 +388,23 @@ export const JSONToCenter = (app: App, json: ILayoutJSON, layout?: Layout | Wnd
|
||||||
}));
|
}));
|
||||||
} else if (json.instance === "Outline") {
|
} else if (json.instance === "Outline") {
|
||||||
(layout as Tab).addModel(new Outline({
|
(layout as Tab).addModel(new Outline({
|
||||||
|
app,
|
||||||
tab: (layout as Tab),
|
tab: (layout as Tab),
|
||||||
blockId: json.blockId,
|
blockId: json.blockId,
|
||||||
type: json.type as "pin" | "local",
|
type: json.type as "pin" | "local",
|
||||||
}));
|
}));
|
||||||
} else if (json.instance === "Tag") {
|
} else if (json.instance === "Tag") {
|
||||||
(layout as Tab).addModel(new Tag((layout as Tab)));
|
(layout as Tab).addModel(new Tag(app, (layout as Tab)));
|
||||||
} else if (json.instance === "Search") {
|
} else if (json.instance === "Search") {
|
||||||
(layout as Tab).addModel(new Search({
|
(layout as Tab).addModel(new Search({
|
||||||
|
app,
|
||||||
tab: (layout as Tab),
|
tab: (layout as Tab),
|
||||||
config: json.config
|
config: json.config
|
||||||
}));
|
}));
|
||||||
} else if (json.instance === "Custom") {
|
} else if (json.instance === "Custom") {
|
||||||
if (json.customModelType === "siyuan-card") {
|
if (json.customModelType === "siyuan-card") {
|
||||||
(layout as Tab).addModel(newCardModel({
|
(layout as Tab).addModel(newCardModel({
|
||||||
|
app,
|
||||||
tab: (layout as Tab),
|
tab: (layout as Tab),
|
||||||
data: json.customModelData
|
data: json.customModelData
|
||||||
}));
|
}));
|
||||||
|
|
@ -454,6 +461,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
|
||||||
// 启动时 layout 中有该文档,该文档还原会在此之后,因此需有延迟
|
// 启动时 layout 中有该文档,该文档还原会在此之后,因此需有延迟
|
||||||
if (idZoomIn.id) {
|
if (idZoomIn.id) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id: idZoomIn.id,
|
id: idZoomIn.id,
|
||||||
action: idZoomIn.isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: idZoomIn.isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
zoomIn: idZoomIn.isZoomIn
|
zoomIn: idZoomIn.isZoomIn
|
||||||
|
|
@ -654,17 +662,20 @@ export const copyTab = (app: App, tab: Tab) => {
|
||||||
let model: Model;
|
let model: Model;
|
||||||
if (tab.model instanceof Editor) {
|
if (tab.model instanceof Editor) {
|
||||||
model = new Editor({
|
model = new Editor({
|
||||||
|
app,
|
||||||
tab: newTab,
|
tab: newTab,
|
||||||
blockId: tab.model.editor.protyle.block.id,
|
blockId: tab.model.editor.protyle.block.id,
|
||||||
scrollAttr: saveScroll(tab.model.editor.protyle, true)
|
scrollAttr: saveScroll(tab.model.editor.protyle, true)
|
||||||
});
|
});
|
||||||
} else if (tab.model instanceof Asset) {
|
} else if (tab.model instanceof Asset) {
|
||||||
model = new Asset({
|
model = new Asset({
|
||||||
|
app,
|
||||||
tab: newTab,
|
tab: newTab,
|
||||||
path: tab.model.path
|
path: tab.model.path
|
||||||
});
|
});
|
||||||
} else if (tab.model instanceof Graph) {
|
} else if (tab.model instanceof Graph) {
|
||||||
model = new Graph({
|
model = new Graph({
|
||||||
|
app,
|
||||||
tab: newTab,
|
tab: newTab,
|
||||||
blockId: tab.model.blockId,
|
blockId: tab.model.blockId,
|
||||||
rootId: tab.model.rootId,
|
rootId: tab.model.rootId,
|
||||||
|
|
@ -672,27 +683,31 @@ export const copyTab = (app: App, tab: Tab) => {
|
||||||
});
|
});
|
||||||
} else if (tab.model instanceof Files) {
|
} else if (tab.model instanceof Files) {
|
||||||
model = new Files({
|
model = new Files({
|
||||||
|
app,
|
||||||
tab: newTab
|
tab: newTab
|
||||||
});
|
});
|
||||||
} else if (tab.model instanceof Outline) {
|
} else if (tab.model instanceof Outline) {
|
||||||
model = new Outline({
|
model = new Outline({
|
||||||
|
app,
|
||||||
tab: newTab,
|
tab: newTab,
|
||||||
blockId: tab.model.blockId,
|
blockId: tab.model.blockId,
|
||||||
type: tab.model.type
|
type: tab.model.type
|
||||||
});
|
});
|
||||||
} else if (tab.model instanceof Backlink) {
|
} else if (tab.model instanceof Backlink) {
|
||||||
model = new Backlink({
|
model = new Backlink({
|
||||||
|
app,
|
||||||
tab: newTab,
|
tab: newTab,
|
||||||
blockId: tab.model.blockId,
|
blockId: tab.model.blockId,
|
||||||
rootId: tab.model.rootId,
|
rootId: tab.model.rootId,
|
||||||
type: tab.model.type
|
type: tab.model.type
|
||||||
});
|
});
|
||||||
} else if (tab.model instanceof Bookmark) {
|
} else if (tab.model instanceof Bookmark) {
|
||||||
model = new Bookmark(newTab);
|
model = new Bookmark(app, newTab);
|
||||||
} else if (tab.model instanceof Tag) {
|
} else if (tab.model instanceof Tag) {
|
||||||
model = new Tag(newTab);
|
model = new Tag(app, newTab);
|
||||||
} else if (tab.model instanceof Search) {
|
} else if (tab.model instanceof Search) {
|
||||||
model = new Search({
|
model = new Search({
|
||||||
|
app,
|
||||||
tab: newTab,
|
tab: newTab,
|
||||||
config: tab.model.config
|
config: tab.model.config
|
||||||
});
|
});
|
||||||
|
|
@ -700,6 +715,7 @@ export const copyTab = (app: App, tab: Tab) => {
|
||||||
const custom = tab.model as Custom;
|
const custom = tab.model as Custom;
|
||||||
if (custom.type === "siyuan-card") {
|
if (custom.type === "siyuan-card") {
|
||||||
model = newCardModel({
|
model = newCardModel({
|
||||||
|
app,
|
||||||
tab: newTab,
|
tab: newTab,
|
||||||
data: custom.data
|
data: custom.data
|
||||||
});
|
});
|
||||||
|
|
@ -720,6 +736,7 @@ export const copyTab = (app: App, tab: Tab) => {
|
||||||
initData.scrollAttr.rootId = initData.rootId;
|
initData.scrollAttr.rootId = initData.rootId;
|
||||||
}
|
}
|
||||||
model = new Editor({
|
model = new Editor({
|
||||||
|
app,
|
||||||
tab: newTab,
|
tab: newTab,
|
||||||
blockId: initData.blockId,
|
blockId: initData.blockId,
|
||||||
mode: initData.mode,
|
mode: initData.mode,
|
||||||
|
|
@ -882,7 +899,7 @@ export const addResize = (obj: Layout | Wnd) => {
|
||||||
resizeWnd(resizeElement, obj.resize);
|
resizeWnd(resizeElement, obj.resize);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const newCenterEmptyTab = () => {
|
export const newCenterEmptyTab = (app: App) => {
|
||||||
return new Tab({
|
return new Tab({
|
||||||
panel: `<div class="layout__empty b3-list">
|
panel: `<div class="layout__empty b3-list">
|
||||||
<div class="${!window.siyuan.config.readonly ? " fn__none" : ""}">
|
<div class="${!window.siyuan.config.readonly ? " fn__none" : ""}">
|
||||||
|
|
@ -927,7 +944,10 @@ export const newCenterEmptyTab = () => {
|
||||||
let target = event.target as HTMLElement;
|
let target = event.target as HTMLElement;
|
||||||
while (target && !target.isEqualNode(tab.panelElement)) {
|
while (target && !target.isEqualNode(tab.panelElement)) {
|
||||||
if (target.id === "editorEmptySearch") {
|
if (target.id === "editorEmptySearch") {
|
||||||
openSearch(window.siyuan.config.keymap.general.globalSearch.custom);
|
openSearch( {
|
||||||
|
app,
|
||||||
|
hotkey: window.siyuan.config.keymap.general.globalSearch.custom,
|
||||||
|
});
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
|
|
@ -946,12 +966,12 @@ export const newCenterEmptyTab = () => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
} else if (target.id === "editorEmptyHistory") {
|
} else if (target.id === "editorEmptyHistory") {
|
||||||
openHistory();
|
openHistory(app);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
} else if (target.id === "editorEmptyFile") {
|
} else if (target.id === "editorEmptyFile") {
|
||||||
newFile(undefined, undefined, undefined, true);
|
newFile(app, undefined, undefined, undefined, true);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ 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 {exportImage} from "../protyle/export/util";
|
import {exportImage} from "../protyle/export/util";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
const bindAttrInput = (inputElement: HTMLInputElement, confirmElement: Element) => {
|
const bindAttrInput = (inputElement: HTMLInputElement, confirmElement: Element) => {
|
||||||
inputElement.addEventListener("keydown", (event) => {
|
inputElement.addEventListener("keydown", (event) => {
|
||||||
|
|
@ -741,7 +742,7 @@ export const exportMd = (id: string) => {
|
||||||
}).element;
|
}).element;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const openMenu = (src: string, onlyMenu: boolean, showAccelerator: boolean) => {
|
export const openMenu = (app: App, src: string, onlyMenu: boolean, showAccelerator: boolean) => {
|
||||||
const submenu = [];
|
const submenu = [];
|
||||||
if (isLocalPath(src)) {
|
if (isLocalPath(src)) {
|
||||||
if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname(src)) &&
|
if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname(src)) &&
|
||||||
|
|
@ -753,7 +754,7 @@ export const openMenu = (src: string, onlyMenu: boolean, showAccelerator: boolea
|
||||||
label: window.siyuan.languages.insertRight,
|
label: window.siyuan.languages.insertRight,
|
||||||
accelerator: showAccelerator ? "Click" : "",
|
accelerator: showAccelerator ? "Click" : "",
|
||||||
click() {
|
click() {
|
||||||
openAsset(src.trim(), parseInt(getSearch("page", src)), "right");
|
openAsset(app, src.trim(), parseInt(getSearch("page", src)), "right");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/// #endif
|
/// #endif
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ export class Menus {
|
||||||
}
|
}
|
||||||
this.unselect();
|
this.unselect();
|
||||||
// navigation 根上:新建文档/文件夹/取消挂在/打开文件位置
|
// navigation 根上:新建文档/文件夹/取消挂在/打开文件位置
|
||||||
initNavigationMenu(target).popup({x: event.clientX, y: event.clientY});
|
initNavigationMenu(app, target).popup({x: event.clientX, y: event.clientY});
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -46,7 +46,7 @@ export class Menus {
|
||||||
if (dataType === "navigation-file") {
|
if (dataType === "navigation-file") {
|
||||||
this.unselect();
|
this.unselect();
|
||||||
// navigation 文件上:删除/重命名/打开文件位置/导出
|
// navigation 文件上:删除/重命名/打开文件位置/导出
|
||||||
initFileMenu(this.getDir(target), target.getAttribute("data-path"), target).popup({
|
initFileMenu(app, this.getDir(target), target.getAttribute("data-path"), target).popup({
|
||||||
x: event.clientX,
|
x: event.clientX,
|
||||||
y: event.clientY
|
y: event.clientY
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import {Files} from "../layout/dock/Files";
|
||||||
import {openNewWindowById} from "../window/openNewWindow";
|
import {openNewWindowById} from "../window/openNewWindow";
|
||||||
import {openCardByData} from "../card/openCard";
|
import {openCardByData} from "../card/openCard";
|
||||||
import {viewCards} from "../card/viewCards";
|
import {viewCards} from "../card/viewCards";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
const initMultiMenu = (selectItemElements: NodeListOf<Element>) => {
|
const initMultiMenu = (selectItemElements: NodeListOf<Element>) => {
|
||||||
const fileItemElement = Array.from(selectItemElements).find(item => {
|
const fileItemElement = Array.from(selectItemElements).find(item => {
|
||||||
|
|
@ -55,7 +56,7 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>) => {
|
||||||
return window.siyuan.menus.menu;
|
return window.siyuan.menus.menu;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initNavigationMenu = (liElement: HTMLElement) => {
|
export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
|
||||||
window.siyuan.menus.menu.remove();
|
window.siyuan.menus.menu.remove();
|
||||||
const fileElement = hasClosestByTag(liElement, "DIV");
|
const fileElement = hasClosestByTag(liElement, "DIV");
|
||||||
if (!fileElement) {
|
if (!fileElement) {
|
||||||
|
|
@ -133,7 +134,7 @@ export const initNavigationMenu = (liElement: HTMLElement) => {
|
||||||
accelerator: window.siyuan.config.keymap.editor.general.spaceRepetition.custom,
|
accelerator: window.siyuan.config.keymap.editor.general.spaceRepetition.custom,
|
||||||
click: () => {
|
click: () => {
|
||||||
fetchPost("/api/riff/getNotebookRiffDueCards", {notebook: notebookId}, (response) => {
|
fetchPost("/api/riff/getNotebookRiffDueCards", {notebook: notebookId}, (response) => {
|
||||||
openCardByData(response.data, "notebook", notebookId, name);
|
openCardByData(app, response.data, "notebook", notebookId, name);
|
||||||
});
|
});
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
closePanel();
|
closePanel();
|
||||||
|
|
@ -143,7 +144,7 @@ export const initNavigationMenu = (liElement: HTMLElement) => {
|
||||||
iconHTML: Constants.ZWSP,
|
iconHTML: Constants.ZWSP,
|
||||||
label: window.siyuan.languages.mgmt,
|
label: window.siyuan.languages.mgmt,
|
||||||
click: () => {
|
click: () => {
|
||||||
viewCards(notebookId, name, "Notebook");
|
viewCards(app, notebookId, name, "Notebook");
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
closePanel();
|
closePanel();
|
||||||
/// #endif
|
/// #endif
|
||||||
|
|
@ -157,7 +158,7 @@ export const initNavigationMenu = (liElement: HTMLElement) => {
|
||||||
click() {
|
click() {
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
||||||
popSearch({
|
popSearch(app, {
|
||||||
removed: localData.removed,
|
removed: localData.removed,
|
||||||
sort: localData.sort,
|
sort: localData.sort,
|
||||||
group: localData.group,
|
group: localData.group,
|
||||||
|
|
@ -171,7 +172,11 @@ export const initNavigationMenu = (liElement: HTMLElement) => {
|
||||||
types: Object.assign({}, localData.types)
|
types: Object.assign({}, localData.types)
|
||||||
});
|
});
|
||||||
/// #else
|
/// #else
|
||||||
openSearch(window.siyuan.config.keymap.general.search.custom, undefined, notebookId);
|
openSearch({
|
||||||
|
app,
|
||||||
|
hotkey: window.siyuan.config.keymap.general.search.custom,
|
||||||
|
notebookId,
|
||||||
|
});
|
||||||
/// #endif
|
/// #endif
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
|
|
@ -183,7 +188,7 @@ export const initNavigationMenu = (liElement: HTMLElement) => {
|
||||||
click() {
|
click() {
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
||||||
popSearch({
|
popSearch(app, {
|
||||||
removed: localData.removed,
|
removed: localData.removed,
|
||||||
sort: localData.sort,
|
sort: localData.sort,
|
||||||
group: localData.group,
|
group: localData.group,
|
||||||
|
|
@ -197,7 +202,11 @@ export const initNavigationMenu = (liElement: HTMLElement) => {
|
||||||
types: Object.assign({}, localData.types)
|
types: Object.assign({}, localData.types)
|
||||||
});
|
});
|
||||||
/// #else
|
/// #else
|
||||||
openSearch(window.siyuan.config.keymap.general.replace.custom, undefined, notebookId);
|
openSearch({
|
||||||
|
app,
|
||||||
|
hotkey: window.siyuan.config.keymap.general.replace.custom,
|
||||||
|
notebookId,
|
||||||
|
});
|
||||||
/// #endif
|
/// #endif
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
|
|
@ -267,7 +276,7 @@ export const initNavigationMenu = (liElement: HTMLElement) => {
|
||||||
return window.siyuan.menus.menu;
|
return window.siyuan.menus.menu;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initFileMenu = (notebookId: string, pathString: string, liElement: Element) => {
|
export const initFileMenu = (app: App, notebookId: string, pathString: string, liElement: Element) => {
|
||||||
window.siyuan.menus.menu.remove();
|
window.siyuan.menus.menu.remove();
|
||||||
const fileElement = hasClosestByTag(liElement, "DIV");
|
const fileElement = hasClosestByTag(liElement, "DIV");
|
||||||
if (!fileElement) {
|
if (!fileElement) {
|
||||||
|
|
@ -303,7 +312,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
|
||||||
paths.push(item.getAttribute("data-path"));
|
paths.push(item.getAttribute("data-path"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
newFile(notebookId, pathPosix().dirname(pathString), paths);
|
newFile(app, notebookId, pathPosix().dirname(pathString), paths);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
|
|
@ -319,7 +328,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
newFile(notebookId, pathPosix().dirname(pathString), paths);
|
newFile(app, notebookId, pathPosix().dirname(pathString), paths);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||||
|
|
@ -376,7 +385,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
|
||||||
accelerator: window.siyuan.config.keymap.editor.general.spaceRepetition.custom,
|
accelerator: window.siyuan.config.keymap.editor.general.spaceRepetition.custom,
|
||||||
click: () => {
|
click: () => {
|
||||||
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: id}, (response) => {
|
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: id}, (response) => {
|
||||||
openCardByData(response.data, "doc", id, name);
|
openCardByData(app, response.data, "doc", id, name);
|
||||||
});
|
});
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
closePanel();
|
closePanel();
|
||||||
|
|
@ -389,7 +398,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
|
||||||
fetchPost("/api/filetree/getHPathByID", {
|
fetchPost("/api/filetree/getHPathByID", {
|
||||||
id
|
id
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
viewCards(id, pathPosix().join(getNotebookName(notebookId), response.data), "Tree");
|
viewCards(app, id, pathPosix().join(getNotebookName(notebookId), response.data), "Tree");
|
||||||
});
|
});
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
closePanel();
|
closePanel();
|
||||||
|
|
@ -409,7 +418,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
|
||||||
path: searchPath + ".sy"
|
path: searchPath + ".sy"
|
||||||
});
|
});
|
||||||
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
||||||
popSearch({
|
popSearch(app, {
|
||||||
removed: localData.removed,
|
removed: localData.removed,
|
||||||
sort: localData.sort,
|
sort: localData.sort,
|
||||||
group: localData.group,
|
group: localData.group,
|
||||||
|
|
@ -423,7 +432,12 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
|
||||||
types: Object.assign({}, localData.types)
|
types: Object.assign({}, localData.types)
|
||||||
});
|
});
|
||||||
/// #else
|
/// #else
|
||||||
openSearch(window.siyuan.config.keymap.general.search.custom, undefined, notebookId, searchPath);
|
openSearch({
|
||||||
|
app,
|
||||||
|
hotkey: window.siyuan.config.keymap.general.search.custom,
|
||||||
|
notebookId,
|
||||||
|
searchPath
|
||||||
|
});
|
||||||
/// #endif
|
/// #endif
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
|
|
@ -439,7 +453,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
|
||||||
path: searchPath + ".sy"
|
path: searchPath + ".sy"
|
||||||
});
|
});
|
||||||
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
||||||
popSearch({
|
popSearch(app, {
|
||||||
removed: localData.removed,
|
removed: localData.removed,
|
||||||
sort: localData.sort,
|
sort: localData.sort,
|
||||||
group: localData.group,
|
group: localData.group,
|
||||||
|
|
@ -453,7 +467,12 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
|
||||||
types: Object.assign({}, localData.types)
|
types: Object.assign({}, localData.types)
|
||||||
});
|
});
|
||||||
/// #else
|
/// #else
|
||||||
openSearch(window.siyuan.config.keymap.general.replace.custom, undefined, notebookId, searchPath);
|
openSearch({
|
||||||
|
app,
|
||||||
|
hotkey: window.siyuan.config.keymap.general.replace.custom,
|
||||||
|
notebookId,
|
||||||
|
searchPath
|
||||||
|
});
|
||||||
/// #endif
|
/// #endif
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
|
|
@ -465,14 +484,14 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
|
||||||
label: window.siyuan.languages.insertRight,
|
label: window.siyuan.languages.insertRight,
|
||||||
accelerator: "⌥Click",
|
accelerator: "⌥Click",
|
||||||
click: () => {
|
click: () => {
|
||||||
openFileById({id, position: "right", action: [Constants.CB_GET_FOCUS]});
|
openFileById({app, id, position: "right", action: [Constants.CB_GET_FOCUS]});
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
icon: "iconLayoutBottom",
|
icon: "iconLayoutBottom",
|
||||||
label: window.siyuan.languages.insertBottom,
|
label: window.siyuan.languages.insertBottom,
|
||||||
accelerator: "⇧Click",
|
accelerator: "⇧Click",
|
||||||
click: () => {
|
click: () => {
|
||||||
openFileById({id, position: "bottom", action: [Constants.CB_GET_FOCUS]});
|
openFileById({app, id, position: "bottom", action: [Constants.CB_GET_FOCUS]});
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
|
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
|
||||||
|
|
@ -481,6 +500,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
|
||||||
accelerator: "⌥⌘Click",
|
accelerator: "⌥⌘Click",
|
||||||
click: () => {
|
click: () => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id, action: [Constants.CB_GET_FOCUS],
|
id, action: [Constants.CB_GET_FOCUS],
|
||||||
removeCurrentTab: false
|
removeCurrentTab: false
|
||||||
});
|
});
|
||||||
|
|
@ -501,7 +521,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
|
||||||
icon: "iconPreview",
|
icon: "iconPreview",
|
||||||
label: window.siyuan.languages.preview,
|
label: window.siyuan.languages.preview,
|
||||||
click: () => {
|
click: () => {
|
||||||
openFileById({id, mode: "preview"});
|
openFileById({app, id, mode: "preview"});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,9 @@ import {removeLink} from "../protyle/toolbar/Link";
|
||||||
import {alignImgCenter, alignImgLeft} from "../protyle/wysiwyg/commonHotkey";
|
import {alignImgCenter, alignImgLeft} from "../protyle/wysiwyg/commonHotkey";
|
||||||
import {renameTag} from "../util/noRelyPCFunction";
|
import {renameTag} from "../util/noRelyPCFunction";
|
||||||
import {hideElements} from "../protyle/ui/hideElements";
|
import {hideElements} from "../protyle/ui/hideElements";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
|
export const refMenu = (app: App, protyle: IProtyle, element: HTMLElement) => {
|
||||||
const nodeElement = hasClosestBlock(element);
|
const nodeElement = hasClosestBlock(element);
|
||||||
if (!nodeElement) {
|
if (!nodeElement) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -99,6 +100,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
|
||||||
click() {
|
click() {
|
||||||
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id: refBlockId,
|
id: refBlockId,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
zoomIn: foldResponse.data
|
zoomIn: foldResponse.data
|
||||||
|
|
@ -112,6 +114,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
|
||||||
click() {
|
click() {
|
||||||
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id: refBlockId,
|
id: refBlockId,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
|
||||||
keepCursor: true,
|
keepCursor: true,
|
||||||
|
|
@ -127,6 +130,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
|
||||||
click() {
|
click() {
|
||||||
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id: refBlockId,
|
id: refBlockId,
|
||||||
position: "right",
|
position: "right",
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
|
|
@ -142,6 +146,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
|
||||||
click() {
|
click() {
|
||||||
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id: refBlockId,
|
id: refBlockId,
|
||||||
position: "bottom",
|
position: "bottom",
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
|
|
@ -501,7 +506,7 @@ export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushB
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLElement, position: {
|
export const imgMenu = (app: App, protyle: IProtyle, range: Range, assetElement: HTMLElement, position: {
|
||||||
clientX: number,
|
clientX: number,
|
||||||
clientY: number
|
clientY: number
|
||||||
}) => {
|
}) => {
|
||||||
|
|
@ -703,7 +708,7 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
|
||||||
const imgSrc = imgElement.getAttribute("src");
|
const imgSrc = imgElement.getAttribute("src");
|
||||||
if (imgSrc) {
|
if (imgSrc) {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||||
openMenu(imgSrc, false, false);
|
openMenu(app, imgSrc, false, false);
|
||||||
}
|
}
|
||||||
window.siyuan.menus.menu.popup({x: position.clientX, y: position.clientY});
|
window.siyuan.menus.menu.popup({x: position.clientX, y: position.clientY});
|
||||||
const textElements = window.siyuan.menus.menu.element.querySelectorAll("textarea");
|
const textElements = window.siyuan.menus.menu.element.querySelectorAll("textarea");
|
||||||
|
|
@ -722,7 +727,7 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const linkMenu = (protyle: IProtyle, linkElement: HTMLElement, focusText = false) => {
|
export const linkMenu = (app: App, protyle: IProtyle, linkElement: HTMLElement, focusText = false) => {
|
||||||
window.siyuan.menus.menu.remove();
|
window.siyuan.menus.menu.remove();
|
||||||
const nodeElement = hasClosestBlock(linkElement);
|
const nodeElement = hasClosestBlock(linkElement);
|
||||||
if (!nodeElement) {
|
if (!nodeElement) {
|
||||||
|
|
@ -815,7 +820,7 @@ export const linkMenu = (protyle: IProtyle, linkElement: HTMLElement, focusText
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
if (linkAddress) {
|
if (linkAddress) {
|
||||||
openMenu(linkAddress, false, true);
|
openMenu(app, linkAddress, false, true);
|
||||||
}
|
}
|
||||||
if (linkAddress?.startsWith("siyuan://blocks/")) {
|
if (linkAddress?.startsWith("siyuan://blocks/")) {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
|
|
@ -897,7 +902,7 @@ export const linkMenu = (protyle: IProtyle, linkElement: HTMLElement, focusText
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const tagMenu = (protyle: IProtyle, tagElement: HTMLElement) => {
|
export const tagMenu = (app: App, protyle: IProtyle, tagElement: HTMLElement) => {
|
||||||
window.siyuan.menus.menu.remove();
|
window.siyuan.menus.menu.remove();
|
||||||
const nodeElement = hasClosestBlock(tagElement);
|
const nodeElement = hasClosestBlock(tagElement);
|
||||||
if (!nodeElement) {
|
if (!nodeElement) {
|
||||||
|
|
@ -953,7 +958,7 @@ export const tagMenu = (protyle: IProtyle, tagElement: HTMLElement) => {
|
||||||
accelerator: "Click",
|
accelerator: "Click",
|
||||||
icon: "iconSearch",
|
icon: "iconSearch",
|
||||||
click() {
|
click() {
|
||||||
openGlobalSearch(`#${tagElement.textContent}#`, false);
|
openGlobalSearch(app, `#${tagElement.textContent}#`, false);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
/// #endif
|
/// #endif
|
||||||
|
|
@ -1017,7 +1022,7 @@ const genImageWidthMenu = (label: string, assetElement: HTMLElement, imgElement:
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const iframeMenu = (protyle: IProtyle, nodeElement: Element) => {
|
export const iframeMenu = (app: App, protyle: IProtyle, nodeElement: Element) => {
|
||||||
const id = nodeElement.getAttribute("data-node-id");
|
const id = nodeElement.getAttribute("data-node-id");
|
||||||
const iframeElement = nodeElement.querySelector("iframe");
|
const iframeElement = nodeElement.querySelector("iframe");
|
||||||
let html = nodeElement.outerHTML;
|
let html = nodeElement.outerHTML;
|
||||||
|
|
@ -1076,12 +1081,12 @@ export const iframeMenu = (protyle: IProtyle, nodeElement: Element) => {
|
||||||
subMenus.push({
|
subMenus.push({
|
||||||
type: "separator"
|
type: "separator"
|
||||||
});
|
});
|
||||||
return subMenus.concat(openMenu(iframeSrc, true, false) as IMenu[]);
|
return subMenus.concat(openMenu(app, iframeSrc, true, false) as IMenu[]);
|
||||||
}
|
}
|
||||||
return subMenus;
|
return subMenus;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const videoMenu = (protyle: IProtyle, nodeElement: Element, type: string) => {
|
export const videoMenu = (app: App, protyle: IProtyle, nodeElement: Element, type: string) => {
|
||||||
const id = nodeElement.getAttribute("data-node-id");
|
const id = nodeElement.getAttribute("data-node-id");
|
||||||
const videoElement = nodeElement.querySelector(type === "NodeVideo" ? "video" : "audio");
|
const videoElement = nodeElement.querySelector(type === "NodeVideo" ? "video" : "audio");
|
||||||
let html = nodeElement.outerHTML;
|
let html = nodeElement.outerHTML;
|
||||||
|
|
@ -1113,7 +1118,7 @@ export const videoMenu = (protyle: IProtyle, nodeElement: Element, type: string)
|
||||||
/// #endif
|
/// #endif
|
||||||
const VideoSrc = videoElement.getAttribute("src");
|
const VideoSrc = videoElement.getAttribute("src");
|
||||||
if (VideoSrc) {
|
if (VideoSrc) {
|
||||||
return subMenus.concat(openMenu(VideoSrc, true, false) as IMenu[]);
|
return subMenus.concat(openMenu(app, VideoSrc, true, false) as IMenu[]);
|
||||||
}
|
}
|
||||||
return subMenus;
|
return subMenus;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -242,13 +242,13 @@ export const workspaceMenu = (app:App, rect: DOMRect) => {
|
||||||
label: window.siyuan.languages.spaceRepetition,
|
label: window.siyuan.languages.spaceRepetition,
|
||||||
accelerator: window.siyuan.config.keymap.general.riffCard.custom,
|
accelerator: window.siyuan.config.keymap.general.riffCard.custom,
|
||||||
click: () => {
|
click: () => {
|
||||||
openCard();
|
openCard(app);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
iconHTML: Constants.ZWSP,
|
iconHTML: Constants.ZWSP,
|
||||||
label: window.siyuan.languages.mgmt,
|
label: window.siyuan.languages.mgmt,
|
||||||
click: () => {
|
click: () => {
|
||||||
viewCards("", window.siyuan.languages.all, "");
|
viewCards(app, "", window.siyuan.languages.all, "");
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
}).element);
|
}).element);
|
||||||
|
|
@ -265,7 +265,7 @@ export const workspaceMenu = (app:App, rect: DOMRect) => {
|
||||||
icon: "iconHistory",
|
icon: "iconHistory",
|
||||||
accelerator: window.siyuan.config.keymap.general.dataHistory.custom,
|
accelerator: window.siyuan.config.keymap.general.dataHistory.custom,
|
||||||
click: () => {
|
click: () => {
|
||||||
openHistory();
|
openHistory(app);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {Tree} from "../../util/Tree";
|
||||||
import {fetchPost} from "../../util/fetch";
|
import {fetchPost} from "../../util/fetch";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
import {openMobileFileById} from "../editor";
|
import {openMobileFileById} from "../editor";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class MobileBacklinks {
|
export class MobileBacklinks {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
@ -10,7 +11,7 @@ export class MobileBacklinks {
|
||||||
private mTree: Tree;
|
private mTree: Tree;
|
||||||
public beforeLen = 10;
|
public beforeLen = 10;
|
||||||
|
|
||||||
constructor() {
|
constructor(app: App) {
|
||||||
this.element = document.querySelector('#sidebar [data-type="sidebar-backlink"]');
|
this.element = document.querySelector('#sidebar [data-type="sidebar-backlink"]');
|
||||||
this.element.innerHTML = `<div class="toolbar toolbar--border toolbar--dark">
|
this.element.innerHTML = `<div class="toolbar toolbar--border toolbar--dark">
|
||||||
<div class="fn__space"></div>
|
<div class="fn__space"></div>
|
||||||
|
|
@ -43,14 +44,14 @@ export class MobileBacklinks {
|
||||||
element: this.element.querySelector(".backlinkList") as HTMLElement,
|
element: this.element.querySelector(".backlinkList") as HTMLElement,
|
||||||
data: null,
|
data: null,
|
||||||
click(element: HTMLElement) {
|
click(element: HTMLElement) {
|
||||||
openMobileFileById(element.getAttribute("data-node-id"), [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
|
openMobileFileById(app, element.getAttribute("data-node-id"), [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.mTree = new Tree({
|
this.mTree = new Tree({
|
||||||
element: this.element.querySelector(".backlinkMList") as HTMLElement,
|
element: this.element.querySelector(".backlinkMList") as HTMLElement,
|
||||||
data: null,
|
data: null,
|
||||||
click: (element) => {
|
click: (element) => {
|
||||||
openMobileFileById(element.getAttribute("data-node-id"), [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
|
openMobileFileById(app, element.getAttribute("data-node-id"), [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.element.addEventListener("click", (event) => {
|
this.element.addEventListener("click", (event) => {
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,14 @@ import {Constants} from "../../constants";
|
||||||
import {hasClosestByClassName} from "../../protyle/util/hasClosest";
|
import {hasClosestByClassName} from "../../protyle/util/hasClosest";
|
||||||
import {openMobileFileById} from "../editor";
|
import {openMobileFileById} from "../editor";
|
||||||
import {openBookmarkMenu} from "../../menus/bookmark";
|
import {openBookmarkMenu} from "../../menus/bookmark";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class MobileBookmarks {
|
export class MobileBookmarks {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
private tree: Tree;
|
private tree: Tree;
|
||||||
private openNodes: string[];
|
private openNodes: string[];
|
||||||
|
|
||||||
constructor() {
|
constructor(app: App) {
|
||||||
this.element = document.querySelector('#sidebar [data-type="sidebar-bookmark"]');
|
this.element = document.querySelector('#sidebar [data-type="sidebar-bookmark"]');
|
||||||
this.element.innerHTML = `<div class="toolbar toolbar--border toolbar--dark">
|
this.element.innerHTML = `<div class="toolbar toolbar--border toolbar--dark">
|
||||||
<div class="fn__space"></div>
|
<div class="fn__space"></div>
|
||||||
|
|
@ -38,7 +39,7 @@ export class MobileBookmarks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||||
openMobileFileById(id, foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_FOCUS, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML]);
|
openMobileFileById(app, id, foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_FOCUS, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML]);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
blockExtHTML: '<span class="b3-list-item__action"><svg><use xlink:href="#iconMore"></use></svg></span>',
|
blockExtHTML: '<span class="b3-list-item__action"><svg><use xlink:href="#iconMore"></use></svg></span>',
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,16 @@ import {mountHelp, newNotebook} from "../../util/mount";
|
||||||
import {confirmDialog} from "../../dialog/confirmDialog";
|
import {confirmDialog} from "../../dialog/confirmDialog";
|
||||||
import {newFile} from "../../util/newFile";
|
import {newFile} from "../../util/newFile";
|
||||||
import {MenuItem} from "../../menus/Menu";
|
import {MenuItem} from "../../menus/Menu";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class MobileFiles extends Model {
|
export class MobileFiles extends Model {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
private actionsElement: HTMLElement;
|
private actionsElement: HTMLElement;
|
||||||
private closeElement: HTMLElement;
|
private closeElement: HTMLElement;
|
||||||
|
|
||||||
constructor() {
|
constructor(app: App) {
|
||||||
super({
|
super({
|
||||||
|
app,
|
||||||
id: genUUID(),
|
id: genUUID(),
|
||||||
type: "filetree",
|
type: "filetree",
|
||||||
msgCallback(data) {
|
msgCallback(data) {
|
||||||
|
|
@ -177,15 +179,15 @@ export class MobileFiles extends Model {
|
||||||
const notebookId = ulElement.getAttribute("data-url");
|
const notebookId = ulElement.getAttribute("data-url");
|
||||||
if (!window.siyuan.config.readonly) {
|
if (!window.siyuan.config.readonly) {
|
||||||
if (type === "new") {
|
if (type === "new") {
|
||||||
newFile(notebookId, pathString);
|
newFile(app, notebookId, pathString);
|
||||||
} else if (type === "more-root") {
|
} else if (type === "more-root") {
|
||||||
initNavigationMenu(target.parentElement);
|
initNavigationMenu(app, target.parentElement);
|
||||||
window.siyuan.menus.menu.fullscreen("bottom");
|
window.siyuan.menus.menu.fullscreen("bottom");
|
||||||
window.siyuan.menus.menu.element.style.zIndex = "310";
|
window.siyuan.menus.menu.element.style.zIndex = "310";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type === "more-file") {
|
if (type === "more-file") {
|
||||||
initFileMenu(notebookId, pathString, target.parentElement);
|
initFileMenu(app, notebookId, pathString, target.parentElement);
|
||||||
window.siyuan.menus.menu.fullscreen("bottom");
|
window.siyuan.menus.menu.fullscreen("bottom");
|
||||||
window.siyuan.menus.menu.element.style.zIndex = "310";
|
window.siyuan.menus.menu.element.style.zIndex = "310";
|
||||||
}
|
}
|
||||||
|
|
@ -196,7 +198,7 @@ export class MobileFiles extends Model {
|
||||||
} else if (target.tagName === "LI") {
|
} else if (target.tagName === "LI") {
|
||||||
this.setCurrent(target);
|
this.setCurrent(target);
|
||||||
if (target.getAttribute("data-type") === "navigation-file") {
|
if (target.getAttribute("data-type") === "navigation-file") {
|
||||||
openMobileFileById(target.getAttribute("data-node-id"));
|
openMobileFileById(app, target.getAttribute("data-node-id"));
|
||||||
} else if (target.getAttribute("data-type") === "navigation-root") {
|
} else if (target.getAttribute("data-type") === "navigation-root") {
|
||||||
const ulElement = hasTopClosestByTag(target, "UL");
|
const ulElement = hasTopClosestByTag(target, "UL");
|
||||||
if (ulElement) {
|
if (ulElement) {
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,14 @@ import {fetchPost} from "../../util/fetch";
|
||||||
import {openMobileFileById} from "../editor";
|
import {openMobileFileById} from "../editor";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
import {getEventName} from "../../protyle/util/compatibility";
|
import {getEventName} from "../../protyle/util/compatibility";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class MobileOutline {
|
export class MobileOutline {
|
||||||
private tree: Tree;
|
private tree: Tree;
|
||||||
private openNodes: { [key: string]: string[] } = {};
|
private openNodes: { [key: string]: string[] } = {};
|
||||||
private element: Element;
|
private element: Element;
|
||||||
|
|
||||||
constructor() {
|
constructor(app: App) {
|
||||||
this.element = document.querySelector('#sidebar [data-type="sidebar-outline"]');
|
this.element = document.querySelector('#sidebar [data-type="sidebar-outline"]');
|
||||||
this.element.innerHTML = `<div class="toolbar toolbar--border toolbar--dark">
|
this.element.innerHTML = `<div class="toolbar toolbar--border toolbar--dark">
|
||||||
<div class="fn__space"></div>
|
<div class="fn__space"></div>
|
||||||
|
|
@ -28,7 +29,7 @@ export class MobileOutline {
|
||||||
click: (element: HTMLElement) => {
|
click: (element: HTMLElement) => {
|
||||||
const id = element.getAttribute("data-node-id");
|
const id = element.getAttribute("data-node-id");
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||||
openMobileFileById(id, foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_FOCUS, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML]);
|
openMobileFileById(app, id, foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_FOCUS, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,14 @@ import {confirmDialog} from "../../dialog/confirmDialog";
|
||||||
import {escapeHtml} from "../../util/escape";
|
import {escapeHtml} from "../../util/escape";
|
||||||
import {popSearch} from "../menu/search";
|
import {popSearch} from "../menu/search";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class MobileTags {
|
export class MobileTags {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
private tree: Tree;
|
private tree: Tree;
|
||||||
private openNodes: string[];
|
private openNodes: string[];
|
||||||
|
|
||||||
constructor() {
|
constructor(app: App) {
|
||||||
this.element = document.querySelector('#sidebar [data-type="sidebar-tag"]');
|
this.element = document.querySelector('#sidebar [data-type="sidebar-tag"]');
|
||||||
this.element.innerHTML = `<div class="toolbar toolbar--border toolbar--dark">
|
this.element.innerHTML = `<div class="toolbar toolbar--border toolbar--dark">
|
||||||
<div class="fn__space"></div>
|
<div class="fn__space"></div>
|
||||||
|
|
@ -67,7 +68,7 @@ export class MobileTags {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const searchOption = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
const searchOption = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
||||||
popSearch({
|
popSearch(app, {
|
||||||
removed: searchOption.removed,
|
removed: searchOption.removed,
|
||||||
sort: searchOption.sort,
|
sort: searchOption.sort,
|
||||||
group: searchOption.group,
|
group: searchOption.group,
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,13 @@ import {pushBack} from "./util/MobileBackFoward";
|
||||||
import {setStorageVal} from "../protyle/util/compatibility";
|
import {setStorageVal} from "../protyle/util/compatibility";
|
||||||
import {showMessage} from "../dialog/message";
|
import {showMessage} from "../dialog/message";
|
||||||
import {saveScroll} from "../protyle/scroll/saveScroll";
|
import {saveScroll} from "../protyle/scroll/saveScroll";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
export const getCurrentEditor = () => {
|
export const getCurrentEditor = () => {
|
||||||
return window.siyuan.mobile.popEditor || window.siyuan.mobile.editor;
|
return window.siyuan.mobile.popEditor || window.siyuan.mobile.editor;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) => {
|
export const openMobileFileById = (app: App, id: string, action = [Constants.CB_GET_HL]) => {
|
||||||
window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id, action};
|
window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id, action};
|
||||||
setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
|
setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
|
||||||
if (window.siyuan.mobile.editor) {
|
if (window.siyuan.mobile.editor) {
|
||||||
|
|
@ -62,7 +63,7 @@ export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) =
|
||||||
});
|
});
|
||||||
window.siyuan.mobile.editor.protyle.undo.clear();
|
window.siyuan.mobile.editor.protyle.undo.clear();
|
||||||
} else {
|
} else {
|
||||||
window.siyuan.mobile.editor = new Protyle(document.getElementById("editor"), {
|
window.siyuan.mobile.editor = new Protyle(app, document.getElementById("editor"), {
|
||||||
blockId: id,
|
blockId: id,
|
||||||
action,
|
action,
|
||||||
render: {
|
render: {
|
||||||
|
|
|
||||||
|
|
@ -42,13 +42,14 @@ class App {
|
||||||
blockPanels: [],
|
blockPanels: [],
|
||||||
mobile: {},
|
mobile: {},
|
||||||
ws: new Model({
|
ws: new Model({
|
||||||
|
app: this,
|
||||||
id: genUUID(),
|
id: genUUID(),
|
||||||
type: "main",
|
type: "main",
|
||||||
msgCallback: (data)=> {
|
msgCallback: (data) => {
|
||||||
this.plugins.forEach((plugin) => {
|
this.plugins.forEach((plugin) => {
|
||||||
plugin.eventBus.emit("ws-main", data);
|
plugin.eventBus.emit("ws-main", data);
|
||||||
});
|
});
|
||||||
onMessage(data);
|
onMessage(this, data);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
@ -64,7 +65,7 @@ class App {
|
||||||
getLocalStorage(() => {
|
getLocalStorage(() => {
|
||||||
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => {
|
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => {
|
||||||
window.siyuan.languages = lauguages;
|
window.siyuan.languages = lauguages;
|
||||||
window.siyuan.menus = new Menus(siyuanApp);
|
window.siyuan.menus = new Menus(this);
|
||||||
document.title = window.siyuan.languages.siyuanNote;
|
document.title = window.siyuan.languages.siyuanNote;
|
||||||
bootSync();
|
bootSync();
|
||||||
loadAssets(confResponse.data.conf.appearance);
|
loadAssets(confResponse.data.conf.appearance);
|
||||||
|
|
@ -74,9 +75,9 @@ class App {
|
||||||
window.siyuan.user = userResponse.data;
|
window.siyuan.user = userResponse.data;
|
||||||
fetchPost("/api/system/getEmojiConf", {}, emojiResponse => {
|
fetchPost("/api/system/getEmojiConf", {}, emojiResponse => {
|
||||||
window.siyuan.emojis = emojiResponse.data as IEmoji[];
|
window.siyuan.emojis = emojiResponse.data as IEmoji[];
|
||||||
initFramework(siyuanApp);
|
initFramework(this);
|
||||||
initRightMenu();
|
initRightMenu(this);
|
||||||
loadPlugins(siyuanApp);
|
loadPlugins(this);
|
||||||
openChangelog();
|
openChangelog();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -85,7 +86,9 @@ class App {
|
||||||
});
|
});
|
||||||
document.addEventListener("touchstart", handleTouchStart, false);
|
document.addEventListener("touchstart", handleTouchStart, false);
|
||||||
document.addEventListener("touchmove", handleTouchMove, false);
|
document.addEventListener("touchmove", handleTouchMove, false);
|
||||||
document.addEventListener("touchend", handleTouchEnd, false);
|
document.addEventListener("touchend", (event) => {
|
||||||
|
handleTouchEnd(this, event);
|
||||||
|
}, false);
|
||||||
});
|
});
|
||||||
setNoteBook();
|
setNoteBook();
|
||||||
promiseTransactions();
|
promiseTransactions();
|
||||||
|
|
@ -102,7 +105,7 @@ window.showKeyboardToolbar = (height) => {
|
||||||
window.hideKeyboardToolbar = hideKeyboardToolbar;
|
window.hideKeyboardToolbar = hideKeyboardToolbar;
|
||||||
window.openFileByURL = (openURL) => {
|
window.openFileByURL = (openURL) => {
|
||||||
if (openURL && isSYProtocol(openURL)) {
|
if (openURL && isSYProtocol(openURL)) {
|
||||||
openMobileFileById(getIdFromSYProtocol(openURL),
|
openMobileFileById(siyuanApp, getIdFromSYProtocol(openURL),
|
||||||
getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
|
getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,9 @@ import {escapeHtml} from "../../util/escape";
|
||||||
import {hasClosestByClassName} from "../../protyle/util/hasClosest";
|
import {hasClosestByClassName} from "../../protyle/util/hasClosest";
|
||||||
import {openModel} from "./model";
|
import {openModel} from "./model";
|
||||||
import {openMobileFileById} from "../editor";
|
import {openMobileFileById} from "../editor";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export const getRecentDocs = () => {
|
export const getRecentDocs = (app: App) => {
|
||||||
fetchPost("/api/storage/getRecentDocs", {}, (response) => {
|
fetchPost("/api/storage/getRecentDocs", {}, (response) => {
|
||||||
let html = "";
|
let html = "";
|
||||||
response.data.forEach((item: any, index: number) => {
|
response.data.forEach((item: any, index: number) => {
|
||||||
|
|
@ -23,7 +24,7 @@ ${unicode2Emoji(item.icon || Constants.SIYUAN_IMAGE_FILE, false, "b3-list-item__
|
||||||
element.firstElementChild.addEventListener("click", (event) => {
|
element.firstElementChild.addEventListener("click", (event) => {
|
||||||
const liElement = hasClosestByClassName(event.target as HTMLElement, "b3-list-item");
|
const liElement = hasClosestByClassName(event.target as HTMLElement, "b3-list-item");
|
||||||
if (liElement) {
|
if (liElement) {
|
||||||
openMobileFileById(liElement.dataset.nodeId, [Constants.CB_GET_SCROLL]);
|
openMobileFileById(app, liElement.dataset.nodeId, [Constants.CB_GET_SCROLL]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import {openModel} from "./model";
|
||||||
import {initAbout} from "../settings/about";
|
import {initAbout} from "../settings/about";
|
||||||
import {getRecentDocs} from "./getRecentDocs";
|
import {getRecentDocs} from "./getRecentDocs";
|
||||||
import {initEditor} from "../settings/editor";
|
import {initEditor} from "../settings/editor";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export const popMenu = () => {
|
export const popMenu = () => {
|
||||||
activeBlur();
|
activeBlur();
|
||||||
|
|
@ -22,7 +23,7 @@ export const popMenu = () => {
|
||||||
document.getElementById("menu").style.transform = "translateX(0px)";
|
document.getElementById("menu").style.transform = "translateX(0px)";
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initRightMenu = () => {
|
export const initRightMenu = (app: App) => {
|
||||||
const menuElement = document.getElementById("menu");
|
const menuElement = document.getElementById("menu");
|
||||||
let accountHTML = "";
|
let accountHTML = "";
|
||||||
if (window.siyuan.user && !window.siyuan.config.readonly) {
|
if (window.siyuan.user && !window.siyuan.config.readonly) {
|
||||||
|
|
@ -118,12 +119,12 @@ export const initRightMenu = () => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
} else if (target.id === "menuSearch") {
|
} else if (target.id === "menuSearch") {
|
||||||
popSearch();
|
popSearch(app);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
} else if (target.id === "menuRecent") {
|
} else if (target.id === "menuRecent") {
|
||||||
getRecentDocs();
|
getRecentDocs(app);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
|
|
@ -164,7 +165,7 @@ export const initRightMenu = () => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
} else if (target.id === "menuCard") {
|
} else if (target.id === "menuCard") {
|
||||||
openCard();
|
openCard(app);
|
||||||
closePanel();
|
closePanel();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
@ -204,7 +205,7 @@ export const initRightMenu = () => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
} else if (target.id === "menuHistory") {
|
} else if (target.id === "menuHistory") {
|
||||||
openHistory();
|
openHistory(app);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import {newFileByName} from "../../util/newFile";
|
||||||
import {showMessage} from "../../dialog/message";
|
import {showMessage} from "../../dialog/message";
|
||||||
import {reloadProtyle} from "../../protyle/util/reload";
|
import {reloadProtyle} from "../../protyle/util/reload";
|
||||||
import {activeBlur, hideKeyboardToolbar} from "../util/keyboardToolbar";
|
import {activeBlur, hideKeyboardToolbar} from "../util/keyboardToolbar";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
const replace = (element: Element, config: ISearchOption, isAll: boolean) => {
|
const replace = (element: Element, config: ISearchOption, isAll: boolean) => {
|
||||||
if (config.method === 1 || config.method === 2) {
|
if (config.method === 1 || config.method === 2) {
|
||||||
|
|
@ -245,7 +246,7 @@ const updateSearchResult = (config: ISearchOption, element: Element) => {
|
||||||
}, Constants.TIMEOUT_INPUT);
|
}, Constants.TIMEOUT_INPUT);
|
||||||
};
|
};
|
||||||
|
|
||||||
const initSearchEvent = (element: Element, config: ISearchOption) => {
|
const initSearchEvent = (app: App, element: Element, config: ISearchOption) => {
|
||||||
const searchInputElement = document.getElementById("toolbarSearch") as HTMLInputElement;
|
const searchInputElement = document.getElementById("toolbarSearch") as HTMLInputElement;
|
||||||
searchInputElement.value = config.k || "";
|
searchInputElement.value = config.k || "";
|
||||||
searchInputElement.addEventListener("compositionend", (event: InputEvent) => {
|
searchInputElement.addEventListener("compositionend", (event: InputEvent) => {
|
||||||
|
|
@ -494,14 +495,14 @@ const initSearchEvent = (element: Element, config: ISearchOption) => {
|
||||||
break;
|
break;
|
||||||
} else if (target.classList.contains("b3-list-item")) {
|
} else if (target.classList.contains("b3-list-item")) {
|
||||||
if (target.getAttribute("data-type") === "search-new") {
|
if (target.getAttribute("data-type") === "search-new") {
|
||||||
newFileByName(searchInputElement.value);
|
newFileByName(app, searchInputElement.value);
|
||||||
} else if (target.getAttribute("data-type") === "search-item") {
|
} else if (target.getAttribute("data-type") === "search-item") {
|
||||||
const id = target.getAttribute("data-node-id");
|
const id = target.getAttribute("data-node-id");
|
||||||
if (window.siyuan.mobile.editor.protyle) {
|
if (window.siyuan.mobile.editor.protyle) {
|
||||||
preventScroll(window.siyuan.mobile.editor.protyle);
|
preventScroll(window.siyuan.mobile.editor.protyle);
|
||||||
}
|
}
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
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]);
|
openMobileFileById(app, id, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
||||||
});
|
});
|
||||||
closePanel();
|
closePanel();
|
||||||
} else if (target.querySelector(".b3-list-item__toggle")) {
|
} else if (target.querySelector(".b3-list-item__toggle")) {
|
||||||
|
|
@ -517,7 +518,7 @@ const initSearchEvent = (element: Element, config: ISearchOption) => {
|
||||||
}, false);
|
}, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const popSearch = (config = window.siyuan.storage[Constants.LOCAL_SEARCHDATA] as ISearchOption) => {
|
export const popSearch = (app: App, config = window.siyuan.storage[Constants.LOCAL_SEARCHDATA] as ISearchOption) => {
|
||||||
activeBlur();
|
activeBlur();
|
||||||
hideKeyboardToolbar();
|
hideKeyboardToolbar();
|
||||||
let includeChild = true;
|
let includeChild = true;
|
||||||
|
|
@ -575,7 +576,7 @@ export const popSearch = (config = window.siyuan.storage[Constants.LOCAL_SEARCHD
|
||||||
<div class="fn__loading fn__loading--top"><img width="120px" src="/stage/loading-pure.svg"></div>
|
<div class="fn__loading fn__loading--top"><img width="120px" src="/stage/loading-pure.svg"></div>
|
||||||
</div>`,
|
</div>`,
|
||||||
bindEvent(element) {
|
bindEvent(element) {
|
||||||
initSearchEvent(element.firstElementChild, config);
|
initSearchEvent(app, element.firstElementChild, config);
|
||||||
updateSearchResult(config, element);
|
updateSearchResult(config, element);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -52,30 +52,30 @@ export const initFramework = (app: App) => {
|
||||||
if (itemType === type) {
|
if (itemType === type) {
|
||||||
if (type === "sidebar-outline-tab") {
|
if (type === "sidebar-outline-tab") {
|
||||||
if (!outline) {
|
if (!outline) {
|
||||||
outline = new MobileOutline();
|
outline = new MobileOutline(app);
|
||||||
} else {
|
} else {
|
||||||
outline.update();
|
outline.update();
|
||||||
}
|
}
|
||||||
} else if (type === "sidebar-backlink-tab") {
|
} else if (type === "sidebar-backlink-tab") {
|
||||||
if (!backlink) {
|
if (!backlink) {
|
||||||
backlink = new MobileBacklinks();
|
backlink = new MobileBacklinks(app);
|
||||||
} else {
|
} else {
|
||||||
backlink.update();
|
backlink.update();
|
||||||
}
|
}
|
||||||
} else if (type === "sidebar-bookmark-tab") {
|
} else if (type === "sidebar-bookmark-tab") {
|
||||||
if (!bookmark) {
|
if (!bookmark) {
|
||||||
bookmark = new MobileBookmarks();
|
bookmark = new MobileBookmarks(app);
|
||||||
} else {
|
} else {
|
||||||
backlink.update();
|
backlink.update();
|
||||||
}
|
}
|
||||||
} else if (type === "sidebar-tag-tab") {
|
} else if (type === "sidebar-tag-tab") {
|
||||||
if (!tag) {
|
if (!tag) {
|
||||||
tag = new MobileTags();
|
tag = new MobileTags(app);
|
||||||
} else {
|
} else {
|
||||||
tag.update();
|
tag.update();
|
||||||
}
|
}
|
||||||
} else if (type === "sidebar-inbox-tab" && !inbox) {
|
} else if (type === "sidebar-inbox-tab" && !inbox) {
|
||||||
inbox = new Inbox(document.querySelector('#sidebar [data-type="sidebar-inbox"]'));
|
inbox = new Inbox(app, document.querySelector('#sidebar [data-type="sidebar-inbox"]'));
|
||||||
}
|
}
|
||||||
svgElement.classList.add("toolbar__icon--active");
|
svgElement.classList.add("toolbar__icon--active");
|
||||||
sidebarElement.lastElementChild.querySelector(`[data-type="${itemType.replace("-tab", "")}"]`).classList.remove("fn__none");
|
sidebarElement.lastElementChild.querySelector(`[data-type="${itemType.replace("-tab", "")}"]`).classList.remove("fn__none");
|
||||||
|
|
@ -85,7 +85,7 @@ export const initFramework = (app: App) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
window.siyuan.mobile.files = new MobileFiles();
|
window.siyuan.mobile.files = new MobileFiles(app);
|
||||||
document.getElementById("toolbarFile").addEventListener("click", () => {
|
document.getElementById("toolbarFile").addEventListener("click", () => {
|
||||||
hideKeyboardToolbar();
|
hideKeyboardToolbar();
|
||||||
activeBlur();
|
activeBlur();
|
||||||
|
|
@ -144,27 +144,27 @@ export const initFramework = (app: App) => {
|
||||||
}
|
}
|
||||||
const idZoomIn = getIdZoomInByPath();
|
const idZoomIn = getIdZoomInByPath();
|
||||||
if (idZoomIn.id) {
|
if (idZoomIn.id) {
|
||||||
openMobileFileById(idZoomIn.id,
|
openMobileFileById(app, idZoomIn.id,
|
||||||
idZoomIn.isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
|
idZoomIn.isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const localDoc = window.siyuan.storage[Constants.LOCAL_DOCINFO];
|
const localDoc = window.siyuan.storage[Constants.LOCAL_DOCINFO];
|
||||||
fetchPost("/api/block/checkBlockExist", {id: localDoc.id}, existResponse => {
|
fetchPost("/api/block/checkBlockExist", {id: localDoc.id}, existResponse => {
|
||||||
if (existResponse.data) {
|
if (existResponse.data) {
|
||||||
openMobileFileById(localDoc.id, localDoc.action);
|
openMobileFileById(app, localDoc.id, localDoc.action);
|
||||||
} else {
|
} else {
|
||||||
fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => {
|
fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => {
|
||||||
if (response.data.length !== 0) {
|
if (response.data.length !== 0) {
|
||||||
openMobileFileById(response.data[0].id, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
openMobileFileById(app, response.data[0].id, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
||||||
} else {
|
} else {
|
||||||
setEmpty();
|
setEmpty(app);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setEmpty();
|
setEmpty(app);
|
||||||
};
|
};
|
||||||
|
|
||||||
const initEditorName = () => {
|
const initEditorName = () => {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import {openMobileFileById} from "../editor";
|
import {openMobileFileById} from "../editor";
|
||||||
import {processSync, progressLoading, progressStatus, reloadSync, transactionError} from "../../dialog/processSystem";
|
import {processSync, progressLoading, progressStatus, reloadSync, transactionError} from "../../dialog/processSystem";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
const processReadonly = () => {
|
const processReadonly = () => {
|
||||||
const inputElement = document.getElementById("toolbarName") as HTMLInputElement;
|
const inputElement = document.getElementById("toolbarName") as HTMLInputElement;
|
||||||
|
|
@ -14,11 +15,11 @@ const processReadonly = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const onMessage = (data: IWebSocketData) => {
|
export const onMessage = (app: App, data: IWebSocketData) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
switch (data.cmd) {
|
switch (data.cmd) {
|
||||||
case "syncMergeResult":
|
case "syncMergeResult":
|
||||||
reloadSync(data.data);
|
reloadSync(app, data.data);
|
||||||
break;
|
break;
|
||||||
case "readonly":
|
case "readonly":
|
||||||
window.siyuan.config.editor.readOnly = data.data;
|
window.siyuan.config.editor.readOnly = data.data;
|
||||||
|
|
@ -34,10 +35,10 @@ export const onMessage = (data: IWebSocketData) => {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "createdailynote":
|
case "createdailynote":
|
||||||
openMobileFileById(data.data.id);
|
openMobileFileById(app, data.data.id);
|
||||||
break;
|
break;
|
||||||
case "openFileById":
|
case "openFileById":
|
||||||
openMobileFileById(data.data.id, [Constants.CB_GET_FOCUS]);
|
openMobileFileById(app, data.data.id, [Constants.CB_GET_FOCUS]);
|
||||||
break;
|
break;
|
||||||
case"txerr":
|
case"txerr":
|
||||||
transactionError();
|
transactionError();
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,9 @@ import {getOpenNotebookCount} from "../../util/pathName";
|
||||||
import {popSearch} from "../menu/search";
|
import {popSearch} from "../menu/search";
|
||||||
import {getRecentDocs} from "../menu/getRecentDocs";
|
import {getRecentDocs} from "../menu/getRecentDocs";
|
||||||
import {openHistory} from "../../history/history";
|
import {openHistory} from "../../history/history";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export const setEmpty = () => {
|
export const setEmpty = (app: App) => {
|
||||||
document.getElementById("toolbarName").classList.add("fn__hidden");
|
document.getElementById("toolbarName").classList.add("fn__hidden");
|
||||||
document.getElementById("toolbarEdit").classList.add("fn__hidden");
|
document.getElementById("toolbarEdit").classList.add("fn__hidden");
|
||||||
document.getElementById("editor").classList.add("fn__none");
|
document.getElementById("editor").classList.add("fn__none");
|
||||||
|
|
@ -37,27 +38,27 @@ export const setEmpty = () => {
|
||||||
let target = event.target as HTMLElement;
|
let target = event.target as HTMLElement;
|
||||||
while (target && !target.isEqualNode(emptyElement)) {
|
while (target && !target.isEqualNode(emptyElement)) {
|
||||||
if (target.id === "emptySearch") {
|
if (target.id === "emptySearch") {
|
||||||
popSearch();
|
popSearch(app);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
} else if (target.id === "emptyRecent") {
|
} else if (target.id === "emptyRecent") {
|
||||||
getRecentDocs();
|
getRecentDocs(app);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
} else if (target.id === "emptyHistory") {
|
} else if (target.id === "emptyHistory") {
|
||||||
openHistory();
|
openHistory(app);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
} else if (target.id === "emptyNewFile") {
|
} else if (target.id === "emptyNewFile") {
|
||||||
if (window.siyuan.mobile.editor) {
|
if (window.siyuan.mobile.editor) {
|
||||||
newFile(window.siyuan.mobile.editor.protyle.notebookId, window.siyuan.mobile.editor.protyle.path, undefined, true);
|
newFile(app, window.siyuan.mobile.editor.protyle.notebookId, window.siyuan.mobile.editor.protyle.path, undefined, true);
|
||||||
} else {
|
} else {
|
||||||
window.siyuan.notebooks.find(item => {
|
window.siyuan.notebooks.find(item => {
|
||||||
if (!item.closed) {
|
if (!item.closed) {
|
||||||
newFile(item.id, "/", undefined, true);
|
newFile(app, item.id, "/", undefined, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import {popMenu} from "../menu";
|
||||||
import {activeBlur, hideKeyboardToolbar} from "./keyboardToolbar";
|
import {activeBlur, hideKeyboardToolbar} from "./keyboardToolbar";
|
||||||
import {getCurrentEditor} from "../editor";
|
import {getCurrentEditor} from "../editor";
|
||||||
import {linkMenu, refMenu, tagMenu} from "../../menus/protyle";
|
import {linkMenu, refMenu, tagMenu} from "../../menus/protyle";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
let clientX: number;
|
let clientX: number;
|
||||||
let clientY: number;
|
let clientY: number;
|
||||||
|
|
@ -23,7 +24,7 @@ const popSide = (render = true) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const handleTouchEnd = (event: TouchEvent) => {
|
export const handleTouchEnd = (app: App, event: TouchEvent) => {
|
||||||
const editor = getCurrentEditor();
|
const editor = getCurrentEditor();
|
||||||
if (editor) {
|
if (editor) {
|
||||||
document.querySelectorAll(".protyle-breadcrumb__bar--hide").forEach(item => {
|
document.querySelectorAll(".protyle-breadcrumb__bar--hide").forEach(item => {
|
||||||
|
|
@ -44,13 +45,13 @@ export const handleTouchEnd = (event: TouchEvent) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (types.includes("block-ref")) {
|
if (types.includes("block-ref")) {
|
||||||
refMenu(editor.protyle, target);
|
refMenu(app, editor.protyle, target);
|
||||||
} else if (types.includes("file-annotation-ref")) {
|
} else if (types.includes("file-annotation-ref")) {
|
||||||
editor.protyle.toolbar.showFileAnnotationRef(editor.protyle, target);
|
editor.protyle.toolbar.showFileAnnotationRef(editor.protyle, target);
|
||||||
} else if (types.includes("tag")) {
|
} else if (types.includes("tag")) {
|
||||||
tagMenu(editor.protyle, target);
|
tagMenu(app, editor.protyle, target);
|
||||||
} else if (types.includes("a")) {
|
} else if (types.includes("a")) {
|
||||||
linkMenu(editor.protyle, target);
|
linkMenu(app, editor.protyle, target);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import {getDockByType, setPanelFocus} from "../layout/util";
|
||||||
import {hasClosestByAttribute} from "../protyle/util/hasClosest";
|
import {hasClosestByAttribute} from "../protyle/util/hasClosest";
|
||||||
|
|
||||||
export class Plugin {
|
export class Plugin {
|
||||||
|
private app: App;
|
||||||
public i18n: IObject;
|
public i18n: IObject;
|
||||||
public eventBus: EventBus;
|
public eventBus: EventBus;
|
||||||
public data: any = {};
|
public data: any = {};
|
||||||
|
|
@ -34,6 +35,7 @@ export class Plugin {
|
||||||
name: string,
|
name: string,
|
||||||
i18n: IObject
|
i18n: IObject
|
||||||
}) {
|
}) {
|
||||||
|
this.app = options.app;
|
||||||
this.i18n = options.i18n;
|
this.i18n = options.i18n;
|
||||||
this.name = options.name;
|
this.name = options.name;
|
||||||
this.eventBus = new EventBus(options.name);
|
this.eventBus = new EventBus(options.name);
|
||||||
|
|
@ -141,6 +143,7 @@ export class Plugin {
|
||||||
const type2 = this.name + options.type;
|
const type2 = this.name + options.type;
|
||||||
this.models[type2] = (arg: { data: any, tab: Tab }) => {
|
this.models[type2] = (arg: { data: any, tab: Tab }) => {
|
||||||
const customObj = new Custom({
|
const customObj = new Custom({
|
||||||
|
app: this.app,
|
||||||
tab: arg.tab,
|
tab: arg.tab,
|
||||||
type: type2,
|
type: type2,
|
||||||
data: arg.data,
|
data: arg.data,
|
||||||
|
|
@ -173,6 +176,7 @@ export class Plugin {
|
||||||
config: options.config,
|
config: options.config,
|
||||||
model: (arg: { tab: Tab }) => {
|
model: (arg: { tab: Tab }) => {
|
||||||
const customObj = new Custom({
|
const customObj = new Custom({
|
||||||
|
app: this.app,
|
||||||
tab: arg.tab,
|
tab: arg.tab,
|
||||||
type: type2,
|
type: type2,
|
||||||
data: options.data,
|
data: options.data,
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import {hideElements} from "../ui/hideElements";
|
||||||
import {confirmDialog} from "../../dialog/confirmDialog";
|
import {confirmDialog} from "../../dialog/confirmDialog";
|
||||||
import {reloadProtyle} from "../util/reload";
|
import {reloadProtyle} from "../util/reload";
|
||||||
import {deleteFile} from "../../editor/deleteFile";
|
import {deleteFile} from "../../editor/deleteFile";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class Breadcrumb {
|
export class Breadcrumb {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
@ -32,7 +33,7 @@ export class Breadcrumb {
|
||||||
private id: string;
|
private id: string;
|
||||||
private messageId: string;
|
private messageId: string;
|
||||||
|
|
||||||
constructor(protyle: IProtyle) {
|
constructor(app: App, protyle: IProtyle) {
|
||||||
const element = document.createElement("div");
|
const element = document.createElement("div");
|
||||||
element.className = "protyle-breadcrumb";
|
element.className = "protyle-breadcrumb";
|
||||||
const isFocus = protyle.options.action.includes(Constants.CB_GET_ALL) && !isMobile();
|
const isFocus = protyle.options.action.includes(Constants.CB_GET_ALL) && !isMobile();
|
||||||
|
|
@ -50,6 +51,7 @@ export class Breadcrumb {
|
||||||
if (protyle.options.render.breadcrumbDocName && window.siyuan.ctrlIsPressed) {
|
if (protyle.options.render.breadcrumbDocName && window.siyuan.ctrlIsPressed) {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id,
|
id,
|
||||||
action: id === protyle.block.rootID ? [Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL]
|
action: id === protyle.block.rootID ? [Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL]
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -38,11 +38,14 @@ import {isMobile} from "../../util/functions";
|
||||||
import {AIActions} from "../../ai/actions";
|
import {AIActions} from "../../ai/actions";
|
||||||
import {activeBlur} from "../../mobile/util/keyboardToolbar";
|
import {activeBlur} from "../../mobile/util/keyboardToolbar";
|
||||||
import {hideTooltip} from "../../dialog/tooltip";
|
import {hideTooltip} from "../../dialog/tooltip";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class Gutter {
|
export class Gutter {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
private app: App;
|
||||||
|
|
||||||
constructor(protyle: IProtyle) {
|
constructor(app: App, protyle: IProtyle) {
|
||||||
|
this.app = app;
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "protyle-gutters";
|
this.element.className = "protyle-gutters";
|
||||||
if (/Mac/.test(navigator.platform) || navigator.platform === "iPhone") {
|
if (/Mac/.test(navigator.platform) || navigator.platform === "iPhone") {
|
||||||
|
|
@ -701,7 +704,7 @@ export class Gutter {
|
||||||
}
|
}
|
||||||
ids.push(item.getAttribute("data-node-id"));
|
ids.push(item.getAttribute("data-node-id"));
|
||||||
});
|
});
|
||||||
makeCard(ids);
|
makeCard(this.app, ids);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
}
|
}
|
||||||
|
|
@ -1202,7 +1205,7 @@ export class Gutter {
|
||||||
type: "submenu",
|
type: "submenu",
|
||||||
icon: type === "NodeVideo" ? "iconVideo" : "iconRecord",
|
icon: type === "NodeVideo" ? "iconVideo" : "iconRecord",
|
||||||
label: window.siyuan.languages.assets,
|
label: window.siyuan.languages.assets,
|
||||||
submenu: videoMenu(protyle, nodeElement, type)
|
submenu: videoMenu(this.app, protyle, nodeElement, type)
|
||||||
}).element);
|
}).element);
|
||||||
} else if (type === "NodeIFrame" && !protyle.disabled) {
|
} else if (type === "NodeIFrame" && !protyle.disabled) {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||||
|
|
@ -1211,7 +1214,7 @@ export class Gutter {
|
||||||
type: "submenu",
|
type: "submenu",
|
||||||
icon: "iconLanguage",
|
icon: "iconLanguage",
|
||||||
label: window.siyuan.languages.assets,
|
label: window.siyuan.languages.assets,
|
||||||
submenu: iframeMenu(protyle, nodeElement)
|
submenu: iframeMenu(this.app, protyle, nodeElement)
|
||||||
}).element);
|
}).element);
|
||||||
} else if (type === "NodeHTMLBlock" && !protyle.disabled) {
|
} else if (type === "NodeHTMLBlock" && !protyle.disabled) {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||||
|
|
@ -1369,14 +1372,15 @@ export class Gutter {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
accelerator: window.siyuan.config.keymap.general.enterBack.custom,
|
accelerator: window.siyuan.config.keymap.general.enterBack.custom,
|
||||||
label: window.siyuan.languages.enterBack,
|
label: window.siyuan.languages.enterBack,
|
||||||
click() {
|
click: () => {
|
||||||
if (!protyle.block.showAll) {
|
if (!protyle.block.showAll) {
|
||||||
const ids = protyle.path.split("/");
|
const ids = protyle.path.split("/");
|
||||||
if (ids.length > 2) {
|
if (ids.length > 2) {
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
openMobileFileById(ids[ids.length - 2], [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]);
|
openMobileFileById(this.app, ids[ids.length - 2], [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]);
|
||||||
/// #else
|
/// #else
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: this.app,
|
||||||
id: ids[ids.length - 2],
|
id: ids[ids.length - 2],
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
|
||||||
});
|
});
|
||||||
|
|
@ -1482,7 +1486,7 @@ export class Gutter {
|
||||||
label: window.siyuan.languages.addToDeck,
|
label: window.siyuan.languages.addToDeck,
|
||||||
icon: "iconRiffCard",
|
icon: "iconRiffCard",
|
||||||
click() {
|
click() {
|
||||||
makeCard([nodeElement.getAttribute("data-node-id")]);
|
makeCard(this.app, [nodeElement.getAttribute("data-node-id")]);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
}
|
}
|
||||||
|
|
@ -1497,6 +1501,9 @@ export class Gutter {
|
||||||
type: "readonly",
|
type: "readonly",
|
||||||
label: `${updateHTML}${window.siyuan.languages.createdAt} ${dayjs(id.substr(0, 14)).format("YYYY-MM-DD HH:mm:ss")}`,
|
label: `${updateHTML}${window.siyuan.languages.createdAt} ${dayjs(id.substr(0, 14)).format("YYYY-MM-DD HH:mm:ss")}`,
|
||||||
}).element);
|
}).element);
|
||||||
|
this.app.plugins.forEach((plugin) => {
|
||||||
|
plugin.eventBus.emit("click-blockicon", [nodeElement]);
|
||||||
|
});
|
||||||
return window.siyuan.menus.menu;
|
return window.siyuan.menus.menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import {popSearch} from "../../mobile/menu/search";
|
||||||
import {getEventName} from "../util/compatibility";
|
import {getEventName} from "../util/compatibility";
|
||||||
import {Dialog} from "../../dialog";
|
import {Dialog} from "../../dialog";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class Background {
|
export class Background {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
@ -22,7 +23,7 @@ export class Background {
|
||||||
private tagsElement: HTMLElement;
|
private tagsElement: HTMLElement;
|
||||||
private transparentData = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
|
private transparentData = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
|
||||||
|
|
||||||
constructor(protyle: IProtyle) {
|
constructor(app: App, protyle: IProtyle) {
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "protyle-background";
|
this.element.className = "protyle-background";
|
||||||
this.element.innerHTML = `<div class="protyle-background__img">
|
this.element.innerHTML = `<div class="protyle-background__img">
|
||||||
|
|
@ -331,10 +332,10 @@ export class Background {
|
||||||
break;
|
break;
|
||||||
} else if (type === "open-search") {
|
} else if (type === "open-search") {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openGlobalSearch(`#${target.textContent}#`, !window.siyuan.ctrlIsPressed);
|
openGlobalSearch(app, `#${target.textContent}#`, !window.siyuan.ctrlIsPressed);
|
||||||
/// #else
|
/// #else
|
||||||
const searchOption = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
const searchOption = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
||||||
popSearch({
|
popSearch(app, {
|
||||||
removed: searchOption.removed,
|
removed: searchOption.removed,
|
||||||
sort: searchOption.sort,
|
sort: searchOption.sort,
|
||||||
group: searchOption.group,
|
group: searchOption.group,
|
||||||
|
|
|
||||||
|
|
@ -36,13 +36,16 @@ import {makeCard, quickMakeCard} from "../../card/makeCard";
|
||||||
import {viewCards} from "../../card/viewCards";
|
import {viewCards} from "../../card/viewCards";
|
||||||
import {getNotebookName, pathPosix} from "../../util/pathName";
|
import {getNotebookName, pathPosix} from "../../util/pathName";
|
||||||
import {commonClick} from "../wysiwyg/commonClick";
|
import {commonClick} from "../wysiwyg/commonClick";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class Title {
|
export class Title {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
public editElement: HTMLElement;
|
public editElement: HTMLElement;
|
||||||
private timeout: number;
|
private timeout: number;
|
||||||
|
private app: App;
|
||||||
|
|
||||||
constructor(protyle: IProtyle) {
|
constructor(app: App, protyle: IProtyle) {
|
||||||
|
this.app = app;
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "protyle-title";
|
this.element.className = "protyle-title";
|
||||||
if (window.siyuan.config.editor.displayBookmarkIcon) {
|
if (window.siyuan.config.editor.displayBookmarkIcon) {
|
||||||
|
|
@ -90,13 +93,14 @@ export class Title {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commonHotkey(protyle, event)) {
|
if (commonHotkey(app, protyle, event)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (matchHotKey(window.siyuan.config.keymap.general.enterBack.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.general.enterBack.custom, event)) {
|
||||||
const ids = protyle.path.split("/");
|
const ids = protyle.path.split("/");
|
||||||
if (ids.length > 2) {
|
if (ids.length > 2) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id: ids[ids.length - 2],
|
id: ids[ids.length - 2],
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
|
||||||
});
|
});
|
||||||
|
|
@ -264,7 +268,7 @@ export class Title {
|
||||||
fetchPost("/api/block/getDocInfo", {
|
fetchPost("/api/block/getDocInfo", {
|
||||||
id: protyle.block.rootID
|
id: protyle.block.rootID
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
commonClick(event, protyle, response.data.ial);
|
commonClick(app, event, protyle, response.data.ial);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -330,7 +334,7 @@ export class Title {
|
||||||
label: window.siyuan.languages.outline,
|
label: window.siyuan.languages.outline,
|
||||||
accelerator: window.siyuan.config.keymap.editor.general.outline.custom,
|
accelerator: window.siyuan.config.keymap.editor.general.outline.custom,
|
||||||
click: () => {
|
click: () => {
|
||||||
openOutline(protyle);
|
openOutline(this.app, protyle);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
|
|
@ -338,7 +342,7 @@ export class Title {
|
||||||
label: window.siyuan.languages.backlinks,
|
label: window.siyuan.languages.backlinks,
|
||||||
accelerator: window.siyuan.config.keymap.editor.general.backlinks.custom,
|
accelerator: window.siyuan.config.keymap.editor.general.backlinks.custom,
|
||||||
click: () => {
|
click: () => {
|
||||||
openBacklink(protyle);
|
openBacklink(this.app, protyle);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
|
|
@ -346,7 +350,7 @@ export class Title {
|
||||||
label: window.siyuan.languages.graphView,
|
label: window.siyuan.languages.graphView,
|
||||||
accelerator: window.siyuan.config.keymap.editor.general.graphView.custom,
|
accelerator: window.siyuan.config.keymap.editor.general.graphView.custom,
|
||||||
click: () => {
|
click: () => {
|
||||||
openGraph(protyle);
|
openGraph(this.app, protyle);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||||
|
|
@ -363,7 +367,7 @@ export class Title {
|
||||||
accelerator: window.siyuan.config.keymap.editor.general.spaceRepetition.custom,
|
accelerator: window.siyuan.config.keymap.editor.general.spaceRepetition.custom,
|
||||||
click: () => {
|
click: () => {
|
||||||
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: protyle.block.rootID}, (response) => {
|
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: protyle.block.rootID}, (response) => {
|
||||||
openCardByData(response.data, "doc", protyle.block.rootID, this.editElement.textContent);
|
openCardByData(this.app, response.data, "doc", protyle.block.rootID, this.editElement.textContent);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -373,7 +377,7 @@ export class Title {
|
||||||
fetchPost("/api/filetree/getHPathByID", {
|
fetchPost("/api/filetree/getHPathByID", {
|
||||||
id: protyle.block.rootID
|
id: protyle.block.rootID
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
viewCards(protyle.block.rootID, pathPosix().join(getNotebookName(protyle.notebookId), (response.data)), "Tree");
|
viewCards(this.app, protyle.block.rootID, pathPosix().join(getNotebookName(protyle.notebookId), (response.data)), "Tree");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -389,7 +393,7 @@ export class Title {
|
||||||
iconHTML: Constants.ZWSP,
|
iconHTML: Constants.ZWSP,
|
||||||
label: window.siyuan.languages.addToDeck,
|
label: window.siyuan.languages.addToDeck,
|
||||||
click: () => {
|
click: () => {
|
||||||
makeCard([protyle.block.rootID]);
|
makeCard(this.app, [protyle.block.rootID]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,17 +32,20 @@ import {processRender} from "../util/processCode";
|
||||||
import {AIChat} from "../../ai/chat";
|
import {AIChat} from "../../ai/chat";
|
||||||
import {isMobile} from "../../util/functions";
|
import {isMobile} from "../../util/functions";
|
||||||
import {isCtrl} from "../util/compatibility";
|
import {isCtrl} from "../util/compatibility";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class Hint {
|
export class Hint {
|
||||||
public timeId: number;
|
public timeId: number;
|
||||||
public element: HTMLDivElement;
|
public element: HTMLDivElement;
|
||||||
public enableSlash = true;
|
public enableSlash = true;
|
||||||
private enableEmoji = true;
|
private enableEmoji = true;
|
||||||
|
private app: App;
|
||||||
public enableExtend = false;
|
public enableExtend = false;
|
||||||
public splitChar = "";
|
public splitChar = "";
|
||||||
public lastIndex = -1;
|
public lastIndex = -1;
|
||||||
|
|
||||||
constructor(protyle: IProtyle) {
|
constructor(app: App, protyle: IProtyle) {
|
||||||
|
this.app = app;
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.setAttribute("data-close", "false");
|
this.element.setAttribute("data-close", "false");
|
||||||
// height 402 根据 .emojis max-height+8 得来
|
// height 402 根据 .emojis max-height+8 得来
|
||||||
|
|
@ -577,9 +580,10 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
||||||
}, () => {
|
}, () => {
|
||||||
insertHTML(`<span data-type="block-ref" data-id="${newSubDocId}" data-subtype="d">Untitled</span>`, protyle);
|
insertHTML(`<span data-type="block-ref" data-id="${newSubDocId}" data-subtype="d">Untitled</span>`, protyle);
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
openMobileFileById(newSubDocId, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
openMobileFileById(this.app, newSubDocId, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
||||||
/// #else
|
/// #else
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: this.app,
|
||||||
id: newSubDocId,
|
id: newSubDocId,
|
||||||
action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]
|
action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]
|
||||||
});
|
});
|
||||||
|
|
@ -645,7 +649,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const rect = imgElement.getBoundingClientRect();
|
const rect = imgElement.getBoundingClientRect();
|
||||||
imgMenu(protyle, range, imgElement, {
|
imgMenu(this.app, protyle, range, imgElement, {
|
||||||
clientX: rect.left,
|
clientX: rect.left,
|
||||||
clientY: rect.top
|
clientY: rect.top
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -28,17 +28,20 @@ import {renderBacklink} from "./wysiwyg/renderBacklink";
|
||||||
import {setEmpty} from "../mobile/util/setEmpty";
|
import {setEmpty} from "../mobile/util/setEmpty";
|
||||||
import {resize} from "./util/resize";
|
import {resize} from "./util/resize";
|
||||||
import {getDocByScroll} from "./scroll/saveScroll";
|
import {getDocByScroll} from "./scroll/saveScroll";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
export class Protyle {
|
export class Protyle {
|
||||||
|
|
||||||
public readonly version: string;
|
public readonly version: string;
|
||||||
public protyle: IProtyle;
|
public protyle: IProtyle;
|
||||||
|
private app: App;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id 要挂载 Protyle 的元素或者元素 ID。
|
* @param id 要挂载 Protyle 的元素或者元素 ID。
|
||||||
* @param options Protyle 参数
|
* @param options Protyle 参数
|
||||||
*/
|
*/
|
||||||
constructor(id: HTMLElement, options?: IOptions) {
|
constructor(app: App, id: HTMLElement, options?: IOptions) {
|
||||||
|
this.app = app;
|
||||||
this.version = Constants.SIYUAN_VERSION;
|
this.version = Constants.SIYUAN_VERSION;
|
||||||
const getOptions = new Options(options);
|
const getOptions = new Options(options);
|
||||||
const mergedOptions = getOptions.merge();
|
const mergedOptions = getOptions.merge();
|
||||||
|
|
@ -53,17 +56,17 @@ export class Protyle {
|
||||||
block: {},
|
block: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
this.protyle.hint = new Hint(this.protyle);
|
this.protyle.hint = new Hint(app, this.protyle);
|
||||||
if (mergedOptions.render.breadcrumb) {
|
if (mergedOptions.render.breadcrumb) {
|
||||||
this.protyle.breadcrumb = new Breadcrumb(this.protyle);
|
this.protyle.breadcrumb = new Breadcrumb(app, this.protyle);
|
||||||
}
|
}
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
if (mergedOptions.render.title) {
|
if (mergedOptions.render.title) {
|
||||||
this.protyle.title = new Title(this.protyle);
|
this.protyle.title = new Title(app, this.protyle);
|
||||||
}
|
}
|
||||||
/// #endif
|
/// #endif
|
||||||
if (mergedOptions.render.background) {
|
if (mergedOptions.render.background) {
|
||||||
this.protyle.background = new Background(this.protyle);
|
this.protyle.background = new Background(app, this.protyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.protyle.element.innerHTML = "";
|
this.protyle.element.innerHTML = "";
|
||||||
|
|
@ -72,11 +75,11 @@ export class Protyle {
|
||||||
this.protyle.element.appendChild(this.protyle.breadcrumb.element.parentElement);
|
this.protyle.element.appendChild(this.protyle.breadcrumb.element.parentElement);
|
||||||
}
|
}
|
||||||
this.protyle.undo = new Undo();
|
this.protyle.undo = new Undo();
|
||||||
this.protyle.wysiwyg = new WYSIWYG(this.protyle);
|
this.protyle.wysiwyg = new WYSIWYG(app, this.protyle);
|
||||||
this.protyle.toolbar = new Toolbar(this.protyle);
|
this.protyle.toolbar = new Toolbar(app, this.protyle);
|
||||||
this.protyle.scroll = new Scroll(this.protyle); // 不能使用 render.scroll 来判读是否初始化,除非重构后面用到的相关变量
|
this.protyle.scroll = new Scroll(this.protyle); // 不能使用 render.scroll 来判读是否初始化,除非重构后面用到的相关变量
|
||||||
if (this.protyle.options.render.gutter) {
|
if (this.protyle.options.render.gutter) {
|
||||||
this.protyle.gutter = new Gutter(this.protyle);
|
this.protyle.gutter = new Gutter(app, this.protyle);
|
||||||
}
|
}
|
||||||
if (mergedOptions.upload.url || mergedOptions.upload.handler) {
|
if (mergedOptions.upload.url || mergedOptions.upload.handler) {
|
||||||
this.protyle.upload = new Upload();
|
this.protyle.upload = new Upload();
|
||||||
|
|
@ -85,6 +88,7 @@ export class Protyle {
|
||||||
this.init();
|
this.init();
|
||||||
if (!mergedOptions.action.includes(Constants.CB_GET_HISTORY)) {
|
if (!mergedOptions.action.includes(Constants.CB_GET_HISTORY)) {
|
||||||
this.protyle.ws = new Model({
|
this.protyle.ws = new Model({
|
||||||
|
app,
|
||||||
id: this.protyle.id,
|
id: this.protyle.id,
|
||||||
type: "protyle",
|
type: "protyle",
|
||||||
msgCallback: (data) => {
|
msgCallback: (data) => {
|
||||||
|
|
@ -170,7 +174,7 @@ export class Protyle {
|
||||||
case "unmount":
|
case "unmount":
|
||||||
if (this.protyle.notebookId === data.data.box) {
|
if (this.protyle.notebookId === data.data.box) {
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
setEmpty();
|
setEmpty(app);
|
||||||
/// #else
|
/// #else
|
||||||
if (this.protyle.model) {
|
if (this.protyle.model) {
|
||||||
this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false, false);
|
this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false, false);
|
||||||
|
|
@ -181,7 +185,7 @@ export class Protyle {
|
||||||
case "removeDoc":
|
case "removeDoc":
|
||||||
if (data.data.ids.includes(this.protyle.block.rootID)) {
|
if (data.data.ids.includes(this.protyle.block.rootID)) {
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
setEmpty();
|
setEmpty(app);
|
||||||
/// #else
|
/// #else
|
||||||
if (this.protyle.model) {
|
if (this.protyle.model) {
|
||||||
this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false, false);
|
this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false, false);
|
||||||
|
|
@ -325,7 +329,7 @@ export class Protyle {
|
||||||
sanitize: this.protyle.options.preview.markdown.sanitize,
|
sanitize: this.protyle.options.preview.markdown.sanitize,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.protyle.preview = new Preview(this.protyle);
|
this.protyle.preview = new Preview(this.app, this.protyle);
|
||||||
|
|
||||||
initUI(this.protyle);
|
initUI(this.protyle);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,14 @@ 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 {App} from "../../index";
|
||||||
|
|
||||||
export class Preview {
|
export class Preview {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
public previewElement: HTMLElement;
|
public previewElement: HTMLElement;
|
||||||
private mdTimeoutId: number;
|
private mdTimeoutId: number;
|
||||||
|
|
||||||
constructor(protyle: IProtyle) {
|
constructor(app: App, protyle: IProtyle) {
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "protyle-preview fn__none";
|
this.element.className = "protyle-preview fn__none";
|
||||||
|
|
||||||
|
|
@ -55,7 +56,7 @@ export class Preview {
|
||||||
if (isLocalPath(linkAddress)) {
|
if (isLocalPath(linkAddress)) {
|
||||||
/// #if !MOBILE
|
/// #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(app, linkAddress.split("?page")[0], parseInt(getSearch("page", linkAddress)));
|
||||||
} else {
|
} else {
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
openBy(linkAddress, "folder");
|
openBy(linkAddress, "folder");
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,12 @@ import {hasClosestBlock, hasClosestByAttribute} from "../util/hasClosest";
|
||||||
import {focusByRange, focusByWbr} from "../util/selection";
|
import {focusByRange, focusByWbr} from "../util/selection";
|
||||||
import {readText} from "../util/compatibility";
|
import {readText} from "../util/compatibility";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class Link extends ToolbarItem {
|
export class Link extends ToolbarItem {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
||||||
constructor(protyle: IProtyle, menuItem: IMenuItem) {
|
constructor(app: App, protyle: IProtyle, menuItem: IMenuItem) {
|
||||||
super(protyle, menuItem);
|
super(protyle, menuItem);
|
||||||
// 不能用 getEventName,否则会导致光标位置变动到点击的文档中
|
// 不能用 getEventName,否则会导致光标位置变动到点击的文档中
|
||||||
this.element.addEventListener("click", async (event: MouseEvent & { changedTouches: MouseEvent[] }) => {
|
this.element.addEventListener("click", async (event: MouseEvent & { changedTouches: MouseEvent[] }) => {
|
||||||
|
|
@ -22,7 +23,7 @@ export class Link extends ToolbarItem {
|
||||||
}
|
}
|
||||||
const aElement = hasClosestByAttribute(range.startContainer, "data-type", "a");
|
const aElement = hasClosestByAttribute(range.startContainer, "data-type", "a");
|
||||||
if (aElement) {
|
if (aElement) {
|
||||||
linkMenu(protyle, aElement);
|
linkMenu(app, protyle, aElement);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ import {mathRender} from "../markdown/mathRender";
|
||||||
import {linkMenu} from "../../menus/protyle";
|
import {linkMenu} from "../../menus/protyle";
|
||||||
import {addScript} from "../util/addScript";
|
import {addScript} from "../util/addScript";
|
||||||
import {confirmDialog} from "../../dialog/confirmDialog";
|
import {confirmDialog} from "../../dialog/confirmDialog";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class Toolbar {
|
export class Toolbar {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
@ -49,10 +50,11 @@ export class Toolbar {
|
||||||
public subElementCloseCB: () => void;
|
public subElementCloseCB: () => void;
|
||||||
public range: Range;
|
public range: Range;
|
||||||
private toolbarHeight: number;
|
private toolbarHeight: number;
|
||||||
|
private app: App;
|
||||||
|
|
||||||
constructor(protyle: IProtyle) {
|
constructor(app: App, protyle: IProtyle) {
|
||||||
const options = protyle.options;
|
const options = protyle.options;
|
||||||
|
this.app = app;
|
||||||
const element = document.createElement("div");
|
const element = document.createElement("div");
|
||||||
element.className = "protyle-toolbar fn__none";
|
element.className = "protyle-toolbar fn__none";
|
||||||
this.element = element;
|
this.element = element;
|
||||||
|
|
@ -224,7 +226,7 @@ export class Toolbar {
|
||||||
menuItemObj = new Font(protyle, menuItem);
|
menuItemObj = new Font(protyle, menuItem);
|
||||||
break;
|
break;
|
||||||
case "a":
|
case "a":
|
||||||
menuItemObj = new Link(protyle, menuItem);
|
menuItemObj = new Link(this.app, protyle, menuItem);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!menuItemObj) {
|
if (!menuItemObj) {
|
||||||
|
|
@ -500,23 +502,23 @@ export class Toolbar {
|
||||||
} else if (type === "block-ref" && (types.includes("a") || types.includes("file-annotation-ref"))) {
|
} else if (type === "block-ref" && (types.includes("a") || types.includes("file-annotation-ref"))) {
|
||||||
// 虚拟引用和链接/标注不能同时存在
|
// 虚拟引用和链接/标注不能同时存在
|
||||||
types.find((item, index) => {
|
types.find((item, index) => {
|
||||||
if (item === "a"||item === "file-annotation-ref") {
|
if (item === "a" || item === "file-annotation-ref") {
|
||||||
types.splice(index, 1);
|
types.splice(index, 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (type === "a" && (types.includes("block-ref")|| types.includes("file-annotation-ref"))) {
|
} else if (type === "a" && (types.includes("block-ref") || types.includes("file-annotation-ref"))) {
|
||||||
// 链接和引用/标注不能同时存在
|
// 链接和引用/标注不能同时存在
|
||||||
types.find((item, index) => {
|
types.find((item, index) => {
|
||||||
if (item === "block-ref"||item === "file-annotation-ref") {
|
if (item === "block-ref" || item === "file-annotation-ref") {
|
||||||
types.splice(index, 1);
|
types.splice(index, 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (type === "file-annotation-ref" && (types.includes("block-ref")|| types.includes("a"))) {
|
} else if (type === "file-annotation-ref" && (types.includes("block-ref") || types.includes("a"))) {
|
||||||
// 引用和链接/标注不能同时存在
|
// 引用和链接/标注不能同时存在
|
||||||
types.find((item, index) => {
|
types.find((item, index) => {
|
||||||
if (item === "block-ref"||item === "a") {
|
if (item === "block-ref" || item === "a") {
|
||||||
types.splice(index, 1);
|
types.splice(index, 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -728,7 +730,7 @@ export class Toolbar {
|
||||||
const aElement = newNodes[0] as HTMLElement;
|
const aElement = newNodes[0] as HTMLElement;
|
||||||
if (aElement.textContent.replace(Constants.ZWSP, "") === "" || !aElement.getAttribute("data-href")) {
|
if (aElement.textContent.replace(Constants.ZWSP, "") === "" || !aElement.getAttribute("data-href")) {
|
||||||
needFocus = false;
|
needFocus = false;
|
||||||
linkMenu(protyle, aElement, aElement.getAttribute("data-href") ? true : false);
|
linkMenu(this.app, protyle, aElement, aElement.getAttribute("data-href") ? true : false);
|
||||||
} else {
|
} else {
|
||||||
this.range.collapse(false);
|
this.range.collapse(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,9 @@ import {openAttr, openFileAttr} from "../../menus/commonMenuItem";
|
||||||
import {openGlobalSearch} from "../../search/util";
|
import {openGlobalSearch} from "../../search/util";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {isMobile} from "../../util/functions";
|
import {isMobile} from "../../util/functions";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export const commonClick = (event: MouseEvent & {
|
export const commonClick = (app: App, event: MouseEvent & {
|
||||||
target: HTMLElement
|
target: HTMLElement
|
||||||
}, protyle: IProtyle, data?:IObject) => {
|
}, protyle: IProtyle, data?:IObject) => {
|
||||||
const isM = isMobile();
|
const isM = isMobile();
|
||||||
|
|
@ -13,7 +14,7 @@ export const commonClick = (event: MouseEvent & {
|
||||||
if (attrBookmarkElement) {
|
if (attrBookmarkElement) {
|
||||||
if (!isM && (event.ctrlKey || event.metaKey)) {
|
if (!isM && (event.ctrlKey || event.metaKey)) {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openGlobalSearch(attrBookmarkElement.textContent.trim(), true);
|
openGlobalSearch(app, attrBookmarkElement.textContent.trim(), true);
|
||||||
/// #endif
|
/// #endif
|
||||||
} else {
|
} else {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|
@ -30,7 +31,7 @@ export const commonClick = (event: MouseEvent & {
|
||||||
if (attrNameElement) {
|
if (attrNameElement) {
|
||||||
if (!isM && (event.ctrlKey || event.metaKey)) {
|
if (!isM && (event.ctrlKey || event.metaKey)) {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openGlobalSearch(attrNameElement.textContent.trim(), true);
|
openGlobalSearch(app, attrNameElement.textContent.trim(), true);
|
||||||
/// #endif
|
/// #endif
|
||||||
} else {
|
} else {
|
||||||
if (data ) {
|
if (data ) {
|
||||||
|
|
@ -47,7 +48,7 @@ export const commonClick = (event: MouseEvent & {
|
||||||
if (attrAliasElement) {
|
if (attrAliasElement) {
|
||||||
if (!isM && (event.ctrlKey || event.metaKey)) {
|
if (!isM && (event.ctrlKey || event.metaKey)) {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openGlobalSearch(attrAliasElement.textContent.trim(), true);
|
openGlobalSearch(app, attrAliasElement.textContent.trim(), true);
|
||||||
/// #endif
|
/// #endif
|
||||||
} else {
|
} else {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|
@ -64,7 +65,7 @@ export const commonClick = (event: MouseEvent & {
|
||||||
if (attrMemoElement) {
|
if (attrMemoElement) {
|
||||||
if (!isM && (event.ctrlKey || event.metaKey)) {
|
if (!isM && (event.ctrlKey || event.metaKey)) {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openGlobalSearch(attrMemoElement.getAttribute("aria-label").trim(), true);
|
openGlobalSearch(app, attrMemoElement.getAttribute("aria-label").trim(), true);
|
||||||
/// #endif
|
/// #endif
|
||||||
} else {
|
} else {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,9 @@ import {transaction, updateTransaction} from "./transaction";
|
||||||
import {onGet} from "../util/onGet";
|
import {onGet} from "../util/onGet";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
import * as dayjs from "dayjs";
|
import * as dayjs from "dayjs";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent) => {
|
export const commonHotkey = (app: App, protyle: IProtyle, event: KeyboardEvent) => {
|
||||||
const target = event.target as HTMLElement;
|
const target = event.target as HTMLElement;
|
||||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) {
|
||||||
fetchPost("/api/filetree/getHPathByID", {
|
fetchPost("/api/filetree/getHPathByID", {
|
||||||
|
|
@ -51,20 +52,20 @@ export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent) => {
|
||||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
openBacklink(protyle);
|
openBacklink(app, protyle);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.graphView.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.graphView.custom, event)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
openGraph(protyle);
|
openGraph(app, protyle);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.outline.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.outline.custom, event)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const offset = getSelectionOffset(target);
|
const offset = getSelectionOffset(target);
|
||||||
openOutline(protyle);
|
openOutline(app, protyle);
|
||||||
// switchWnd 后,range会被清空,需要重新设置
|
// switchWnd 后,range会被清空,需要重新设置
|
||||||
focusByOffset(target, offset.start, offset.end);
|
focusByOffset(target, offset.start, offset.end);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -66,14 +66,17 @@ import {getBacklinkHeadingMore, loadBreadcrumb} from "./renderBacklink";
|
||||||
import {removeSearchMark} from "../toolbar/util";
|
import {removeSearchMark} from "../toolbar/util";
|
||||||
import {activeBlur, hideKeyboardToolbar} from "../../mobile/util/keyboardToolbar";
|
import {activeBlur, hideKeyboardToolbar} from "../../mobile/util/keyboardToolbar";
|
||||||
import {commonClick} from "./commonClick";
|
import {commonClick} from "./commonClick";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export class WYSIWYG {
|
export class WYSIWYG {
|
||||||
public lastHTMLs: { [key: string]: string } = {};
|
public lastHTMLs: { [key: string]: string } = {};
|
||||||
|
|
||||||
public element: HTMLDivElement;
|
public element: HTMLDivElement;
|
||||||
public preventKeyup: boolean;
|
public preventKeyup: boolean;
|
||||||
|
private app: App;
|
||||||
|
|
||||||
constructor(protyle: IProtyle) {
|
constructor(app: App, protyle: IProtyle) {
|
||||||
|
this.app = app;
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "protyle-wysiwyg";
|
this.element.className = "protyle-wysiwyg";
|
||||||
this.element.setAttribute("spellcheck", "false");
|
this.element.setAttribute("spellcheck", "false");
|
||||||
|
|
@ -91,7 +94,7 @@ export class WYSIWYG {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.bindEvent(protyle);
|
this.bindEvent(protyle);
|
||||||
keydown(protyle, this.element);
|
keydown(app, protyle, this.element);
|
||||||
dropEvent(protyle, this.element);
|
dropEvent(protyle, this.element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1216,7 +1219,7 @@ export class WYSIWYG {
|
||||||
removeSearchMark(target);
|
removeSearchMark(target);
|
||||||
}
|
}
|
||||||
if (types.includes("block-ref") && !protyle.disabled) {
|
if (types.includes("block-ref") && !protyle.disabled) {
|
||||||
refMenu(protyle, target);
|
refMenu(this.app, protyle, target);
|
||||||
// 阻止 popover
|
// 阻止 popover
|
||||||
target.setAttribute("prevent-popover", "true");
|
target.setAttribute("prevent-popover", "true");
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
@ -1227,13 +1230,13 @@ export class WYSIWYG {
|
||||||
protyle.toolbar.showFileAnnotationRef(protyle, target);
|
protyle.toolbar.showFileAnnotationRef(protyle, target);
|
||||||
return false;
|
return false;
|
||||||
} else if (types.includes("tag") && !protyle.disabled) {
|
} else if (types.includes("tag") && !protyle.disabled) {
|
||||||
tagMenu(protyle, target);
|
tagMenu(this.app, protyle, target);
|
||||||
return false;
|
return false;
|
||||||
} else if (types.includes("inline-memo")) {
|
} else if (types.includes("inline-memo")) {
|
||||||
protyle.toolbar.showRender(protyle, target);
|
protyle.toolbar.showRender(protyle, target);
|
||||||
return false;
|
return false;
|
||||||
} else if (types.includes("a") && !protyle.disabled) {
|
} else if (types.includes("a") && !protyle.disabled) {
|
||||||
linkMenu(protyle, target);
|
linkMenu(this.app, protyle, target);
|
||||||
if (window.siyuan.config.editor.floatWindowMode === 0 &&
|
if (window.siyuan.config.editor.floatWindowMode === 0 &&
|
||||||
target.getAttribute("data-href")?.startsWith("siyuan://blocks")) {
|
target.getAttribute("data-href")?.startsWith("siyuan://blocks")) {
|
||||||
// 阻止 popover
|
// 阻止 popover
|
||||||
|
|
@ -1246,7 +1249,7 @@ export class WYSIWYG {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!protyle.disabled && target.tagName === "IMG" && hasClosestByClassName(target, "img")) {
|
if (!protyle.disabled && target.tagName === "IMG" && hasClosestByClassName(target, "img")) {
|
||||||
imgMenu(protyle, protyle.toolbar.range, target.parentElement.parentElement, {
|
imgMenu(this.app, protyle, protyle.toolbar.range, target.parentElement.parentElement, {
|
||||||
clientX: x + 4,
|
clientX: x + 4,
|
||||||
clientY: y
|
clientY: y
|
||||||
});
|
});
|
||||||
|
|
@ -1509,6 +1512,7 @@ export class WYSIWYG {
|
||||||
if (ctrlIsPressed) {
|
if (ctrlIsPressed) {
|
||||||
fetchPost("/api/block/checkBlockFold", {id: breadcrumbId}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id: breadcrumbId}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: this.app,
|
||||||
id: breadcrumbId,
|
id: breadcrumbId,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
zoomIn: foldResponse.data
|
zoomIn: foldResponse.data
|
||||||
|
|
@ -1567,7 +1571,7 @@ export class WYSIWYG {
|
||||||
|
|
||||||
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
openMobileFileById(refBlockId, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
openMobileFileById(this.app, refBlockId, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
||||||
activeBlur();
|
activeBlur();
|
||||||
hideKeyboardToolbar();
|
hideKeyboardToolbar();
|
||||||
/// #else
|
/// #else
|
||||||
|
|
@ -1577,6 +1581,7 @@ export class WYSIWYG {
|
||||||
}
|
}
|
||||||
if (event.shiftKey) {
|
if (event.shiftKey) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: this.app,
|
||||||
id: refBlockId,
|
id: refBlockId,
|
||||||
position: "bottom",
|
position: "bottom",
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
|
|
@ -1584,6 +1589,7 @@ export class WYSIWYG {
|
||||||
});
|
});
|
||||||
} else if (event.altKey) {
|
} else if (event.altKey) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: this.app,
|
||||||
id: refBlockId,
|
id: refBlockId,
|
||||||
position: "right",
|
position: "right",
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
|
|
@ -1591,6 +1597,7 @@ export class WYSIWYG {
|
||||||
});
|
});
|
||||||
} else if (ctrlIsPressed) {
|
} else if (ctrlIsPressed) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: this.app,
|
||||||
id: refBlockId,
|
id: refBlockId,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
|
||||||
keepCursor: true,
|
keepCursor: true,
|
||||||
|
|
@ -1598,6 +1605,7 @@ export class WYSIWYG {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: this.app,
|
||||||
id: refBlockId,
|
id: refBlockId,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
zoomIn: foldResponse.data
|
zoomIn: foldResponse.data
|
||||||
|
|
@ -1636,7 +1644,7 @@ export class WYSIWYG {
|
||||||
} else if (event.shiftKey) {
|
} else if (event.shiftKey) {
|
||||||
openBy(linkAddress, "app");
|
openBy(linkAddress, "app");
|
||||||
} else {
|
} else {
|
||||||
openAsset(linkAddress, fileIds[2], "right");
|
openAsset(this.app, linkAddress, fileIds[2], "right");
|
||||||
}
|
}
|
||||||
/// #endif
|
/// #endif
|
||||||
return;
|
return;
|
||||||
|
|
@ -1660,7 +1668,7 @@ export class WYSIWYG {
|
||||||
} else if (event.shiftKey) {
|
} else if (event.shiftKey) {
|
||||||
openBy(linkAddress, "app");
|
openBy(linkAddress, "app");
|
||||||
} else {
|
} else {
|
||||||
openAsset(linkPathname, parseInt(getSearch("page", linkAddress)), "right");
|
openAsset(this.app, linkPathname, parseInt(getSearch("page", linkAddress)), "right");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
|
|
@ -1689,11 +1697,11 @@ export class WYSIWYG {
|
||||||
const tagElement = hasClosestByAttribute(event.target, "data-type", "tag");
|
const tagElement = hasClosestByAttribute(event.target, "data-type", "tag");
|
||||||
if (tagElement && !event.altKey) {
|
if (tagElement && !event.altKey) {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openGlobalSearch(`#${tagElement.textContent}#`, !ctrlIsPressed);
|
openGlobalSearch(this.app, `#${tagElement.textContent}#`, !ctrlIsPressed);
|
||||||
hideElements(["dialog"]);
|
hideElements(["dialog"]);
|
||||||
/// #else
|
/// #else
|
||||||
const searchOption = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
const searchOption = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
||||||
popSearch({
|
popSearch(this.app, {
|
||||||
removed: searchOption.removed,
|
removed: searchOption.removed,
|
||||||
sort: searchOption.sort,
|
sort: searchOption.sort,
|
||||||
group: searchOption.group,
|
group: searchOption.group,
|
||||||
|
|
@ -1714,12 +1722,13 @@ export class WYSIWYG {
|
||||||
if (embedItemElement) {
|
if (embedItemElement) {
|
||||||
const embedId = embedItemElement.getAttribute("data-id");
|
const embedId = embedItemElement.getAttribute("data-id");
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
openMobileFileById(embedId, [Constants.CB_GET_ALL]);
|
openMobileFileById(this.app, embedId, [Constants.CB_GET_ALL]);
|
||||||
activeBlur();
|
activeBlur();
|
||||||
hideKeyboardToolbar();
|
hideKeyboardToolbar();
|
||||||
/// #else
|
/// #else
|
||||||
if (event.shiftKey) {
|
if (event.shiftKey) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: this.app,
|
||||||
id: embedId,
|
id: embedId,
|
||||||
position: "bottom",
|
position: "bottom",
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL],
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL],
|
||||||
|
|
@ -1727,6 +1736,7 @@ export class WYSIWYG {
|
||||||
});
|
});
|
||||||
} else if (event.altKey) {
|
} else if (event.altKey) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: this.app,
|
||||||
id: embedId,
|
id: embedId,
|
||||||
position: "right",
|
position: "right",
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL],
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL],
|
||||||
|
|
@ -1734,6 +1744,7 @@ export class WYSIWYG {
|
||||||
});
|
});
|
||||||
} else if (ctrlIsPressed) {
|
} else if (ctrlIsPressed) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app: this.app,
|
||||||
id: embedId,
|
id: embedId,
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL],
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL],
|
||||||
keepCursor: true,
|
keepCursor: true,
|
||||||
|
|
@ -1741,6 +1752,7 @@ export class WYSIWYG {
|
||||||
});
|
});
|
||||||
} else if (!protyle.disabled) {
|
} else if (!protyle.disabled) {
|
||||||
window.siyuan.blockPanels.push(new BlockPanel({
|
window.siyuan.blockPanels.push(new BlockPanel({
|
||||||
|
app: this.app,
|
||||||
targetElement: embedItemElement,
|
targetElement: embedItemElement,
|
||||||
nodeIds: [embedId],
|
nodeIds: [embedId],
|
||||||
}));
|
}));
|
||||||
|
|
@ -1750,7 +1762,7 @@ export class WYSIWYG {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commonClick(event, protyle)) {
|
if (commonClick(this.app, event, protyle)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1815,7 +1827,7 @@ export class WYSIWYG {
|
||||||
if (actionElement) {
|
if (actionElement) {
|
||||||
const type = actionElement.parentElement.parentElement.getAttribute("data-type");
|
const type = actionElement.parentElement.parentElement.getAttribute("data-type");
|
||||||
if (type === "img" && !protyle.disabled) {
|
if (type === "img" && !protyle.disabled) {
|
||||||
imgMenu(protyle, range, actionElement.parentElement.parentElement, {
|
imgMenu(this.app, protyle, range, actionElement.parentElement.parentElement, {
|
||||||
clientX: event.clientX + 4,
|
clientX: event.clientX + 4,
|
||||||
clientY: event.clientY
|
clientY: event.clientY
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -71,8 +71,9 @@ import {escapeHtml} from "../../util/escape";
|
||||||
import {insertHTML} from "../util/insertHTML";
|
import {insertHTML} from "../util/insertHTML";
|
||||||
import {quickMakeCard} from "../../card/makeCard";
|
import {quickMakeCard} from "../../card/makeCard";
|
||||||
import {removeSearchMark} from "../toolbar/util";
|
import {removeSearchMark} from "../toolbar/util";
|
||||||
|
import {App} from "../../index";
|
||||||
|
|
||||||
export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
editorElement.addEventListener("keydown", (event: KeyboardEvent & { target: HTMLElement }) => {
|
editorElement.addEventListener("keydown", (event: KeyboardEvent & { target: HTMLElement }) => {
|
||||||
if (event.target.localName === "protyle-html") {
|
if (event.target.localName === "protyle-html") {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
@ -441,6 +442,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
const ids = protyle.path.split("/");
|
const ids = protyle.path.split("/");
|
||||||
if (ids.length > 2) {
|
if (ids.length > 2) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id: ids[ids.length - 2],
|
id: ids[ids.length - 2],
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
|
||||||
});
|
});
|
||||||
|
|
@ -530,7 +532,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
removeSearchMark(inlineElement);
|
removeSearchMark(inlineElement);
|
||||||
}
|
}
|
||||||
if (types.includes("block-ref")) {
|
if (types.includes("block-ref")) {
|
||||||
refMenu(protyle, inlineElement);
|
refMenu(app, protyle, inlineElement);
|
||||||
return;
|
return;
|
||||||
} else if (types.includes("inline-memo")) {
|
} else if (types.includes("inline-memo")) {
|
||||||
protyle.toolbar.showRender(protyle, inlineElement);
|
protyle.toolbar.showRender(protyle, inlineElement);
|
||||||
|
|
@ -539,10 +541,10 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
protyle.toolbar.showFileAnnotationRef(protyle, inlineElement);
|
protyle.toolbar.showFileAnnotationRef(protyle, inlineElement);
|
||||||
return;
|
return;
|
||||||
} else if (types.includes("a")) {
|
} else if (types.includes("a")) {
|
||||||
linkMenu(protyle, inlineElement);
|
linkMenu(app, protyle, inlineElement);
|
||||||
return;
|
return;
|
||||||
} else if (types.includes("tag")) {
|
} else if (types.includes("tag")) {
|
||||||
tagMenu(protyle, inlineElement);
|
tagMenu(app, protyle, inlineElement);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -952,7 +954,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
if (commonHotkey(protyle, event)) {
|
if (commonHotkey(app, protyle, event)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// #endif
|
/// #endif
|
||||||
|
|
@ -1588,6 +1590,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.openBy.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.openBy.custom, event)) {
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id,
|
id,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
zoomIn: foldResponse.data
|
zoomIn: foldResponse.data
|
||||||
|
|
@ -1600,6 +1603,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
// 打开块引和编辑器中引用、反链、书签中点击事件需保持一致,都加载上下文
|
// 打开块引和编辑器中引用、反链、书签中点击事件需保持一致,都加载上下文
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id,
|
id,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
|
||||||
keepCursor: true,
|
keepCursor: true,
|
||||||
|
|
@ -1612,6 +1616,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertRight.custom, event)) {
|
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertRight.custom, event)) {
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id,
|
id,
|
||||||
position: "right",
|
position: "right",
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
|
|
@ -1624,6 +1629,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertBottom.custom, event)) {
|
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertBottom.custom, event)) {
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id,
|
id,
|
||||||
position: "bottom",
|
position: "bottom",
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
|
|
@ -1636,6 +1642,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.refPopover.custom, event)) {
|
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.refPopover.custom, event)) {
|
||||||
// open popover
|
// open popover
|
||||||
window.siyuan.blockPanels.push(new BlockPanel({
|
window.siyuan.blockPanels.push(new BlockPanel({
|
||||||
|
app,
|
||||||
targetElement: refElement,
|
targetElement: refElement,
|
||||||
nodeIds: [id],
|
nodeIds: [id],
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,21 @@ import {Tab} from "../layout/Tab";
|
||||||
import {Protyle} from "../protyle";
|
import {Protyle} from "../protyle";
|
||||||
import {genSearch} from "./util";
|
import {genSearch} from "./util";
|
||||||
import {setPanelFocus} from "../layout/util";
|
import {setPanelFocus} from "../layout/util";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
export class Search extends Model {
|
export class Search extends Model {
|
||||||
private element: HTMLElement;
|
private element: HTMLElement;
|
||||||
public config: ISearchOption;
|
public config: ISearchOption;
|
||||||
public edit: Protyle;
|
public edit: Protyle;
|
||||||
|
|
||||||
constructor(options: { tab: Tab, config: ISearchOption }) {
|
constructor(options: { tab: Tab, config: ISearchOption, app: App }) {
|
||||||
super({
|
super({
|
||||||
|
app: options.app,
|
||||||
id: options.tab.id,
|
id: options.tab.id,
|
||||||
});
|
});
|
||||||
this.element = options.tab.panelElement as HTMLElement;
|
this.element = options.tab.panelElement as HTMLElement;
|
||||||
this.config = options.config;
|
this.config = options.config;
|
||||||
this.edit = genSearch(this.config, this.element);
|
this.edit = genSearch(options.app, this.config, this.element);
|
||||||
this.element.addEventListener("click", () => {
|
this.element.addEventListener("click", () => {
|
||||||
setPanelFocus(this.element.parentElement.parentElement);
|
setPanelFocus(this.element.parentElement.parentElement);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,35 +4,42 @@ import {Dialog} from "../dialog";
|
||||||
import {fetchSyncPost} from "../util/fetch";
|
import {fetchSyncPost} from "../util/fetch";
|
||||||
import {focusByRange} from "../protyle/util/selection";
|
import {focusByRange} from "../protyle/util/selection";
|
||||||
import {genSearch} from "./util";
|
import {genSearch} from "./util";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
export const openSearch = async (hotkey: string, key?: string, notebookId?: string, searchPath?: string) => {
|
export const openSearch = async (options: {
|
||||||
|
app: App,
|
||||||
|
hotkey: string,
|
||||||
|
key?: string,
|
||||||
|
notebookId?: string,
|
||||||
|
searchPath?: string
|
||||||
|
}) => {
|
||||||
const exitDialog = window.siyuan.dialogs.find((item) => {
|
const exitDialog = window.siyuan.dialogs.find((item) => {
|
||||||
if (item.element.querySelector("#searchList")) {
|
if (item.element.querySelector("#searchList")) {
|
||||||
const lastKey = item.element.getAttribute("data-key");
|
const lastKey = item.element.getAttribute("data-key");
|
||||||
const replaceHeaderElement = item.element.querySelectorAll(".search__header")[1];
|
const replaceHeaderElement = item.element.querySelectorAll(".search__header")[1];
|
||||||
if (lastKey !== hotkey && hotkey === window.siyuan.config.keymap.general.replace.custom && replaceHeaderElement.classList.contains("fn__none")) {
|
if (lastKey !== options.hotkey && options.hotkey === window.siyuan.config.keymap.general.replace.custom && replaceHeaderElement.classList.contains("fn__none")) {
|
||||||
replaceHeaderElement.classList.remove("fn__none");
|
replaceHeaderElement.classList.remove("fn__none");
|
||||||
item.element.setAttribute("data-key", hotkey);
|
item.element.setAttribute("data-key", options.hotkey);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const searchPathElement = item.element.querySelector("#searchPathInput");
|
const searchPathElement = item.element.querySelector("#searchPathInput");
|
||||||
if (lastKey !== hotkey && hotkey === window.siyuan.config.keymap.general.globalSearch.custom) {
|
if (lastKey !== options.hotkey && options.hotkey === window.siyuan.config.keymap.general.globalSearch.custom) {
|
||||||
if (searchPathElement.textContent !== "") {
|
if (searchPathElement.textContent !== "") {
|
||||||
item.destroy();
|
item.destroy();
|
||||||
return false;
|
return false;
|
||||||
} else if (!replaceHeaderElement.classList.contains("fn__none")) {
|
} else if (!replaceHeaderElement.classList.contains("fn__none")) {
|
||||||
replaceHeaderElement.classList.add("fn__none");
|
replaceHeaderElement.classList.add("fn__none");
|
||||||
item.element.setAttribute("data-key", hotkey);
|
item.element.setAttribute("data-key", options.hotkey);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lastKey !== hotkey && hotkey === window.siyuan.config.keymap.general.search.custom) {
|
if (lastKey !== options.hotkey && options.hotkey === window.siyuan.config.keymap.general.search.custom) {
|
||||||
if (searchPathElement.textContent === "") {
|
if (searchPathElement.textContent === "") {
|
||||||
item.destroy();
|
item.destroy();
|
||||||
return false;
|
return false;
|
||||||
} else if (!replaceHeaderElement.classList.contains("fn__none")) {
|
} else if (!replaceHeaderElement.classList.contains("fn__none")) {
|
||||||
replaceHeaderElement.classList.add("fn__none");
|
replaceHeaderElement.classList.add("fn__none");
|
||||||
item.element.setAttribute("data-key", hotkey);
|
item.element.setAttribute("data-key", options.hotkey);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -47,18 +54,18 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
|
||||||
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
||||||
let hPath = "";
|
let hPath = "";
|
||||||
let idPath: string[] = [];
|
let idPath: string[] = [];
|
||||||
if (notebookId) {
|
if (options.notebookId) {
|
||||||
hPath = getNotebookName(notebookId);
|
hPath = getNotebookName(options.notebookId);
|
||||||
idPath.push(notebookId);
|
idPath.push(options.notebookId);
|
||||||
if (searchPath && searchPath !== "/") {
|
if (options.searchPath && options.searchPath !== "/") {
|
||||||
const response = await fetchSyncPost("/api/filetree/getHPathByPath", {
|
const response = await fetchSyncPost("/api/filetree/getHPathByPath", {
|
||||||
notebook: notebookId,
|
notebook: options.notebookId,
|
||||||
path: searchPath.endsWith(".sy") ? searchPath : searchPath + ".sy"
|
path: options.searchPath.endsWith(".sy") ? options.searchPath : options.searchPath + ".sy"
|
||||||
});
|
});
|
||||||
hPath = pathPosix().join(hPath, response.data);
|
hPath = pathPosix().join(hPath, response.data);
|
||||||
idPath[0] = pathPosix().join(idPath[0], searchPath);
|
idPath[0] = pathPosix().join(idPath[0], options.searchPath);
|
||||||
}
|
}
|
||||||
} else if (window.siyuan.config.keymap.general.globalSearch.custom === hotkey) {
|
} else if (window.siyuan.config.keymap.general.globalSearch.custom === options.hotkey) {
|
||||||
hPath = localData.hPath;
|
hPath = localData.hPath;
|
||||||
idPath = localData.idPath;
|
idPath = localData.idPath;
|
||||||
// 历史原因,2.5.2 之前为 string https://github.com/siyuan-note/siyuan/issues/6902
|
// 历史原因,2.5.2 之前为 string https://github.com/siyuan-note/siyuan/issues/6902
|
||||||
|
|
@ -84,19 +91,19 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dialog.element.setAttribute("data-key", hotkey);
|
dialog.element.setAttribute("data-key", options.hotkey);
|
||||||
const edit = genSearch({
|
const edit = genSearch( options.app, {
|
||||||
removed: localData.removed,
|
removed: localData.removed,
|
||||||
k: key || localData.k,
|
k: options.key || localData.k,
|
||||||
r: localData.r,
|
r: localData.r,
|
||||||
hasReplace: hotkey === window.siyuan.config.keymap.general.replace.custom,
|
hasReplace: options.hotkey === window.siyuan.config.keymap.general.replace.custom,
|
||||||
method: localData.method,
|
method: localData.method,
|
||||||
hPath,
|
hPath,
|
||||||
idPath,
|
idPath,
|
||||||
group: localData.group,
|
group: localData.group,
|
||||||
sort: localData.sort,
|
sort: localData.sort,
|
||||||
types: Object.assign({}, localData.types),
|
types: Object.assign({}, localData.types),
|
||||||
page: key ? 1 : localData.page
|
page: options.key ? 1 : localData.page
|
||||||
}, dialog.element.querySelector(".b3-dialog__container").lastElementChild, () => {
|
}, dialog.element.querySelector(".b3-dialog__container").lastElementChild, () => {
|
||||||
dialog.destroy({focus: "false"});
|
dialog.destroy({focus: "false"});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import {setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
|
||||||
import {newFileByName} from "../util/newFile";
|
import {newFileByName} from "../util/newFile";
|
||||||
import {matchHotKey} from "../protyle/util/hotKey";
|
import {matchHotKey} from "../protyle/util/hotKey";
|
||||||
import {filterMenu, getKeyByLiElement, initCriteriaMenu, moreMenu, queryMenu} from "./menu";
|
import {filterMenu, getKeyByLiElement, initCriteriaMenu, moreMenu, queryMenu} from "./menu";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
const saveKeyList = (type: "keys" | "replaceKeys", value: string) => {
|
const saveKeyList = (type: "keys" | "replaceKeys", value: string) => {
|
||||||
let list: string[] = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS][type];
|
let list: string[] = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS][type];
|
||||||
|
|
@ -30,7 +31,7 @@ const saveKeyList = (type: "keys" | "replaceKeys", value: string) => {
|
||||||
setStorageVal(Constants.LOCAL_SEARCHKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHKEYS]);
|
setStorageVal(Constants.LOCAL_SEARCHKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHKEYS]);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const openGlobalSearch = (text: string, replace: boolean) => {
|
export const openGlobalSearch = (app: App, text: string, replace: boolean) => {
|
||||||
text = text.trim();
|
text = text.trim();
|
||||||
const searchModel = getAllModels().search.find((item) => {
|
const searchModel = getAllModels().search.find((item) => {
|
||||||
item.parent.parent.switchTab(item.parent.headElement);
|
item.parent.parent.switchTab(item.parent.headElement);
|
||||||
|
|
@ -42,6 +43,7 @@ export const openGlobalSearch = (text: string, replace: boolean) => {
|
||||||
}
|
}
|
||||||
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
||||||
openFile({
|
openFile({
|
||||||
|
app,
|
||||||
searchData: {
|
searchData: {
|
||||||
k: text,
|
k: text,
|
||||||
r: "",
|
r: "",
|
||||||
|
|
@ -60,7 +62,7 @@ export const openGlobalSearch = (text: string, replace: boolean) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// closeCB 不存在为页签搜索
|
// closeCB 不存在为页签搜索
|
||||||
export const genSearch = (config: ISearchOption, element: Element, closeCB?: () => void) => {
|
export const genSearch = (app: App, config: ISearchOption, element: Element, closeCB?: () => void) => {
|
||||||
let methodText = window.siyuan.languages.keyword;
|
let methodText = window.siyuan.languages.keyword;
|
||||||
if (config.method === 1) {
|
if (config.method === 1) {
|
||||||
methodText = window.siyuan.languages.querySyntax;
|
methodText = window.siyuan.languages.querySyntax;
|
||||||
|
|
@ -181,7 +183,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
|
||||||
const historyElement = element.querySelector("#searchHistoryList");
|
const historyElement = element.querySelector("#searchHistoryList");
|
||||||
|
|
||||||
const lineHeight = 30;
|
const lineHeight = 30;
|
||||||
const edit = new Protyle(element.querySelector("#searchPreview") as HTMLElement, {
|
const edit = new Protyle(app, element.querySelector("#searchPreview") as HTMLElement, {
|
||||||
blockId: "",
|
blockId: "",
|
||||||
render: {
|
render: {
|
||||||
gutter: true,
|
gutter: true,
|
||||||
|
|
@ -409,7 +411,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
|
||||||
} else if (target.id === "searchOpen") {
|
} else if (target.id === "searchOpen") {
|
||||||
config.k = searchInputElement.value;
|
config.k = searchInputElement.value;
|
||||||
config.r = replaceInputElement.value;
|
config.r = replaceInputElement.value;
|
||||||
openFile({searchData: config, position: "right"});
|
openFile({app, searchData: config, position: "right"});
|
||||||
if (closeCB) {
|
if (closeCB) {
|
||||||
closeCB();
|
closeCB();
|
||||||
}
|
}
|
||||||
|
|
@ -599,7 +601,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
|
||||||
replaceInputElement.value = target.textContent;
|
replaceInputElement.value = target.textContent;
|
||||||
replaceHistoryElement.classList.add("fn__none");
|
replaceHistoryElement.classList.add("fn__none");
|
||||||
} else if (type === "search-new") {
|
} else if (type === "search-new") {
|
||||||
newFileByName(searchInputElement.value);
|
newFileByName(app, searchInputElement.value);
|
||||||
} else if (type === "search-item") {
|
} else if (type === "search-item") {
|
||||||
if (event.detail === 1) {
|
if (event.detail === 1) {
|
||||||
clickTimeout = window.setTimeout(() => {
|
clickTimeout = window.setTimeout(() => {
|
||||||
|
|
@ -607,6 +609,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
|
||||||
const id = target.getAttribute("data-node-id");
|
const id = target.getAttribute("data-node-id");
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id,
|
id,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
zoomIn: foldResponse.data,
|
zoomIn: foldResponse.data,
|
||||||
|
|
@ -639,6 +642,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
|
||||||
const id = target.getAttribute("data-node-id");
|
const id = target.getAttribute("data-node-id");
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id,
|
id,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
zoomIn: foldResponse.data
|
zoomIn: foldResponse.data
|
||||||
|
|
@ -685,7 +689,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (searchInputElement.value && matchHotKey(window.siyuan.config.keymap.general.newFile.custom, event)) {
|
if (searchInputElement.value && matchHotKey(window.siyuan.config.keymap.general.newFile.custom, event)) {
|
||||||
newFileByName(searchInputElement.value);
|
newFileByName(app, searchInputElement.value);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return;
|
return;
|
||||||
|
|
@ -693,11 +697,12 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
|
||||||
const focusIsNew = currentList.getAttribute("data-type") === "search-new";
|
const focusIsNew = currentList.getAttribute("data-type") === "search-new";
|
||||||
if (event.key === "Enter") {
|
if (event.key === "Enter") {
|
||||||
if (focusIsNew) {
|
if (focusIsNew) {
|
||||||
newFileByName(searchInputElement.value);
|
newFileByName(app, searchInputElement.value);
|
||||||
} else {
|
} else {
|
||||||
const id = currentList.getAttribute("data-node-id");
|
const id = currentList.getAttribute("data-node-id");
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
app,
|
||||||
id,
|
id,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
zoomIn: foldResponse.data
|
zoomIn: foldResponse.data
|
||||||
|
|
|
||||||
3
app/src/types/index.d.ts
vendored
3
app/src/types/index.d.ts
vendored
|
|
@ -22,7 +22,7 @@ type TOperation =
|
||||||
| "removeFlashcards"
|
| "removeFlashcards"
|
||||||
type TBazaarType = "templates" | "icons" | "widgets" | "themes" | "plugins"
|
type TBazaarType = "templates" | "icons" | "widgets" | "themes" | "plugins"
|
||||||
type TCardType = "doc" | "notebook" | "all"
|
type TCardType = "doc" | "notebook" | "all"
|
||||||
type TEventBus = "ws-main"
|
type TEventBus = "ws-main" | "click-blockicon"
|
||||||
|
|
||||||
declare module "blueimp-md5"
|
declare module "blueimp-md5"
|
||||||
|
|
||||||
|
|
@ -316,6 +316,7 @@ declare interface IPluginDockTab {
|
||||||
}
|
}
|
||||||
|
|
||||||
declare interface IOpenFileOptions {
|
declare interface IOpenFileOptions {
|
||||||
|
app: import("../index").App,
|
||||||
searchData?: ISearchOption, // 搜索必填
|
searchData?: ISearchOption, // 搜索必填
|
||||||
// card 和自定义页签 必填
|
// card 和自定义页签 必填
|
||||||
custom?: {
|
custom?: {
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,12 @@ import {zoomOut} from "../menus/protyle";
|
||||||
import {showMessage} from "../dialog/message";
|
import {showMessage} from "../dialog/message";
|
||||||
import {saveScroll} from "../protyle/scroll/saveScroll";
|
import {saveScroll} from "../protyle/scroll/saveScroll";
|
||||||
import {getAllModels} from "../layout/getAll";
|
import {getAllModels} from "../layout/getAll";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
let forwardStack: IBackStack[] = [];
|
let forwardStack: IBackStack[] = [];
|
||||||
let previousIsBack = false;
|
let previousIsBack = false;
|
||||||
|
|
||||||
const focusStack = async (stack: IBackStack) => {
|
const focusStack = async (app: App, stack: IBackStack) => {
|
||||||
hideElements(["gutter", "toolbar", "hint", "util", "dialog"], stack.protyle);
|
hideElements(["gutter", "toolbar", "hint", "util", "dialog"], stack.protyle);
|
||||||
let blockElement: HTMLElement;
|
let blockElement: HTMLElement;
|
||||||
if (!document.contains(stack.protyle.element)) {
|
if (!document.contains(stack.protyle.element)) {
|
||||||
|
|
@ -52,6 +53,7 @@ const focusStack = async (stack: IBackStack) => {
|
||||||
scrollAttr.focusStart = stack.position.start;
|
scrollAttr.focusStart = stack.position.start;
|
||||||
scrollAttr.focusEnd = stack.position.end;
|
scrollAttr.focusEnd = stack.position.end;
|
||||||
const editor = new Editor({
|
const editor = new Editor({
|
||||||
|
app: app,
|
||||||
tab,
|
tab,
|
||||||
scrollAttr,
|
scrollAttr,
|
||||||
blockId: stack.zoomId || stack.protyle.block.rootID,
|
blockId: stack.zoomId || stack.protyle.block.rootID,
|
||||||
|
|
@ -172,10 +174,10 @@ const focusStack = async (stack: IBackStack) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const goBack = async () => {
|
export const goBack = async (app: App) => {
|
||||||
if (window.siyuan.backStack.length === 0) {
|
if (window.siyuan.backStack.length === 0) {
|
||||||
if (forwardStack.length > 0) {
|
if (forwardStack.length > 0) {
|
||||||
await focusStack(forwardStack[forwardStack.length - 1]);
|
await focusStack(app, forwardStack[forwardStack.length - 1]);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -187,7 +189,7 @@ export const goBack = async () => {
|
||||||
}
|
}
|
||||||
let stack = window.siyuan.backStack.pop();
|
let stack = window.siyuan.backStack.pop();
|
||||||
while (stack) {
|
while (stack) {
|
||||||
const isFocus = await focusStack(stack);
|
const isFocus = await focusStack(app, stack);
|
||||||
if (isFocus) {
|
if (isFocus) {
|
||||||
forwardStack.push(stack);
|
forwardStack.push(stack);
|
||||||
break;
|
break;
|
||||||
|
|
@ -201,10 +203,10 @@ export const goBack = async () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const goForward = async () => {
|
export const goForward = async (app: App) => {
|
||||||
if (forwardStack.length === 0) {
|
if (forwardStack.length === 0) {
|
||||||
if (window.siyuan.backStack.length > 0) {
|
if (window.siyuan.backStack.length > 0) {
|
||||||
await focusStack(window.siyuan.backStack[window.siyuan.backStack.length - 1]);
|
await focusStack(app, window.siyuan.backStack[window.siyuan.backStack.length - 1]);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -215,7 +217,7 @@ export const goForward = async () => {
|
||||||
|
|
||||||
let stack = forwardStack.pop();
|
let stack = forwardStack.pop();
|
||||||
while (stack) {
|
while (stack) {
|
||||||
const isFocus = await focusStack(stack);
|
const isFocus = await focusStack(app, stack);
|
||||||
if (isFocus) {
|
if (isFocus) {
|
||||||
window.siyuan.backStack.push(stack);
|
window.siyuan.backStack.push(stack);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import {Constants} from "../constants";
|
||||||
import {replaceFileName, validateName} from "../editor/rename";
|
import {replaceFileName, validateName} from "../editor/rename";
|
||||||
import {hideElements} from "../protyle/ui/hideElements";
|
import {hideElements} from "../protyle/ui/hideElements";
|
||||||
import {openMobileFileById} from "../mobile/editor";
|
import {openMobileFileById} from "../mobile/editor";
|
||||||
|
import {App} from "../index";
|
||||||
|
|
||||||
export const getNewFilePath = (useSavePath: boolean) => {
|
export const getNewFilePath = (useSavePath: boolean) => {
|
||||||
let notebookId = "";
|
let notebookId = "";
|
||||||
|
|
@ -62,7 +63,7 @@ export const getNewFilePath = (useSavePath: boolean) => {
|
||||||
return {notebookId, currentPath};
|
return {notebookId, currentPath};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const newFile = (notebookId?: string, currentPath?: string, paths?: string[], useSavePath = false) => {
|
export const newFile = (app: App, notebookId?: string, currentPath?: string, paths?: string[], useSavePath = false) => {
|
||||||
if (getOpenNotebookCount() === 0) {
|
if (getOpenNotebookCount() === 0) {
|
||||||
showMessage(window.siyuan.languages.newFileTip);
|
showMessage(window.siyuan.languages.newFileTip);
|
||||||
return;
|
return;
|
||||||
|
|
@ -81,9 +82,9 @@ export const newFile = (notebookId?: string, currentPath?: string, paths?: strin
|
||||||
markdown: ""
|
markdown: ""
|
||||||
}, response => {
|
}, response => {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openFileById({id: response.data, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});
|
openFileById({app, id: response.data, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});
|
||||||
/// #else
|
/// #else
|
||||||
openMobileFileById(response.data, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
openMobileFileById(app, response.data, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
||||||
/// #endif
|
/// #endif
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -97,9 +98,9 @@ export const newFile = (notebookId?: string, currentPath?: string, paths?: strin
|
||||||
markdown: ""
|
markdown: ""
|
||||||
}, response => {
|
}, response => {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openFileById({id: response.data, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});
|
openFileById({app, id: response.data, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});
|
||||||
/// #else
|
/// #else
|
||||||
openMobileFileById(response.data, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
openMobileFileById(app, response.data, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
||||||
/// #endif
|
/// #endif
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -123,9 +124,9 @@ export const newFile = (notebookId?: string, currentPath?: string, paths?: strin
|
||||||
sorts: paths
|
sorts: paths
|
||||||
}, () => {
|
}, () => {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openFileById({id, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});
|
openFileById({app, id, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});
|
||||||
/// #else
|
/// #else
|
||||||
openMobileFileById(id, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
openMobileFileById(app, id, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
||||||
/// #endif
|
/// #endif
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -158,7 +159,7 @@ export const getSavePath = (pathString: string, notebookId: string, cb: (p: stri
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const newFileByName = (value: string) => {
|
export const newFileByName = (app: App, value: string) => {
|
||||||
const newData = getNewFilePath(true);
|
const newData = getNewFilePath(true);
|
||||||
fetchPost("/api/filetree/getHPathByPath", {
|
fetchPost("/api/filetree/getHPathByPath", {
|
||||||
notebook: newData.notebookId,
|
notebook: newData.notebookId,
|
||||||
|
|
@ -171,9 +172,9 @@ export const newFileByName = (value: string) => {
|
||||||
}, response => {
|
}, response => {
|
||||||
hideElements(["dialog"]);
|
hideElements(["dialog"]);
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
openMobileFileById(response.data, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
openMobileFileById(app, response.data, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
||||||
/// #else
|
/// #else
|
||||||
openFileById({id: response.data, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});
|
openFileById({app, id: response.data, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});
|
||||||
/// #endif
|
/// #endif
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ class App {
|
||||||
ctrlIsPressed: false,
|
ctrlIsPressed: false,
|
||||||
altIsPressed: false,
|
altIsPressed: false,
|
||||||
ws: new Model({
|
ws: new Model({
|
||||||
|
app: this,
|
||||||
id: genUUID(),
|
id: genUUID(),
|
||||||
type: "main",
|
type: "main",
|
||||||
msgCallback: (data) => {
|
msgCallback: (data) => {
|
||||||
|
|
@ -49,7 +50,7 @@ class App {
|
||||||
if (data) {
|
if (data) {
|
||||||
switch (data.cmd) {
|
switch (data.cmd) {
|
||||||
case "syncMergeResult":
|
case "syncMergeResult":
|
||||||
reloadSync(data.data);
|
reloadSync(this, data.data);
|
||||||
break;
|
break;
|
||||||
case "progress":
|
case "progress":
|
||||||
progressLoading(data);
|
progressLoading(data);
|
||||||
|
|
@ -116,10 +117,10 @@ class App {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "createdailynote":
|
case "createdailynote":
|
||||||
openFileById({id: data.data.id, action: [Constants.CB_GET_FOCUS]});
|
openFileById({app: this, id: data.data.id, action: [Constants.CB_GET_FOCUS]});
|
||||||
break;
|
break;
|
||||||
case "openFileById":
|
case "openFileById":
|
||||||
openFileById({id: data.data.id, action: [Constants.CB_GET_FOCUS]});
|
openFileById({app: this, id: data.data.id, action: [Constants.CB_GET_FOCUS]});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -131,11 +132,11 @@ class App {
|
||||||
getLocalStorage(() => {
|
getLocalStorage(() => {
|
||||||
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => {
|
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => {
|
||||||
window.siyuan.languages = lauguages;
|
window.siyuan.languages = lauguages;
|
||||||
window.siyuan.menus = new Menus(siyuanApp);
|
window.siyuan.menus = new Menus(this);
|
||||||
fetchPost("/api/setting/getCloudUser", {}, userResponse => {
|
fetchPost("/api/setting/getCloudUser", {}, userResponse => {
|
||||||
window.siyuan.user = userResponse.data;
|
window.siyuan.user = userResponse.data;
|
||||||
loadPlugins(siyuanApp);
|
loadPlugins(this);
|
||||||
init(siyuanApp);
|
init(this);
|
||||||
setTitle(window.siyuan.languages.siyuanNote);
|
setTitle(window.siyuan.languages.siyuanNote);
|
||||||
initMessage();
|
initMessage();
|
||||||
});
|
});
|
||||||
|
|
@ -143,12 +144,12 @@ class App {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
setNoteBook();
|
setNoteBook();
|
||||||
initBlockPopover();
|
initBlockPopover(this);
|
||||||
promiseTransactions();
|
promiseTransactions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const siyuanApp = new App();
|
new App();
|
||||||
|
|
||||||
// 再次点击新窗口已打开的 PDF 时,需进行定位
|
// 再次点击新窗口已打开的 PDF 时,需进行定位
|
||||||
window.newWindow = {
|
window.newWindow = {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ export const init = (app: App) => {
|
||||||
window.siyuan.layout.centerLayout = window.siyuan.layout.layout;
|
window.siyuan.layout.centerLayout = window.siyuan.layout.layout;
|
||||||
});
|
});
|
||||||
initStatus(true);
|
initStatus(true);
|
||||||
initWindow();
|
initWindow(app);
|
||||||
appearance.onSetappearance(window.siyuan.config.appearance);
|
appearance.onSetappearance(window.siyuan.config.appearance);
|
||||||
initAssets();
|
initAssets();
|
||||||
renderSnippet();
|
renderSnippet();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue