@xiongtao.xt/tau-plugins 0.33.0 → 0.34.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/client/{chunk-SVY5LBAT.js → chunk-FZTR4KOY.js} +10 -0
  3. package/docs/README.md +18 -17
  4. package/docs/editor.md +47 -1
  5. package/docs/excerpts.md +1 -1
  6. package/docs/plugin-basics.md +3 -0
  7. package/docs/storage-and-network.md +1 -1
  8. package/docs/ui.md +229 -1
  9. package/docs/user-data.md +388 -72
  10. package/package.js +1 -1
  11. package/package.json +1 -1
  12. package/publish-artifacts.js +29 -2
  13. package/types/packages/editor/src/core/api/extension.d.ts +3 -0
  14. package/types/packages/editor/src/core/api/index.d.ts +1 -0
  15. package/types/packages/editor/src/core/api/inputRules.d.ts +37 -0
  16. package/types/packages/plugins/src/actions.d.ts +61 -0
  17. package/types/packages/plugins/src/app.d.ts +106 -8
  18. package/types/packages/plugins/src/components.d.ts +22 -0
  19. package/types/packages/plugins/src/content-input.d.ts +34 -0
  20. package/types/packages/plugins/src/contract.d.ts +18 -0
  21. package/types/packages/plugins/src/data.d.ts +179 -11
  22. package/types/packages/plugins/src/editor-fields.d.ts +10 -0
  23. package/types/packages/plugins/src/editor.d.ts +2 -1
  24. package/types/packages/plugins/src/entities.d.ts +28 -3
  25. package/types/packages/plugins/src/events.d.ts +9 -3
  26. package/types/packages/plugins/src/excerpts.d.ts +1 -1
  27. package/types/packages/plugins/src/home.d.ts +20 -0
  28. package/types/packages/plugins/src/index.d.ts +17 -5
  29. package/types/packages/plugins/src/links.d.ts +39 -0
  30. package/types/packages/plugins/src/pages.d.ts +12 -0
  31. package/types/packages/plugins/src/permissions.d.ts +1 -1
  32. package/types/packages/plugins/src/query.d.ts +64 -0
  33. package/types/packages/plugins/src/records.d.ts +50 -0
  34. package/types/packages/plugins/src/sidebar.d.ts +63 -1
  35. package/types/packages/plugins/src/transaction.d.ts +40 -0
  36. package/types/packages/plugins/src/views.d.ts +26 -0
@@ -3,6 +3,9 @@
3
3
  * 每次调用前宿主按 manifest.permissions 与用户授权校验,未获准抛出 PluginPermissionError。
4
4
  * 修改与删除要传读到的 revision,数据已被别处修改时抛出 PluginConflictError。
5
5
  */
6
+ import type { Descendant } from "slate";
7
+ import type { PluginContentInput } from "./content-input";
8
+ import type { PluginEntityRef } from "./app";
6
9
  /** 一份正文的句柄,从实体上取得,传给 context.content 读取 */
7
10
  export type PluginContentRef = string;
