@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.
- package/CHANGELOG.md +44 -0
- package/client/{chunk-SVY5LBAT.js → chunk-FZTR4KOY.js} +10 -0
- package/docs/README.md +18 -17
- package/docs/editor.md +47 -1
- package/docs/excerpts.md +1 -1
- package/docs/plugin-basics.md +3 -0
- package/docs/storage-and-network.md +1 -1
- package/docs/ui.md +229 -1
- package/docs/user-data.md +388 -72
- package/package.js +1 -1
- package/package.json +1 -1
- package/publish-artifacts.js +29 -2
- package/types/packages/editor/src/core/api/extension.d.ts +3 -0
- package/types/packages/editor/src/core/api/index.d.ts +1 -0
- package/types/packages/editor/src/core/api/inputRules.d.ts +37 -0
- package/types/packages/plugins/src/actions.d.ts +61 -0
- package/types/packages/plugins/src/app.d.ts +106 -8
- package/types/packages/plugins/src/components.d.ts +22 -0
- package/types/packages/plugins/src/content-input.d.ts +34 -0
- package/types/packages/plugins/src/contract.d.ts +18 -0
- package/types/packages/plugins/src/data.d.ts +179 -11
- package/types/packages/plugins/src/editor-fields.d.ts +10 -0
- package/types/packages/plugins/src/editor.d.ts +2 -1
- package/types/packages/plugins/src/entities.d.ts +28 -3
- package/types/packages/plugins/src/events.d.ts +9 -3
- package/types/packages/plugins/src/excerpts.d.ts +1 -1
- package/types/packages/plugins/src/home.d.ts +20 -0
- package/types/packages/plugins/src/index.d.ts +17 -5
- package/types/packages/plugins/src/links.d.ts +39 -0
- package/types/packages/plugins/src/pages.d.ts +12 -0
- package/types/packages/plugins/src/permissions.d.ts +1 -1
- package/types/packages/plugins/src/query.d.ts +64 -0
- package/types/packages/plugins/src/records.d.ts +50 -0
- package/types/packages/plugins/src/sidebar.d.ts +63 -1
- package/types/packages/plugins/src/transaction.d.ts +40 -0
- package/types/packages/plugins/src/views.d.ts +26 -0
package/package.json
CHANGED
package/publish-artifacts.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PLUGIN_SHARED_MODULES,
|
|
3
3
|
validatePluginManifest
|
|
4
|
-
} from "./client/chunk-
|
|
4
|
+
} from "./client/chunk-FZTR4KOY.js";
|
|
5
5
|
|
|
6
6
|
// packages/db-schema/content-resources.ts
|
|
7
7
|
var CONTENT_RESOURCE_KINDS = [
|
|
@@ -33,6 +33,33 @@ function assertContentResourceSpecs(value) {
|
|
|
33
33
|
throw new Error("\u8D44\u6E90\u58F0\u660E\u65E0\u6548");
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
// packages/plugins/src/editor-fields.ts
|
|
37
|
+
var OPEN_EXTENSION_FIELDS = [
|
|
38
|
+
"id",
|
|
39
|
+
"apiVersion",
|
|
40
|
+
"elements",
|
|
41
|
+
"commands",
|
|
42
|
+
"hotkeys",
|
|
43
|
+
"menu",
|
|
44
|
+
"blockPanel",
|
|
45
|
+
"behaviorsFor"
|
|
46
|
+
];
|
|
47
|
+
var PLUGIN_EXTENSION_FIELDS = /* @__PURE__ */ new Set([
|
|
48
|
+
...OPEN_EXTENSION_FIELDS,
|
|
49
|
+
"styleSources",
|
|
50
|
+
"htmlSerializers"
|
|
51
|
+
]);
|
|
52
|
+
function assertPluginEditorExtension(extension) {
|
|
53
|
+
if (typeof extension !== "object" || extension === null) throw new Error("\u7F16\u8F91\u5668\u6269\u5C55\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
54
|
+
const prototype = Object.getPrototypeOf(extension);
|
|
55
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
56
|
+
throw new Error("\u7F16\u8F91\u5668\u6269\u5C55\u5FC5\u987B\u662F\u666E\u901A\u5BF9\u8C61");
|
|
57
|
+
if ("plugins" in extension) throw new Error("\u7F16\u8F91\u5668\u63D2\u4EF6\u4E0D\u652F\u6301\u539F\u59CB Slate \u5305\u88C5\u5668");
|
|
58
|
+
const closed = Reflect.ownKeys(extension).filter((key) => !PLUGIN_EXTENSION_FIELDS.has(key));
|
|
59
|
+
if (closed.length)
|
|
60
|
+
throw new Error(`\u7F16\u8F91\u5668\u6269\u5C55\u542B\u672A\u5F00\u653E\u7684\u5B57\u6BB5\uFF1A${closed.map((key) => String(key)).join("\u3001")}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
36
63
|
// packages/plugins/src/rendering.ts
|
|
37
64
|
var PLUGIN_RENDER_VERSION = 1;
|
|
38
65
|
function evaluatePluginPackage(artifact, modules) {
|
|
@@ -75,7 +102,7 @@ function validatePluginDefinition(manifest, definition) {
|
|
|
75
102
|
function getPluginNodeTypes(definition) {
|
|
76
103
|
const types = [];
|
|
77
104
|
for (const extension of definition.editorExtensions ?? []) {
|
|
78
|
-
|
|
105
|
+
assertPluginEditorExtension(extension);
|
|
79
106
|
for (const element of extension.elements ?? []) {
|
|
80
107
|
if (!element.type || types.includes(element.type))
|
|
81
108
|
throw new Error(`\u63D2\u4EF6\u8282\u70B9\u7C7B\u578B\u4E3A\u7A7A\u6216\u91CD\u590D\uFF1A${element.type}`);
|
|
@@ -9,6 +9,7 @@ import type { ElementDrag } from "./drag";
|
|
|
9
9
|
import type { ElementIngestSpec } from "./ingest";
|
|
10
10
|
import type { ElementCopy } from "./copy";
|
|
11
11
|
import type { DecorationSpec, MarkSpec } from "./marks";
|
|
12
|
+
import type { InputRule } from "./inputRules";
|
|
12
13
|
import type { ContentResourceSpec } from "../../../../db-schema/content-resources";
|
|
13
14
|
/**
|
|
14
15
|
* 扩展 API v2(01 §5.1):声明式描述「这个扩展贡献了什么」,内核负责装配、隔离与分发。
|
|
@@ -79,6 +80,8 @@ export interface EditorExtension {
|
|
|
79
80
|
readonly apiVersion: typeof EXTENSION_API_VERSION;
|
|
80
81
|
readonly elements?: readonly ElementSpec[];
|
|
81
82
|
readonly marks?: readonly MarkSpec[];
|
|
83
|
+
/** 行内输入规则:输入成对定界符时转成标记或行内元素,如 `**粗体**`、`$公式$` */
|
|
84
|
+
readonly inputRules?: readonly InputRule[];
|
|
82
85
|
/** 暂态装饰(不进文档);外观由本扩展 marks 里 keys 对应的声明渲染 */
|
|
83
86
|
readonly decorations?: readonly DecorationSpec[];
|
|
84
87
|
/** 在编辑器的 Slate/Kit 上下文挂载辅助 UI,组件自行接宿主浮层仲裁。 */
|
|
@@ -8,6 +8,7 @@ export { EXTENSION_API_VERSION, defineExtension, defineElement, type EditorExten
|
|
|
8
8
|
export type { AnyExtension } from "./legacy";
|
|
9
9
|
export type { CopyDecision, CopyContext, ElementCopy } from "./copy";
|
|
10
10
|
export type { MarkSpec, MarkRenderProps, DecorationSpec } from "./marks";
|
|
11
|
+
export type { InputRule, MarkInputRule, InlineInputRule } from "./inputRules";
|
|
11
12
|
export { useToolbarState } from "./toolbar";
|
|
12
13
|
export { default as ToolbarSubmenu } from "../components/HoveringToolbar/FloatingSubmenu";
|
|
13
14
|
export { Tooltip as EditorTooltip } from "../ui/Tooltip";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 行内输入规则:输入成对定界符的收尾字符时,把两段定界符之间的文字转成标记(`**粗体**`)
|
|
3
|
+
* 或行内元素(`$公式$`)。只在键入(含输入法上屏)时触发,粘贴不触发;转换单独成一个撤销步,
|
|
4
|
+
* 撤销回到原始符号。
|
|
5
|
+
*/
|
|
6
|
+
interface InputRuleBase {
|
|
7
|
+
/** 全局唯一,冲突在 kit 创建时报错 */
|
|
8
|
+
id: string;
|
|
9
|
+
/** 由同一字符重复组成的定界符,如 `**`、`~~`;末字符即触发字符 */
|
|
10
|
+
delimiter: string;
|
|
11
|
+
/** 定界符外侧不能紧邻字母或数字(`_` 写法,避免把 snake_case 当成斜体) */
|
|
12
|
+
wordBoundary?: boolean;
|
|
13
|
+
/** 光标所在文本已带这些标记时不触发(如行内代码里的原样文本) */
|
|
14
|
+
excludeMarks?: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
export interface MarkInputRule extends InputRuleBase {
|
|
17
|
+
/** 匹配后给定界符之间的文字加的标记字段,必须由已安装扩展的 marks 声明 */
|
|
18
|
+
marks: Readonly<Record<string, unknown>>;
|
|
19
|
+
inline?: never;
|
|
20
|
+
}
|
|
21
|
+
export interface InlineInputRule extends InputRuleBase {
|
|
22
|
+
/**
|
|
23
|
+
* 匹配后把定界符连同其间文字替换成行内元素;`type` 必须是已安装扩展声明的 inline 元素,
|
|
24
|
+
* `create` 由定界符之间的文字给出元素的其余字段(children 由内核补空文本)。
|
|
25
|
+
*/
|
|
26
|
+
inline: {
|
|
27
|
+
type: string;
|
|
28
|
+
create(text: string): Readonly<Record<string, unknown>>;
|
|
29
|
+
};
|
|
30
|
+
marks?: never;
|
|
31
|
+
}
|
|
32
|
+
export type InputRule = MarkInputRule | InlineInputRule;
|
|
33
|
+
export interface RegisteredInputRule {
|
|
34
|
+
readonly owner: string;
|
|
35
|
+
readonly rule: InputRule;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Disposable } from "./contract";
|
|
2
|
+
import type { PluginIcon } from "./icons";
|
|
3
|
+
/**
|
|
4
|
+
* 对象动作可以挂在哪类对象上:document 为项目文档;material 为划线、PDF 标注与剪藏;
|
|
5
|
+
* chat-message 为对话里的一条消息;text 为用户在命令面板里输入的文字。
|
|
6
|
+
*/
|
|
7
|
+
export type PluginActionTargetKind = "card" | "article" | "document" | "material" | "chat-message" | "text";
|
|
8
|
+
type PluginActionEntityKind = "card" | "article" | "document" | "material";
|
|
9
|
+
/** 卡片、文章、项目文档、材料:与 PluginEntityRef 相同 */
|
|
10
|
+
export type PluginActionEntityTarget = {
|
|
11
|
+
[K in PluginActionEntityKind]: {
|
|
12
|
+
kind: K;
|
|
13
|
+
id: string;
|
|
14
|
+
};
|
|
15
|
+
}[PluginActionEntityKind];
|
|
16
|
+
/**
|
|
17
|
+
* 对话里的一条消息。text 是消息正文(用户亲手交给插件,不需要权限);
|
|
18
|
+
* session 之后与 pick 选中的一样,可以显示与关联;messageIds 是这条消息在会话里的记录 ID,
|
|
19
|
+
* 一条 AI 回答可能由多条记录组成。
|
|
20
|
+
*/
|
|
21
|
+
export interface PluginChatMessageTarget {
|
|
22
|
+
kind: "chat-message";
|
|
23
|
+
session: {
|
|
24
|
+
kind: "chat-session";
|
|
25
|
+
id: string;
|
|
26
|
+
};
|
|
27
|
+
messageIds: readonly string[];
|
|
28
|
+
role: "user" | "assistant";
|
|
29
|
+
text: string;
|
|
30
|
+
}
|
|
31
|
+
/** 用户在命令面板里输入的文字(亲手交给插件,不需要权限) */
|
|
32
|
+
export interface PluginTextTarget {
|
|
33
|
+
kind: "text";
|
|
34
|
+
text: string;
|
|
35
|
+
}
|
|
36
|
+
export type PluginActionTarget = PluginActionEntityTarget | PluginChatMessageTarget | PluginTextTarget;
|
|
37
|
+
/** 某几类目标对应的对象:run 的参数随 targets 收窄 */
|
|
38
|
+
export type PluginActionTargetOf<K extends PluginActionTargetKind> = Extract<PluginActionTarget, {
|
|
39
|
+
kind: K;
|
|
40
|
+
}>;
|
|
41
|
+
export interface PluginActionDefinition<K extends PluginActionTargetKind = PluginActionTargetKind> {
|
|
42
|
+
id: string;
|
|
43
|
+
/** 菜单里显示的名称 */
|
|
44
|
+
title: string;
|
|
45
|
+
/** 缺省使用插件图标 */
|
|
46
|
+
icon?: PluginIcon;
|
|
47
|
+
targets: readonly K[];
|
|
48
|
+
/**
|
|
49
|
+
* 用户在对象的「⋯」菜单里点击时调用。这个对象(对话消息为所在会话)之后与 pick 选中的一样,
|
|
50
|
+
* 不需要读取权限就能读标题、显示与关联;读正文仍按权限。
|
|
51
|
+
*/
|
|
52
|
+
run(target: PluginActionTargetOf<K>): unknown;
|
|
53
|
+
}
|
|
54
|
+
export interface PluginActions {
|
|
55
|
+
/** 只在主窗口出现,独立编辑窗口不列插件动作 */
|
|
56
|
+
register<K extends PluginActionTargetKind>(definition: PluginActionDefinition<K>): Disposable;
|
|
57
|
+
}
|
|
58
|
+
export declare const PLUGIN_ACTION_TARGET_KINDS: readonly PluginActionTargetKind[];
|
|
59
|
+
/** 交给插件前复制并冻结,插件拿不到宿主对象上的其他字段 */
|
|
60
|
+
export declare function snapshotActionTarget(target: PluginActionTarget): PluginActionTarget;
|
|
61
|
+
export {};
|
|
@@ -1,19 +1,46 @@
|
|
|
1
|
+
import type { PluginContentInput } from "./content-input";
|
|
1
2
|
import type { PluginContentRef } from "./data";
|
|
2
3
|
/**
|
|
3
4
|
* 关联与打开已有内容:插件页面(如自建画布)引用用户的卡片、日记、待办等,并在点击时打开。
|
|
4
|
-
* 引用可以序列化后存入插件自己的数据;id
|
|
5
|
+
* 引用可以序列化后存入插件自己的数据;id 对插件不透明,与 context.data 中同类实体的 id 一致。
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
+
import type { PluginPermission } from "./permissions";
|
|
8
|
+
export type PluginEntityKind = "card" | "article" | "document" | "diary" | "whiteboard" | "todo" | "event" | "project" | "notebook"
|
|
9
|
+
/** 外部材料:划线、PDF 标注与剪藏 */
|
|
10
|
+
| "material" | "chat-session"
|
|
11
|
+
/** 插件自建的内容,包括其他插件的 */
|
|
12
|
+
| "plugin-entity";
|
|
7
13
|
export declare const PLUGIN_ENTITY_KINDS: readonly PluginEntityKind[];
|
|
14
|
+
/**
|
|
15
|
+
* 不经选择时,读取一类引用的标题所需的权限;null 表示只能经用户选择获得。
|
|
16
|
+
* 插件读取自己创建的插件内容不需要权限。
|
|
17
|
+
*/
|
|
18
|
+
export declare const PLUGIN_ENTITY_READ_PERMISSIONS: Readonly<Record<PluginEntityKind, PluginPermission | null>>;
|
|
8
19
|
export interface PluginEntityRef {
|
|
9
20
|
kind: PluginEntityKind;
|
|
10
21
|
id: string;
|
|
11
22
|
}
|
|
12
|
-
/**
|
|
23
|
+
/** 用户选中的一项:标题是选择时的快照;之后可用 describe 取最新标题,不需要读取权限 */
|
|
13
24
|
export interface PluginPickedEntity {
|
|
14
25
|
ref: PluginEntityRef;
|
|
15
26
|
title: string;
|
|
16
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* 一项引用的当前状态。ok:title 为最新标题;missing:内容已删除;denied:用户没有选择过这项,
|
|
30
|
+
* 也没有授予 permission(为 null 时这类内容只能经用户选择获得)。
|
|
31
|
+
*/
|
|
32
|
+
export type PluginEntityDescription = {
|
|
33
|
+
ref: PluginEntityRef;
|
|
34
|
+
status: "ok";
|
|
35
|
+
title: string;
|
|
36
|
+
} | {
|
|
37
|
+
ref: PluginEntityRef;
|
|
38
|
+
status: "missing";
|
|
39
|
+
} | {
|
|
40
|
+
ref: PluginEntityRef;
|
|
41
|
+
status: "denied";
|
|
42
|
+
permission: PluginPermission | null;
|
|
43
|
+
};
|
|
17
44
|
export interface PluginPickOptions {
|
|
18
45
|
/** 可选类型,顺序即弹窗中的分组顺序 */
|
|
19
46
|
kinds: readonly PluginEntityKind[];
|
|
@@ -24,7 +51,10 @@ export interface PluginPickOptions {
|
|
|
24
51
|
}
|
|
25
52
|
export type PluginExportFormat = "markdown" | "image" | "pdf" | "epub";
|
|
26
53
|
export declare const PLUGIN_EXPORT_FORMATS: readonly PluginExportFormat[];
|
|
27
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* 宿主动作:界面与确认都由 Tau 提供,插件拿不到正文。content.* 支持卡片、文章、项目文档与
|
|
56
|
+
* 插件内容的正文。
|
|
57
|
+
*/
|
|
28
58
|
export interface PluginAppActions {
|
|
29
59
|
/** Markdown 直接保存文件;图片、PDF、EPUB 打开导出窗口 */
|
|
30
60
|
"content.export": {
|
|
@@ -39,6 +69,63 @@ export interface PluginAppActions {
|
|
|
39
69
|
"content.share": {
|
|
40
70
|
ref: PluginContentRef;
|
|
41
71
|
};
|
|
72
|
+
/** 打开 Tau 的新建卡片窗口并预填,用户可以修改后保存 */
|
|
73
|
+
"card.create": {
|
|
74
|
+
content?: PluginContentInput;
|
|
75
|
+
tags?: string[];
|
|
76
|
+
};
|
|
77
|
+
/** 打开「插入到项目」窗口,由用户选择项目与位置,复制这份正文为新的项目文档 */
|
|
78
|
+
"project.insertDocument": {
|
|
79
|
+
content: PluginContentInput;
|
|
80
|
+
title?: string;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* 确认后新建 Notebook,sources 作为资料一次性带入(之后不同步):有正文的内容成为笔记资料,
|
|
84
|
+
* 划线与 PDF 标注合并为一份、剪藏各一份,其他类型不带入。from 记为 Notebook 的来源,
|
|
85
|
+
* 显示在 Notebook 页顶部,见 PLUGIN_NOTEBOOK_FROM_KINDS。
|
|
86
|
+
*/
|
|
87
|
+
"notebook.create": {
|
|
88
|
+
title: string;
|
|
89
|
+
sources?: PluginEntityRef[];
|
|
90
|
+
from?: PluginEntityRef;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* 在对话页(page,默认)或右侧停靠栏(dock)开一个新对话:prompt 预填进输入框,context 作为
|
|
94
|
+
* 引用插入,由用户修改后发送。context 只支持 PLUGIN_CHAT_CONTEXT_KINDS 中的类型。
|
|
95
|
+
*/
|
|
96
|
+
"chat.start": {
|
|
97
|
+
prompt?: string;
|
|
98
|
+
context?: PluginEntityRef[];
|
|
99
|
+
placement?: "page" | "dock";
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** 正文中的位置:第几个顶层块(从 0 开始,与 content.read 的 nodes 顺序一致),越界时落到开头 */
|
|
103
|
+
export interface PluginContentLocation {
|
|
104
|
+
block: number;
|
|
105
|
+
}
|
|
106
|
+
export interface PluginOpenOptions {
|
|
107
|
+
/**
|
|
108
|
+
* page(默认):主窗口的页面;window:独立编辑窗口,只支持卡片、文章与项目文档,不能同时定位;
|
|
109
|
+
* dock:右侧停靠栏,只支持主对话。
|
|
110
|
+
*/
|
|
111
|
+
placement?: "page" | "window" | "dock";
|
|
112
|
+
/** 打开后滚动并闪烁到的位置;只支持卡片、文章、项目文档、日记与插件内容 */
|
|
113
|
+
at?: PluginContentLocation;
|
|
114
|
+
}
|
|
115
|
+
/** 可以作为对话上下文(chat.start 的 context)的类型 */
|
|
116
|
+
export declare const PLUGIN_CHAT_CONTEXT_KINDS: readonly PluginEntityKind[];
|
|
117
|
+
/** 可以作为 Notebook 来源(notebook.create 的 from)的类型 */
|
|
118
|
+
export declare const PLUGIN_NOTEBOOK_FROM_KINDS: readonly PluginEntityKind[];
|
|
119
|
+
/** 各动作的结果:新建类返回新内容的引用,用户取消时为 null */
|
|
120
|
+
export interface PluginAppActionResults {
|
|
121
|
+
"content.export": void;
|
|
122
|
+
"content.present": void;
|
|
123
|
+
"content.share": void;
|
|
124
|
+
"card.create": PluginEntityRef | null;
|
|
125
|
+
"project.insertDocument": PluginEntityRef | null;
|
|
126
|
+
"notebook.create": PluginEntityRef | null;
|
|
127
|
+
/** 用户发出第一条消息后返回对话的引用;没发送就关闭、切到别的对话或插件停用时为 null */
|
|
128
|
+
"chat.start": PluginEntityRef | null;
|
|
42
129
|
}
|
|
43
130
|
export type PluginAppAction = keyof PluginAppActions;
|
|
44
131
|
export declare const PLUGIN_APP_ACTIONS: readonly PluginAppAction[];
|
|
@@ -48,8 +135,19 @@ export interface PluginApp {
|
|
|
48
135
|
* 用户亲手挑选即视为同意插件引用这些内容,不需要读取权限。只能在用户操作(点击、按键)后调用。
|
|
49
136
|
*/
|
|
50
137
|
pick(options: PluginPickOptions): Promise<PluginPickedEntity[]>;
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
138
|
+
/**
|
|
139
|
+
* 打开对应的页面:卡片详情、日记当天、待办详情、日程详情等。只能在用户操作后调用;内容已删除时抛错。
|
|
140
|
+
* 打开位置与定位见 PluginOpenOptions,不支持的组合抛错。
|
|
141
|
+
*/
|
|
142
|
+
open(ref: PluginEntityRef, options?: PluginOpenOptions): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* 批量取引用的当前标题与是否已删除,结果与 refs 一一对应,每次最多 200 项。用户选择过的内容、
|
|
145
|
+
* 本插件自己的内容不需要权限;其余需要该类的读取权限,未获准时为 denied,不弹窗询问。
|
|
146
|
+
*/
|
|
147
|
+
describe(refs: readonly PluginEntityRef[]): Promise<PluginEntityDescription[]>;
|
|
148
|
+
/**
|
|
149
|
+
* 执行宿主动作,用户关闭对应界面后返回结果,见 PluginAppActionResults。只能在用户操作后调用,
|
|
150
|
+
* 同一时间只能打开一个;不需要数据权限,用户在界面中确认即同意。内容已删除时抛错。
|
|
151
|
+
*/
|
|
152
|
+
run<A extends PluginAppAction>(action: A, options: PluginAppActions[A]): Promise<PluginAppActionResults[A]>;
|
|
55
153
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { ReactElement } from "react";
|
|
2
2
|
import type { PluginContentRef } from "./data";
|
|
3
|
+
import type { PluginEntityRef } from "./app";
|
|
4
|
+
/**
|
|
5
|
+
* 编辑器套件。full(默认):与卡片详情相同的完整套件。compact:精简套件,与白板图形文字、
|
|
6
|
+
* PDF 批注等简短内容的编辑器相同,不含内容链接、文件附件、白板块、数据库块与文档待办;
|
|
7
|
+
* 正文里已有的这些块显示为占位,数据原样保留。编辑与预览同一份内容时应使用同一套件。
|
|
8
|
+
*/
|
|
9
|
+
export type ContentEditorKit = "full" | "compact";
|
|
3
10
|
/**
|
|
4
11
|
* 与卡片详情相同的正文编辑器:协作、内置与已安装的编辑器扩展、文档待办都由宿主提供。
|
|
5
12
|
* 可编辑需要所属实体的写入权限,只读需要读取权限;未授权时显示「允许访问」,由用户点击后询问。
|
|
@@ -13,18 +20,33 @@ export interface ContentEditorProps {
|
|
|
13
20
|
placeholder?: string;
|
|
14
21
|
/** 打开后滚动并闪烁到的位置:从 Tau 打开插件内容时页面参数 params.at 原样传入 */
|
|
15
22
|
at?: string;
|
|
23
|
+
/** 默认 full */
|
|
24
|
+
kit?: ContentEditorKit;
|
|
16
25
|
}
|
|
17
26
|
/** 正文开头几块的只读渲染,用于列表与卡面;需要所属实体的读取权限。 */
|
|
18
27
|
export interface ContentPreviewProps {
|
|
19
28
|
contentRef: PluginContentRef;
|
|
20
29
|
/** 显示的块数,默认 3 */
|
|
21
30
|
maxBlocks?: number;
|
|
31
|
+
/** 默认 full;与编辑这份内容的 ContentEditor 保持一致 */
|
|
32
|
+
kit?: ContentEditorKit;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 一项引用的显示:图标、类型名与标题由宿主渲染,内容已删除时显示「已删除」。授权口径与
|
|
36
|
+
* context.app.describe 相同;未获准时显示类型名与「允许访问」,由用户点击后询问。
|
|
37
|
+
*/
|
|
38
|
+
export interface EntityRefProps {
|
|
39
|
+
target: PluginEntityRef;
|
|
40
|
+
/** 默认 true:点击时用 context.app.open 打开 */
|
|
41
|
+
openable?: boolean;
|
|
22
42
|
}
|
|
23
43
|
/** 宿主注入的实现;SDK 根入口只引用 React 类型,不加载 React 运行时。 */
|
|
24
44
|
export interface ContentComponentsRuntime {
|
|
25
45
|
ContentEditor(props: ContentEditorProps): ReactElement | null;
|
|
26
46
|
ContentPreview(props: ContentPreviewProps): ReactElement | null;
|
|
47
|
+
EntityRef(props: EntityRefProps): ReactElement | null;
|
|
27
48
|
}
|
|
28
49
|
export declare function configureContentComponents(value: ContentComponentsRuntime): void;
|
|
29
50
|
export declare const ContentEditor: (props: ContentEditorProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
|
|
30
51
|
export declare const ContentPreview: (props: ContentPreviewProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
|
|
52
|
+
export declare const EntityRef: (props: EntityRefProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 正文输入:新建内容与修改正文时统一使用。宿主写入前校验结构;节点类型不做白名单,
|
|
3
|
+
* 未注册的类型与编辑器对缺包节点的处理一致,原样保存。
|
|
4
|
+
*/
|
|
5
|
+
import type { Descendant } from "slate";
|
|
6
|
+
import type { PluginContentRef } from "./data";
|
|
7
|
+
/** 编辑器节点结构的版本:节点形状有不兼容变化时递增,随 nodes 格式的正文快照返回 */
|
|
8
|
+
export declare const EDITOR_NODE_SCHEMA_VERSION = 1;
|
|
9
|
+
export type PluginContentInput =
|
|
10
|
+
/** Markdown,宿主转换为节点;Markdown 表达不了的格式会丢失 */
|
|
11
|
+
{
|
|
12
|
+
markdown: string;
|
|
13
|
+
}
|
|
14
|
+
/** 编辑器节点,原样写入,与 content.read 的 nodes 格式相同 */
|
|
15
|
+
| {
|
|
16
|
+
nodes: Descendant[];
|
|
17
|
+
}
|
|
18
|
+
/** 整份复制一份已有正文:只需要目标的写入权限,插件拿不到正文 */
|
|
19
|
+
| {
|
|
20
|
+
copyOf: PluginContentRef;
|
|
21
|
+
};
|
|
22
|
+
export declare const CONTENT_INPUT_LIMITS: Readonly<{
|
|
23
|
+
markdown: 2000000;
|
|
24
|
+
/** 节点序列化为 JSON 后的字符数 */
|
|
25
|
+
nodes: 8000000;
|
|
26
|
+
/** 节点层级;每层节点占 copyJson 两层(对象与 children),与其 64 层上限对齐 */
|
|
27
|
+
depth: 30;
|
|
28
|
+
}>;
|
|
29
|
+
/** 节点结构校验:顶层为元素;元素有 type 与非空 children;文本节点有 text、没有 children。 */
|
|
30
|
+
export declare function assertContentNodes(value: unknown): asserts value is Descendant[];
|
|
31
|
+
/** 读取并复制插件传入的正文输入;allowEmpty 为 false 时拒绝空 Markdown 与空节点数组。 */
|
|
32
|
+
export declare function readContentInput(value: unknown, options: {
|
|
33
|
+
allowEmpty: boolean;
|
|
34
|
+
}): PluginContentInput;
|
|
@@ -13,6 +13,9 @@ import type { PluginImages } from "./images";
|
|
|
13
13
|
import type { PluginVideo } from "./video";
|
|
14
14
|
import type { PluginPublish } from "./publish";
|
|
15
15
|
import type { PluginSidebar } from "./sidebar";
|
|
16
|
+
import type { PluginHome } from "./home";
|
|
17
|
+
import type { PluginActions } from "./actions";
|
|
18
|
+
import type { PluginViews } from "./views";
|
|
16
19
|
import type { PluginExcerpts, PluginMaterials } from "./excerpts";
|
|
17
20
|
import type { PluginMCP } from "./mcp";
|
|
18
21
|
import type { PluginChat } from "./chat";
|
|
@@ -22,6 +25,9 @@ import type { PluginContent, PluginData } from "./data";
|
|
|
22
25
|
import type { PluginEvents } from "./events";
|
|
23
26
|
import type { PluginApp } from "./app";
|
|
24
27
|
import type { PluginOwnEntities } from "./entities";
|
|
28
|
+
import type { PluginRecords } from "./records";
|
|
29
|
+
import type { PluginLinks } from "./links";
|
|
30
|
+
import type { PluginTransactionRunner } from "./transaction";
|
|
25
31
|
import type { PluginFlashcards } from "./flashcards";
|
|
26
32
|
import type { PluginNotifications } from "./notifications";
|
|
27
33
|
import type { JsonValue } from "./json";
|
|
@@ -59,6 +65,12 @@ export interface PluginContext {
|
|
|
59
65
|
readonly video: PluginVideo;
|
|
60
66
|
readonly publish: PluginPublish;
|
|
61
67
|
readonly sidebar: PluginSidebar;
|
|
68
|
+
/** 首页面板 */
|
|
69
|
+
readonly home: PluginHome;
|
|
70
|
+
/** 对象动作:卡片、文章、项目文档「⋯」菜单里的条目 */
|
|
71
|
+
readonly actions: PluginActions;
|
|
72
|
+
/** 卡片、文章、项目文档详情里的区块 */
|
|
73
|
+
readonly views: PluginViews;
|
|
62
74
|
readonly excerpts: PluginExcerpts;
|
|
63
75
|
readonly materials: PluginMaterials;
|
|
64
76
|
readonly fetch: typeof globalThis.fetch;
|
|
@@ -78,6 +90,12 @@ export interface PluginContext {
|
|
|
78
90
|
readonly app: PluginApp;
|
|
79
91
|
/** 插件自建、各带一份正文的内容;读写自己的内容不需要业务数据权限 */
|
|
80
92
|
readonly entities: PluginOwnEntities;
|
|
93
|
+
/** 插件内部使用的结构化数据;读写自己的记录不需要业务数据权限 */
|
|
94
|
+
readonly records: PluginRecords;
|
|
95
|
+
/** 从本插件的内容指向其他内容的有序关联,显示在目标的脉络里 */
|
|
96
|
+
readonly links: PluginLinks;
|
|
97
|
+
/** 把对本插件内容、记录与关联的多条写入作为一个整体提交:全部生效或全部不生效 */
|
|
98
|
+
readonly transaction: PluginTransactionRunner;
|
|
81
99
|
readonly flashcards: PluginFlashcards;
|
|
82
100
|
readonly notifications: PluginNotifications;
|
|
83
101
|
/** 将订阅等资源交给宿主,在停用或激活失败时逆序回收。 */
|