siyuan 0.8.3 → 0.8.5

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.4 2023-09
3
+ ## 0.8.6 2023-10
4
+
5
+ ## 0.8.5 2023-10-10
6
+
7
+ * [Add plugin event bus `open-menu-doctree`](https://github.com/siyuan-note/siyuan/issues/9351)
8
+
9
+ ## 0.8.4 2023-09-19
10
+
11
+ * [Improve `Menu`](https://github.com/siyuan-note/petal/pull/16)
12
+ * [Add plugin function `transaction`](https://github.com/siyuan-note/siyuan/issues/9172)
13
+ * [Add `CustomEvent` type definition](https://github.com/siyuan-note/petal/pull/15)
4
14
 
5
15
  ## 0.8.3 2023-09-05
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.3",
8
+ "files": [
9
+ "types",
10
+ "CHANGELOG.md",
11
+ "package.json",
12
+ "README.md",
13
+ "siyuan.d.ts"
14
+ ],
15
+ "version": "0.8.5",
6
16
  "repository": "https://github.com/siyuan-note/petal"
7
17
  }
package/siyuan.d.ts CHANGED
@@ -1,12 +1,13 @@
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 {IProtyle, Lute, Protyle, Toolbar} from "./types/protyle";
2
+ import {IMenuBaseDetail} from "./types/events";
3
+ import {IGetDocInfo, IGetTreeStat} from "./types/response";
4
+
5
+ declare global {
6
+ interface Window extends Global {
7
+ }
8
+ }
9
+
10
+ type TEventBus = keyof IEventBusMap
10
11
 
11
12
  type TCardType = "doc" | "notebook" | "all"
12
13
 
@@ -25,10 +26,125 @@ type TProtyleAction = "cb-get-append" | // 向下滚动加载
25
26
  "cb-get-html" | // 直接渲染,不需要再 /api/block/getDocInfo,否则搜索表格无法定位
26
27
  "cb-get-history" // 历史渲染
27
28
 
28
- declare global {
29
- interface Window {
30
- Lute: Lute
29
+ type TOperation =
30
+ "insert"
31
+ | "update"
32
+ | "delete"
33
+ | "move"
34
+ | "foldHeading"
35
+ | "unfoldHeading"
36
+ | "setAttrs"
37
+ | "updateAttrs"
38
+ | "append"
39
+ | "insertAttrViewBlock"
40
+ | "removeAttrViewBlock"
41
+ | "addAttrViewCol"
42
+ | "removeAttrViewCol"
43
+ | "addFlashcards"
44
+ | "removeFlashcards"
45
+ | "updateAttrViewCell"
46
+ | "updateAttrViewCol"
47
+ | "sortAttrViewRow"
48
+ | "sortAttrViewCol"
49
+ | "setAttrViewColHidden"
50
+ | "setAttrViewColWrap"
51
+ | "setAttrViewColWidth"
52
+ | "updateAttrViewColOptions"
53
+ | "removeAttrViewColOption"
54
+ | "updateAttrViewColOption"
55
+ | "setAttrViewName"
56
+ | "setAttrViewFilters"
57
+ | "setAttrViewSorts"
58
+ | "setAttrViewColCalc"
59
+ | "updateAttrViewColNumberFormat"
60
+
61
+ type TAVCol =
62
+ "text"
63
+ | "date"
64
+ | "number"
65
+ | "relation"
66
+ | "rollup"
67
+ | "select"
68
+ | "block"
69
+ | "mSelect"
70
+ | "url"
71
+ | "email"
72
+ | "phone"
73
+
74
+ interface Global {
75
+ Lute: Lute;
76
+ }
77
+
78
+ interface IEventBusMap {
79
+ "click-blockicon": {
80
+ protyle: IProtyle,
81
+ blockElements: HTMLElement[]
82
+ };
83
+ "click-editorcontent": {
84
+ protyle: IProtyle,
85
+ event: MouseEvent
86
+ };
87
+ "click-editortitleicon": {
88
+ protyle: IProtyle,
89
+ data: IGetDocInfo,
90
+ };
91
+ "click-pdf": {
92
+ event: MouseEvent
93
+ };
94
+ "destroy-protyle": {
95
+ protyle: IProtyle
96
+ };
97
+ "input-search": {
98
+ protyle: Protyle,
99
+ config: ISearchOption,
100
+ searchElement: HTMLInputElement,
101
+ };
102
+ "loaded-protyle-dynamic": {
103
+ protyle: IProtyle,
104
+ positon: "afterend" | "beforebegin"
105
+ };
106
+ "loaded-protyle": {
107
+ protyle: IProtyle,
108
+ };
109
+ "open-menu-av": IMenuBaseDetail;
110
+ "open-menu-blockref": IMenuBaseDetail;
111
+ "open-menu-breadcrumbmore": {
112
+ menu: EventMenu,
113
+ protyle: IProtyle,
114
+ data: IGetTreeStat,
115
+ };
116
+ "open-menu-content": IMenuBaseDetail & { range: Range };
117
+ "open-menu-fileannotationref": IMenuBaseDetail
118
+ "open-menu-image": IMenuBaseDetail
119
+ "open-menu-link": IMenuBaseDetail
120
+ "open-menu-tag": IMenuBaseDetail
121
+ "open-menu-doctree": {
122
+ menu: EventMenu,
123
+ elements: NodeListOf<Element>,
124
+ type: "doc" | "docs" | "notebook"
125
+ };
126
+ "open-noneditableblock": {
127
+ protyle: IProtyle,
128
+ toolbar: Toolbar
129
+ };
130
+ "open-siyuan-url-block": {
131
+ url: string,
132
+ id: string,
133
+ focus: boolean,
134
+ exist: boolean,
135
+ };
136
+ "open-siyuan-url-plugin": {
137
+ url: string
31
138
  }
139
+ "ws-main": IWebSocketData;
140
+ }
141
+
142
+ interface IPosition {
143
+ x: number,
144
+ y: number,
145
+ w?: number,
146
+ h?: number,
147
+ isLeft?: boolean
32
148
  }
33
149
 
34
150
  interface ITab {
@@ -98,6 +214,9 @@ interface ILuteNode {
98
214
 
99
215
  interface ISearchOption {
100
216
  page?: number
217
+ removed?: boolean // 移除后需记录搜索内容 https://github.com/siyuan-note/siyuan/issues/7745
218
+ name?: string
219
+ sort?: number, // 0:按块类型(默认),1:按创建时间升序,2:按创建时间降序,3:按更新时间升序,4:按更新时间降序,5:按内容顺序(仅在按文档分组时),6:按相关度升序,7:按相关度降序
101
220
  group?: number, // 0:不分组,1:按文档分组
102
221
  hasReplace?: boolean,
103
222
  method?: number // 0:文本,1:查询语法,2:SQL,3:正则表达式
@@ -118,6 +237,7 @@ interface ISearchOption {
118
237
  codeBlock: boolean
119
238
  htmlBlock: boolean
120
239
  embedBlock: boolean
240
+ databaseBlock: boolean
121
241
  }
122
242
  }
123
243
 
@@ -141,8 +261,9 @@ interface IPluginDockTab {
141
261
  }
142
262
 
143
263
  interface IMenuItemOption {
264
+ iconClass?: string,
144
265
  label?: string,
145
- click?: (element: HTMLElement) => void,
266
+ click?: (element: HTMLElement, event: MouseEvent) => boolean | void | Promise<boolean | void>
146
267
  type?: "separator" | "submenu" | "readonly",
147
268
  accelerator?: string,
148
269
  action?: string,
@@ -208,6 +329,25 @@ interface IProtyleOption {
208
329
  after?(protyle: Protyle): void;
209
330
  }
210
331
 
332
+ interface IOperation {
333
+ action: TOperation, // move, delete 不需要传 data
334
+ id?: string,
335
+ avID?: string, // av
336
+ format?: string // updateAttrViewColNumberFormat 专享
337
+ keyID?: string // updateAttrViewCell 专享
338
+ rowID?: string // updateAttrViewCell 专享
339
+ data?: any, // updateAttr 时为 { old: IObject, new: IObject }, updateAttrViewCell 时为 {TAVCol: {content: string}}
340
+ parentID?: string
341
+ previousID?: string
342
+ retData?: any
343
+ nextID?: string // insert 专享
344
+ srcIDs?: string[] // insertAttrViewBlock 专享
345
+ name?: string // addAttrViewCol 专享
346
+ type?: TAVCol // addAttrViewCol 专享
347
+ deckID?: string // add/removeFlashcards 专享
348
+ blockIDs?: string[] // add/removeFlashcards 专享
349
+ }
350
+
211
351
  export function fetchPost(url: string, data?: any, callback?: (response: IWebSocketData) => void, headers?: IObject): void;
212
352
 
213
353
  export function fetchSyncPost(url: string, data?: any): Promise<IWebSocketData>;
@@ -375,27 +515,6 @@ export abstract class Plugin {
375
515
  }): void
376
516
  }
377
517
 
378
- export class Protyle {
379
-
380
- public protyle: any;
381
-
382
- constructor(app: App, element: HTMLElement, options?: IProtyleOption)
383
-
384
- isUploading(): boolean
385
-
386
- destroy(): void
387
-
388
- resize(): void
389
-
390
- reload(focus: boolean): void
391
-
392
- /**
393
- * @param {boolean} [isBlock=false]
394
- * @param {boolean} [useProtyleRange=false]
395
- */
396
- insert(html: string, isBlock?: boolean, useProtyleRange?: boolean): void
397
- }
398
-
399
518
  export class Setting {
400
519
  constructor(options: {
401
520
  height?: string,
@@ -415,13 +534,25 @@ export class Setting {
415
534
  }
416
535
 
417
536
  export class EventBus {
418
- on(type: TEventBus, listener: (event: CustomEvent<any>) => void): void;
419
-
420
- once(type: TEventBus, listener: (event: CustomEvent<any>) => void): void;
421
-
422
- off(type: TEventBus, listener: (event: CustomEvent<any>) => void): void;
423
-
424
- emit(type: TEventBus, detail?: any): boolean;
537
+ on<
538
+ K extends TEventBus,
539
+ D = IEventBusMap[K],
540
+ >(type: K, listener: (event: CustomEvent<D>) => any): void;
541
+
542
+ once<
543
+ K extends TEventBus,
544
+ D = IEventBusMap[K],
545
+ >(type: K, listener: (event: CustomEvent<D>) => any): void;
546
+
547
+ off<
548
+ K extends TEventBus,
549
+ D = IEventBusMap[K],
550
+ >(type: K, listener: (event: CustomEvent<D>) => any): void;
551
+
552
+ emit<
553
+ K extends TEventBus,
554
+ D = IEventBusMap[K],
555
+ >(type: K, detail?: D): boolean;
425
556
  }
426
557
 
427
558
  export class Dialog {
@@ -447,6 +578,8 @@ export class Dialog {
447
578
  export class Menu {
448
579
  constructor(id?: string, closeCallback?: () => void);
449
580
 
581
+ element: HTMLElement;
582
+
450
583
  showSubMenu(subMenuElement: HTMLElement): void;
451
584
 
452
585
  addItem(options: IMenuItemOption): HTMLElement;
@@ -463,108 +596,12 @@ export class Menu {
463
596
  close(): void;
464
597
  }
465
598
 
466
- export class Lute {
467
- public static WalkStop: number;
468
- public static WalkSkipChildren: number;
469
- public static WalkContinue: number;
470
- public static Version: string;
471
- public static Caret: string;
472
-
473
- public static New(): Lute;
474
-
475
- public static EChartsMindmapStr(text: string): string;
476
-
477
- public static NewNodeID(): string;
478
-
479
- public static Sanitize(html: string): string;
480
-
481
- public static EscapeHTMLStr(str: string): string;
482
-
483
- public static UnEscapeHTMLStr(str: string): string;
484
-
485
- public static GetHeadingID(node: ILuteNode): string;
486
-
487
- public static BlockDOM2Content(html: string): string;
488
-
489
- private constructor();
490
-
491
- public BlockDOM2Content(text: string): string;
492
-
493
- public BlockDOM2EscapeMarkerContent(text: string): string;
494
-
495
- public SetTextMark(enable: boolean): void;
496
-
497
- public SetHeadingID(enable: boolean): void;
498
-
499
- public SetProtyleMarkNetImg(enable: boolean): void;
500
-
501
- public SetSpellcheck(enable: boolean): void;
502
-
503
- public SetFileAnnotationRef(enable: boolean): void;
504
-
505
- public SetSetext(enable: boolean): void;
506
-
507
- public SetYamlFrontMatter(enable: boolean): void;
508
-
509
- public SetChineseParagraphBeginningSpace(enable: boolean): void;
510
-
511
- public SetRenderListStyle(enable: boolean): void;
512
-
513
- public SetImgPathAllowSpace(enable: boolean): void;
514
-
515
- public SetKramdownIAL(enable: boolean): void;
516
-
517
- public BlockDOM2Md(html: string): string;
518
-
519
- public BlockDOM2StdMd(html: string): string;
520
-
521
- public SetGitConflict(enable: boolean): void;
522
-
523
- public SetSuperBlock(enable: boolean): void;
524
-
525
- public SetTag(enable: boolean): void;
526
-
527
- public SetMark(enable: boolean): void;
528
-
529
- public SetSub(enable: boolean): void;
530
-
531
- public SetSup(enable: boolean): void;
532
-
533
- public SetBlockRef(enable: boolean): void;
534
-
535
- public SetSanitize(enable: boolean): void;
536
-
537
- public SetHeadingAnchor(enable: boolean): void;
538
-
539
- public SetImageLazyLoading(imagePath: string): void;
540
-
541
- public SetInlineMathAllowDigitAfterOpenMarker(enable: boolean): void;
542
-
543
- public SetToC(enable: boolean): void;
544
-
545
- public SetIndentCodeBlock(enable: boolean): void;
546
-
547
- public SetParagraphBeginningSpace(enable: boolean): void;
548
-
549
- public SetFootnotes(enable: boolean): void;
550
-
551
- public SetLinkRef(enalbe: boolean): void;
552
-
553
- public SetEmojiSite(emojiSite: string): void;
554
-
555
- public PutEmojis(emojis: IObject): void;
556
-
557
- public SpinBlockDOM(html: string): string;
558
-
559
- public Md2BlockDOM(html: string): string;
560
-
561
- public SetProtyleWYSIWYG(wysiwyg: boolean): void;
562
-
563
- public MarkdownStr(name: string, md: string): string;
599
+ export class EventMenu {
600
+ public menus: IMenuItemOption[];
564
601
 
565
- public IsValidLinkDest(text: string): boolean;
602
+ constructor()
566
603
 
567
- public BlockDOM2InlineBlockDOM(html: string): string;
604
+ public addSeparator(index?: number): void
568
605
 
569
- public BlockDOM2HTML(html: string): string;
606
+ public addItem(menu: IMenuItemOption): void
570
607
  }
@@ -0,0 +1,8 @@
1
+ import type {IProtyle} from "./protyle";
2
+ import {EventMenu} from "./../siyuan";
3
+
4
+ interface IMenuBaseDetail {
5
+ menu: EventMenu,
6
+ protyle: IProtyle,
7
+ element: HTMLElement,
8
+ }
@@ -0,0 +1,213 @@
1
+ import {App, ILuteNode, IObject, IOperation, IPosition, IProtyleOption} 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
+ }
55
+
56
+ export class Protyle {
57
+
58
+ public protyle: IProtyle;
59
+
60
+ constructor(app: App, element: HTMLElement, options?: IProtyleOption)
61
+
62
+ isUploading(): boolean
63
+
64
+ destroy(): void
65
+
66
+ resize(): void
67
+
68
+ reload(focus: boolean): void
69
+
70
+ /**
71
+ * @param {boolean} [isBlock=false]
72
+ * @param {boolean} [useProtyleRange=false]
73
+ */
74
+ insert(html: string, isBlock?: boolean, useProtyleRange?: boolean): void
75
+
76
+ transaction(doOperations: IOperation[], undoOperations?: IOperation[]): void;
77
+ }
78
+
79
+ export class Toolbar {
80
+ public element: HTMLElement;
81
+ public subElement: HTMLElement;
82
+ public subElementCloseCB: () => void;
83
+ public range: Range;
84
+
85
+ constructor(protyle: IProtyle)
86
+
87
+ public render(protyle: IProtyle, range: Range, event?: KeyboardEvent)
88
+
89
+ public showContent(protyle: IProtyle, range: Range, nodeElement: Element)
90
+
91
+ public showWidget(protyle: IProtyle, nodeElement: HTMLElement, range: Range)
92
+
93
+ public showTpl(protyle: IProtyle, nodeElement: HTMLElement, range: Range)
94
+
95
+ public showCodeLanguage(protyle: IProtyle, languageElement: HTMLElement)
96
+
97
+ public showRender(protyle: IProtyle, renderElement: Element, updateElements?: Element[], oldHTML?: string)
98
+
99
+ public setInlineMark(protyle: IProtyle, type: string, action: "range" | "toolbar", textObj?: {
100
+ color?: string,
101
+ type: string
102
+ })
103
+
104
+ public getCurrentType(range: Range): string[]
105
+
106
+ public showAssets(protyle: IProtyle, position: IPosition, avCB?: (url: string) => void)
107
+ }
108
+
109
+ export class Lute {
110
+ public static WalkStop: number;
111
+ public static WalkSkipChildren: number;
112
+ public static WalkContinue: number;
113
+ public static Version: string;
114
+ public static Caret: string;
115
+
116
+ public static New(): Lute;
117
+
118
+ public static EChartsMindmapStr(text: string): string;
119
+
120
+ public static NewNodeID(): string;
121
+
122
+ public static Sanitize(html: string): string;
123
+
124
+ public static EscapeHTMLStr(str: string): string;
125
+
126
+ public static UnEscapeHTMLStr(str: string): string;
127
+
128
+ public static GetHeadingID(node: ILuteNode): string;
129
+
130
+ public static BlockDOM2Content(html: string): string;
131
+
132
+ private constructor();
133
+
134
+ public BlockDOM2Content(text: string): string;
135
+
136
+ public BlockDOM2EscapeMarkerContent(text: string): string;
137
+
138
+ public SetTextMark(enable: boolean): void;
139
+
140
+ public SetHeadingID(enable: boolean): void;
141
+
142
+ public SetProtyleMarkNetImg(enable: boolean): void;
143
+
144
+ public SetSpellcheck(enable: boolean): void;
145
+
146
+ public SetFileAnnotationRef(enable: boolean): void;
147
+
148
+ public SetSetext(enable: boolean): void;
149
+
150
+ public SetYamlFrontMatter(enable: boolean): void;
151
+
152
+ public SetChineseParagraphBeginningSpace(enable: boolean): void;
153
+
154
+ public SetRenderListStyle(enable: boolean): void;
155
+
156
+ public SetImgPathAllowSpace(enable: boolean): void;
157
+
158
+ public SetKramdownIAL(enable: boolean): void;
159
+
160
+ public BlockDOM2Md(html: string): string;
161
+
162
+ public BlockDOM2StdMd(html: string): string;
163
+
164
+ public SetGitConflict(enable: boolean): void;
165
+
166
+ public SetSuperBlock(enable: boolean): void;
167
+
168
+ public SetTag(enable: boolean): void;
169
+
170
+ public SetMark(enable: boolean): void;
171
+
172
+ public SetSub(enable: boolean): void;
173
+
174
+ public SetSup(enable: boolean): void;
175
+
176
+ public SetBlockRef(enable: boolean): void;
177
+
178
+ public SetSanitize(enable: boolean): void;
179
+
180
+ public SetHeadingAnchor(enable: boolean): void;
181
+
182
+ public SetImageLazyLoading(imagePath: string): void;
183
+
184
+ public SetInlineMathAllowDigitAfterOpenMarker(enable: boolean): void;
185
+
186
+ public SetToC(enable: boolean): void;
187
+
188
+ public SetIndentCodeBlock(enable: boolean): void;
189
+
190
+ public SetParagraphBeginningSpace(enable: boolean): void;
191
+
192
+ public SetFootnotes(enable: boolean): void;
193
+
194
+ public SetLinkRef(enalbe: boolean): void;
195
+
196
+ public SetEmojiSite(emojiSite: string): void;
197
+
198
+ public PutEmojis(emojis: IObject): void;
199
+
200
+ public SpinBlockDOM(html: string): string;
201
+
202
+ public Md2BlockDOM(html: string): string;
203
+
204
+ public SetProtyleWYSIWYG(wysiwyg: boolean): void;
205
+
206
+ public MarkdownStr(name: string, md: string): string;
207
+
208
+ public IsValidLinkDest(text: string): boolean;
209
+
210
+ public BlockDOM2InlineBlockDOM(html: string): string;
211
+
212
+ public BlockDOM2HTML(html: string): string;
213
+ }
@@ -0,0 +1,20 @@
1
+ import {IObject} from "../siyuan";
2
+
3
+ interface IGetDocInfo {
4
+ ial: IObject
5
+ icon: number
6
+ id: number
7
+ name: number
8
+ refCount: number
9
+ refIDs: string[]
10
+ rootID: string
11
+ subFileCount: number
12
+ }
13
+
14
+ interface IGetTreeStat {
15
+ imageCount: number;
16
+ linkCount: number;
17
+ refCount: number;
18
+ runeCount: number;
19
+ wordCount: number;
20
+ }