-
Notifications
You must be signed in to change notification settings - Fork 21
/
siyuan.d.ts
491 lines (423 loc) · 12.6 KB
/
siyuan.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
import {
IGetDocInfo,
IGetTreeStat,
IMenuBaseDetail,
Config,
Custom,
Dock,
IMenu,
IObject,
IPosition,
ISiyuan,
IWebSocketData,
IProtyle,
Lute,
Protyle,
Toolbar,
IProtyleOptions,
TProtyleAction,
subMenu,
App,
Files,
Tab, Model,
IMenuItem,
} from "./types";
export * from "./types";
declare global {
export interface Window extends Global {
}
}
export type TDock = "file" | "outline" | "inbox" | "bookmark" | "tag" | "graph" | "globalGraph" | "backlink"
export type TCardType = "doc" | "notebook" | "all"
export type TEventBus = keyof IEventBusMap
export type TPluginDockPosition = "LeftTop" | "LeftBottom" | "RightTop" | "RightBottom" | "BottomLeft" | "BottomRight"
export type TOperation =
"insert"
| "update"
| "delete"
| "move"
| "foldHeading"
| "unfoldHeading"
| "setAttrs"
| "updateAttrs"
| "append"
| "insertAttrViewBlock"
| "removeAttrViewBlock"
| "addAttrViewCol"
| "removeAttrViewCol"
| "addFlashcards"
| "removeFlashcards"
| "updateAttrViewCell"
| "updateAttrViewCol"
| "sortAttrViewRow"
| "sortAttrViewCol"
| "setAttrViewColHidden"
| "setAttrViewColWrap"
| "setAttrViewColWidth"
| "updateAttrViewColOptions"
| "removeAttrViewColOption"
| "updateAttrViewColOption"
| "setAttrViewName"
| "setAttrViewFilters"
| "setAttrViewSorts"
| "setAttrViewColCalc"
| "updateAttrViewColNumberFormat"
export interface Global {
Lute: typeof Lute;
siyuan: ISiyuan;
}
export interface IEventBusMap {
"click-flashcard-action": {
card: ICard,
type: string, // 1 - 重来;2 - 困难;3 - 良好;4 - 简单;-1 - 显示答案;-2 - 上一个 ;-3 - 跳过
};
"click-blockicon": {
menu: subMenu,
protyle: IProtyle,
blockElements: HTMLElement[],
};
"click-editorcontent": {
protyle: IProtyle,
event: MouseEvent,
};
"click-editortitleicon": {
menu: subMenu,
protyle: IProtyle,
data: IGetDocInfo,
};
"click-pdf": {
event: MouseEvent,
};
"closed-notebook": IWebSocketData;
"destroy-protyle": {
protyle: IProtyle,
};
"input-search": {
protyle: Protyle,
config: Config.IUILayoutTabSearchConfig,
searchElement: HTMLInputElement,
};
"loaded-protyle-dynamic": {
protyle: IProtyle,
position: "afterend" | "beforebegin",
};
"loaded-protyle-static": {
protyle: IProtyle,
};
"lock-screen": void;
"switch-protyle": {
protyle: IProtyle,
};
"open-menu-av": IMenuBaseDetail & { selectRowElements: HTMLElement[] };
"open-menu-blockref": IMenuBaseDetail;
"open-menu-breadcrumbmore": {
menu: subMenu,
protyle: IProtyle,
data: IGetTreeStat,
};
"open-menu-content": IMenuBaseDetail & { range: Range };
"open-menu-fileannotationref": IMenuBaseDetail;
"open-menu-image": IMenuBaseDetail;
"open-menu-link": IMenuBaseDetail;
"open-menu-tag": IMenuBaseDetail;
"open-menu-doctree": {
menu: subMenu,
elements: NodeListOf<HTMLElement>,
type: "doc" | "docs" | "notebook",
};
"open-menu-inbox": {
menu: subMenu,
element: HTMLElement,
ids: string[],
};
"open-noneditableblock": {
protyle: IProtyle,
toolbar: Toolbar,
blockElement: HTMLElement,
renderElement: HTMLElement,
};
"open-siyuan-url-block": {
url: string,
id: string,
focus: boolean,
exist: boolean,
};
"open-siyuan-url-plugin": {
url: string,
};
"opened-notebook": IWebSocketData;
"paste": {
protyle: IProtyle,
resolve: new <T>(value: T | PromiseLike<T>) => void,
textHTML: string,
textPlain: string,
siyuanHTML: string,
files: FileList | DataTransferItemList | string[]; // 读取本地文件时为 string[]
}
"ws-main": IWebSocketData;
"sync-start": IWebSocketData;
"sync-end": IWebSocketData;
"sync-fail": IWebSocketData;
"mobile-keyboard-show": void;
"mobile-keyboard-hide": void;
}
export interface IPluginDockTab {
position: TPluginDockPosition,
size: Config.IUILayoutDockPanelSize,
icon: string,
hotkey?: string,
title: string,
index?: number
show?: boolean
}
export interface ICommand {
langKey: string, // 用于区分不同快捷键的 key, 同时作为 i18n 的字段名
langText?: string, // 显示的文本, 指定后不再使用 langKey 对应的 i18n 文本
/**
* 目前需使用 MacOS 符号标识,顺序按照 ⌥⇧⌘,入 ⌥⇧⌘A
* "Ctrl": "⌘",
* "Shift": "⇧",
* "Alt": "⌥",
* "Tab": "⇥",
* "Backspace": "⌫",
* "Delete": "⌦",
* "Enter": "↩",
*/
hotkey: string,
customHotkey?: string,
callback?: () => void // 其余回调存在时将不会触
globalCallback?: () => void // 焦点不在应用内时执行的回调
fileTreeCallback?: (file: Files) => void // 焦点在文档树上时执行的回调
editorCallback?: (protyle: IProtyle) => void // 焦点在编辑器上时执行的回调
dockCallback?: (element: HTMLElement) => void // 焦点在 dock 上时执行的回调
}
export interface ICard {
deckID: string
cardID: string
blockID: string
nextDues: IObject
lapses: number // 遗忘次数
lastReview: number // 最后复习时间
reps: number // 复习次数
state: number // 卡片状态 0:新卡
}
export interface ICardData {
cards: ICard[],
unreviewedCount: number
unreviewedNewCardCount: number
unreviewedOldCardCount: number
}
export function adaptHotkey(hotkey: string): string
export function confirm(title: string, text: string, confirmCallback?: (dialog: Dialog) => void, cancelCallback?: (dialog: Dialog) => void): void;
export function fetchPost(url: string, data?: any, callback?: (response: IWebSocketData) => void, headers?: IObject): void;
export function fetchSyncPost(url: string, data?: any): Promise<IWebSocketData>;
export function fetchGet(url: string, callback: (response: IWebSocketData) => void): void;
export function openWindow(options: {
position?: {
x: number,
y: number,
},
height?: number,
width?: number,
tab?: Tab,
doc?: {
id: string; // 块 id
},
}): void;
export function openMobileFileById(app: App, id: string, action?: TProtyleAction[]): void;
export function openTab(options: {
app: App,
doc?: {
id: string, // 块 id
action?: TProtyleAction[],
zoomIn?: boolean, // 是否缩放
};
pdf?: {
path: string,
page?: number, // pdf 页码
id?: string, // File Annotation id
};
asset?: {
path: string,
};
search?: Config.IUILayoutTabSearchConfig;
card?: {
type: TCardType,
id?: string, // cardType 为 all 时不传,否则传文档或笔记本 id
title?: string, // cardType 为 all 时不传,否则传文档或笔记本名称
};
custom?: {
id: string, // 插件名称+页签类型:plugin.name + tab.type
icon: string,
title: string,
data?: any,
};
position?: "right" | "bottom";
keepCursor?: boolean; // 是否跳转到新 tab 上
removeCurrentTab?: boolean; // 在当前页签打开时需移除原有页签
afterOpen?: () => void; // 打开后回调
}): Promise<Tab>
export function getFrontend(): "desktop" | "desktop-window" | "mobile" | "browser-desktop" | "browser-mobile";
export function getBackend(): "windows" | "linux" | "darwin" | "docker" | "android" | "ios" | "harmony";
export function lockScreen(app: App): void
export function exitSiYuan(): void
export function getAllEditor(): Protyle[]
export function getModelByDockType(type: TDock | string): Model | any;
/**
* @param timeout - ms. 0: manual close;-1: always show; 6000: default
* @param {string} [type=info]
*/
export function showMessage(text: string, timeout?: number, type?: "info" | "error", id?: string): void;
export abstract class Plugin {
eventBus: EventBus;
i18n: IObject;
data: any;
displayName: string;
readonly name: string;
app: App;
commands: ICommand[];
setting: Setting;
protyleSlash: {
filter: string[],
html: string,
id: string,
callback(protyle: Protyle): void,
}[];
protyleOptions: IProtyleOptions;
constructor(options: {
app: App,
name: string,
i18n: IObject,
});
onload(): void;
onunload(): void;
uninstall(): void;
onLayoutReady(): void;
/**
* Must be executed before the synchronous function.
* @param {string} [options.position=right]
* @param {string} options.icon - Support svg id or svg tag.
*/
addTopBar(options: {
icon: string,
title: string,
callback: (event: MouseEvent) => void
position?: "right" | "left"
}): HTMLElement;
/**
* Must be executed before the synchronous function.
* @param {string} [options.position=right]
*/
addStatusBar(options: {
element: HTMLElement,
position?: "right" | "left",
}): HTMLElement;
openSetting(): void;
loadData(storageName: string): Promise<any>;
saveData(storageName: string, content: any): Promise<void>;
removeData(storageName: string): Promise<any>;
addIcons(svg: string): void;
getOpenedTab(): { [key: string]: Custom[] };
/**
* Must be executed before the synchronous function.
*/
addTab(options: {
type: string,
beforeDestroy?: (this: Custom) => void,
destroy?: (this: Custom) => void,
resize?: (this: Custom) => void,
update?: (this: Custom) => void,
init: (this: Custom) => void,
}): () => Custom;
/**
* Must be executed before the synchronous function.
*/
addDock(options: {
config: IPluginDockTab,
data: any,
type: string,
destroy?: (this: Dock) => void,
resize?: (this: Dock) => void,
update?: (this: Dock) => void,
init: (this: Dock, dock: Dock) => void,
}): { config: IPluginDockTab, model: Dock };
addCommand(options: ICommand): void;
addFloatLayer(options: {
ids: string[],
defIds?: string[],
x?: number,
y?: number,
targetElement?: HTMLElement
}): void;
updateCards(options: ICardData): Promise<ICardData> | ICardData;
updateProtyleToolbar(toolbar: Array<string | IMenuItem>): Array<string | IMenuItem>;
}
export class Setting {
constructor(options: {
height?: string,
width?: string,
destroyCallback?: () => void,
confirmCallback?: () => void,
});
addItem(options: {
title: string,
direction?: "column" | "row"
description?: string,
actionElement?: HTMLElement,
createActionElement?(): HTMLElement,
}): void;
open(name: string): void;
}
export class EventBus {
on<
K extends TEventBus,
D = IEventBusMap[K],
>(type: K, listener: (event: CustomEvent<D>) => any): void;
once<
K extends TEventBus,
D = IEventBusMap[K],
>(type: K, listener: (event: CustomEvent<D>) => any): void;
off<
K extends TEventBus,
D = IEventBusMap[K],
>(type: K, listener: (event: CustomEvent<D>) => any): void;
emit<
K extends TEventBus,
D = IEventBusMap[K],
>(type: K, detail?: D): boolean;
}
export class Dialog {
element: HTMLElement;
editors: { [key: string]: Protyle };
data: any;
constructor(options: {
positionId?: string,
title?: string,
transparent?: boolean,
content: string,
width?: string,
height?: string,
destroyCallback?: (options?: IObject) => void,
disableClose?: boolean,
hideCloseIcon?: boolean,
disableAnimation?: boolean,
resizeCallback?: (type: string) => void
});
destroy(options?: IObject): void;
bindInput(inputElement: HTMLInputElement | HTMLTextAreaElement, enterEvent?: () => void): void;
}
export class Menu {
private menu;
isOpen: boolean;
element: HTMLElement;
constructor(id?: string, closeCB?: () => void);
showSubMenu(subMenuElement: HTMLElement): void;
addItem(option: IMenu): HTMLElement;
addSeparator(index?: number, ignore?: boolean): HTMLElement;
open(options: IPosition): void;
/**
* @param {string} [position=all]
*/
fullscreen(position?: "bottom" | "all"): void;
close(): void;
}