siyuan 0.8.1 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/package.json +1 -1
  3. package/siyuan.d.ts +76 -21
package/CHANGELOG.md CHANGED
@@ -1,6 +1,17 @@
1
1
  # Changelog
2
2
 
3
- ## 0.8.2 2023-08
3
+ ## 0.8.4 2023-09
4
+
5
+ ## 0.8.3 2023-09-05
6
+
7
+ * [Plugin API add openWindow and command.globalCallback](https://github.com/siyuan-note/siyuan/issues/9032)
8
+
9
+ ## 0.8.2 2023-08-29
10
+
11
+ * [Improve IModel type definitions](https://github.com/siyuan-note/petal/pull/14)
12
+ * [Add plugin type `TProtyleAction`](https://github.com/siyuan-note/siyuan/issues/8988)
13
+ * [Add plugin event bus `destroy-protyle`](https://github.com/siyuan-note/siyuan/issues/9033)
14
+ * [Add plugin event bus `loaded-protyle-dynamic`](https://github.com/siyuan-note/siyuan/issues/9021)
4
15
 
5
16
  ## 0.8.1 2023-08-21
6
17
 
package/package.json CHANGED
@@ -2,6 +2,6 @@
2
2
  "name": "siyuan",
3
3
  "contributors": ["zuoez02", "Vanessa"],
4
4
  "types": "siyuan.d.ts",
5
- "version": "0.8.1",
5
+ "version": "0.8.3",
6
6
  "repository": "https://github.com/siyuan-note/petal"
7
7
  }
package/siyuan.d.ts CHANGED
@@ -5,10 +5,26 @@ type TEventBus = "ws-main" |
5
5
  "open-menu-av" | "open-menu-content" | "open-menu-breadcrumbmore" |
6
6
  "open-siyuan-url-plugin" | "open-siyuan-url-block" |
7
7
  "input-search" |
8
- "loaded-protyle"
8
+ "loaded-protyle" | "loaded-protyle-dynamic" |
9
+ "destroy-protyle"
9
10
 
10
11
  type TCardType = "doc" | "notebook" | "all"
11
12
 
13
+ type TProtyleAction = "cb-get-append" | // 向下滚动加载
14
+ "cb-get-before" | // 向上滚动加载
15
+ "cb-get-unchangeid" | // 上下滚动,定位时不修改 blockid
16
+ "cb-get-hl" | // 高亮
17
+ "cb-get-focus" | // 光标定位
18
+ "cb-get-focusfirst" | // 动态定位到第一个块
19
+ "cb-get-setid" | // 重置 blockid
20
+ "cb-get-all" | // 获取所有块
21
+ "cb-get-backlink" | // 悬浮窗为传递型需展示上下文
22
+ "cb-get-unundo" | // 不需要记录历史
23
+ "cb-get-scroll" | // 滚动到指定位置
24
+ "cb-get-context" | // 包含上下文
25
+ "cb-get-html" | // 直接渲染,不需要再 /api/block/getDocInfo,否则搜索表格无法定位
26
+ "cb-get-history" // 历史渲染
27
+
12
28
  declare global {
13
29
  interface Window {
14
30
  Lute: Lute
@@ -31,10 +47,35 @@ interface ITab {
31
47
  }
32
48
 
33
49
  interface IModel {
34
- element: Element;
50
+ ws: WebSocket;
51
+ app: App;
52
+ reqId: number;
53
+ parent: ITab | any;
54
+
55
+ send(cmd: string, param: Record<string, unknown>, process?: boolean): void;
56
+ }
57
+
58
+ interface ICustomModel extends IModel {
35
59
  tab: ITab;
36
60
  data: any;
37
61
  type: string;
62
+ element: HTMLElement;
63
+
64
+ init(): void;
65
+
66
+ update?(): void;
67
+
68
+ resize?(): void;
69
+
70
+ beforeDestroy?(): void;
71
+
72
+ destroy?(): void;
73
+ }
74
+
75
+ interface IDockModel extends Omit<ICustomModel, "beforeDestroy"> {
76
+ }
77
+
78
+ interface ITabModel extends ICustomModel {
38
79
  }
39
80
 
40
81
  interface IObject {
@@ -131,14 +172,15 @@ interface ICommandOption {
131
172
  */
132
173
  hotkey: string,
133
174
  customHotkey?: string,
134
- callback?: () => void
135
- fileTreeCallback?: (file: any) => void
136
- editorCallback?: (protyle: any) => void
137
- dockCallback?: (element: HTMLElement) => void
175
+ callback?: () => void // 其余回调存在时将不会触
176
+ globalCallback?: () => void // 焦点不在应用内时执行的回调
177
+ fileTreeCallback?: (file: any) => void // 焦点在文档树上时执行的回调
178
+ editorCallback?: (protyle: any) => void // 焦点在编辑器上时执行的回调
179
+ dockCallback?: (element: HTMLElement) => void // 焦点在 dock 上时执行的回调
138
180
  }
139
181
 
140
182
  interface IProtyleOption {
141
- action?: string[],
183
+ action?: TProtyleAction[],
142
184
  mode?: "preview" | "wysiwyg",
143
185
  blockId: string
144
186
  key?: string
@@ -172,11 +214,24 @@ export function fetchSyncPost(url: string, data?: any): Promise<IWebSocketData>;
172
214
 
173
215
  export function fetchGet(url: string, callback: (response: IWebSocketData) => void): void;
174
216
 
217
+ export function openWindow(options: {
218
+ position?: {
219
+ x: number,
220
+ y: number,
221
+ },
222
+ height?: number,
223
+ width?: number,
224
+ tab?: ITab,
225
+ doc?: {
226
+ id: string, // 块 id
227
+ },
228
+ }): void;
229
+
175
230
  export function openTab(options: {
176
231
  app: App,
177
232
  doc?: {
178
233
  id: string, // 块 id
179
- action?: string [] // cb-get-all:获取所有内容;cb-get-focus:打开后光标定位在 id 所在的块;cb-get-hl: 打开后 id 块高亮
234
+ action?: string[] // cb-get-all:获取所有内容;cb-get-focus:打开后光标定位在 id 所在的块;cb-get-hl: 打开后 id 块高亮
180
235
  zoomIn?: boolean // 是否缩放
181
236
  },
182
237
  pdf?: {
@@ -197,7 +252,7 @@ export function openTab(options: {
197
252
  title: string,
198
253
  icon: string,
199
254
  data?: any
200
- id: string,
255
+ id: string, // 插件名称+页签类型:plugin.name + tab.type
201
256
  }
202
257
  position?: "right" | "bottom",
203
258
  keepCursor?: boolean // 是否跳转到新 tab 上
@@ -282,19 +337,19 @@ export abstract class Plugin {
282
337
 
283
338
  addIcons(svg: string): void;
284
339
 
285
- getOpenedTab(): { [key: string]: IModel[] } ;
340
+ getOpenedTab(): { [key: string]: ICustomModel[] };
286
341
 
287
342
  /**
288
343
  * Must be executed before the synchronous function.
289
344
  */
290
345
  addTab(options: {
291
346
  type: string,
292
- beforeDestroy?: () => void,
293
- destroy?: () => void,
294
- resize?: () => void,
295
- update?: () => void,
296
- init: () => void
297
- }): () => IModel
347
+ beforeDestroy?: (this: ITabModel) => void,
348
+ destroy?: (this: ITabModel) => void,
349
+ resize?: (this: ITabModel) => void,
350
+ update?: (this: ITabModel) => void,
351
+ init: (this: ITabModel) => void
352
+ }): () => ITabModel
298
353
 
299
354
  /**
300
355
  * Must be executed before the synchronous function.
@@ -303,11 +358,11 @@ export abstract class Plugin {
303
358
  config: IPluginDockTab,
304
359
  data: any,
305
360
  type: string,
306
- destroy?: () => void,
307
- resize?: () => void,
308
- update?: () => void,
309
- init: () => void
310
- }): { config: IPluginDockTab, model: IModel }
361
+ destroy?: (this: IDockModel) => void,
362
+ resize?: (this: IDockModel) => void,
363
+ update?: (this: IDockModel) => void,
364
+ init: (this: IDockModel) => void
365
+ }): { config: IPluginDockTab, model: IDockModel }
311
366
 
312
367
  addCommand(options: ICommandOption): void
313
368