@xiongtao.xt/tau-plugins 0.33.0 → 0.35.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 (38) hide show
  1. package/CHANGELOG.md +50 -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 +395 -72
  10. package/package.js +1 -1
  11. package/package.json +1 -1
  12. package/publish-artifacts.js +29 -2
  13. package/publish-client.js +2 -2
  14. package/types/packages/editor/src/core/api/extension.d.ts +3 -0
  15. package/types/packages/editor/src/core/api/index.d.ts +1 -0
  16. package/types/packages/editor/src/core/api/inputRules.d.ts +37 -0
  17. package/types/packages/plugins/src/actions.d.ts +61 -0
  18. package/types/packages/plugins/src/app.d.ts +106 -8
  19. package/types/packages/plugins/src/components.d.ts +22 -0
  20. package/types/packages/plugins/src/content-input.d.ts +45 -0
  21. package/types/packages/plugins/src/contract.d.ts +18 -0
  22. package/types/packages/plugins/src/data.d.ts +179 -11
  23. package/types/packages/plugins/src/editor-fields.d.ts +10 -0
  24. package/types/packages/plugins/src/editor.d.ts +2 -1
  25. package/types/packages/plugins/src/entities.d.ts +28 -3
  26. package/types/packages/plugins/src/events.d.ts +9 -3
  27. package/types/packages/plugins/src/excerpts.d.ts +1 -1
  28. package/types/packages/plugins/src/home.d.ts +20 -0
  29. package/types/packages/plugins/src/index.d.ts +17 -5
  30. package/types/packages/plugins/src/links.d.ts +39 -0
  31. package/types/packages/plugins/src/pages.d.ts +12 -0
  32. package/types/packages/plugins/src/permissions.d.ts +1 -1
  33. package/types/packages/plugins/src/publish-data.d.ts +6 -62
  34. package/types/packages/plugins/src/query.d.ts +64 -0
  35. package/types/packages/plugins/src/records.d.ts +50 -0
  36. package/types/packages/plugins/src/sidebar.d.ts +63 -1
  37. package/types/packages/plugins/src/transaction.d.ts +40 -0
  38. package/types/packages/plugins/src/views.d.ts +26 -0
@@ -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
+ }
@@ -30,7 +30,69 @@ export interface PluginSidebarItemDefinition {
30
30
  page: PluginPageHandle;
31
31
  params?: PluginPageParams;
32
32
  }
33
+ /** 子项色点,与宿主待办项目、分组同一套色板 */
34
+ export type PluginSidebarTone = "rose" | "orange" | "yellow" | "green" | "blue" | "purple" | "gray";
35
+ export interface PluginSidebarMenuEntry {
36
+ title: string;
37
+ /** 危险操作(如删除)显示为红色,并与前面的条目隔开 */
38
+ danger?: boolean;
39
+ run(): unknown;
40
+ }
41
+ export interface PluginSidebarChild {
42
+ /** 在同一条目内唯一 */
43
+ id: string;
44
+ title: string;
45
+ /** 点击后以这组参数打开条目的页面;当前页参数包含这组参数时,子项显示为选中 */
46
+ params: PluginPageParams;
47
+ tone?: PluginSidebarTone;
48
+ /** 子项右侧的计数,0 不显示 */
49
+ count?: number;
50
+ /** 右键菜单 */
51
+ menu?: readonly PluginSidebarMenuEntry[];
52
+ /** 接收拖放:type 为 dragType 的参数,run 收到拖拽数据 */
53
+ onDrop?: {
54
+ type: string;
55
+ run(data: string): unknown;
56
+ };
57
+ }
58
+ /** 子项列表末尾的动作行(如「新建分组」) */
59
+ export interface PluginSidebarAction {
60
+ title: string;
61
+ /** 缺省为加号 */
62
+ icon?: PluginSidebarIcon;
63
+ run(): unknown;
64
+ }
65
+ /** 只改传入的字段;badge 为 null 或 0 时隐藏,action 为 null 时移除 */
66
+ export interface PluginSidebarItemUpdate {
67
+ badge?: number | null;
68
+ children?: readonly PluginSidebarChild[];
69
+ action?: PluginSidebarAction | null;
70
+ }
71
+ export interface PluginSidebarItemHandle extends Disposable {
72
+ update(patch: PluginSidebarItemUpdate): void;
73
+ }
33
74
  export interface PluginSidebar {
34
75
  registerGroup(definition: PluginSidebarGroupDefinition): PluginSidebarGroupHandle;
35
- registerItem(definition: PluginSidebarItemDefinition): Disposable;
76
+ /** 条目所在页面在栈顶且侧栏展开时,子项与动作行展开在条目下方 */
77
+ registerItem(definition: PluginSidebarItemDefinition): PluginSidebarItemHandle;
78
+ /**
79
+ * 拖拽类型:插件页面拖起数据时用 dataTransfer.setData(dragType(type), data),
80
+ * 子项 onDrop 声明同一个 type 才能接收;宿主和其他插件的拖拽不会落到插件子项上。
81
+ */
82
+ dragType(type: string): string;
83
+ }
84
+ /** 侧栏条目的展示状态,宿主据此渲染;回调已由宿主包装 */
85
+ export interface PluginSidebarItemState {
86
+ badge: number;
87
+ children: readonly PluginSidebarChild[];
88
+ action: PluginSidebarAction | null;
36
89
  }
