siyuan 0.8.2 → 0.8.4

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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # Changelog
2
2
 
3
- ## 0.8.3 2023-09
3
+ ## 0.8.5 2023-09
4
+
5
+ ## 0.8.4 2023-09-19
6
+
7
+ * [Improve `Menu`](https://github.com/siyuan-note/petal/pull/16)
8
+ * [Add plugin function `transaction`](https://github.com/siyuan-note/siyuan/issues/9172)
9
+ * [Add `CustomEvent` type definition](https://github.com/siyuan-note/petal/pull/15)
10
+
11
+ ## 0.8.3 2023-09-05
12
+
13
+ * [Plugin API add openWindow and command.globalCallback](https://github.com/siyuan-note/siyuan/issues/9032)
4
14
 
5
15
  ## 0.8.2 2023-08-29
6
16
 
package/package.json CHANGED
@@ -1,7 +1,17 @@
1
1
  {
2
2
  "name": "siyuan",
3
- "contributors": ["zuoez02", "Vanessa"],
3
+ "contributors": [
4
+ "zuoez02",
5
+ "Vanessa"
6
+ ],
4
7
  "types": "siyuan.d.ts",
5
- "version": "0.8.2",
8
+ "files": [
9
+ "types",
10
+ "CHANGELOG.md",
11
+ "package.json",
12
+ "README.md",
13
+ "siyuan.d.ts"
14
+ ],
15
+ "version": "0.8.4",
6
16
  "repository": "https://github.com/siyuan-note/petal"
7
17
  }
package/siyuan.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- type TEventBus = "ws-main" |
2
- "click-blockicon" | "click-editorcontent" | "click-pdf" | "click-editortitleicon" |
3
- "open-noneditableblock" |
4
- "open-menu-blockref" | "open-menu-fileannotationref" | "open-menu-tag" | "open-menu-link" | "open-menu-image" |
5
- "open-menu-av" | "open-menu-content" | "open-menu-breadcrumbmore" |
6
- "open-siyuan-url-plugin" | "open-siyuan-url-block" |
7
- "input-search" |
8
- "loaded-protyle" | "loaded-protyle-dynamic" |
9
- "destroy-protyle"
1
+ import type * as types from "./types";
2
+ import {IProtyle} from "./types/protyle";
3
+
4
+ declare global {
5
+ interface Window extends Global {
6
+ }
7
+ }
8
+
9
+ type TEventBus = keyof IEventBusMap
10
10
 
11
11
  type TCardType = "doc" | "notebook" | "all"
12
12
 
@@ -25,10 +25,76 @@ type TProtyleAction = "cb-get-append" | // 向下滚动加载
25
25
  "cb-get-html" | // 直接渲染,不需要再 /api/block/getDocInfo,否则搜索表格无法定位
26
26
  "cb-get-history" // 历史渲染
27
27
 
28
- declare global {
29
- interface Window {
30
- Lute: Lute
31
- }
28
+ type TOperation =
29
+ "insert"
30
+ | "update"
31
+ | "delete"
32
+ | "move"
33
+ | "foldHeading"
34
+ | "unfoldHeading"
35
+ | "setAttrs"
36
+ | "updateAttrs"
37
+ | "append"
38
+ | "insertAttrViewBlock"
39
+ | "removeAttrViewBlock"
40
+ | "addAttrViewCol"
41
+ | "removeAttrViewCol"
42
+ | "addFlashcards"
43
+ | "removeFlashcards"
44
+ | "updateAttrViewCell"
45
+ | "updateAttrViewCol"
46
+ | "sortAttrViewRow"
47
+ | "sortAttrViewCol"
48
+ | "setAttrViewColHidden"
49
+ | "setAttrViewColWrap"
50
+ | "setAttrViewColWidth"
51
+ | "updateAttrViewColOptions"
52
+ | "removeAttrViewColOption"
53
+ | "updateAttrViewColOption"
54
+ | "setAttrViewName"
55
+ | "setAttrViewFilters"
56
+ | "setAttrViewSorts"
57
+ | "setAttrViewColCalc"
58
+ | "updateAttrViewColNumberFormat"
59
+
60
+ type TAVCol =
61
+ "text"
62
+ | "date"
63
+ | "number"
64
+ | "relation"
65
+ | "rollup"
66
+ | "select"
67
+ | "block"
68
+ | "mSelect"
69
+ | "url"
70
+ | "email"
71
+ | "phone"
72
+
73
+ interface Global {
74
+ Lute: Lute;
75
+ }
76
+
77
+ interface IEventBusMap {
78
+ "click-blockicon": types.events.IClickBlockIconDetail;
79
+ "click-editorcontent": types.events.IClickEditorContentDetail;
80
+ "click-editortitleicon": types.events.IClickEditorTitleIconDetail;
81
+ "click-pdf": types.events.IClickPdfDetail;
82
+ "destroy-protyle": types.events.IDestroyProtyleDetail;
83
+ "input-search": types.events.IInputSearchDetail;
84
+ "loaded-protyle-dynamic": types.events.ILoadedProtyleDynamicDetail;
85
+ "loaded-protyle": types.events.ILoadedProtyleDetail;
86
+ "open-menu-av": any;
87
+ "open-menu-blockref": types.events.IOpenMenuBlockRefDetail;
88
+ "open-menu-breadcrumbmore": types.events.IOpenMenuBreadcrumbMoreDetail;
89
+ "open-menu-content": types.events.IOpenMenuContentDetail;
90
+ "open-menu-fileannotationref": types.events.IOpenMenuFileAnnotationRefDetail;
91
+ "open-menu-image": types.events.IOpenMenuImageDetail;
92
+ "open-menu-link": types.events.IOpenMenuLinkDetail;
93
+ "open-menu-tag": types.events.IOpenMenuTagDetail;
94
+ "open-noneditableblock": types.events.IOpenNonEditableBlockDetail;
95
+ "open-siyuan-url-block": types.events.IOpenSiyuanUrlBlockDetail;
96
+ "open-siyuan-url-plugin": types.events.IOpenSiyuanUrlPluginDetail;
97
+ "ws-main": types.events.IWebSocketMainDetail;
32
98
  }
33
99
 
34
100
  interface ITab {
@@ -51,6 +117,7 @@ interface IModel {
51
117
  app: App;
52
118
  reqId: number;
53
119
  parent: ITab | any;
120
+
54
121
  send(cmd: string, param: Record<string, unknown>, process?: boolean): void;
55
122
  }
56
123
 
@@ -59,10 +126,15 @@ interface ICustomModel extends IModel {
59
126
  data: any;
60
127
  type: string;
61
128
  element: HTMLElement;
129
+
62
130
  init(): void;
131
+
63
132
  update?(): void;
133
+
64
134
  resize?(): void;
135
+
65
136
  beforeDestroy?(): void;
137
+
66
138
  destroy?(): void;
67
139
  }
68
140
 
@@ -166,10 +238,11 @@ interface ICommandOption {
166
238
  */
167
239
  hotkey: string,
168
240
  customHotkey?: string,
169
- callback?: () => void
170
- fileTreeCallback?: (file: any) => void
171
- editorCallback?: (protyle: any) => void
172
- dockCallback?: (element: HTMLElement) => void
241
+ callback?: () => void // 其余回调存在时将不会触
242
+ globalCallback?: () => void // 焦点不在应用内时执行的回调
243
+ fileTreeCallback?: (file: any) => void // 焦点在文档树上时执行的回调
244
+ editorCallback?: (protyle: any) => void // 焦点在编辑器上时执行的回调
245
+ dockCallback?: (element: HTMLElement) => void // 焦点在 dock 上时执行的回调
173
246
  }
174
247
 
175
248
  interface IProtyleOption {
@@ -201,12 +274,44 @@ interface IProtyleOption {
201
274
  after?(protyle: Protyle): void;
202
275
  }
203
276
 
277
+ interface IOperation {
278
+ action: TOperation, // move, delete 不需要传 data
279
+ id?: string,
280
+ avID?: string, // av
281
+ format?: string // updateAttrViewColNumberFormat 专享
282
+ keyID?: string // updateAttrViewCell 专享
283
+ rowID?: string // updateAttrViewCell 专享
284
+ data?: any, // updateAttr 时为 { old: IObject, new: IObject }, updateAttrViewCell 时为 {TAVCol: {content: string}}
285
+ parentID?: string
286
+ previousID?: string
287
+ retData?: any
288
+ nextID?: string // insert 专享
289
+ srcIDs?: string[] // insertAttrViewBlock 专享
290
+ name?: string // addAttrViewCol 专享
291
+ type?: TAVCol // addAttrViewCol 专享
292
+ deckID?: string // add/removeFlashcards 专享
293
+ blockIDs?: string[] // add/removeFlashcards 专享
294
+ }
295
+
204
296
  export function fetchPost(url: string, data?: any, callback?: (response: IWebSocketData) => void, headers?: IObject): void;
205
297
 
206
298
  export function fetchSyncPost(url: string, data?: any): Promise<IWebSocketData>;
207
299
 
208
300
  export function fetchGet(url: string, callback: (response: IWebSocketData) => void): void;
209
301
 
302
+ export function openWindow(options: {
303
+ position?: {
304
+ x: number,
305
+ y: number,
306
+ },
307
+ height?: number,
308
+ width?: number,
309
+ tab?: ITab,
310
+ doc?: {
311
+ id: string, // 块 id
312
+ },
313
+ }): void;
314
+
210
315
  export function openTab(options: {
211
316
  app: App,
212
317
  doc?: {
@@ -374,6 +479,8 @@ export class Protyle {
374
479
  * @param {boolean} [useProtyleRange=false]
375
480
  */
376
481
  insert(html: string, isBlock?: boolean, useProtyleRange?: boolean): void
482
+
483
+ transaction(doOperations: IOperation[], undoOperations?: IOperation[]): void;
377
484
  }
378
485
 
379
486
  export class Setting {
@@ -395,13 +502,25 @@ export class Setting {
395
502
  }
396
503
 
397
504
  export class EventBus {
398
- on(type: TEventBus, listener: (event: CustomEvent<any>) => void): void;
399
-
400
- once(type: TEventBus, listener: (event: CustomEvent<any>) => void): void;
401
-
402
- off(type: TEventBus, listener: (event: CustomEvent<any>) => void): void;
403
-
404
- emit(type: TEventBus, detail?: any): boolean;
505
+ on<
506
+ K extends TEventBus,
507
+ D = IEventBusMap[K],
508
+ >(type: K, listener: (event: CustomEvent<D>) => any): void;
509
+
510
+ once<
511
+ K extends TEventBus,
512
+ D = IEventBusMap[K],
513
+ >(type: K, listener: (event: CustomEvent<D>) => any): void;
514
+
515
+ off<
516
+ K extends TEventBus,
517
+ D = IEventBusMap[K],
518
+ >(type: K, listener: (event: CustomEvent<D>) => any): void;
519
+
520
+ emit<
521
+ K extends TEventBus,
522
+ D = IEventBusMap[K],
523
+ >(type: K, detail?: D): boolean;
405
524
  }
406
525
 
407
526
  export class Dialog {
@@ -427,6 +546,8 @@ export class Dialog {
427
546
  export class Menu {
428
547
  constructor(id?: string, closeCallback?: () => void);
429
548
 
549
+ element: HTMLElement;
550
+
430
551
  showSubMenu(subMenuElement: HTMLElement): void;
431
552
 
432
553
  addItem(options: IMenuItemOption): HTMLElement;
@@ -0,0 +1,237 @@
1
+ import type { IProtyle } from "./protyle";
2
+ import {Menu} from "./../siyuan";
3
+
4
+ //#region click-block-icon
5
+ interface IBlockIconDetail {
6
+ menu: InstanceType<typeof Menu>;
7
+ protyle: IProtyle;
8
+ data?: IDocumentData;
9
+ blockElements?: HTMLElement[];
10
+ }
11
+
12
+ interface IDocumentData {
13
+ id: string;
14
+ ial: Record<string, string>;
15
+ icon: string;
16
+ name: string;
17
+ rootID: string;
18
+ refIDs: string[];
19
+ refCount: number;
20
+ subFileCount: number;
21
+ }
22
+
23
+ /**
24
+ * `click-blockicon`
25
+ */
26
+ export interface IClickBlockIconDetail extends IBlockIconDetail {
27
+ blockElements: HTMLElement[];
28
+ }
29
+
30
+ /**
31
+ * `click-editortitleicon`
32
+ */
33
+ export interface IClickEditorTitleIconDetail extends IBlockIconDetail {
34
+ data: IDocumentData;
35
+ }
36
+ //#endregion click-block-icon
37
+
38
+ //#region click-editor-content
39
+ /**
40
+ * `click-editorcontent`
41
+ */
42
+ export interface IClickEditorContentDetail {
43
+ event: PointerEvent;
44
+ protyle: IProtyle;
45
+ }
46
+ //#endregion click-editor-content
47
+
48
+ //#region click-pdf
49
+ /**
50
+ * `click-pdf`
51
+ */
52
+ export interface IClickPdfDetail {
53
+ event: PointerEvent;
54
+ }
55
+ //#endregion click-pdf
56
+
57
+ //#region protyle
58
+ /**
59
+ * `loaded-protyle`
60
+ */
61
+ export interface ILoadedProtyleDetail extends IProtyle {
62
+ }
63
+
64
+ /**
65
+ * `loaded-protyle-dynamic`
66
+ */
67
+ export interface ILoadedProtyleDynamicDetail {
68
+ protyle: IProtyle;
69
+ positon: string;
70
+ }
71
+
72
+ /**
73
+ * `destroy-protyle`
74
+ */
75
+ export interface IDestroyProtyleDetail {
76
+ protyle: IProtyle;
77
+ }
78
+ //#endregion protyle
79
+
80
+ //#region input-search
81
+ interface IInputSearchConfig {
82
+ removed: boolean;
83
+ k: string;
84
+ r: string;
85
+ hasReplace: boolean;
86
+ method: number;
87
+ hPath: string;
88
+ idPath: string[];
89
+ group: number;
90
+ sort: number;
91
+ types: {
92
+ blockquote: boolean;
93
+ codeBlock: boolean;
94
+ document: boolean;
95
+ embedBlock: boolean;
96
+ heading: boolean;
97
+ htmlBlock: boolean;
98
+ list: boolean;
99
+ listItem: boolean;
100
+ mathBlock: boolean;
101
+ paragraph: boolean;
102
+ superBlock: boolean;
103
+ table: boolean;
104
+ };
105
+ page: number;
106
+ }
107
+
108
+ interface IInputSearchProtyle {
109
+ protyle: IProtyle;
110
+ }
111
+
112
+ /**
113
+ * `input-search`
114
+ */
115
+ export interface IInputSearchDetail {
116
+ config: IInputSearchConfig;
117
+ protyle: IInputSearchProtyle;
118
+ searchElement: HTMLInputElement;
119
+ }
120
+ //#endregion input-search
121
+
122
+ //#region open-menu
123
+ interface IMenuBaseDetail {
124
+ menu: InstanceType<typeof Menu>;
125
+ protyle: IProtyle;
126
+ }
127
+
128
+ interface IMenuInlineDetail extends IMenuBaseDetail {
129
+ element: HTMLSpanElement,
130
+ }
131
+
132
+ interface IBreadcrumbData {
133
+ imageCount: number;
134
+ linkCount: number;
135
+ refCount: number;
136
+ runeCount: number;
137
+ wordCount: number;
138
+ }
139
+
140
+ /**
141
+ * `open-menu-breadcrumbmore`
142
+ */
143
+ export interface IOpenMenuBreadcrumbMoreDetail extends IMenuBaseDetail {
144
+ data: IBreadcrumbData;
145
+ }
146
+
147
+ /**
148
+ * `open-menu-content`
149
+ */
150
+ export interface IOpenMenuContentDetail extends IMenuBaseDetail {
151
+ element: HTMLDivElement,
152
+ range: Range;
153
+ }
154
+
155
+ /**
156
+ * `open-menu-blockref`
157
+ */
158
+ export interface IOpenMenuBlockRefDetail extends IMenuInlineDetail {
159
+ }
160
+
161
+ /**
162
+ * `open-menu-fileannotationref`
163
+ */
164
+ export interface IOpenMenuFileAnnotationRefDetail extends IMenuInlineDetail {
165
+ }
166
+
167
+ /**
168
+ * `open-menu-image`
169
+ */
170
+ export interface IOpenMenuImageDetail extends IMenuInlineDetail {
171
+ }
172
+
173
+ /**
174
+ * `open-menu-link`
175
+ */
176
+ export interface IOpenMenuLinkDetail extends IMenuInlineDetail {
177
+ }
178
+
179
+ /**
180
+ * `open-menu-tag`
181
+ */
182
+ export interface IOpenMenuTagDetail extends IMenuInlineDetail {
183
+ }
184
+ //#endregion open-menu
185
+
186
+ //#region open-noneditableblock
187
+ interface INonEditableBlockToolbar {
188
+ element: HTMLDivElement;
189
+ range: Range;
190
+ subElement: HTMLDivElement;
191
+ subElementCloseCB: () => any;
192
+ toolbarHeight: number;
193
+ }
194
+
195
+ /**
196
+ * `open-noneditableblock`
197
+ */
198
+ export interface IOpenNonEditableBlockDetail {
199
+ protyle: IProtyle;
200
+ toolbar: INonEditableBlockToolbar;
201
+ }
202
+ //#endregion open-noneditableblock
203
+
204
+ //#region open-siyuan-url
205
+ interface IOpenSiyuanUrlDetail {
206
+ url: string;
207
+ }
208
+
209
+ /**
210
+ * `open-siyuan-url-block`
211
+ */
212
+ export interface IOpenSiyuanUrlBlockDetail extends IOpenSiyuanUrlDetail {
213
+ id: string;
214
+ focus: boolean;
215
+ exist: boolean;
216
+ }
217
+
218
+ /**
219
+ * `open-siyuan-url-plugin`
220
+ */
221
+ export interface IOpenSiyuanUrlPluginDetail extends IOpenSiyuanUrlDetail {
222
+ }
223
+ //#endregion open-siyuan-url
224
+
225
+ //#region ws-main
226
+ /**
227
+ * `ws-main`
228
+ */
229
+ export interface IWebSocketMainDetail {
230
+ cmd?: string
231
+ callback?: string
232
+ data?: any
233
+ msg: string
234
+ code: number
235
+ sid?: string
236
+ }
237
+ //#endregion ws-main
@@ -0,0 +1,2 @@
1
+ export * as events from "./events";
2
+ export * as protyle from "./protyle";
@@ -0,0 +1,54 @@
1
+ import {App, Lute} from "./../siyuan";
2
+
3
+ // REF: https://github.com/siyuan-note/siyuan/blob/dev/app/src/types/protyle.d.ts
4
+ export interface IProtyle {
5
+ app: App;
6
+ transactionTime: number;
7
+ id: string;
8
+ block: {
9
+ id?: string;
10
+ scroll?: boolean;
11
+ parentID?: string;
12
+ parent2ID?: string;
13
+ rootID?: string;
14
+ showAll?: boolean;
15
+ mode?: number;
16
+ blockCount?: number;
17
+ action?: string[];
18
+ };
19
+ disabled: boolean;
20
+ selectElement?: HTMLElement;
21
+ ws?: any;
22
+ notebookId?: string;
23
+ path?: string;
24
+ model?: any;
25
+ updated: boolean;
26
+ element: HTMLElement;
27
+ scroll?: any;
28
+ gutter?: any;
29
+ breadcrumb?: {
30
+ id: string;
31
+ element: HTMLElement;
32
+ };
33
+ title?: {
34
+ editElement: HTMLElement;
35
+ element: HTMLElement;
36
+ };
37
+ background?: {
38
+ element: HTMLElement;
39
+ ial: Record<string, string>;
40
+ iconElement: HTMLElement;
41
+ imgElement: HTMLElement;
42
+ tagsElement: HTMLElement;
43
+ transparentData: string;
44
+ };
45
+ contentElement?: HTMLElement;
46
+ options: any;
47
+ lute?: Lute;
48
+ toolbar?: any;
49
+ preview?: any;
50
+ hint?: any;
51
+ upload?: any;
52
+ undo?: any;
53
+ wysiwyg?: any;
54
+ }