8
11
  export interface PluginPage<T> {
@@ -51,6 +54,136 @@ export interface PluginDocument extends PluginEntityBase {
51
54
  contentRef: PluginContentRef | null;
52
55
  projectIds: string[];
53
56
  }
57
+ export interface PluginWhiteboard {
58
+ id: string;
59
+ /** 白板信息(标题、说明、标签)的版本;画板内容的编辑不改变它 */
60
+ revision: string;
61
+ title: string;
62
+ description: string;
63
+ tags: string[];
64
+ /** 画板页数 */
65
+ pageCount: number;
66
+ createdAt: number;
67
+ updatedAt: number;
68
+ }
69
+ export interface PluginWhiteboardInput {
70
+ title: string;
71
+ description?: string;
72
+ tags?: string[];
73
+ }
74
+ export type PluginWhiteboardPatch = Partial<PluginWhiteboardInput>;
75
+ export interface PluginProject {
76
+ id: string;
77
+ /** 项目的版本:改名、归档、置顶以及文档目录的变化都会改变它 */
78
+ revision: string;
79
+ title: string;
80
+ archived: boolean;
81
+ pinned: boolean;
82
+ /** 根目录下的文档数 */
83
+ documentCount: number;
84
+ createdAt: number;
85
+ updatedAt: number;
86
+ }
87
+ export interface PluginProjectInput {
88
+ title: string;
89
+ }
90
+ export interface PluginProjectPatch {
91
+ title?: string;
92
+ archived?: boolean;
93
+ pinned?: boolean;
94
+ }
95
+ /**
96
+ * 项目目录中的一处。同一篇文档可以挂在多处,这时会在目录里出现多次,documentId 相同。
97
+ */
98
+ export interface PluginProjectNode {
99
+ documentId: string;
100
+ /** 文档的版本,documents.move 时作为 expectedRevision 传回 */
101
+ revision: string;
102
+ title: string;
103
+ /** document(富文本)、white-board 等 */
104
+ kind: string;
105
+ /** 引用卡片或文章的条目:正文归被引用的内容,documents.get 读不到这一项 */
106
+ ref?: PluginEntityRef;
107
+ children: PluginProjectNode[];
108
+ }
109
+ export interface PluginDocumentInput {
110
+ projectId: string;
111
+ /** 挂在哪篇文档下;省略时挂在项目根目录末尾 */
112
+ parentId?: string;
113
+ title: string;
114
+ /** 正文;省略时为空 */
115
+ content?: PluginContentInput;
116
+ tags?: string[];
117
+ }
118
+ /** 在同一项目内移动文档的一处位置;from / to 为父文档 ID,null 表示项目根目录 */
119
+ export interface PluginDocumentMove {
120
+ projectId: string;
121
+ from: string | null;
122
+ to: string | null;
123
+ /** 移动后在新位置中的序号,从 0 开始;省略时放在末尾 */
124
+ index?: number;
125
+ }
126
+ export interface PluginNotebook {
127
+ id: string;
128
+ title: string;
129
+ archived: boolean;
130
+ pinned: boolean;
131
+ /** 资料数 */
132
+ resourceCount: number;
133
+ createdAt: number;
134
+ updatedAt: number;
135
+ }
136
+ /**
137
+ * Notebook 里的一份资料。只给清单信息:不含本机文件路径与资料转换后的文字。
138
+ * source:local 本机文件、remote 网络链接、note 加入时的笔记快照、material 材料快照、
139
+ * online-video 在线视频。
140
+ */
141
+ export interface PluginNotebookResource {
142
+ id: string;
143
+ name: string;
144
+ /** 文件类型:pdf、video、audio、image、md、html、docx 等,无法识别时为 other */
145
+ type: string;
146
+ source: "local" | "remote" | "note" | "material" | "online-video";
147
+ /** remote 的网址 */
148
+ url?: string;
149
+ /** note / material:快照来自哪些内容,原内容可能已删除 */
150
+ from?: PluginEntityRef[];
151
+ /** 字节数,未知时为 null */
152
+ size: number | null;
153
+ /** 音视频时长(秒),未知时为 null */
154
+ duration: number | null;
155
+ createdAt: number;
156
+ }
157
+ /** 划线(excerpt)、PDF 标注(pdf-annotation)与剪藏(web-clip) */
158
+ export type PluginMaterialKind = "excerpt" | "pdf-annotation" | "web-clip";
159
+ export interface PluginMaterial {
160
+ /** 与 PluginEntityRef 的 material 引用 ID 相同 */
161
+ id: string;
162
+ kind: PluginMaterialKind;
163
+ title: string;
164
+ /** 划下或标注的原文;剪藏为空 */
165
+ quote: string;
166
+ /** 用户写下的想法 */
167
+ note: string;
168
+ /** 出处说明,如「PDF · 文件名 · 第 3 页」 */
169
+ source: string;
170
+ /** 原处的网址:划线的外部链接、剪藏的网页 */
171
+ url?: string;
172
+ createdAt: number;
173
+ updatedAt: number;
174
+ }
175
+ /** 对话的信息;消息内容不开放 */
176
+ export interface PluginChatSession {
177
+ id: string;
178
+ /** 未命名的对话为空字符串 */
179
+ title: string;
180
+ /** main 主对话、pdf PDF 对话、video-note 视频笔记对话、notebook Notebook 对话 */
181
+ scene: "main" | "pdf" | "video-note" | "notebook";
182
+ messageCount: number;
183
+ archived: boolean;
184
+ createdAt: number;
185
+ updatedAt: number;
186
+ }
54
187
  export interface PluginEntityReader<T> {
55
188
  get(id: string): Promise<T | null>;
56
189
  query(query?: PluginEntityQuery): Promise<PluginPage<T>>;
@@ -60,8 +193,8 @@ export interface PluginWriteOptions {
60
193
  expectedRevision: string;
61
194
  }
62
195
  export interface PluginCardInput {
63
- /** 正文,Markdown;省略时为空卡片 */
64
- markdown?: string;
196
+ /** 正文;省略时为空卡片 */
197
+ content?: PluginContentInput;
65
198
  tags?: string[];
66
199
  pinned?: boolean;
67
200
  }
@@ -71,7 +204,8 @@ export interface PluginCardPatch {
71
204
  }
72
205
  export interface PluginArticleInput {
73
206
  title: string;
74
- markdown?: string;
207
+ /** 正文;省略时为空文章 */
208
+ content?: PluginContentInput;
75
209
  tags?: string[];
76
210
  }
77
211
  export interface PluginArticlePatch {
@@ -157,10 +291,41 @@ export type PluginCalendarPatch = Partial<PluginCalendarInput>;
157
291
  export interface PluginData {
158
292
  readonly cards: PluginEntityWriter<PluginCard, PluginCardInput, PluginCardPatch>;
159
293
  readonly articles: PluginEntityWriter<PluginArticle, PluginArticleInput, PluginArticlePatch>;
160
- /** 项目文档只能修改标题与标签;新建、移动与删除涉及文档树,暂不开放 */
294
+ /** 白板的信息;画板内容不开放读写,用户在 Tau 中编辑 */
295
+ readonly whiteboards: PluginEntityWriter<PluginWhiteboard, PluginWhiteboardInput, PluginWhiteboardPatch>;
296
+ /** 项目本身;query 不支持 tag。项目里的文档见 documents */
297
+ readonly projects: PluginEntityReader<PluginProject> & {
298
+ /** 新建一个空项目 */
299
+ create(input: PluginProjectInput): Promise<PluginProject>;
300
+ /** 项目的文档目录;项目不存在时为 null */
301
+ tree(id: string): Promise<PluginProjectNode[] | null>;
302
+ update(id: string, patch: PluginProjectPatch, options: PluginWriteOptions): Promise<PluginProject>;
303
+ /** 只能删除空项目:项目里还有文档时拒绝 */
304
+ delete(id: string, options: PluginWriteOptions): Promise<void>;
305
+ };
306
+ /** 项目文档:新建、修改标题与标签、在项目内移动与删除 */
161
307
  readonly documents: PluginEntityReader<PluginDocument> & {
308
+ create(input: PluginDocumentInput): Promise<PluginDocument>;
162
309
  update(id: string, patch: PluginDocumentPatch, options: PluginWriteOptions): Promise<PluginDocument>;
310
+ /** 移动挂在 from 下的那一处;不能移到自己或自己的子文档下。返回文档的新版本 */
311
+ move(id: string, move: PluginDocumentMove, options: PluginWriteOptions): Promise<{
312
+ revision: string;
313
+ }>;
314
+ /**
315
+ * 从所有挂载处删除这篇文档。有子文档时拒绝;视频笔记不能由插件删除。
316
+ * 用户可在插件详情页 7 天内恢复,恢复后挂回仍存在的原位置。
317
+ */
318
+ delete(id: string, options: PluginWriteOptions): Promise<void>;
163
319
  };
320
+ /** Notebook 的信息与资料清单;query 不支持 tag */
321
+ readonly notebooks: PluginEntityReader<PluginNotebook> & {
322
+ /** 按 Notebook 中的顺序;Notebook 不存在时为 null */
323
+ resources(id: string): Promise<PluginNotebookResource[] | null>;
324
+ };
325
+ /** 划线、PDF 标注与剪藏;query 不支持 tag,已删除的不返回 */
326
+ readonly materials: PluginEntityReader<PluginMaterial>;
327
+ /** AI 对话的信息,不含消息内容;query 不支持 tag */
328
+ readonly chats: PluginEntityReader<PluginChatSession>;
164
329
  readonly todos: {
165
330
  query(query?: PluginTodoQuery): Promise<PluginPage<PluginTodo>>;
166
331
  create(input: PluginTodoInput): Promise<PluginTodo>;
@@ -182,21 +347,24 @@ export interface PluginContentSnapshot {
182
347
  revision: string;
183
348
  /** format 为 markdown(默认)时给出 */
184
349
  markdown?: string;
185
- /** format 为 nodes 时给出编辑器节点 JSON;结构随编辑器演进,优先使用 markdown */
186
- nodes?: unknown[];
350
+ /** format 为 nodes 时给出编辑器节点,可原样作为 PluginContentInput 的 nodes 写回 */
351
+ nodes?: Descendant[];
352
+ /** format 为 nodes 时给出节点结构版本,见 EDITOR_NODE_SCHEMA_VERSION */
353
+ schemaVersion?: number;
187
354
  wordCount: number;
188
355
  updatedAt: number;
189
356
  }
190
357
  /**
191
- * 正文修改。append / prepend 只追加新内容,原有内容保持不变;replaceText 与 replaceAll 会把整篇
192
- * 经 Markdown 重建,Markdown 无法表达的格式可能简化。
358
+ * 正文修改。append / prepend 只加入新内容(不能为空),原有内容保持不变;replaceAll 用新内容替换
359
+ * 整篇(可以为空)。replaceText 在 Markdown 文本上查找替换,会把整篇经 Markdown 重建,
360
+ * Markdown 无法表达的格式可能简化。
193
361
  */
194
362
  export type PluginContentEdit = {
195
363
  op: "append";
196
- markdown: string;
364
+ content: PluginContentInput;
197
365
  } | {
198
366
  op: "prepend";
199
- markdown: string;
367
+ content: PluginContentInput;
200
368
  }
201
369
  /** find 必须在当前 Markdown 中恰好出现一次 */
202
370
  | {
@@ -205,7 +373,7 @@ export type PluginContentEdit = {
205
373
  markdown: string;
206
374
  } | {
207
375
  op: "replaceAll";
208
- markdown: string;
376
+ content: PluginContentInput;
209
377
  };
210
378
  export interface PluginContent {
211
379
  /** 需要拥有该正文所属实体的读取权限;正文不存在时返回 null */
@@ -0,0 +1,10 @@
1
+ import type { PluginEditorExtension } from "./editor";
2
+ /** 向插件开放的编辑器扩展字段;类型与运行时校验共用这一份,新增开放须同时评估宿主隔离。 */
3
+ declare const OPEN_EXTENSION_FIELDS: readonly ["id", "apiVersion", "elements", "commands", "hotkeys", "menu", "blockPanel", "behaviorsFor"];
4
+ export type OpenEditorExtensionField = (typeof OPEN_EXTENSION_FIELDS)[number];
5
+ /**
6
+ * 运行时按白名单校验插件给的编辑器扩展:编辑器装配直接读取属性,类型约束拦不住纯 JS 插件,
7
+ * 继承或不可枚举的属性同样会被读到,所以要求普通对象且自有键全部开放。
8
+ */
9
+ export declare function assertPluginEditorExtension(extension: unknown): asserts extension is PluginEditorExtension;
10
+ export {};
@@ -1,6 +1,7 @@
1
1
  import type { EditorExtension as InternalExtension } from "../../editor/contracts";
2
2
  import type { MarkdownCodec } from "../../markdown/src/index";
3
3
  import type { Disposable } from "./index";
4
+ import { type OpenEditorExtensionField } from "./editor-fields";
4
5
  export { defineElement as defineEditorElement } from "../../editor/contracts";
5
6
  export type { ElementRenderProps as EditorElementRenderProps } from "../../editor/contracts";
6
7
  export type { MarkdownCodec as EditorMarkdownCodec } from "../../markdown/src/index";
@@ -22,7 +23,7 @@ declare module "../../editor/api" {
22
23
  [inlineMapBrand]: never;
23
24
  }
24
25
  }
25
- export type PluginEditorExtension = Pick<InternalExtension, "id" | "apiVersion" | "elements" | "commands" | "hotkeys" | "menu" | "blockPanel" | "behaviorsFor"> & {
26
+ export type PluginEditorExtension = Pick<InternalExtension, OpenEditorExtensionField> & {
26
27
  plugins?: never;
27
28
  /** 发布时从节点字段收集 Tailwind 源码,复用宿主编译器。 */
28
29
  styleSources?: readonly {
@@ -8,6 +8,8 @@ import type { JsonValue } from "./json";
8
8
  import type { PluginPageParams } from "./pages";
9
9
  import type { PluginEntityRef } from "./app";
10
10
  import type { PluginIcon } from "./icons";
11
+ import type { PluginContentInput } from "./content-input";
12
+ import type { PluginIndexes, PluginOrderBy, PluginWhere } from "./query";
11
13
  export type PluginOwnEntityMeta = Record<string, JsonValue>;
12
14
  export interface PluginOwnEntity {
13
15
  id: string;
@@ -42,19 +44,40 @@ export interface PluginOwnEntityKind {
42
44
  };
43
45
  /** 是否可在正文中用 @ 引用,默认 false */
44
46
  mentionable?: boolean;
47
+ /**
48
+ * 可用于 query 筛选与排序的 meta 字段及类型,如 `{ status: "string", sortIndex: "number" }`。
49
+ * 最多 16 个;写入时这些字段的值必须是声明的类型或 null。只在插件运行时生效。
50
+ */
51
+ indexes?: PluginIndexes;
45
52
  }
46
53
  export interface PluginOwnEntityInput {
47
54
  kind: string;
48
55
  key: string;
49
56
  title?: string;
50
57
  meta?: PluginOwnEntityMeta;
58
+ /** 初始正文;省略时为空 */
59
+ content?: PluginContentInput;
51
60
  }
52
61
  export interface PluginOwnEntityPatch {
53
62
  title?: string;
54
63
  meta?: PluginOwnEntityMeta;
55
64
  }
56
- export interface PluginOwnEntityQuery {
65
+ /** 实体自带的排序列;其余排序字段取 registerKind 声明的 indexes */
66
+ export type PluginOwnEntitySortField = "createdAt" | "updatedAt" | "title";
67
+ export interface PluginOwnEntityFilter {
57
68
  kind?: string;
69
+ /** 按 indexes 中的字段筛选,需同时给出 kind */
70
+ where?: PluginWhere;
71
+ /** 标题包含这段文字(英文字母不区分大小写) */
72
+ titleContains?: string;
73
+ }
74
+ export interface PluginOwnEntityQuery extends PluginOwnEntityFilter {
75
+ /**
76
+ * 最多两项,ID 兜底保证顺序稳定;默认按创建时间倒序。字段为 createdAt、updatedAt、title,
77
+ * 或 kind 的 indexes 中声明的字段。
78
+ */
79
+ orderBy?: PluginOrderBy | PluginOrderBy[];
80
+ /** 原样传回上一页的 cursor;换了筛选或排序后不能再用 */
58
81
  cursor?: string;
59
82
  /** 默认 50,最多 200 */
60
83
  limit?: number;
@@ -74,12 +97,14 @@ export interface PluginOwnEntityBacklink {
74
97
  export interface PluginOwnEntities {
75
98
  /** 声明一种内容类型;create 只接受已声明的类型 */
76
99
  registerKind(definition: PluginOwnEntityKind): Disposable;
77
- /** 新建一项,正文为空。同一类型下 key 已存在时抛出 PluginConflictError */
100
+ /** 新建一项,content 为初始正文(缺省为空)。同一类型下 key 已存在时抛出 PluginConflictError */
78
101
  create(input: PluginOwnEntityInput): Promise<PluginOwnEntity>;
79
102
  get(id: string): Promise<PluginOwnEntity | null>;
80
103
  find(kind: string, key: string): Promise<PluginOwnEntity | null>;
81
- /** 按创建时间倒序分页 */
104
+ /** 分页查询,默认按创建时间倒序 */
82
105
  query(query?: PluginOwnEntityQuery): Promise<PluginPage<PluginOwnEntity>>;
106
+ /** 符合条件的数量 */
107
+ count(filter?: PluginOwnEntityFilter): Promise<number>;
83
108
  /** 修改标题或 meta;revision 不是最新时抛出 PluginConflictError */
84
109
  update(id: string, patch: PluginOwnEntityPatch, options: PluginWriteOptions): Promise<PluginOwnEntity>;
85
110
  /**
@@ -2,9 +2,11 @@ import type { Disposable } from "./contract";
2
2
  import type { PluginPermission } from "./permissions";
3
3
  /**
4
4
  * 业务数据变更事件。事件只说明「哪一项变了」,不携带数据:需要时用 context.data 重新读取。
5
- * 正文修改计入所属卡片、文章或项目文档的 updated;待办与日程只给出集合级变化。
5
+ * 正文修改计入所属卡片、文章、项目文档或插件实体的 updated;Notebook 资料的增删改计入所属
6
+ * Notebook 的 updated;待办与日程只给出集合级变化。entity.* 与 record.* 是本插件实体
7
+ * (context.entities)与记录(context.records)的变化,只发给拥有它的插件。
6
8
  */
7
- export declare const PLUGIN_EVENT_TYPES: readonly ["card.created", "card.updated", "card.deleted", "article.created", "article.updated", "article.deleted", "document.created", "document.updated", "document.deleted", "todos.changed", "calendar.changed", "workspace.reset"];
9
+ export declare const PLUGIN_EVENT_TYPES: readonly ["card.created", "card.updated", "card.deleted", "article.created", "article.updated", "article.deleted", "document.created", "document.updated", "document.deleted", "whiteboard.created", "whiteboard.updated", "whiteboard.deleted", "project.created", "project.updated", "project.deleted", "notebook.created", "notebook.updated", "notebook.deleted", "material.created", "material.updated", "material.deleted", "chat.created", "chat.updated", "chat.deleted", "entity.created", "entity.updated", "entity.deleted", "record.created", "record.updated", "record.deleted", "todos.changed", "calendar.changed", "workspace.reset"];
8
10
  export type PluginEventType = (typeof PLUGIN_EVENT_TYPES)[number];
9
11
  /** 变化来自哪里:插件经 context.data / context.content 写入时为 plugin,其余(用户、同步、AI 等)为 app */
10
12
  export type PluginEventOrigin = {
@@ -15,8 +17,12 @@ export type PluginEventOrigin = {
15
17
  };
16
18
  export interface PluginDomainEvent {
17
19
  type: PluginEventType;
18
- /** 实体事件给出与 context.data 相同的 ID;集合级事件没有 */
20
+ /** 实体事件给出与 context.data / context.entities 相同的 ID;集合级事件没有 */
19
21
  id?: string;
22
+ /** entity.* 事件给出实体类型(registerKind 声明的 kind);删除后读不到实体时据此区分 */
23
+ kind?: string;
24
+ /** record.* 事件给出记录所在的集合 */
25
+ collection?: string;
20
26
  /** 宿主发出事件的时间(毫秒) */
21
27
  at: number;
22
28
  /** 用来忽略自己写入引起的事件;待办与日程的集合级事件恒为 app */
@@ -86,6 +86,6 @@ export interface PluginMaterialAction {
86
86
  run(): Promise<void>;
87
87
  }
88
88
  export interface PluginMaterials {
89
- /** 客户端对该材料当前可执行的动作(转为卡片、转为问题…);动作随客户端增加 */
89
+ /** 客户端对该材料当前可执行的动作(转为卡片…),不含其他插件注册的对象动作;动作随客户端增加 */
90
90
  actions(ref: PluginMaterialRef): Promise<PluginMaterialAction[]>;
91
91
  }
@@ -0,0 +1,20 @@
1
+ import type { ComponentType } from "react";
2
+ import type { Disposable, PluginContext } from "./contract";
3
+ /** compact:有最小宽度、可伸展,宽度足够时与其他紧凑面板并排;wide:占整行 */
4
+ export type PluginHomePanelSize = "compact" | "wide";
5
+ export interface PluginHomePanelProps {
6
+ readonly context: PluginContext;
7
+ }
8
+ export interface PluginHomePanelDefinition {
9
+ id: string;
10
+ /** 面板标题,也是「显示已隐藏的面板」里的名称 */
11
+ title: string;
12
+ /** 面板正文;返回 null 时整块不显示 */
13
+ component: ComponentType<PluginHomePanelProps>;
14
+ /** 缺省为 wide */
15
+ size?: PluginHomePanelSize;
16
+ }
17
+ export interface PluginHome {
18
+ /** 面板出现在首页:新面板排在末尾,位置由用户调整;插件停用后消失,重新启用回到原位置 */
19
+ registerPanel(definition: PluginHomePanelDefinition): Disposable;
20
+ }
@@ -11,21 +11,33 @@ export * from "./editor";
11
11
  export { SourceBlockEditor, useSourceBlock, useReportPreviewError, insertSourceBlock, sourceBlockParagraphBehavior, } from "./source-editor";
12
12
  export type { SourceBlockEditorProps, PluginRuntimeStyleCompiler } from "./source-editor";
13
13
  export { useInlineSource, insertInlineSource, InlineSourceBoundary } from "./inline-source";
14
- export { ContentEditor, ContentPreview } from "./components";
14
+ export { ContentEditor, ContentPreview, EntityRef } from "./components";
15
15
  export { useElement, useMediaViewer, BlockToolbar, BlockToolbarButton, BlockToolbarGap, } from "./element";
16
16
  export type { ElementAccess, BlockToolbarProps, BlockToolbarButtonProps, EditorElementFrame, } from "./element";
17
17
  export { MediaImage, MediaVideo, MediaAudio, useResource, useResourceUpload, useMediaAppearance, } from "./media";
18
18
  export type { ResourceKind, ResourceState, ResourceUpload, MediaAppearance, MediaAppearancePreset, MediaImageProps, MediaVideoProps, MediaAudioProps, MediaRuntime, } from "./media";
19
- export type { ContentEditorProps, ContentPreviewProps } from "./components";
20
- export * from "./sidebar";
19
+ export type { ContentEditorKit, ContentEditorProps, ContentPreviewProps, EntityRefProps, } from "./components";
20
+ export type * from "./sidebar";
21
+ export { SIDEBAR_GROUPS } from "./sidebar";
21
22
  export type * from "./icons";
23
+ export type * from "./home";
24
+ export type * from "./actions";
25
+ export { PLUGIN_ACTION_TARGET_KINDS } from "./actions";
26
+ export type * from "./views";
27
+ export { PLUGIN_ENTITY_PANEL_KINDS } from "./views";
22
28
  export type * from "./excerpts";
23
29
  export type * from "./data";
30
+ export type { PluginContentInput } from "./content-input";
31
+ export { EDITOR_NODE_SCHEMA_VERSION, CONTENT_INPUT_LIMITS } from "./content-input";
24
32
  export type * from "./entities";
33
+ export type * from "./records";
34
+ export type * from "./links";
35
+ export type * from "./transaction";
36
+ export type { PluginFieldCondition, PluginIndexes, PluginIndexType, PluginIndexValue, PluginOrderBy, PluginWhere, } from "./query";
25
37
  export { PluginConflictError } from "./errors";
26
- export { PLUGIN_ENTITY_KINDS, PLUGIN_APP_ACTIONS, PLUGIN_EXPORT_FORMATS } from "./app";
38
+ export { PLUGIN_ENTITY_KINDS, PLUGIN_ENTITY_READ_PERMISSIONS, PLUGIN_APP_ACTIONS, PLUGIN_EXPORT_FORMATS, PLUGIN_NOTEBOOK_FROM_KINDS, PLUGIN_CHAT_CONTEXT_KINDS, } from "./app";
27
39
  export type { PluginNotifications, PluginNotificationOptions, PluginNotificationMode, PluginNotificationAction, } from "./notifications";
28
- export type { PluginApp, PluginAppAction, PluginAppActions, PluginExportFormat, PluginEntityKind, PluginEntityRef, PluginPickOptions, PluginPickedEntity, } from "./app";
40
+ export type { PluginApp, PluginAppAction, PluginAppActions, PluginAppActionResults, PluginContentLocation, PluginOpenOptions, PluginExportFormat, PluginEntityKind, PluginEntityRef, PluginEntityDescription, PluginPickOptions, PluginPickedEntity, } from "./app";
29
41
  export { PLUGIN_EVENT_TYPES } from "./events";
30
42
  export type { PluginDomainEvent, PluginEventOrigin, PluginEventType, PluginEvents } from "./events";
31
43
  export { PLUGIN_PERMISSIONS, PluginPermissionError, isPluginPermission } from "./permissions";
@@ -0,0 +1,39 @@
1
+ /**
2
+ * 插件关联:从本插件的内容(context.entities)指向任意可引用内容的有序关联,如「问题 → 探究材料」。
3
+ * 关联随笔记库保存;目标被删除时关联保留,由 describe / EntityRef 显示为已删除。
4
+ */
5
+ import type { PluginEntityRef } from "./app";
6
+ import type { JsonValue } from "./json";
7
+ export type PluginLinkData = Record<string, JsonValue>;
8
+ export interface PluginLink {
9
+ /** 宿主生成的不透明 ID */
10
+ id: string;
11
+ /** 来源:本插件内容的 ID */
12
+ from: string;
13
+ to: PluginEntityRef;
14
+ /** 插件定义的关联角色,如 material、answer;缺省为空字符串 */
15
+ role: string;
16
+ /** 少量附加数据(不超过 4 KB),如对话里的消息位置 */
17
+ data: PluginLinkData;
18
+ createdAt: number;
19
+ }
20
+ export interface PluginLinkOptions {
21
+ role?: string;
22
+ data?: PluginLinkData;
23
+ }
24
+ export interface PluginLinks {
25
+ /**
26
+ * 添加一条关联,排在同一角色的末尾;同一来源、目标与角色已关联时返回已有的那条,不修改 data。
27
+ * 目标须是插件能看到的内容:用户选择过或请 Tau 新建的、本插件自己的内容,或已获准读取的类型;
28
+ * 否则抛错,且不透露目标是否存在。
29
+ */
30
+ add(from: string, to: PluginEntityRef, options?: PluginLinkOptions): Promise<PluginLink>;
31
+ /** 按角色与顺序列出来源的关联;给出 role 时只列这一角色 */
32
+ list(from: string, options?: {
33
+ role?: string;
34
+ }): Promise<PluginLink[]>;
35
+ /** 删除一条关联;已不存在时不报错 */
36
+ remove(id: string): Promise<void>;
37
+ /** 重排同一来源、同一角色的全部关联:ids 须恰好是这一角色当前的全部关联 */
38
+ reorder(from: string, ids: readonly string[]): Promise<void>;
39
+ }
@@ -5,6 +5,18 @@ export type PluginPageParams = Record<string, string | number | boolean>;
5
5
  export interface PluginPageContext {
6
6
  /** 在组件 effect 中登记当前状态提供器;返回值的形状由插件决定。 */
7
7
  register(provider: () => JsonValue): Disposable;
8
+ /**
9
+ * 本页是否为当前显示的页面(在页面栈顶);页面隐藏、卸载或插件停用后为 false。
10
+ * 页面隐藏时组件的 effect 会被清理、显示时重新执行,订阅与键盘监听放在 effect 里即可随之暂停;
11
+ * 这里供命令等 effect 之外的回调判断。
12
+ */
13
+ isActive(): boolean;
14
+ /**
15
+ * 登记一个浮层(抽屉、弹出面板)的关闭函数:用户按 Esc 时 Tau 先关最后登记的浮层,
16
+ * 不会后退页面。只在本页显示时生效。@tau/ui 的模态 Dialog / Drawer 已自带,不必登记;
17
+ * 插件不要自己监听 Esc。
18
+ */
19
+ registerDismiss(dismiss: () => void): Disposable;
8
20
  }
9
21
  export interface PluginPageProps {
10
22
  readonly context: PluginContext;
@@ -1,4 +1,4 @@
1
- export declare const PLUGIN_PERMISSIONS: readonly ["cards:read", "cards:write", "cards:delete", "articles:read", "articles:write", "articles:delete", "documents:read", "documents:write", "todos:read", "todos:write", "todos:delete", "calendar:read", "calendar:write", "calendar:delete", "flashcards:read", "flashcards:write", ...("ai:chat" | "ai:titleSummary" | "ai:webClip" | "ai:podcastGeneration" | "ai:flashcardGeneration" | "ai:aiJudgement" | "ai:transcriptionOptimization" | "ai:videoSummary" | "ai:videoEbookRewrite" | "ai:vibeLearningImageDescription" | "ai:contentMetadata" | "ai:contentInsights")[]];
1
+ export declare const PLUGIN_PERMISSIONS: readonly ["cards:read", "cards:write", "cards:delete", "articles:read", "articles:write", "articles:delete", "documents:read", "documents:write", "documents:delete", "whiteboards:read", "whiteboards:write", "whiteboards:delete", "projects:read", "projects:write", "projects:delete", "todos:read", "todos:write", "todos:delete", "calendar:read", "calendar:write", "calendar:delete", "notebooks:read", "materials:read", "chats:read", "flashcards:read", "flashcards:write", ...("ai:chat" | "ai:titleSummary" | "ai:webClip" | "ai:podcastGeneration" | "ai:flashcardGeneration" | "ai:aiJudgement" | "ai:transcriptionOptimization" | "ai:videoSummary" | "ai:videoEbookRewrite" | "ai:vibeLearningImageDescription" | "ai:contentMetadata" | "ai:contentInsights")[]];
2
2
  export type PluginPermission = (typeof PLUGIN_PERMISSIONS)[number];
3
3
  export declare const isPluginPermission: (value: unknown) => value is PluginPermission;
4
4
  /** granted:可直接调用;prompt:调用时会询问用户;denied:本次运行已拒绝或已被阻止 */
@@ -0,0 +1,64 @@
1
+ /**
2
+ * 插件自有数据(插件实体、记录)的查询:按声明的索引字段筛选与排序。
3
+ * 子路径 `@tau/plugins/query` 供宿主主进程复核写入的值与查询参数。
4
+ */
5
+ import type { JsonValue } from "./json";
6
+ /** 索引字段的类型 */
7
+ export type PluginIndexType = "string" | "number" | "boolean";
8
+ /** 字段名 → 类型;字段取自 meta(实体)或 data(记录)的顶层键 */
9
+ export type PluginIndexes = Record<string, PluginIndexType>;
10
+ export type PluginIndexValue = string | number | boolean;
11
+ /**
12
+ * 一个字段的条件。直接给值表示等于,`null` 表示没有值(缺失或为 null);
13
+ * 同一对象里的多个运算符同时成立。类型与声明不符的值按没有值处理。
14
+ */
15
+ export type PluginFieldCondition = PluginIndexValue | null | {
16
+ eq?: PluginIndexValue | null;
17
+ /** 不等于;没有值的也算不等于 */
18
+ ne?: PluginIndexValue | null;
19
+ /** 等于其中之一,可以包含 null */
20
+ in?: (PluginIndexValue | null)[];
21
+ gt?: string | number;
22
+ gte?: string | number;
23
+ lt?: string | number;
24
+ lte?: string | number;
25
+ };
26
+ export type PluginWhere = Record<string, PluginFieldCondition>;
27
+ export interface PluginOrderBy {
28
+ field: string;
29
+ /** 默认 asc;升序时没有值的排在最前,降序时排在最后 */
30
+ direction?: "asc" | "desc";
31
+ }
32
+ export type PluginQueryOperator = "eq" | "ne" | "in" | "gt" | "gte" | "lt" | "lte";
33
+ /** 校验后的条件:字段已声明,值与类型一致 */
34
+ export interface PluginQueryCondition {
35
+ field: string;
36
+ type: PluginIndexType;
37
+ op: PluginQueryOperator;
38
+ value: PluginIndexValue | null | (PluginIndexValue | null)[];
39
+ }
40
+ /** 校验后的排序;builtin 为宿主自带的列(如创建时间),否则为索引字段 */
41
+ export type PluginQueryOrder = {
42
+ builtin: string;
43
+ direction: "asc" | "desc";
44
+ } | {
45
+ field: string;
46
+ type: PluginIndexType;
47
+ direction: "asc" | "desc";
48
+ };
49
+ export declare const QUERY_LIMITS: {
50
+ readonly indexes: 16;
51
+ readonly conditions: 16;
52
+ readonly inValues: 100;
53
+ readonly orderBy: 2;
54
+ readonly textValue: 1000;
55
+ };
56
+ export declare const isIndexFieldName: (value: unknown) => value is string;
57
+ /** 校验索引声明;reserved 为宿主自带的排序列名,不能用作索引字段 */
58
+ export declare function readIndexes(value: unknown, reserved?: readonly string[]): PluginIndexes;
59
+ /** 校验筛选条件,字段必须已在 indexes 中声明 */
60
+ export declare function readWhere(value: unknown, indexes: PluginIndexes): PluginQueryCondition[];
61
+ /** 校验排序;builtins 为宿主自带的可排序列 */
62
+ export declare function readOrderBy(value: unknown, indexes: PluginIndexes, builtins: readonly string[]): PluginQueryOrder[];
63
+ /** 写入前核对:已声明为索引的字段,值必须是声明的类型或 null */
64
+ export declare function assertIndexedValues(values: Record<string, JsonValue | undefined>, indexes: PluginIndexes): void;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * 插件记录:插件内部使用的结构化数据(如分组、操作轨迹),用户看不到、不进搜索。
3
+ * 随笔记库保存与同步;读写自己的记录不需要业务数据权限。用户能看见、能打开的内容用 context.entities。
4
+ */
5
+ import type { Disposable } from "./contract";
6
+ import type { PluginPage, PluginWriteOptions } from "./data";
7
+ import type { JsonValue } from "./json";
8
+ import type { PluginIndexes, PluginOrderBy, PluginWhere } from "./query";
9
+ export type PluginRecordData = Record<string, JsonValue>;
10
+ export interface PluginRecord {
11
+ /** 宿主生成的不透明 ID */
12
+ id: string;
13
+ collection: string;
14
+ data: PluginRecordData;
15
+ createdAt: number;
16
+ updatedAt: number;
17
+ /** update 与 delete 时作为 expectedRevision */
18
+ revision: string;
19
+ }
20
+ export interface PluginRecordCollection {
21
+ /** 插件内唯一的集合名 */
22
+ name: string;
23
+ /** 可用于 query 筛选与排序的 data 字段及类型,最多 16 个 */
24
+ indexes?: PluginIndexes;
25
+ }
26
+ /** 记录自带的排序列;其余排序字段取集合声明的 indexes */
27
+ export type PluginRecordSortField = "createdAt" | "updatedAt";
28
+ export interface PluginRecordFilter {
29
+ where?: PluginWhere;
30
+ }
31
+ export interface PluginRecordQuery extends PluginRecordFilter {
32
+ /** 最多两项,ID 兜底;默认按创建时间升序 */
33
+ orderBy?: PluginOrderBy | PluginOrderBy[];
34
+ /** 原样传回上一页的 cursor;换了筛选或排序后不能再用 */
35
+ cursor?: string;
36
+ /** 默认 50,最多 200 */
37
+ limit?: number;
38
+ }
39
+ export interface PluginRecords {
40
+ /** 声明一个集合;读写只接受已声明的集合。在 activate 中声明,停用时自动撤销 */
41
+ registerCollection(definition: PluginRecordCollection): Disposable;
42
+ insert(collection: string, data: PluginRecordData): Promise<PluginRecord>;
43
+ get(collection: string, id: string): Promise<PluginRecord | null>;
44
+ query(collection: string, query?: PluginRecordQuery): Promise<PluginPage<PluginRecord>>;
45
+ count(collection: string, filter?: PluginRecordFilter): Promise<number>;
46
+ /** 整体替换 data;revision 不是最新时抛出 PluginConflictError */
47
+ update(collection: string, id: string, data: PluginRecordData, options: PluginWriteOptions): Promise<PluginRecord>;
48
+ /** 直接删除,不进「最近删除」;revision 不是最新时抛出 PluginConflictError */
49
+ delete(collection: string, id: string, options: PluginWriteOptions): Promise<void>;
50
+ }