@wetoria/siyuan-sdk 0.0.2 → 0.0.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.
- package/README.md +83 -7
- package/dist/api/attr/index.d.ts +17 -12
- package/dist/api/attr/index.d.ts.map +1 -1
- package/dist/api/attr/index.js.map +1 -1
- package/dist/api/block/index.d.ts +52 -10
- package/dist/api/block/index.d.ts.map +1 -1
- package/dist/api/block/index.js +6 -6
- package/dist/api/block/index.js.map +1 -1
- package/dist/api/file/index.d.ts +11 -2
- package/dist/api/file/index.d.ts.map +1 -1
- package/dist/api/file/index.js.map +1 -1
- package/dist/api/notebook/index.d.ts +7 -3
- package/dist/api/notebook/index.d.ts.map +1 -1
- package/dist/api/notebook/index.js.map +1 -1
- package/dist/core/index.d.ts +23 -4
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +34 -0
- package/dist/core/index.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +54 -24
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/transaction/index.d.ts +39 -0
- package/dist/types/transaction/index.d.ts.map +1 -0
- package/dist/types/transaction/index.js +8 -0
- package/dist/types/transaction/index.js.map +1 -0
- package/package.json +1 -1
- package/src/api/attr/index.ts +24 -11
- package/src/api/block/index.ts +68 -20
- package/src/api/file/index.ts +11 -1
- package/src/api/notebook/index.ts +12 -3
- package/src/core/index.ts +57 -7
- package/src/index.ts +7 -0
- package/src/types/index.ts +85 -24
- package/src/types/transaction/index.ts +45 -0
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './transaction';
|
|
1
2
|
/**
|
|
2
3
|
* Frequently used data structures in SiYuan
|
|
3
4
|
*/
|
|
@@ -6,6 +7,7 @@ export type BlockId = string;
|
|
|
6
7
|
export type NotebookId = string;
|
|
7
8
|
export type PreviousID = BlockId;
|
|
8
9
|
export type ParentID = BlockId | DocumentId;
|
|
10
|
+
export type DataType = "markdown" | "dom";
|
|
9
11
|
export interface Notebook {
|
|
10
12
|
id: NotebookId;
|
|
11
13
|
name: string;
|
|
@@ -23,6 +25,41 @@ export interface NotebookConf {
|
|
|
23
25
|
}
|
|
24
26
|
export type BlockType = "d" | "s" | "h" | "t" | "i" | "p" | "f" | "audio" | "video" | "other";
|
|
25
27
|
export type BlockSubType = "d1" | "d2" | "s1" | "s2" | "s3" | "t1" | "t2" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "table" | "task" | "toggle" | "latex" | "quote" | "html" | "code" | "footnote" | "cite" | "collection" | "bookmark" | "attachment" | "comment" | "mindmap" | "spreadsheet" | "calendar" | "image" | "audio" | "video" | "other";
|
|
28
|
+
/**
|
|
29
|
+
* 块属性接口 - 可以手动修改的属性
|
|
30
|
+
* 注释掉的内容也存在,这里用于展示全部字段类型,但禁止手动修改
|
|
31
|
+
*/
|
|
32
|
+
export interface IBlockAttrs {
|
|
33
|
+
"name"?: string;
|
|
34
|
+
"alias"?: string;
|
|
35
|
+
"memo"?: string;
|
|
36
|
+
"bookmark"?: string;
|
|
37
|
+
"tags"?: string;
|
|
38
|
+
"fold"?: "1" | "";
|
|
39
|
+
"heading-fold"?: "1" | "";
|
|
40
|
+
"style"?: string;
|
|
41
|
+
"scroll"?: string;
|
|
42
|
+
"id"?: string;
|
|
43
|
+
"title"?: string;
|
|
44
|
+
"updated"?: string;
|
|
45
|
+
"type"?: string;
|
|
46
|
+
"icon"?: string;
|
|
47
|
+
"status"?: string;
|
|
48
|
+
"refcount"?: string;
|
|
49
|
+
"parent-heading"?: string;
|
|
50
|
+
"embed-content"?: string;
|
|
51
|
+
"custom-avs"?: string;
|
|
52
|
+
"custom-avs-names"?: string;
|
|
53
|
+
"data-av-type"?: string;
|
|
54
|
+
"custom-riff-decks"?: string;
|
|
55
|
+
[key: `custom-dailynote-${string}`]: string;
|
|
56
|
+
[key: `custom-${string}`]: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 允许设置的块属性类型
|
|
60
|
+
* 排除了系统自动维护的属性:id、updated、type、status、refcount、parent-heading、embed-content、scroll
|
|
61
|
+
*/
|
|
62
|
+
export type ISettableBlockAttrs = Omit<IBlockAttrs, "id" | "updated" | "type" | "status" | "refcount" | "parent-heading" | "embed-content" | "scroll">;
|
|
26
63
|
export interface Block {
|
|
27
64
|
id: BlockId;
|
|
28
65
|
parent_id?: BlockId;
|
|
@@ -42,7 +79,7 @@ export interface Block {
|
|
|
42
79
|
type: BlockType;
|
|
43
80
|
subtype: BlockSubType;
|
|
44
81
|
/**
|
|
45
|
-
*
|
|
82
|
+
* 块属性(Inline Attributes List)
|
|
46
83
|
* For instance: "{: custom-type=\"query-code\" id=\"20230613234017-zkw3pr0\" updated=\"20230613234509\"}"
|
|
47
84
|
*/
|
|
48
85
|
ial?: string;
|
|
@@ -50,29 +87,6 @@ export interface Block {
|
|
|
50
87
|
created: string;
|
|
51
88
|
updated: string;
|
|
52
89
|
}
|
|
53
|
-
export interface doOperation {
|
|
54
|
-
action: string;
|
|
55
|
-
data: string;
|
|
56
|
-
id: BlockId;
|
|
57
|
-
parentID: BlockId | DocumentId;
|
|
58
|
-
previousID: BlockId;
|
|
59
|
-
retData: null;
|
|
60
|
-
}
|
|
61
|
-
declare global {
|
|
62
|
-
interface Window {
|
|
63
|
-
siyuan: {
|
|
64
|
-
notebooks: any;
|
|
65
|
-
menus: any;
|
|
66
|
-
dialogs: any;
|
|
67
|
-
blockPanels: any;
|
|
68
|
-
storage: any;
|
|
69
|
-
user: any;
|
|
70
|
-
ws: any;
|
|
71
|
-
languages: any;
|
|
72
|
-
config: import('siyuan').Config.IConf;
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
90
|
export interface IBreadcrumb {
|
|
77
91
|
id: string;
|
|
78
92
|
name: string;
|
|
@@ -85,4 +99,20 @@ export interface backlinkData {
|
|
|
85
99
|
blockPaths: IBreadcrumb[];
|
|
86
100
|
expand: boolean;
|
|
87
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* 子块信息(用于 getChildBlocks 返回值)
|
|
104
|
+
*/
|
|
105
|
+
export interface ChildBlock {
|
|
106
|
+
id: BlockId;
|
|
107
|
+
type: BlockType;
|
|
108
|
+
content?: string;
|
|
109
|
+
markdown?: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 块的 DOM 结构(用于 getBlockDOM 返回值)
|
|
113
|
+
*/
|
|
114
|
+
export interface BlockDOM {
|
|
115
|
+
dom: string;
|
|
116
|
+
id: BlockId;
|
|
117
|
+
}
|
|
88
118
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAA;AAC/B,MAAM,MAAM,OAAO,GAAG,MAAM,CAAA;AAC5B,MAAM,MAAM,UAAU,GAAG,MAAM,CAAA;AAC/B,MAAM,MAAM,UAAU,GAAG,OAAO,CAAA;AAChC,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAA;AAC/B,MAAM,MAAM,OAAO,GAAG,MAAM,CAAA;AAC5B,MAAM,MAAM,UAAU,GAAG,MAAM,CAAA;AAC/B,MAAM,MAAM,UAAU,GAAG,OAAO,CAAA;AAChC,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAA;AAC3C,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG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AAE,MAAM,CAAA;IACX,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,SAAS,CAAA;IACf,OAAO,EAAE,YAAY,CAAA;IACrB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;CAChB;AAID,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,GAAG,CAAA;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,EAAE,WAAW,EAAE,CAAA;IACzB,MAAM,EAAE,OAAO,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,OAAO,CAAA;IACX,IAAI,EAAE,SAAS,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAA;IACX,EAAE,EAAE,OAAO,CAAA;CACZ"}
|
package/dist/types/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './transaction';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BlockId, DocumentId } from '../index';
|
|
2
|
+
export declare enum ActionTypes {
|
|
3
|
+
insert = "insert",
|
|
4
|
+
update = "update",
|
|
5
|
+
delete = "delete",
|
|
6
|
+
move = "move"
|
|
7
|
+
}
|
|
8
|
+
export interface doOperation {
|
|
9
|
+
action: ActionTypes;
|
|
10
|
+
data: string;
|
|
11
|
+
id: BlockId;
|
|
12
|
+
parentID: BlockId | DocumentId;
|
|
13
|
+
previousID: BlockId;
|
|
14
|
+
nextID?: string;
|
|
15
|
+
retData: null;
|
|
16
|
+
blockIDs?: string[] | null;
|
|
17
|
+
blockID?: string;
|
|
18
|
+
deckID?: string;
|
|
19
|
+
avID?: string;
|
|
20
|
+
srcIDs?: string[] | null;
|
|
21
|
+
srcs?: string[] | null;
|
|
22
|
+
isDetached?: boolean;
|
|
23
|
+
ignoreFillFilter?: boolean;
|
|
24
|
+
name?: string;
|
|
25
|
+
type?: string;
|
|
26
|
+
format?: string;
|
|
27
|
+
keyID?: string;
|
|
28
|
+
rowID?: string;
|
|
29
|
+
isTwoWay?: boolean;
|
|
30
|
+
backRelationKeyID?: string;
|
|
31
|
+
removeDest?: boolean;
|
|
32
|
+
layout?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface TransactionItem {
|
|
35
|
+
timestamp: string;
|
|
36
|
+
doOperations: doOperation[];
|
|
37
|
+
undoOperations: doOperation[] | null;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/transaction/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,UAAU,EACX,MAAM,UAAU,CAAA;AAEjB,oBAAY,WAAW;IACrB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,IAAI,SAAS;CACd;A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ypes["delete"] = "delete";
|
|
6
|
+
ActionTypes["move"] = "move";
|
|
7
|
+
})(ActionTypes || (ActionTypes = {}));
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/transaction/index.ts"],"names":[],"mappings":"AAKA,MAAM,CAAN,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,gCAAiB,CAAA;IACjB,gCAAiB,CAAA;IACjB,4BAAa,CAAA;AACf,CAAC,EALW,WAAW,KAAX,WAAW,QAKtB"}
|
package/package.json
CHANGED
package/src/api/attr/index.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { SyApiMethodResponse } from '../../core/index.js'
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
BlockId,
|
|
4
|
+
IBlockAttrs,
|
|
5
|
+
ISettableBlockAttrs,
|
|
6
|
+
} from '../../types/index.js'
|
|
3
7
|
import { SiYuanAPI } from '../../core/index.js'
|
|
4
8
|
|
|
5
9
|
/**
|
|
@@ -9,36 +13,45 @@ export interface AttrAPI {
|
|
|
9
13
|
/**
|
|
10
14
|
* 设置块属性
|
|
11
15
|
* @path /api/attr/setBlockAttrs
|
|
16
|
+
* @param id - The ID of the block
|
|
17
|
+
* @param attrs - The attributes to set. System properties (id, updated, type, status, refcount, parent-heading, embed-content, scroll) are not allowed to be modified
|
|
18
|
+
* @returns - Promise<{ code: number, msg: string, data: null }>
|
|
12
19
|
*/
|
|
13
20
|
setBlockAttrs: (
|
|
14
21
|
id: BlockId,
|
|
15
|
-
attrs:
|
|
16
|
-
) => SyApiMethodResponse<
|
|
22
|
+
attrs: Partial<ISettableBlockAttrs>
|
|
23
|
+
) => SyApiMethodResponse<null>
|
|
17
24
|
/**
|
|
18
25
|
* 获取块属性
|
|
19
26
|
* @path /api/attr/getBlockAttrs
|
|
27
|
+
* @param id - The ID of the block
|
|
28
|
+
* @returns - Promise<{ code: number, msg: string, data: IBlockAttrs }>
|
|
20
29
|
*/
|
|
21
|
-
getBlockAttrs: (id: BlockId) => SyApiMethodResponse<
|
|
22
|
-
[key: string]: string
|
|
23
|
-
}>
|
|
30
|
+
getBlockAttrs: (id: BlockId) => SyApiMethodResponse<IBlockAttrs>
|
|
24
31
|
/**
|
|
25
32
|
* 批量设置块属性
|
|
26
33
|
* @path /api/attr/batchSetBlockAttrs
|
|
34
|
+
* @param blockAttrs - Array of block attributes to set
|
|
35
|
+
* @param blockAttrs[].id - The ID of the block
|
|
36
|
+
* @param blockAttrs[].attrs - The attributes to set. System properties (id, updated, type, status, refcount, parent-heading, embed-content, scroll) are not allowed to be modified
|
|
37
|
+
* @returns - Promise<{ code: number, msg: string, data: null }>
|
|
27
38
|
*/
|
|
28
39
|
batchSetBlockAttrs: (blockAttrs: Array<{
|
|
29
40
|
id: BlockId
|
|
30
|
-
attrs:
|
|
31
|
-
}>) => SyApiMethodResponse<
|
|
41
|
+
attrs: Partial<ISettableBlockAttrs>
|
|
42
|
+
}>) => SyApiMethodResponse<null>
|
|
32
43
|
/**
|
|
33
44
|
* 批量获取块属性
|
|
34
45
|
* @path /api/attr/batchGetBlockAttrs
|
|
46
|
+
* @param ids - The IDs of the blocks
|
|
47
|
+
* @returns - Promise<{ code: number, msg: string, data: { [key: string]: IBlockAttrs } }>
|
|
35
48
|
*/
|
|
36
49
|
batchGetBlockAttrs: (ids: BlockId[]) => SyApiMethodResponse<{
|
|
37
|
-
[key: string]:
|
|
50
|
+
[key: string]: IBlockAttrs
|
|
38
51
|
}>
|
|
39
52
|
}
|
|
40
53
|
|
|
41
|
-
SiYuanAPI.prototype.setBlockAttrs = function (id: string, attrs:
|
|
54
|
+
SiYuanAPI.prototype.setBlockAttrs = function (id: string, attrs: Partial<ISettableBlockAttrs>) {
|
|
42
55
|
return this.request('/api/attr/setBlockAttrs', {
|
|
43
56
|
id,
|
|
44
57
|
attrs,
|
|
@@ -49,7 +62,7 @@ SiYuanAPI.prototype.getBlockAttrs = function (id: string) {
|
|
|
49
62
|
return this.request('/api/attr/getBlockAttrs', { id })
|
|
50
63
|
}
|
|
51
64
|
|
|
52
|
-
SiYuanAPI.prototype.batchSetBlockAttrs = function (blockAttrs: Array<{ id: string, attrs:
|
|
65
|
+
SiYuanAPI.prototype.batchSetBlockAttrs = function (blockAttrs: Array<{ id: string, attrs: Partial<ISettableBlockAttrs> }>) {
|
|
53
66
|
return this.request('/api/attr/batchSetBlockAttrs', { blockAttrs })
|
|
54
67
|
}
|
|
55
68
|
|
package/src/api/block/index.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { SyApiMethodResponse } from '../../core/index.js'
|
|
2
2
|
import type {
|
|
3
|
+
Block,
|
|
4
|
+
BlockDOM,
|
|
3
5
|
BlockId,
|
|
6
|
+
ChildBlock,
|
|
4
7
|
NotebookId,
|
|
8
|
+
TransactionItem,
|
|
5
9
|
} from '../../types/index.js'
|
|
6
10
|
import { SiYuanAPI } from '../../core/index.js'
|
|
7
11
|
|
|
@@ -12,40 +16,59 @@ export interface BlockAPI {
|
|
|
12
16
|
/**
|
|
13
17
|
* 插入块
|
|
14
18
|
* @path /api/block/insertBlock
|
|
19
|
+
* @param data - The data for the block
|
|
20
|
+
* @param data.dataType - The type of the data(markdown, dom), default is 'markdown'
|
|
21
|
+
* @param data.data - The data for the block
|
|
22
|
+
* @param data.nextID - The next ID of the block
|
|
23
|
+
* @param data.previousID - The previous ID of the block
|
|
24
|
+
* @param data.parentID - The parent ID of the block
|
|
25
|
+
* @returns - Promise<{ code: number, msg: string, data: TransactionItem[] }>
|
|
15
26
|
*/
|
|
16
|
-
insertBlock: (
|
|
17
|
-
dataType
|
|
18
|
-
data: string
|
|
19
|
-
nextID?: BlockId
|
|
20
|
-
previousID?: BlockId
|
|
27
|
+
insertBlock: (data: {
|
|
28
|
+
dataType?: 'markdown' | 'dom'
|
|
29
|
+
data: string
|
|
30
|
+
nextID?: BlockId
|
|
31
|
+
previousID?: BlockId
|
|
21
32
|
parentID?: BlockId
|
|
22
|
-
) => SyApiMethodResponse<
|
|
33
|
+
}) => SyApiMethodResponse<TransactionItem[]>
|
|
23
34
|
/**
|
|
24
35
|
* 在块的开头插入内容
|
|
25
36
|
* @path /api/block/prependBlock
|
|
37
|
+
* @param dataType - The type of the data(markdown, dom)
|
|
38
|
+
* @param data - The data for the block
|
|
39
|
+
* @param parentID - The parent ID of the block
|
|
40
|
+
* @returns - Promise<{ code: number, msg: string, data: TransactionItem[] }>
|
|
26
41
|
*/
|
|
27
42
|
prependBlock: (
|
|
28
43
|
dataType: 'markdown' | 'dom',
|
|
29
44
|
data: string,
|
|
30
45
|
parentID: BlockId
|
|
31
|
-
) => SyApiMethodResponse<
|
|
46
|
+
) => SyApiMethodResponse<TransactionItem[]>
|
|
32
47
|
/**
|
|
33
48
|
* 在块的末尾追加内容
|
|
34
49
|
* @path /api/block/appendBlock
|
|
50
|
+
* @param dataType - The type of the data(markdown, dom), default is 'markdown'
|
|
51
|
+
* @param data - The data for the block
|
|
52
|
+
* @param parentID - The parent ID of the block
|
|
53
|
+
* @returns - Promise<{ code: number, msg: string, data: TransactionItem[] }>
|
|
35
54
|
*/
|
|
36
55
|
appendBlock: (
|
|
37
56
|
dataType: 'markdown' | 'dom',
|
|
38
57
|
data: string,
|
|
39
58
|
parentID: BlockId
|
|
40
|
-
) => SyApiMethodResponse<
|
|
59
|
+
) => SyApiMethodResponse<TransactionItem[]>
|
|
41
60
|
/**
|
|
42
61
|
* 追加 Markdown 内容到块(便捷方法)
|
|
43
62
|
* @path wrapper: uses appendBlock
|
|
63
|
+
* @param params - The parameters for appending markdown content
|
|
64
|
+
* @param params.data - The markdown data for the block
|
|
65
|
+
* @param params.parentID - The parent ID of the block
|
|
66
|
+
* @returns - Promise<{ code: number, msg: string, data: TransactionItem[] }>
|
|
44
67
|
*/
|
|
45
68
|
appendMDToBlock: (params: {
|
|
46
69
|
data: string
|
|
47
70
|
parentID: BlockId
|
|
48
|
-
}) => SyApiMethodResponse<
|
|
71
|
+
}) => SyApiMethodResponse<TransactionItem[]>
|
|
49
72
|
/**
|
|
50
73
|
* 追加 Markdown 内容到块并返回块 ID(便捷方法)
|
|
51
74
|
* @path wrapper: uses appendBlock
|
|
@@ -66,17 +89,23 @@ export interface BlockAPI {
|
|
|
66
89
|
/**
|
|
67
90
|
* 更新块内容
|
|
68
91
|
* @path /api/block/updateBlock
|
|
92
|
+
* @param dataType - The type of the data(markdown, dom)
|
|
93
|
+
* @param data - The data for the block
|
|
94
|
+
* @param id - The ID of the block to update
|
|
95
|
+
* @returns - Promise<{ code: number, msg: string, data: TransactionItem[] }>
|
|
69
96
|
*/
|
|
70
97
|
updateBlock: (
|
|
71
98
|
dataType: 'markdown' | 'dom',
|
|
72
99
|
data: string,
|
|
73
100
|
id: BlockId
|
|
74
|
-
) => SyApiMethodResponse<
|
|
101
|
+
) => SyApiMethodResponse<TransactionItem[]>
|
|
75
102
|
/**
|
|
76
103
|
* 删除块
|
|
77
104
|
* @path /api/block/deleteBlock
|
|
105
|
+
* @param id - The ID of the block to delete
|
|
106
|
+
* @returns - Promise<{ code: number, msg: string, data: TransactionItem[] }>
|
|
78
107
|
*/
|
|
79
|
-
deleteBlock: (id: BlockId) => SyApiMethodResponse<
|
|
108
|
+
deleteBlock: (id: BlockId) => SyApiMethodResponse<TransactionItem[]>
|
|
80
109
|
/**
|
|
81
110
|
* 移动块
|
|
82
111
|
* @path /api/block/moveBlock
|
|
@@ -94,8 +123,10 @@ export interface BlockAPI {
|
|
|
94
123
|
/**
|
|
95
124
|
* 获取子块列表
|
|
96
125
|
* @path /api/block/getChildBlocks
|
|
126
|
+
* @param id - The ID of the parent block
|
|
127
|
+
* @returns - Promise<{ code: number, msg: string, data: ChildBlock[] }>
|
|
97
128
|
*/
|
|
98
|
-
getChildBlocks: (id: BlockId) => SyApiMethodResponse<
|
|
129
|
+
getChildBlocks: (id: BlockId) => SyApiMethodResponse<ChildBlock[]>
|
|
99
130
|
/**
|
|
100
131
|
* 获取块的索引位置
|
|
101
132
|
* @path /api/block/getBlocksIndexes
|
|
@@ -116,21 +147,34 @@ export interface BlockAPI {
|
|
|
116
147
|
* 获取块信息(通过 SQL 查询)
|
|
117
148
|
* @path wrapper: uses sql
|
|
118
149
|
*/
|
|
119
|
-
getBlockInfo: (id: BlockId) => SyApiMethodResponse<
|
|
150
|
+
getBlockInfo: (id: BlockId) => SyApiMethodResponse<Block>
|
|
120
151
|
/**
|
|
121
152
|
* 获取块的 DOM 结构
|
|
122
153
|
* @path /api/block/getBlockDOM
|
|
154
|
+
* @param id - The ID of the block
|
|
155
|
+
* @returns - Promise<{ code: number, msg: string, data: BlockDOM }>
|
|
123
156
|
*/
|
|
124
|
-
getBlockDOM: (id: BlockId) => SyApiMethodResponse<
|
|
157
|
+
getBlockDOM: (id: BlockId) => SyApiMethodResponse<BlockDOM>
|
|
158
|
+
/**
|
|
159
|
+
* 批量获取块的 DOM 结构
|
|
160
|
+
* @path /api/block/getBlockDOMs
|
|
161
|
+
* @param ids - The IDs of the blocks
|
|
162
|
+
* @returns - Promise<{ code: number, msg: string, data: BlockDOM[] }>
|
|
163
|
+
*/
|
|
164
|
+
getBlockDOMs: (ids: BlockId[]) => SyApiMethodResponse<BlockDOM[]>
|
|
125
165
|
}
|
|
126
166
|
|
|
127
|
-
|
|
167
|
+
|
|
168
|
+
SiYuanAPI.prototype.insertBlock = function (data: {
|
|
169
|
+
dataType?: 'markdown' | 'dom'
|
|
170
|
+
data: string
|
|
171
|
+
nextID?: string
|
|
172
|
+
previousID?: string
|
|
173
|
+
parentID?: string
|
|
174
|
+
}) {
|
|
128
175
|
return this.request('/api/block/insertBlock', {
|
|
129
|
-
|
|
130
|
-
data,
|
|
131
|
-
nextID,
|
|
132
|
-
previousID,
|
|
133
|
-
parentID,
|
|
176
|
+
...data,
|
|
177
|
+
dataType: data.dataType || 'markdown',
|
|
134
178
|
})
|
|
135
179
|
}
|
|
136
180
|
|
|
@@ -224,3 +268,7 @@ SiYuanAPI.prototype.getBlockDOM = function (id: string) {
|
|
|
224
268
|
return this.request('/api/block/getBlockDOM', { id })
|
|
225
269
|
}
|
|
226
270
|
|
|
271
|
+
SiYuanAPI.prototype.getBlockDOMs = function (ids: string[]) {
|
|
272
|
+
return this.request('/api/block/getBlockDOMs', { ids })
|
|
273
|
+
}
|
|
274
|
+
|
package/src/api/file/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SiYuanAPI,
|
|
3
3
|
SyApiMethodResponse,
|
|
4
|
+
SyApiResponse,
|
|
4
5
|
} from '../../core/index.js'
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -10,8 +11,17 @@ export interface FileAPI {
|
|
|
10
11
|
/**
|
|
11
12
|
* 获取文件内容
|
|
12
13
|
* @path /api/file/getFile
|
|
14
|
+
* @param path - The file path
|
|
15
|
+
* @returns - Promise<string | SyApiResponse<string | null>>
|
|
16
|
+
* 返回值可能是:
|
|
17
|
+
* - 文件存在时:直接返回文件内容(字符串)
|
|
18
|
+
* - 文件不存在或出错时:标准结构 { code: number, msg: string, data: null }
|
|
19
|
+
* - code: 404 表示文件不存在
|
|
20
|
+
* - code: 403 表示路径无效或权限不足
|
|
21
|
+
* - code: 405 表示路径是目录
|
|
22
|
+
* - code: 500 表示读取文件失败
|
|
13
23
|
*/
|
|
14
|
-
getFile: (path: string) =>
|
|
24
|
+
getFile: (path: string) => Promise<string | SyApiResponse<string | null>>
|
|
15
25
|
/**
|
|
16
26
|
* 上传/创建文件
|
|
17
27
|
* @path /api/file/putFile
|
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
import type { SyApiMethodResponse } from '../../core/index.js'
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
Notebook,
|
|
4
|
+
NotebookId,
|
|
5
|
+
} from '../../types/index.js'
|
|
3
6
|
import { SiYuanAPI } from '../../core/index.js'
|
|
4
7
|
|
|
8
|
+
|
|
9
|
+
export interface RespLsNotebooks {
|
|
10
|
+
notebooks: Notebook[]
|
|
11
|
+
}
|
|
12
|
+
|
|
5
13
|
/**
|
|
6
14
|
* Notebook API 类型定义
|
|
7
15
|
*/
|
|
8
16
|
export interface NotebookAPI {
|
|
9
17
|
/**
|
|
10
|
-
*
|
|
18
|
+
* List all notebooks
|
|
11
19
|
* @path /api/notebook/lsNotebooks
|
|
20
|
+
* @returns - Promise<{ notebooks: Notebook[] }>
|
|
12
21
|
*/
|
|
13
|
-
lsNotebooks: () => SyApiMethodResponse<
|
|
22
|
+
lsNotebooks: () => SyApiMethodResponse<RespLsNotebooks>
|
|
14
23
|
/**
|
|
15
24
|
* 打开笔记本
|
|
16
25
|
* @path /api/notebook/openNotebook
|
package/src/core/index.ts
CHANGED
|
@@ -20,24 +20,34 @@ export interface SyApiResponse<T = any> {
|
|
|
20
20
|
data: T
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export type SyApiMethodResponse<T = any> = Promise<SyApiResponse<T> | IWebSocketData>
|
|
23
|
+
export type SyApiMethodResponse<T = any> = Promise<SyApiResponse<T> | IWebSocketData | T>
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* 请求选项
|
|
28
28
|
*/
|
|
29
29
|
export interface RequestOptions {
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* 请求方法
|
|
32
|
+
* @default POST
|
|
33
|
+
* @description 请求方法
|
|
34
|
+
* @example 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
|
|
35
|
+
*/
|
|
31
36
|
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
|
|
32
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* 请求头
|
|
39
|
+
* @default {}
|
|
40
|
+
* @description 请求头
|
|
41
|
+
* @example { 'Content-Type': 'application/json' }
|
|
42
|
+
*/
|
|
33
43
|
headers?: Record<string, string>
|
|
34
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* 超时时间(毫秒)
|
|
46
|
+
* @default 30000
|
|
47
|
+
*/
|
|
35
48
|
timeout?: number
|
|
36
49
|
}
|
|
37
50
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
51
|
/**
|
|
42
52
|
* 基础 Fetch 函数类型(统一的结构)
|
|
43
53
|
*/
|
|
@@ -76,6 +86,46 @@ export class SiYuanAPI {
|
|
|
76
86
|
|
|
77
87
|
constructor(config: SiYuanAPIConfig) {
|
|
78
88
|
this.setConfig(config)
|
|
89
|
+
// 自动绑定所有原型方法,确保在解构或箭头函数中调用时 this 不会丢失
|
|
90
|
+
this._bindMethods()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 绑定所有原型方法到当前实例
|
|
95
|
+
* 这样即使方法被解构,this 也能正确指向实例
|
|
96
|
+
* @private
|
|
97
|
+
*/
|
|
98
|
+
private _bindMethods(): void {
|
|
99
|
+
const prototype = SiYuanAPI.prototype
|
|
100
|
+
const boundMethods = new Set<string>()
|
|
101
|
+
|
|
102
|
+
// 获取原型上的所有属性名(包括不可枚举的)
|
|
103
|
+
const propertyNames = Object.getOwnPropertyNames(prototype)
|
|
104
|
+
|
|
105
|
+
for (const name of propertyNames) {
|
|
106
|
+
// 跳过已绑定的方法和特殊方法
|
|
107
|
+
if (
|
|
108
|
+
boundMethods.has(name)
|
|
109
|
+
|| name === 'constructor'
|
|
110
|
+
|| name.startsWith('_')
|
|
111
|
+
|| name === 'setConfig'
|
|
112
|
+
|| name === 'getConfig'
|
|
113
|
+
|| name === 'extractData'
|
|
114
|
+
|| name === '_bindMethods'
|
|
115
|
+
|| name === 'request'
|
|
116
|
+
|| name === 'post'
|
|
117
|
+
) {
|
|
118
|
+
continue
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, name)
|
|
122
|
+
|
|
123
|
+
// 只绑定函数类型的属性
|
|
124
|
+
if (descriptor && typeof descriptor.value === 'function') {
|
|
125
|
+
;(this as any)[name] = descriptor.value.bind(this)
|
|
126
|
+
boundMethods.add(name)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
79
129
|
}
|
|
80
130
|
|
|
81
131
|
setConfig(config: SiYuanAPIConfig): void {
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SiYuan SDK
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2023 Wetoria. All rights reserved.
|
|
5
|
+
* https://github.com/wetoria/sy-plugin-enhance
|
|
6
|
+
*
|
|
7
|
+
* See API Document in [API.md](https://github.com/siyuan-note/siyuan/blob/master/API.md)
|
|
8
|
+
* API 文档见 [API_zh_CN.md](https://github.com/siyuan-note/siyuan/blob/master/API_zh_CN.md)
|
|
3
9
|
*/
|
|
4
10
|
|
|
11
|
+
|
|
5
12
|
export * from './api/index.js'
|
|
6
13
|
export type * from './core/index.js'
|
|
7
14
|
export * from './core/index.js'
|