90
+ export declare function sidebarDragType(pluginId: string, type: string): string;
91
+ /**
92
+ * 校验并冻结一次 update 的结果;wrap 包装插件回调(宿主在里面核对插件仍处于启用状态),
93
+ * 拖拽类型由 dragType 加上插件命名空间。
94
+ */
95
+ export declare function snapshotSidebarUpdate(previous: PluginSidebarItemState, patch: PluginSidebarItemUpdate, options: {
96
+ wrap: <A extends unknown[]>(run: (...args: A) => unknown) => (...args: A) => unknown;
97
+ dragType: (type: string) => string;
98
+ }): PluginSidebarItemState;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * 原子提交:回调里对本插件内容、记录与关联的写入先由宿主记下,回调结束后一次提交,
3
+ * 任何一条失败(revision 不符、目标不可关联等)全部不生效。
4
+ */
5
+ import type { PluginEntityRef } from "./app";
6
+ import type { PluginOwnEntityInput, PluginOwnEntityPatch } from "./entities";
7
+ import type { PluginLinkOptions } from "./links";
8
+ import type { PluginRecordData } from "./records";
9
+ /** 事务里的修改与删除可以不带 revision:带了就核对,不带即不论当前版本直接写入 */
10
+ export interface PluginTransactionWriteOptions {
11
+ expectedRevision?: string;
12
+ }
13
+ export interface PluginTransaction {
14
+ readonly entities: {
15
+ /** 立即返回新内容的 ID,同一事务里可以用它添加关联、写记录;提交失败时这个 ID 作废 */
16
+ create(input: PluginOwnEntityInput): Promise<{
17
+ id: string;
18
+ }>;
19
+ update(id: string, patch: PluginOwnEntityPatch, options?: PluginTransactionWriteOptions): Promise<void>;
20
+ delete(id: string, options?: PluginTransactionWriteOptions): Promise<void>;
21
+ };
22
+ readonly records: {
23
+ insert(collection: string, data: PluginRecordData): Promise<{
24
+ id: string;
25
+ }>;
26
+ update(collection: string, id: string, data: PluginRecordData, options?: PluginTransactionWriteOptions): Promise<void>;
27
+ delete(collection: string, id: string, options?: PluginTransactionWriteOptions): Promise<void>;
28
+ };
29
+ readonly links: {
30
+ /** 已经关联过时什么也不做;需要关联的 ID 时在提交后 list */
31
+ add(from: string, to: PluginEntityRef, options?: PluginLinkOptions): Promise<void>;
32
+ remove(id: string): Promise<void>;
33
+ reorder(from: string, ids: readonly string[]): Promise<void>;
34
+ };
35
+ }
36
+ /**
37
+ * 回调里的写入在回调结束后一次提交,返回回调的结果;回调抛错或任何一条写入失败时全部不生效。
38
+ * 回调里用 context 读到的是已提交的数据,看不到本事务尚未提交的写入。最多 500 条写入。
39
+ */
40
+ export type PluginTransactionRunner = <T>(run: (tx: PluginTransaction) => T | Promise<T>) => Promise<T>;
@@ -0,0 +1,26 @@
1
+ import type { ComponentType } from "react";
2
+ import type { Disposable, PluginContext } from "./contract";
3
+ /** 详情区块可以挂在哪类对象的详情里;document 为项目文档 */
4
+ export type PluginEntityPanelKind = "card" | "article" | "document";
5
+ /** 详情区块收到的对象:只是引用,读标题、正文仍按现有权限 */
6
+ export type PluginEntityPanelTarget = {
7
+ [K in PluginEntityPanelKind]: {
8
+ kind: K;
9
+ id: string;
10
+ };
11
+ }[PluginEntityPanelKind];
12
+ export interface PluginEntityPanelProps {
13
+ readonly context: PluginContext;
14
+ readonly target: PluginEntityPanelTarget;
15
+ }
16
+ export interface PluginEntityPanelDefinition {
17
+ id: string;
18
+ kinds: readonly PluginEntityPanelKind[];
19
+ /** 渲染在详情正文上方;返回 null 时不占位。外框与标题由插件决定,宜小而轻 */
20
+ component: ComponentType<PluginEntityPanelProps>;
21
+ }
22
+ export interface PluginViews {
23
+ /** 只在主窗口的详情页出现,独立编辑窗口不显示 */
24
+ registerEntityPanel(definition: PluginEntityPanelDefinition): Disposable;
25
+ }
26
+ export declare const PLUGIN_ENTITY_PANEL_KINDS: readonly PluginEntityPanelKind[];