2023-05-07 17:31:50 +08:00
|
|
|
|
import {confirmDialog} from "../dialog/confirmDialog";
|
|
|
|
|
|
import {Plugin} from "./index";
|
|
|
|
|
|
import {showMessage} from "../dialog/message";
|
2023-05-07 22:00:41 +08:00
|
|
|
|
import {Dialog} from "../dialog";
|
2023-05-08 15:11:50 +08:00
|
|
|
|
import {fetchGet, fetchPost, fetchSyncPost} from "../util/fetch";
|
2023-05-30 09:42:25 +08:00
|
|
|
|
import {getBackend, getFrontend} from "../util/functions";
|
2023-05-10 16:11:02 +08:00
|
|
|
|
/// #if !MOBILE
|
2023-05-28 23:45:23 +08:00
|
|
|
|
import {openFile, openFileById} from "../editor/util";
|
2023-08-30 22:28:25 +08:00
|
|
|
|
import {openNewWindow, openNewWindowById} from "../window/openNewWindow";
|
|
|
|
|
|
import {Tab} from "../layout/Tab";
|
2023-05-10 16:11:02 +08:00
|
|
|
|
/// #endif
|
2023-05-12 17:11:43 +08:00
|
|
|
|
import {updateHotkeyTip} from "../protyle/util/compatibility";
|
2023-05-28 23:20:30 +08:00
|
|
|
|
import {App} from "../index";
|
|
|
|
|
|
import {Constants} from "../constants";
|
2023-06-02 21:49:22 +08:00
|
|
|
|
import {Setting} from "./Setting";
|
2023-06-12 12:42:22 +08:00
|
|
|
|
import {Menu} from "./Menu";
|
2023-08-18 17:38:11 +08:00
|
|
|
|
import {Protyle} from "../protyle";
|
2023-11-24 21:58:16 +08:00
|
|
|
|
import {openMobileFileById} from "../mobile/editor";
|
2023-05-07 17:31:50 +08:00
|
|
|
|
|
2023-05-10 16:11:02 +08:00
|
|
|
|
let openTab;
|
2023-08-30 22:28:25 +08:00
|
|
|
|
let openWindow;
|
2023-05-10 16:11:02 +08:00
|
|
|
|
/// #if MOBILE
|
|
|
|
|
|
openTab = () => {
|
|
|
|
|
|
// TODO: Mobile
|
2023-05-10 16:11:51 +08:00
|
|
|
|
};
|
2023-08-30 22:28:25 +08:00
|
|
|
|
openWindow = () => {
|
|
|
|
|
|
// TODO: Mobile
|
|
|
|
|
|
};
|
2023-05-10 16:11:02 +08:00
|
|
|
|
/// #else
|
2023-08-30 22:28:25 +08:00
|
|
|
|
openWindow = (options: {
|
2023-10-01 10:26:31 +08:00
|
|
|
|
position?: IPosition,
|
2023-09-02 20:09:52 +08:00
|
|
|
|
height?: number,
|
|
|
|
|
|
width?: number,
|
2023-08-30 22:28:25 +08:00
|
|
|
|
tab?: Tab,
|
|
|
|
|
|
doc?: {
|
|
|
|
|
|
id: string, // 块 id
|
|
|
|
|
|
},
|
|
|
|
|
|
}) => {
|
2023-09-06 10:50:13 +08:00
|
|
|
|
if (options.doc && options.doc.id) {
|
2023-09-02 20:09:52 +08:00
|
|
|
|
openNewWindowById(options.doc.id, {position: options.position, width: options.width, height: options.height});
|
2023-08-30 22:28:25 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (options.tab) {
|
2023-09-02 20:09:52 +08:00
|
|
|
|
openNewWindow(options.tab, {position: options.position, width: options.width, height: options.height});
|
2023-08-30 22:28:25 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-05-28 23:20:30 +08:00
|
|
|
|
openTab = (options: {
|
|
|
|
|
|
app: App,
|
|
|
|
|
|
doc?: {
|
|
|
|
|
|
id: string, // 块 id
|
2023-05-28 23:45:23 +08:00
|
|
|
|
action?: string [] // cb-get-all:获取所有内容;cb-get-focus:打开后光标定位在 id 所在的块;cb-get-hl: 打开后 id 块高亮
|
2023-05-28 23:20:30 +08:00
|
|
|
|
zoomIn?: boolean // 是否缩放
|
|
|
|
|
|
},
|
|
|
|
|
|
pdf?: {
|
|
|
|
|
|
path: string,
|
|
|
|
|
|
page?: number, // pdf 页码
|
|
|
|
|
|
id?: string, // File Annotation id
|
|
|
|
|
|
},
|
|
|
|
|
|
asset?: {
|
|
|
|
|
|
path: string,
|
|
|
|
|
|
},
|
|
|
|
|
|
search?: ISearchOption
|
|
|
|
|
|
card?: {
|
2023-05-28 23:45:23 +08:00
|
|
|
|
type: TCardType,
|
2023-05-28 23:20:30 +08:00
|
|
|
|
id?: string, // cardType 为 all 时不传,否则传文档或笔记本 id
|
|
|
|
|
|
title?: string // cardType 为 all 时不传,否则传文档或笔记本名称
|
|
|
|
|
|
},
|
|
|
|
|
|
custom?: {
|
|
|
|
|
|
title: string,
|
|
|
|
|
|
icon: string,
|
|
|
|
|
|
data?: any
|
2023-08-18 17:38:11 +08:00
|
|
|
|
id: string
|
2023-05-28 23:20:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
position?: "right" | "bottom",
|
|
|
|
|
|
keepCursor?: boolean // 是否跳转到新 tab 上
|
|
|
|
|
|
removeCurrentTab?: boolean // 在当前页签打开时需移除原有页签
|
|
|
|
|
|
afterOpen?: () => void // 打开后回调
|
|
|
|
|
|
}) => {
|
|
|
|
|
|
if (options.doc) {
|
2023-05-28 23:45:23 +08:00
|
|
|
|
if (options.doc.zoomIn) {
|
|
|
|
|
|
if (options.doc.action && !options.doc.action.includes(Constants.CB_GET_ALL)) {
|
|
|
|
|
|
options.doc.action.push(Constants.CB_GET_ALL);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
options.doc.action = [Constants.CB_GET_ALL];
|
|
|
|
|
|
}
|
2023-05-28 23:20:30 +08:00
|
|
|
|
}
|
2023-05-30 12:11:50 +08:00
|
|
|
|
if (!options.doc.action) {
|
2023-06-01 20:50:49 +08:00
|
|
|
|
options.doc.action = [];
|
2023-05-30 12:11:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
return openFileById({
|
2023-05-28 23:20:30 +08:00
|
|
|
|
app: options.app,
|
|
|
|
|
|
keepCursor: options.keepCursor,
|
|
|
|
|
|
removeCurrentTab: options.removeCurrentTab,
|
|
|
|
|
|
position: options.position,
|
|
|
|
|
|
afterOpen: options.afterOpen,
|
|
|
|
|
|
id: options.doc.id,
|
|
|
|
|
|
action: options.doc.action,
|
|
|
|
|
|
zoomIn: options.doc.zoomIn
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (options.asset) {
|
2023-05-30 12:11:50 +08:00
|
|
|
|
return openFile({
|
2023-05-28 23:20:30 +08:00
|
|
|
|
app: options.app,
|
|
|
|
|
|
keepCursor: options.keepCursor,
|
|
|
|
|
|
removeCurrentTab: options.removeCurrentTab,
|
|
|
|
|
|
position: options.position,
|
|
|
|
|
|
afterOpen: options.afterOpen,
|
|
|
|
|
|
assetPath: options.asset.path,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (options.pdf) {
|
2023-05-30 12:11:50 +08:00
|
|
|
|
return openFile({
|
2023-05-28 23:20:30 +08:00
|
|
|
|
app: options.app,
|
|
|
|
|
|
keepCursor: options.keepCursor,
|
|
|
|
|
|
removeCurrentTab: options.removeCurrentTab,
|
|
|
|
|
|
position: options.position,
|
|
|
|
|
|
afterOpen: options.afterOpen,
|
|
|
|
|
|
assetPath: options.pdf.path,
|
|
|
|
|
|
page: options.pdf.id || options.pdf.page,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (options.search) {
|
2023-05-28 23:45:23 +08:00
|
|
|
|
if (!options.search.idPath) {
|
|
|
|
|
|
options.search.idPath = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!options.search.hPath) {
|
|
|
|
|
|
options.search.hPath = "";
|
|
|
|
|
|
}
|
2023-05-30 12:11:50 +08:00
|
|
|
|
return openFile({
|
2023-05-28 23:20:30 +08:00
|
|
|
|
app: options.app,
|
|
|
|
|
|
keepCursor: options.keepCursor,
|
|
|
|
|
|
removeCurrentTab: options.removeCurrentTab,
|
|
|
|
|
|
position: options.position,
|
|
|
|
|
|
afterOpen: options.afterOpen,
|
|
|
|
|
|
searchData: options.search,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (options.card) {
|
2023-05-30 12:11:50 +08:00
|
|
|
|
return openFile({
|
2023-05-28 23:20:30 +08:00
|
|
|
|
app: options.app,
|
|
|
|
|
|
keepCursor: options.keepCursor,
|
|
|
|
|
|
removeCurrentTab: options.removeCurrentTab,
|
|
|
|
|
|
position: options.position,
|
|
|
|
|
|
afterOpen: options.afterOpen,
|
|
|
|
|
|
custom: {
|
|
|
|
|
|
icon: "iconRiffCard",
|
|
|
|
|
|
title: window.siyuan.languages.spaceRepetition,
|
2023-05-28 23:45:23 +08:00
|
|
|
|
data: {
|
|
|
|
|
|
cardType: options.card.type,
|
|
|
|
|
|
id: options.card.id || "",
|
|
|
|
|
|
title: options.card.title,
|
|
|
|
|
|
},
|
2023-08-18 17:38:11 +08:00
|
|
|
|
id: "siyuan-card"
|
2023-05-28 23:20:30 +08:00
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (options.custom) {
|
2023-05-30 12:11:50 +08:00
|
|
|
|
return openFile(options);
|
2023-05-28 23:20:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-29 11:20:08 +08:00
|
|
|
|
};
|
2023-05-10 16:11:02 +08:00
|
|
|
|
/// #endif
|
|
|
|
|
|
|
2023-05-07 17:31:50 +08:00
|
|
|
|
export const API = {
|
2023-05-07 22:00:41 +08:00
|
|
|
|
confirm: confirmDialog,
|
|
|
|
|
|
showMessage,
|
2023-05-12 17:11:43 +08:00
|
|
|
|
adaptHotkey: updateHotkeyTip,
|
2023-05-08 15:11:50 +08:00
|
|
|
|
fetchPost,
|
|
|
|
|
|
fetchSyncPost,
|
|
|
|
|
|
fetchGet,
|
2023-05-30 09:29:50 +08:00
|
|
|
|
getFrontend,
|
2023-05-30 09:42:25 +08:00
|
|
|
|
getBackend,
|
2023-05-10 16:11:02 +08:00
|
|
|
|
openTab,
|
2023-08-30 22:28:25 +08:00
|
|
|
|
openWindow,
|
2023-06-23 11:28:32 +08:00
|
|
|
|
Protyle,
|
2023-05-10 00:01:47 +08:00
|
|
|
|
Plugin,
|
2023-05-08 10:56:52 +08:00
|
|
|
|
Dialog,
|
2023-05-08 12:35:56 +08:00
|
|
|
|
Menu,
|
2023-10-30 10:03:27 +08:00
|
|
|
|
Setting,
|
|
|
|
|
|
Constants,
|
2023-11-24 21:58:16 +08:00
|
|
|
|
openMobileFileById
|
2023-05-07 17:31:50 +08:00
|
|
|
|
};
|