@xiongtao.xt/tau-plugins 0.3.0 → 0.4.0
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/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import type { PluginPages } from "./pages";
|
|
|
2
2
|
import type { PluginEditor } from "./editor";
|
|
3
3
|
import type { PluginSettings } from "./settings";
|
|
4
4
|
import type { PluginSidebar } from "./sidebar";
|
|
5
|
+
import type { PluginExcerpts, PluginMaterials } from "./excerpts";
|
|
5
6
|
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
6
7
|
[key: string]: JsonValue;
|
|
7
8
|
};
|
|
@@ -31,6 +32,8 @@ export interface PluginContext {
|
|
|
31
32
|
readonly editor: PluginEditor;
|
|
32
33
|
readonly settings: PluginSettings;
|
|
33
34
|
readonly sidebar: PluginSidebar;
|
|
35
|
+
readonly excerpts: PluginExcerpts;
|
|
36
|
+
readonly materials: PluginMaterials;
|
|
34
37
|
readonly fetch: typeof globalThis.fetch;
|
|
35
38
|
/** 将订阅等资源交给宿主,在停用或激活失败时逆序回收。 */
|
|
36
39
|
register(resource: Disposable): Disposable;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Disposable, JsonValue } from "./contract";
|
|
2
|
+
/** Tau 材料的地址。对插件是不透明值:只用于传回宿主(如 materials.actions),不要依赖其字段。 */
|
|
3
|
+
export interface PluginMaterialRef {
|
|
4
|
+
readonly kind: string;
|
|
5
|
+
readonly id: number;
|
|
6
|
+
}
|
|
7
|
+
/** 摘录来源:一本书、一个网页、一篇文献 */
|
|
8
|
+
export interface PluginExcerptSource {
|
|
9
|
+
/** 来源在本插件内的稳定标识 */
|
|
10
|
+
key: string;
|
|
11
|
+
title: string;
|
|
12
|
+
/** 来源级 http(s) 外链,条目没有 url 时作为打开原处的兜底 */
|
|
13
|
+
url?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface PluginExcerptItem {
|
|
16
|
+
/** 本插件内唯一且稳定;它不变,Tau 中对这条摘录的引用就一直有效 */
|
|
17
|
+
externalId: string;
|
|
18
|
+
quote: string;
|
|
19
|
+
note?: string;
|
|
20
|
+
/** 给人看的位置:「第 3 章 · 标题」「第 12 页」 */
|
|
21
|
+
location?: string;
|
|
22
|
+
/** 条目级 http(s) 深链,优先于来源 url */
|
|
23
|
+
url?: string;
|
|
24
|
+
/** 插件私有定位,宿主只存储、按键名规范化后比较,从不解读 */
|
|
25
|
+
anchor?: {
|
|
26
|
+
[key: string]: JsonValue;
|
|
27
|
+
};
|
|
28
|
+
color?: string;
|
|
29
|
+
/** 在来源中的创建时间(毫秒) */
|
|
30
|
+
time?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface PluginExcerptSyncResult {
|
|
33
|
+
inserted: number;
|
|
34
|
+
updated: number;
|
|
35
|
+
deleted: number;
|
|
36
|
+
}
|
|
37
|
+
export interface PluginExcerptSourceSummary {
|
|
38
|
+
key: string;
|
|
39
|
+
title: string;
|
|
40
|
+
/** 未删除的条目数 */
|
|
41
|
+
count: number;
|
|
42
|
+
}
|
|
43
|
+
/** 读回的条目:写入时的字段(含缺省后的外链)加上 Tau 中的地址与删除状态 */
|
|
44
|
+
export interface PluginExcerptEntry {
|
|
45
|
+
ref: PluginMaterialRef;
|
|
46
|
+
externalId: string;
|
|
47
|
+
quote: string;
|
|
48
|
+
note: string;
|
|
49
|
+
location: string;
|
|
50
|
+
url: string | null;
|
|
51
|
+
anchor: {
|
|
52
|
+
[key: string]: JsonValue;
|
|
53
|
+
} | null;
|
|
54
|
+
color: string | null;
|
|
55
|
+
time: number | null;
|
|
56
|
+
/** 已从来源消失(软删除);引文保留,引用仍可解析 */
|
|
57
|
+
deleted: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface PluginExcerptProviderDefinition {
|
|
60
|
+
/** 提供方名称,持久化;插件停用、卸载后仍用于显示来源 */
|
|
61
|
+
label: string;
|
|
62
|
+
/** 从脉络、搜索、对话打开原处时调用;缺省时打开条目或来源的 url */
|
|
63
|
+
open?(target: {
|
|
64
|
+
sourceKey: string;
|
|
65
|
+
externalId: string;
|
|
66
|
+
}): void | Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
export interface PluginExcerptChange {
|
|
69
|
+
upsert?: PluginExcerptItem[];
|
|
70
|
+
/** 要软删除的 externalId */
|
|
71
|
+
remove?: string[];
|
|
72
|
+
}
|
|
73
|
+
/** 插件作为 Tau 外部摘录的提供方;摘录归用户,插件只能软删除。写入前须在本次激活内 register。 */
|
|
74
|
+
export interface PluginExcerpts {
|
|
75
|
+
register(definition: PluginExcerptProviderDefinition): Disposable;
|
|
76
|
+
/** 快照:以全集覆盖一个来源,缺席条目软删除;items 为空即整个来源下架 */
|
|
77
|
+
replace(source: PluginExcerptSource, items: PluginExcerptItem[]): Promise<PluginExcerptSyncResult>;
|
|
78
|
+
/** 增量:只增改或软删除指定条目 */
|
|
79
|
+
patch(source: PluginExcerptSource, change: PluginExcerptChange): Promise<PluginExcerptSyncResult>;
|
|
80
|
+
sources(): Promise<PluginExcerptSourceSummary[]>;
|
|
81
|
+
items(sourceKey: string): Promise<PluginExcerptEntry[]>;
|
|
82
|
+
}
|
|
83
|
+
export interface PluginMaterialAction {
|
|
84
|
+
id: string;
|
|
85
|
+
label: string;
|
|
86
|
+
run(): Promise<void>;
|
|
87
|
+
}
|
|
88
|
+
export interface PluginMaterials {
|
|
89
|
+
/** 客户端对该材料当前可执行的动作(转为卡片、转为问题…);动作随客户端增加 */
|
|
90
|
+
actions(ref: PluginMaterialRef): Promise<PluginMaterialAction[]>;
|
|
91
|
+
}
|
|
@@ -3,5 +3,6 @@ export type { JsonValue, Disposable, PluginStorage, PluginCommand, PluginContext
|
|
|
3
3
|
export type { PluginSettings, PluginSettingsDefinition, PluginSettingsProps, PluginSettingsHandle, } from "./settings";
|
|
4
4
|
export * from "./editor";
|
|
5
5
|
export * from "./sidebar";
|
|
6
|
+
export type * from "./excerpts";
|
|
6
7
|
export type { PluginPageDefinition, PluginPageHandle, PluginPageParams, PluginPageProps, PluginPages, } from "./pages";
|
|
7
8
|
export declare function definePlugin(definition: Omit<PluginDefinition, "apiVersion">): PluginDefinition;
|