@xiongtao.xt/tau-plugins 0.34.0 → 0.36.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 +17 -0
- package/client/chunk-D4PV3N7Q.js +183 -0
- package/docs/README.md +3 -1
- package/docs/api-support.md +68 -0
- package/docs/editor.md +1 -1
- package/docs/getting-started.md +25 -117
- package/docs/plugin-basics.md +4 -1
- package/docs/portability.md +71 -0
- package/docs/release.md +2 -0
- package/docs/storage-and-network.md +2 -0
- package/docs/ui.md +5 -1
- package/docs/user-data.md +12 -3
- package/package.json +5 -1
- package/portable.js +21 -0
- package/publish-artifacts.js +6 -2
- package/publish-client.js +2 -2
- package/types/packages/editor/src/core/api/index.d.ts +1 -0
- package/types/packages/editor/src/core/services/elementEditingPolicy.d.ts +6 -0
- package/types/packages/plugins/src/capabilities.d.ts +7 -0
- package/types/packages/plugins/src/content-input.d.ts +12 -1
- package/types/packages/plugins/src/contract.d.ts +4 -0
- package/types/packages/plugins/src/environment.d.ts +40 -0
- package/types/packages/plugins/src/index.d.ts +5 -0
- package/types/packages/plugins/src/navigation.d.ts +14 -0
- package/types/packages/plugins/src/pages.d.ts +2 -0
- package/types/packages/plugins/src/portable.d.ts +35 -0
- package/types/packages/plugins/src/publish-data.d.ts +6 -62
- package/types/packages/ui/src/UiHostProvider.d.ts +13 -0
- package/types/packages/ui/src/index.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# 更新记录
|
|
2
2
|
|
|
3
|
+
## 0.36.0
|
|
4
|
+
|
|
5
|
+
- 客户端保留未来可选能力并允许降级,未知必需能力在执行前拒绝;作者和上传仍严格检查能力词表。
|
|
6
|
+
- 模板与上传共用跨端版本及移动权限规则,移动端未支持的权限在执行前再次拒绝;新增逐 API 的宿主支持矩阵,随本地 SDK 和模板分发。
|
|
7
|
+
|
|
8
|
+
- 跨端开发插件可通过统一功能入口注册页面,并订阅布局与输入环境;注销页面会回收关联入口。
|
|
9
|
+
- 提供版本化能力词表与独立格式 3 校验,按平台检查版本、必需/可选能力和节点显示/编辑等级;旧生产校验继续拒绝该开发格式。
|
|
10
|
+
- 统一模板支持页面与编辑器示例,通过本地 SDK/UI tarball 构建;仅供受控开发接入,生产中心分发未开放。
|
|
11
|
+
|
|
12
|
+
- 页面可登记离开守卫;宿主共用节点等级投影,配合提交保护拒绝失效或只读写入。
|
|
13
|
+
|
|
14
|
+
## 0.35.0
|
|
15
|
+
|
|
16
|
+
- 插件用 `cards.create`、`articles.create`、`documents.create`、`whiteboards.create`、`projects.create` 新建的内容,之后不需要读取权限也能 `describe`、`EntityRef` 显示、`open` 与 `links.add`,与 `pick` 选择和 `app.run` 新建的结果一致。
|
|
17
|
+
- 正文输入新增 `{ shareOf: contentRef }`:与本插件的一项内容共用同一份正文,任一处的修改在另一处实时可见,删除其中一处不影响另一处。只能用于 `cards.create`、`articles.create`、`documents.create` 与 `app.run("project.insertDocument")`,来源必须是本插件内容的正文;一份正文只能有一张卡片、一篇文章,已有时报错。
|
|
18
|
+
- 发布数据不再包含求索录:数据类型 `quest` 与 `QuestData`、`QuestStatus`、`QuestAnswer`、`QuestMaterial`、`QuestTrail` 已删除,`DataKind`、`ManifestItem.collectionType`、`TimelineItem`、`ListData`、`SearchDocument` 的类型不再有 `quest`,`ListItem` 去掉了 `groupId`、`groupTitle`、`status`、`answerCount` 与 `updateTime`。博客模板不再需要问题页。
|
|
19
|
+
|
|
3
20
|
## 0.34.0
|
|
4
21
|
|
|
5
22
|
- 新增统一的正文输入 `PluginContentInput`,三选一:`{ markdown }`、`{ nodes }`(编辑器节点,格式完整保留)、`{ copyOf: contentRef }`(Tau 内部整份复制已有正文,只需要目标的写入权限)。
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertLocalId,
|
|
3
|
+
comparePluginVersions,
|
|
4
|
+
validatePluginManifest
|
|
5
|
+
} from "./chunk-FZTR4KOY.js";
|
|
6
|
+
|
|
7
|
+
// packages/plugins/src/capabilities.ts
|
|
8
|
+
var PLUGIN_CAPABILITIES = [
|
|
9
|
+
"commands.v1",
|
|
10
|
+
"storage.v1",
|
|
11
|
+
"pages.v1",
|
|
12
|
+
"navigation.v1",
|
|
13
|
+
"settings.v1",
|
|
14
|
+
"ui.dialog.v1",
|
|
15
|
+
"editor.elements.v1",
|
|
16
|
+
"editor.codecs.v1",
|
|
17
|
+
"editor.source.v1"
|
|
18
|
+
];
|
|
19
|
+
function readPluginCapabilityNames(value) {
|
|
20
|
+
if (!Array.isArray(value) || value.length > 128 || [...value].some(
|
|
21
|
+
(item) => typeof item !== "string" || item.length > 128 || !/^[a-z][a-z0-9]*(?:\.[a-z][a-z0-9-]*)*\.v[1-9][0-9]*$/.test(item)
|
|
22
|
+
) || new Set(value).size !== value.length)
|
|
23
|
+
throw new Error("\u80FD\u529B\u5217\u8868\u5305\u542B\u65E0\u6548\u540D\u79F0\u3001\u91CD\u590D\u9879\u6216\u8D85\u51FA\u6570\u91CF\u9650\u5236");
|
|
24
|
+
return Object.freeze([...value]);
|
|
25
|
+
}
|
|
26
|
+
function isPluginCapability(value) {
|
|
27
|
+
return typeof value === "string" && PLUGIN_CAPABILITIES.some((capability) => capability === value);
|
|
28
|
+
}
|
|
29
|
+
function readPluginCapabilities(value) {
|
|
30
|
+
readPluginCapabilityNames(value);
|
|
31
|
+
if (!Array.isArray(value) || value.some((item) => !isPluginCapability(item)) || new Set(value).size !== value.length)
|
|
32
|
+
throw new Error("\u80FD\u529B\u5217\u8868\u5305\u542B\u672A\u77E5\u80FD\u529B\u6216\u91CD\u590D\u9879");
|
|
33
|
+
return Object.freeze([...value]);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// packages/plugins/src/portable.ts
|
|
37
|
+
var PORTABLE_PLATFORMS = ["desktop", "android", "ios"];
|
|
38
|
+
var PORTABLE_SHARED_MODULES = [
|
|
39
|
+
"@tau/plugins",
|
|
40
|
+
"@tau/ui",
|
|
41
|
+
"react",
|
|
42
|
+
"react-dom",
|
|
43
|
+
"react-dom/client",
|
|
44
|
+
"react/jsx-runtime",
|
|
45
|
+
"react/jsx-dev-runtime"
|
|
46
|
+
];
|
|
47
|
+
function record(value, label) {
|
|
48
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)
|
|
49
|
+
throw new Error(`${label}\u5FC5\u987B\u662F\u666E\u901A\u5BF9\u8C61`);
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
function validatePortablePluginManifest(value) {
|
|
53
|
+
return parsePortablePluginManifest(value, readPluginCapabilities);
|
|
54
|
+
}
|
|
55
|
+
function readPortablePluginManifest(value) {
|
|
56
|
+
return parsePortablePluginManifest(value, readPluginCapabilityNames);
|
|
57
|
+
}
|
|
58
|
+
function validatePortableDistributionManifest(value) {
|
|
59
|
+
const manifest = validatePortablePluginManifest(value);
|
|
60
|
+
if (/[-+]/.test(manifest.version)) throw new Error("\u6B63\u5F0F\u8DE8\u7AEF\u5305\u7248\u672C\u4E0D\u80FD\u542B\u9884\u53D1\u5E03\u6216\u6784\u5EFA\u6807\u8BC6");
|
|
61
|
+
if ((manifest.targets.android || manifest.targets.ios) && manifest.permissions?.length)
|
|
62
|
+
throw new Error("\u79FB\u52A8\u7AEF\u5C1A\u672A\u63A5\u5165\u4E1A\u52A1\u6570\u636E\u6388\u6743\uFF0C\u4E0D\u80FD\u53D1\u5E03\u58F0\u660E\u8FD9\u4E9B\u6743\u9650\u7684\u79FB\u52A8\u76EE\u6807");
|
|
63
|
+
return manifest;
|
|
64
|
+
}
|
|
65
|
+
function parsePortablePluginManifest(value, readCapabilities) {
|
|
66
|
+
const item = record(value, "\u8DE8\u7AEF\u6E05\u5355");
|
|
67
|
+
const keys = /* @__PURE__ */ new Set([
|
|
68
|
+
"formatVersion",
|
|
69
|
+
"apiVersion",
|
|
70
|
+
"id",
|
|
71
|
+
"name",
|
|
72
|
+
"description",
|
|
73
|
+
"version",
|
|
74
|
+
"platform",
|
|
75
|
+
"profile",
|
|
76
|
+
"targets",
|
|
77
|
+
"format",
|
|
78
|
+
"main",
|
|
79
|
+
"styles",
|
|
80
|
+
"editor",
|
|
81
|
+
"categories",
|
|
82
|
+
"keywords",
|
|
83
|
+
"permissions",
|
|
84
|
+
"integrity"
|
|
85
|
+
]);
|
|
86
|
+
if (Object.keys(item).some((key) => !keys.has(key))) throw new Error("\u8DE8\u7AEF\u6E05\u5355\u5305\u542B\u672A\u652F\u6301\u5B57\u6BB5");
|
|
87
|
+
if (item.formatVersion !== 3 || item.platform !== "portable" || item.profile !== "web-v1")
|
|
88
|
+
throw new Error("\u8DE8\u7AEF\u5305\u683C\u5F0F\u6216\u8FD0\u884C\u914D\u7F6E\u4E0D\u517C\u5BB9");
|
|
89
|
+
const base = validatePluginManifest(
|
|
90
|
+
{ ...item, formatVersion: 1, platform: "desktop" },
|
|
91
|
+
{ strict: true }
|
|
92
|
+
);
|
|
93
|
+
const rawTargets = record(item.targets, "\u76EE\u6807\u5E73\u53F0");
|
|
94
|
+
if (!Object.keys(rawTargets).length || Object.keys(rawTargets).some((key) => !PORTABLE_PLATFORMS.some((platform) => platform === key)))
|
|
95
|
+
throw new Error("\u76EE\u6807\u5E73\u53F0\u4E3A\u7A7A\u6216\u5305\u542B\u672A\u77E5\u5E73\u53F0");
|
|
96
|
+
const targets = {};
|
|
97
|
+
for (const platform of PORTABLE_PLATFORMS) {
|
|
98
|
+
if (!Object.hasOwn(rawTargets, platform)) continue;
|
|
99
|
+
const target = record(rawTargets[platform], "\u5E73\u53F0\u914D\u7F6E");
|
|
100
|
+
if (Object.keys(target).some(
|
|
101
|
+
(key) => !["minAppVersion", "required", "optional", "elements"].includes(key)
|
|
102
|
+
))
|
|
103
|
+
throw new Error("\u5E73\u53F0\u914D\u7F6E\u5305\u542B\u672A\u77E5\u5B57\u6BB5");
|
|
104
|
+
if (typeof target.minAppVersion !== "string") throw new Error("\u5E73\u53F0\u7F3A\u5C11\u6700\u4F4E\u5BA2\u6237\u7AEF\u7248\u672C");
|
|
105
|
+
comparePluginVersions(target.minAppVersion, target.minAppVersion);
|
|
106
|
+
const required = readCapabilities(target.required);
|
|
107
|
+
const optional = readCapabilities(target.optional ?? []);
|
|
108
|
+
if (optional.some((capability) => required.includes(capability)))
|
|
109
|
+
throw new Error("\u5FC5\u9700\u4E0E\u53EF\u9009\u80FD\u529B\u4E0D\u80FD\u91CD\u53E0");
|
|
110
|
+
let elements;
|
|
111
|
+
if (target.elements !== void 0) {
|
|
112
|
+
const entries = Object.entries(record(target.elements, "\u8282\u70B9\u652F\u6301\u58F0\u660E"));
|
|
113
|
+
if (!base.editor || !entries.length || entries.length > 128)
|
|
114
|
+
throw new Error("\u8282\u70B9\u652F\u6301\u58F0\u660E\u9700\u8981\u7F16\u8F91\u5668\u8D21\u732E\u4E14\u6570\u91CF\u6709\u6548");
|
|
115
|
+
elements = /* @__PURE__ */ Object.create(null);
|
|
116
|
+
for (const [type, support] of entries) {
|
|
117
|
+
assertLocalId(type);
|
|
118
|
+
if (type === "__proto__" || !["none", "render", "edit"].includes(support))
|
|
119
|
+
throw new Error("\u8282\u70B9\u652F\u6301\u7B49\u7EA7\u65E0\u6548");
|
|
120
|
+
if (support !== "none" && !required.some((capability) => capability === "editor.elements.v1"))
|
|
121
|
+
throw new Error("\u5C55\u793A\u6216\u7F16\u8F91\u8282\u70B9\u9700\u8981\u58F0\u660E\u7F16\u8F91\u5668\u80FD\u529B");
|
|
122
|
+
elements[type] = support;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (base.editor && !elements) throw new Error("\u6BCF\u4E2A\u76EE\u6807\u5E73\u53F0\u5FC5\u987B\u660E\u786E\u58F0\u660E\u8282\u70B9\u652F\u6301\u7B49\u7EA7");
|
|
126
|
+
targets[platform] = Object.freeze({
|
|
127
|
+
minAppVersion: target.minAppVersion,
|
|
128
|
+
required,
|
|
129
|
+
optional,
|
|
130
|
+
...elements ? { elements: Object.freeze(elements) } : {}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
const files = record(item.integrity, "\u6587\u4EF6\u6458\u8981");
|
|
134
|
+
if (Object.keys(files).some((file) => file !== base.main && file !== base.styles))
|
|
135
|
+
throw new Error("\u8DE8\u7AEF\u5305\u5305\u542B\u672A\u58F0\u660E\u6587\u4EF6");
|
|
136
|
+
return Object.freeze({
|
|
137
|
+
...base,
|
|
138
|
+
formatVersion: 3,
|
|
139
|
+
platform: "portable",
|
|
140
|
+
profile: "web-v1",
|
|
141
|
+
targets: Object.freeze(targets)
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function assertPortablePluginCompatibility(manifest, host) {
|
|
145
|
+
if (!host.profiles.includes(manifest.profile)) throw new Error("\u5BBF\u4E3B\u672A\u63A5\u5165\u8DE8\u7AEF\u8FD0\u884C\u914D\u7F6E");
|
|
146
|
+
const platform = host.environment.platform;
|
|
147
|
+
if (!PORTABLE_PLATFORMS.some((value) => value === platform))
|
|
148
|
+
throw new Error("\u5F53\u524D\u5E73\u53F0\u4E0D\u80FD\u6FC0\u6D3B\u8DE8\u7AEF\u5E94\u7528\u63D2\u4EF6");
|
|
149
|
+
const target = manifest.targets[platform];
|
|
150
|
+
if (!target) throw new Error("\u63D2\u4EF6\u4E0D\u652F\u6301\u5F53\u524D\u5E73\u53F0");
|
|
151
|
+
if ((platform === "android" || platform === "ios") && manifest.permissions?.length)
|
|
152
|
+
throw new Error("\u79FB\u52A8\u5BBF\u4E3B\u5C1A\u672A\u63A5\u5165\u4E1A\u52A1\u6570\u636E\u6388\u6743");
|
|
153
|
+
if (comparePluginVersions(host.appVersion, target.minAppVersion) < 0)
|
|
154
|
+
throw new Error("\u5BA2\u6237\u7AEF\u7248\u672C\u4F4E\u4E8E\u63D2\u4EF6\u8981\u6C42");
|
|
155
|
+
const missing = target.required.filter(
|
|
156
|
+
(capability) => !host.environment.capabilities.some((available) => available === capability)
|
|
157
|
+
);
|
|
158
|
+
if (missing.length) throw new Error(`\u5BBF\u4E3B\u7F3A\u5C11\u5FC5\u9700\u80FD\u529B\uFF1A${missing.join("\u3001")}`);
|
|
159
|
+
return target;
|
|
160
|
+
}
|
|
161
|
+
function getPortableElementSupport(manifest, platform, type) {
|
|
162
|
+
const elements = manifest.targets[platform]?.elements;
|
|
163
|
+
return elements && Object.hasOwn(elements, type) ? elements[type] : "none";
|
|
164
|
+
}
|
|
165
|
+
function assertPortableElementDeclarations(manifest, nodeTypes) {
|
|
166
|
+
const actual = new Set(nodeTypes);
|
|
167
|
+
for (const target of Object.values(manifest.targets)) {
|
|
168
|
+
const declared = Object.keys(target.elements ?? {});
|
|
169
|
+
if (declared.length !== actual.size || declared.some((type) => !actual.has(type)))
|
|
170
|
+
throw new Error("\u5E73\u53F0\u8282\u70B9\u58F0\u660E\u4E0E\u63D2\u4EF6\u5B9E\u9645\u8D21\u732E\u4E0D\u4E00\u81F4");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export {
|
|
175
|
+
PORTABLE_PLATFORMS,
|
|
176
|
+
PORTABLE_SHARED_MODULES,
|
|
177
|
+
validatePortablePluginManifest,
|
|
178
|
+
readPortablePluginManifest,
|
|
179
|
+
validatePortableDistributionManifest,
|
|
180
|
+
assertPortablePluginCompatibility,
|
|
181
|
+
getPortableElementSupport,
|
|
182
|
+
assertPortableElementDeclarations
|
|
183
|
+
};
|
package/docs/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Tau 插件开发文档
|
|
2
2
|
|
|
3
|
+
默认模板使用 SDK 0.36.0、UI 0.4.0,生成格式 3 的同一插件包。中心 v2 支持上传待审,格式 3 必须逐平台人工审核;Android/iOS 正式安装要求客户端至少 0.2.1,并通过中心兼容选版。先读 [API 支持矩阵](api-support.md)、[跨端契约](portability.md)与[快速开始](getting-started.md)。下文桌面领域接口不表示移动端可用。
|
|
4
|
+
|
|
3
5
|
Tau 插件用 TypeScript 和 React 编写,打包成一个 ZIP,安装后在 Tau 桌面端运行。插件可以给 Tau 加页面和侧边栏入口,在文档里放自定义块,给 AI 提供工具,接入第三方存储、语音、视频等服务,或者读写用户的卡片和待办。
|
|
4
6
|
|
|
5
7
|
这份文档按"从零写出一个插件"的顺序组织。第一次接触时按下面的路线读,之后按需查阅。
|
|
@@ -37,7 +39,7 @@ Tau 插件用 TypeScript 和 React 编写,打包成一个 ZIP,安装后在 T
|
|
|
37
39
|
- 插件接口从 `@tau/plugins` 导入,界面组件从 `@tau/ui` 导入。它们的实现由 Tau 在运行时提供,模板的构建配置已经处理好,不需要你打包。
|
|
38
40
|
- 文中的 `context` 指 `activate(context)` 收到的插件上下文;代码片段如果没有写出外层结构,默认放在 `activate` 里。
|
|
39
41
|
- 所有接口都有完整的 TypeScript 类型。文档讲用法和规则,参数的精确类型以编辑器里的类型提示为准。
|
|
40
|
-
-
|
|
42
|
+
- 可用版本与能力由目标声明和实际宿主共同决定。
|
|
41
43
|
|
|
42
44
|
## 给 AI 编程助手
|
|
43
45
|
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<!-- 由 scripts/plugins/sync-author-docs.mjs 从 packages/plugins/docs/api-support.md 生成,请勿单独编辑。 -->
|
|
2
|
+
|
|
3
|
+
# 插件 API 支持矩阵
|
|
4
|
+
|
|
5
|
+
本表描述 SDK 0.36.0 与当前仓库宿主实现,不是所有旧客户端的能力承诺。桌面列包含现有正式桌面 API;格式 3 在桌面仍走显式开发目录,正式中心安装链路尚未接入。Android/iOS 0.2.1 起的正式构建支持固定插件中心安装与启用,不开放任意开发 URL 安装;仍需服务端允许目标平台和相应版本通过审核。网页插件中心只浏览与分发,不执行插件。
|
|
6
|
+
|
|
7
|
+
一个 SDK 允许不同宿主实现不同子集。类型中有方法不代表该端可用;`capabilities` 只列当前版本已实现的能力,`permissions` 只声明业务授权上限,两者不能互代。不能通过删除 required、改格式号或伪报 edit 绕过限制。
|
|
8
|
+
|
|
9
|
+
## 上下文 API
|
|
10
|
+
|
|
11
|
+
“已接”表示存在真实适配或公共实现;“部分”后的边界是支持范围;“未接”不能靠作者改布局解决。Android 与 iOS 目前具有相同 API 子集,但交互验收分别进行。
|
|
12
|
+
|
|
13
|
+
| API | 桌面 | Android | iOS | 作者责任与边界 |
|
|
14
|
+
| ----------------------------------------------------------------------------------------------------- | ------------------------------------------ | --------------------------------------- | ------------------ | ------------------------------------------------------------------------------------------------ |
|
|
15
|
+
| `context.pluginId`、`context.workspaceId`、`context.signal`、`context.register` | 已接 | 已接 | 已接 | 数据按工作区隔离;监听/连接交给 register;异步响应检查 signal;不依赖系统退出一定调用 deactivate |
|
|
16
|
+
| `context.environment`、`usePluginEnvironment()` | 已接 | 已接 | 已接 | 用能力判接口、layout/input 判交互;静态正文不缓存 activate 的 context |
|
|
17
|
+
| `context.pages` | 已接 | 已接 | 已接 | 共用页面参数、身份和离开守卫;窄屏布局、触摸操作由作者适配 |
|
|
18
|
+
| `context.navigation` | 侧栏入口 | “我的”功能入口 | “我的”功能入口 | 页面与入口分别注册;不操作宿主 history 或导入宿主路由 |
|
|
19
|
+
| `context.commands` | 注册与命令面板已接 | 部分:注册/回收已接,无统一插件命令面板 | 同 Android | 命令注册不自动产生手机可点击入口,主要功能另注册 navigation |
|
|
20
|
+
| `context.storage` | 工作区 KV | 工作区 SQLite KV | 工作区 SQLite KV | JSON 私有数据;单值上限 1 MiB;不是业务数据库、结构化集合或安全凭据库 |
|
|
21
|
+
| `context.settings` | 插件设置及领域设置已接 | 部分:插件自己的设置页 | 同 Android | 移动不支持带 target 的领域设置;调用可选设置前检查 settings.v1 |
|
|
22
|
+
| `context.editor` | 动态 register 限工作台;普通正文用静态贡献 | 动态 register 未接 | 动态 register 未接 | 跨端正文通过 definePlugin 的 editorExtensions/editorCodecs,不能在 activate 动态注册来替代 |
|
|
23
|
+
| `context.fetch` | 宿主原生传输已接 | 未接 | 未接 | 插件中心能联网不代表插件有网络适配;本轮不承诺原生网络、Cookie、CORS 或下载后台续传 |
|
|
24
|
+
| `context.services` | 按宿主注入服务 | 未注入作者业务服务 | 同 Android | 不把类型中的编译、媒体、转换等服务当成移动通用能力 |
|
|
25
|
+
| `context.permissions` | 业务授权已接 | 未接 | 未接 | 含移动目标的格式 3 包必须 permissions 为空;界面显示权限说明不等于授权可用 |
|
|
26
|
+
| `context.data`、`context.content` | 已接,按权限与修订校验 | 未接 | 未接 | Tau 的卡片/文章/任务/日程读写及 ContentRef 正文,与插件私有 KV 分开 |
|
|
27
|
+
| `context.entities`、`context.records`、`context.links`、`context.transaction` | 已接 | 未接 | 未接 | 即使读写本插件自己的实体/集合不需业务权限,也仍需要移动宿主适配;不能用 KV 支持推断这些接口可用 |
|
|
28
|
+
| `context.events` | 业务事件已接 | 未接 | 未接 | 插件自己的 React 状态与业务数据库变更订阅不是同一能力 |
|
|
29
|
+
| `context.app` | 内容选择/打开/宿主动作已接 | 未接 | 未接 | pages.open 只打开插件页面,不等于可以打开或修改 Tau 内容 |
|
|
30
|
+
| `context.ai` | 已接,需声明和授权 | 未接 | 未接 | 不绕过宿主模型分配、额度或授权自行假定可用 |
|
|
31
|
+
| `context.mcp`、`context.chat` | 已接 | 未接 | 未接 | 工具注册、外部传输和聊天自定义渲染不是移动公共子集 |
|
|
32
|
+
| `context.flashcards` | 已接 | 未接 | 未接 | 正文插件块不会自动加入移动闪卡编辑场景 |
|
|
33
|
+
| `context.excerpts`、`context.materials` | 已接 | 未接 | 未接 | 应用自身能显示材料,不表示提供了插件 API |
|
|
34
|
+
| `context.sidebar`、`context.home`、`context.actions`、`context.views` | 已接 | 未接 | 未接 | 跨端入口改用 navigation;首页面板、对象动作、详情区块不得自动映射为手机支持 |
|
|
35
|
+
| `context.notifications` | 已接 | 未接 | 未接 | 不承诺移动系统通知或后台通知 |
|
|
36
|
+
| `context.sync`、`context.upload`、`context.tts`、`context.images`、`context.video`、`context.publish` | 领域提供方已接 | 未接 | 未接 | 移动内置功能与插件提供方协议独立;无对应能力名可声明为 optional 来绕过 |
|
|
37
|
+
| `context.backend` | 格式 2 独立后台与授权已接 | 格式 3 不支持 | 格式 3 不支持 | Node、子进程、本机程序继续留在旧桌面包;本轮不迁移 |
|
|
38
|
+
|
|
39
|
+
## 正文、UI 与交互
|
|
40
|
+
|
|
41
|
+
| 能力 | 已实现范围 | 作者需要适配 | 宿主未接或待验收 |
|
|
42
|
+
| -------------------------------------------------- | ------------------------------------------------------------------------------- | ---------------------------------------------------------- | ----------------------------------------------------------------------------- |
|
|
43
|
+
| 静态 editorExtensions/editorCodecs | 三端共用节点/codec;移动普通正文与预览装配;none/render/edit 同时约束界面和提交 | 为各平台如实声明全部节点,公共数据与节点 type 不变 | 移动闪卡等其他 Kit 不自动装配;格式 3 博客分发未接 |
|
|
44
|
+
| useElement、SourceBlockEditor/useSourceBlock | 公共节点操作、只读保护、草稿保存/取消;ABC 已在两端模拟器编辑保存 | 使用标准组件;处理外部更新、取消、失活;专有编辑器自行适配 | 真机软键盘、中文输入法、最低 WebView 待验收 |
|
|
45
|
+
| 插入与块菜单 | 手机触摸插入、上下移动/删除等标准命令 | 自定义编辑动作不能仅有 hover/右键;手机提供可点击入口 | 完整长按拖拽、边缘手势、平板与手感待验收 |
|
|
46
|
+
| Dialog/Drawer 与页面退出 | 公共浮层回收和系统返回仲裁,页面离开守卫 | 关闭/取消不误保存;复杂布局使用响应式或分开视图 | 不是所有 @tau/ui 控件都已逐项完成移动交互验收 |
|
|
47
|
+
| ContentEditor/ContentPreview、EntityRef 等业务组件 | 桌面有相应内容/引用适配 | 不能因为组件可导入就宣称手机可编辑任意 Tau 正文 | 移动作者业务组件适配未接;区别于插件节点在已有正文中的渲染 |
|
|
48
|
+
| 媒体与资源 | 正文节点资源声明与原文保留 | 在 nodes 声明资源字段;分别验证目标场景 | 不承诺移动作者媒体 API 的上传/缓存/查看器全集;普通包内展示不等于领域服务已接 |
|
|
49
|
+
| 白板、Skill、博客静态模板 | 保持原桌面协议 | 继续维护旧格式;无需批量改包 | 不纳入 formatVersion 3 / web-v1;web 环境只表示只读渲染上下文 |
|
|
50
|
+
| 搜索、摘要与同步 | 移动保留插件原始节点及 KV;前端导入导出使用 codec | 新字段保持旧版可读,代码回退不回退数据 | 移动搜索不索引插件内部源码;真实同步冲突、长文资源预算待验收 |
|
|
51
|
+
|
|
52
|
+
## 能力词表的准确含义
|
|
53
|
+
|
|
54
|
+
当前三端调试跨端宿主提供 `commands.v1`、`storage.v1`、`pages.v1`、`navigation.v1`、`settings.v1`、`ui.dialog.v1`、`editor.elements.v1`、`editor.codecs.v1`、`editor.source.v1`。其范围以上表为准,例如 commands.v1 不承诺手机命令面板,settings.v1 不承诺领域设置,editor.elements.v1 不代表动态 context.editor.register。
|
|
55
|
+
|
|
56
|
+
没有登记能力名的桌面 API 不属于已承诺的移动可选能力,不能自行发明 data.v1、fetch.v1 等名称。当前移动目标的非空 permissions 会在模板构建、中心上传和移动求值前被拒绝。
|
|
57
|
+
|
|
58
|
+
作者/上传严格校验使用 validatePortablePluginManifest 或更严格的 validatePortableDistributionManifest,未知能力(包括 optional 拼错)均拒绝。客户端使用 readPortablePluginManifest 保留有界、合法的未来能力名称:未知 required 在兼容检查中作为缺能力拒绝,未知 optional 保留但不可用。optional 不是自动补实现;作者调用前仍检查实际环境并提供降级。未知字段、格式、profile、权限词表和节点等级仍拒绝。
|
|
59
|
+
|
|
60
|
+
## 作者选择与发行边界
|
|
61
|
+
|
|
62
|
+
1. 先列出插件用到的 API;全部落在移动已接范围,才声明对应移动 target。
|
|
63
|
+
2. 若仅交互不同,共用数据/codec,按 layout 与 input 提供移动操作;适配未完成的节点填 render 或 none。
|
|
64
|
+
3. 若依赖宿主未接的业务能力,保留桌面版本,不用改清单假装兼容。计数器和 ABC 的结论不能外推到所有插件。
|
|
65
|
+
4. 旧格式 1/2 继续支持;旧客户端经 v1 只收到旧包。增加平台需同一插件 ID 的更高版本,不覆盖已发布 ZIP、重命名节点或自动清数据。
|
|
66
|
+
5. 使用插件 SDK 0.36.0 与 UI 0.4.0;中心 v2 接收格式 3 待审,必须逐平台人工审核。是否可安装由客户端版本、能力与中心开关共同决定,不能由 npm 版本推断。中心首次安装默认保存启用意图,下次打开生效;更新保留显式启停选择。任意开发 URL 安装仅限调试构建。
|
|
67
|
+
|
|
68
|
+
已完成的模拟器行为验证与公共测试不替代真机、最低系统、完整 IPA、桌面正式格式 3 安装、未知旧作者迁移或应用商店发行验收。
|
package/docs/editor.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 编辑器扩展
|
|
2
2
|
|
|
3
|
-
编辑器扩展让你在 Tau
|
|
3
|
+
编辑器扩展让你在 Tau 文档中添加自定义块。跨端使用静态 editorExtensions/editorCodecs,移动普通正文提供触摸插入、标准块操作与源码编辑;动态 context.editor.register 只在桌面工作台适用。桌面拖拽和旧内容插件博客发布不能推断为格式 3 移动长按拖拽或博客分发已经接入,详见 [API 支持矩阵](api-support.md)。
|
|
4
4
|
|
|
5
5
|
这一篇先用一个完整的例子走一遍,再逐项介绍扩展能声明的内容。
|
|
6
6
|
|
package/docs/getting-started.md
CHANGED
|
@@ -1,134 +1,42 @@
|
|
|
1
1
|
# 快速开始
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
模板使用同一套 SDK:`@tau/plugins` 为 npm 别名 @xiongtao.xt/tau-plugins 0.36.0,`@tau/ui` 为 @xiongtao.xt/tau-ui 0.4.0。移动正式安装要求 Android/iOS 客户端至少 0.2.1;具体支持范围先看 [API 矩阵](api-support.md)。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 准备与构建
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- Tau 桌面客户端 0.59.0 或更高版本
|
|
10
|
-
|
|
11
|
-
## 跑通示例
|
|
12
|
-
|
|
13
|
-
在 GitHub 上打开 [tau-plugin-template](https://github.com/LastKnightCoder/tau-plugin-template),点击 **Use this template** 创建你自己的仓库,克隆到本地后执行:
|
|
7
|
+
1. 安装 Node.js 22+ 与 pnpm 11.9.0,复制本版本模板到独立目录。
|
|
8
|
+
2. 安装已锁定的 npm 依赖并构建:
|
|
14
9
|
|
|
15
10
|
```sh
|
|
16
|
-
pnpm install
|
|
11
|
+
pnpm install --frozen-lockfile
|
|
17
12
|
pnpm build
|
|
18
|
-
pnpm install:local
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
- `pnpm build` 检查类型并打包,生成 `dist/<插件ID>-<版本>.zip`。
|
|
22
|
-
- `pnpm install:local` 把这个 ZIP 解压到 Tau 的插件目录 `~/.editor/plugins/<插件ID>/`。
|
|
23
|
-
|
|
24
|
-
然后在 Tau 中:
|
|
25
|
-
|
|
26
|
-
1. 打开侧边栏的「插件」页,点右上角的「⋯ → 重新扫描」,列表里会出现「计数器示例」。
|
|
27
|
-
2. 启用它。
|
|
28
|
-
3. 点击侧边栏「日常」分组下的「计数器」,或按 Ctrl+K 搜索「打开计数器」。
|
|
29
|
-
4. 点「增加并保存」。重启 Tau 后再打开,计数还在。
|
|
30
|
-
|
|
31
|
-
到这里,你已经完成了一次完整的开发、安装和运行。
|
|
32
|
-
|
|
33
|
-
## 模板里有什么
|
|
34
|
-
|
|
35
|
-
| 文件 | 作用 |
|
|
36
|
-
| --------------------------------- | --------------------------------------------------------- |
|
|
37
|
-
| `manifest.json` | 插件的身份证:ID、名称、版本、需要的权限等 |
|
|
38
|
-
| `src/index.tsx` | 插件入口,计数器的页面、设置和命令都在这里 |
|
|
39
|
-
| `src/styles.css` | 插件样式,构建时打包成 `main.css` |
|
|
40
|
-
| `src/CounterIcon.tsx` | 侧边栏图标示例 |
|
|
41
|
-
| `README.md` | 给使用者看的插件说明,显示在插件详情的「说明」里 |
|
|
42
|
-
| `CHANGELOG.md`(需要时自己创建) | 给使用者看的更新日志,显示在插件详情的「更新日志」里 |
|
|
43
|
-
| `build.mjs` / `install-local.mjs` | 打包和本地安装脚本,一般不用改 |
|
|
44
|
-
| `.github/workflows/release.yml` | 推送版本 tag 后自动构建、发布到 GitHub Release 和插件中心 |
|
|
45
|
-
| `AGENTS.md` | 给 AI 编程助手的项目指引 |
|
|
46
|
-
| `docs/` | 本开发文档,不会打进插件包 |
|
|
47
|
-
|
|
48
|
-
打开 `src/index.tsx` 看一下,核心只有这么多:
|
|
49
|
-
|
|
50
|
-
```tsx
|
|
51
|
-
export default definePlugin({
|
|
52
|
-
...__PLUGIN_META__,
|
|
53
|
-
create: () => ({
|
|
54
|
-
activate(context) {
|
|
55
|
-
const page = context.pages.register({ id: "counter", title: "计数器", component: Page });
|
|
56
|
-
context.sidebar.registerItem({
|
|
57
|
-
id: "counter",
|
|
58
|
-
title: "计数器",
|
|
59
|
-
icon: CounterIcon,
|
|
60
|
-
group: SIDEBAR_GROUPS.daily,
|
|
61
|
-
page,
|
|
62
|
-
});
|
|
63
|
-
context.settings.register({ id: "preferences", title: "计数设置", component: Settings });
|
|
64
|
-
context.commands.register({
|
|
65
|
-
id: "open",
|
|
66
|
-
title: "打开计数器",
|
|
67
|
-
run: async () => {
|
|
68
|
-
await page.open();
|
|
69
|
-
return null;
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
},
|
|
73
|
-
}),
|
|
74
|
-
});
|
|
75
13
|
```
|
|
76
14
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
## 改成你自己的插件
|
|
80
|
-
|
|
81
|
-
1. **改身份**。编辑 `manifest.json`:
|
|
82
|
-
- `id` 换成你自己的唯一名称,例如 `yourname.water-tracker`。ID 发布后不要再改,改了会被当成另一个插件,用户已保存的数据也找不回来。
|
|
83
|
-
- `name`、`description` 改成插件的名称和一句话简介(160 字以内)。
|
|
84
|
-
- `version` 从 `1.0.0` 开始即可。
|
|
85
|
-
- `categories`、`keywords` 决定插件在插件中心的分类和搜索词,含义见[插件的组成 · manifest](plugin-basics.md#manifest)。
|
|
86
|
-
2. **改项目名**。把 `package.json` 的 `name` 改成你的项目名,`version` 与 manifest 保持一致。
|
|
87
|
-
3. **写功能**。在 `src/index.tsx` 里实现你的功能,样式写在 `src/styles.css`。
|
|
88
|
-
4. **写说明**。把 `README.md` 改成给使用者看的介绍:插件能做什么、怎么开始用、常见问题。不要写开发过程或内部实现,它会原样显示给用户。
|
|
89
|
-
5. **构建并安装**,按下一节的方法在 Tau 中测试。
|
|
90
|
-
|
|
91
|
-
## 日常开发循环
|
|
92
|
-
|
|
93
|
-
改完代码后:
|
|
94
|
-
|
|
95
|
-
```sh
|
|
96
|
-
pnpm build
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
`pnpm install:local` 只负责首次安装,目标目录已存在时会拒绝覆盖,以免误删。更新已安装的开发版本时:
|
|
100
|
-
|
|
101
|
-
1. 在 Tau 的插件页停用你的插件。
|
|
102
|
-
2. 删除旧目录 `~/.editor/plugins/<插件ID>/`,再执行 `pnpm install:local`。
|
|
103
|
-
3. 在插件页点「⋯ → 重新扫描」,然后重新启用。
|
|
104
|
-
|
|
105
|
-
插件保存的数据在笔记库里,不在这个目录中,删除目录不会丢数据。
|
|
106
|
-
|
|
107
|
-
带有[编辑器扩展](editor.md)或[白板扩展](whiteboard.md)的插件在 Tau 启动时装配,更新代码后需要完全退出并重新打开 Tau 才会生效。
|
|
15
|
+
无需仓库源码或本地 tarball。依赖使用固定版本和锁文件;没有单独的移动 SDK。
|
|
108
16
|
|
|
109
|
-
|
|
17
|
+
3. 构建生成 `dist/<插件ID>-<版本>.zip`;再次安装可用 `pnpm install --frozen-lockfile`。
|
|
18
|
+
4. 在目标宿主验证后按发布指南上传待审;格式 3 必须人工审核。移动用户从应用内中心安装,首次安装保存启用意图,重开应用生效;桌面格式 3 当前只走显式开发目录。install:local 不把格式 3 写进旧桌面正式目录。
|
|
110
19
|
|
|
111
|
-
|
|
112
|
-
| -------------------- | ------------------------------- |
|
|
113
|
-
| `pnpm check` | 只检查 TypeScript 类型 |
|
|
114
|
-
| `pnpm build` | 检查类型并生成插件 ZIP |
|
|
115
|
-
| `pnpm install:local` | 把最近构建的 ZIP 首次安装到 Tau |
|
|
20
|
+
仅调试未发布 SDK 时运行 `node use-local-sdk.mjs /path/to/plugins.tgz /path/to/ui.tgz` 切换到本地 file 依赖,并重新生成开发锁文件;恢复正式 npm 依赖后重建发布锁文件。不提交 .sdk、node_modules 或 dist,不用旧 tarball 冒充新版 npm 内容。
|
|
116
21
|
|
|
117
|
-
|
|
22
|
+
## 模板结构
|
|
118
23
|
|
|
119
|
-
|
|
24
|
+
| 文件 | 用途 |
|
|
25
|
+
| ----------------------------------- | ------------------------------------------- |
|
|
26
|
+
| manifest.json | 身份、平台、版本与能力声明 |
|
|
27
|
+
| src/index.tsx | 共用计数器、页面、功能入口、可选设置/Dialog |
|
|
28
|
+
| src/styles.css、src/CounterIcon.tsx | 样式和图标 |
|
|
29
|
+
| build.mjs | 依赖检查、清单校验、暂存产物与 ZIP |
|
|
30
|
+
| use-local-sdk.mjs | 准备未发布的 SDK/UI 输入 |
|
|
31
|
+
| README.md | 给使用者的说明 |
|
|
120
32
|
|
|
121
|
-
|
|
122
|
-
| ---------------------- | ------------------------------------------------------------------------------------------- |
|
|
123
|
-
| 插件列表里没有我的插件 | 点「重新扫描」;确认解压后的目录是 `~/.editor/plugins/<插件ID>/manifest.json`,没有多套一层 |
|
|
124
|
-
| 提示目标目录已存在 | 按上面「日常开发循环」先删除旧目录 |
|
|
125
|
-
| 改了代码没有变化 | 确认重新构建并安装了;编辑器、白板插件需要重启 Tau |
|
|
126
|
-
| 启用失败 | 看插件卡片上的错误信息,通常是 `activate` 里抛了异常 |
|
|
127
|
-
| 提示需要重启 | 完全退出 Tau 再打开 |
|
|
33
|
+
计数按工作区保存。跨端页面注册与入口分离;设置与 Dialog 仅在宿主提供能力时使用。布局通过 usePluginEnvironment 订阅,不解析 User-Agent。
|
|
128
34
|
|
|
129
|
-
|
|
35
|
+
## 改成自己的插件
|
|
130
36
|
|
|
131
|
-
|
|
37
|
+
1. 修改 manifest 的 id/name/description/version,package.json 版本保持一致。发布后插件 ID 不变。
|
|
38
|
+
2. 先逐项核对 [API 支持矩阵](api-support.md),再声明 targets、最低版本、必需/可选能力。移动 permissions 必须为空;没有 Node 不等于移动完整兼容。
|
|
39
|
+
3. 共用逻辑和模型,差异明显时拆视图,保持节点类型与字段一致。
|
|
40
|
+
4. 更新 README,构建后在目标宿主验收启用、保存、停用与恢复。
|
|
132
41
|
|
|
133
|
-
|
|
134
|
-
- 回到[文档首页](README.md),按你要做的功能找到对应文档。
|
|
42
|
+
契约见[跨端开发](portability.md),生命周期见[插件组成](plugin-basics.md)。仓库外构建只证明作者闭环,不替代宿主和真机验收。
|
package/docs/plugin-basics.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# 插件的组成
|
|
2
2
|
|
|
3
|
+
默认模板使用跨端开发格式 3,targets/profile 与节点支持声明见[跨端契约](portability.md)。下文旧桌面 manifest 示例属于格式 1/2,不应直接混入格式 3。
|
|
4
|
+
|
|
3
5
|
一个 Tau 插件由以下几部分组成:
|
|
4
6
|
|
|
5
7
|
- **manifest.json**:插件是谁、需要什么。Tau 不运行代码就能读到它。
|
|
@@ -64,7 +66,7 @@
|
|
|
64
66
|
|
|
65
67
|
### 保持模板值的字段
|
|
66
68
|
|
|
67
|
-
`formatVersion`、`apiVersion`、`platform`、`format`、`main`
|
|
69
|
+
`formatVersion`、`apiVersion`、`platform`、`profile`、`format`、`main` 按所选协议保持一致。`styles` 和 `integrity` 由构建生成;skills 仅旧桌面格式支持。不要直接修改 ZIP。
|
|
68
70
|
|
|
69
71
|
## 入口与插件定义
|
|
70
72
|
|
|
@@ -139,6 +141,7 @@ create: () => ({
|
|
|
139
141
|
| ----------------------------------------------------- | -------------------------------------------- | --------------------------------------------- |
|
|
140
142
|
| `pluginId`、`workspaceId` | 当前插件 ID 与工作区 ID(不要解析工作区 ID) | |
|
|
141
143
|
| `signal` | 本次运行结束时中止 | [取消与清理](#取消与清理) |
|
|
144
|
+
| `environment`、`navigation` | 当前环境与语义功能入口 | [跨端契约](portability.md) |
|
|
142
145
|
| `register` | 托管需要清理的资源 | [取消与清理](#取消与清理) |
|
|
143
146
|
| `commands` | 注册命令 | [界面](ui.md#命令) |
|
|
144
147
|
| `pages`、`sidebar` | 注册页面与侧边栏入口 | [界面](ui.md#页面) |
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# 跨端开发契约
|
|
2
|
+
|
|
3
|
+
模板使用 SDK 0.36.0、UI 0.4.0 与格式 3。先读 [API 支持矩阵](api-support.md),再按[快速开始](getting-started.md)安装依赖。移动正式安装要求 Android/iOS 客户端至少 0.2.1,且中心允许该平台及版本;桌面格式 3 仍只在显式开发目录装配,不用旧公开客户端冒充支持。
|
|
4
|
+
|
|
5
|
+
## 页面与入口
|
|
6
|
+
|
|
7
|
+
同一个 main.js 可以支持 desktop/android/ios,公共数据模型与业务逻辑保持一致:
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
const page = context.pages.register({ id: "tasks", title: "任务管理", component: TasksPage });
|
|
11
|
+
context.navigation.registerEntry({ id: "tasks", title: "任务管理", page });
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
页面声明不自动创建入口。宿主决定入口位于桌面侧栏还是移动功能列表;作者不导入宿主路由或修改 history。页面注销会回收其入口,旧句柄不能继续打开。页面可在 effect 中登记 pageContext.registerLeaveGuard,返回 false 阻止离开,清理时调用返回句柄的 dispose。
|
|
15
|
+
|
|
16
|
+
## 环境与能力
|
|
17
|
+
|
|
18
|
+
`context.environment` 每次读取取得当前不可变快照。React 页面和静态编辑器组件通过 `usePluginEnvironment()` 订阅环境变化,不依赖 activate:
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { usePluginEnvironment } from "@tau/plugins";
|
|
22
|
+
function TasksView() {
|
|
23
|
+
const environment = usePluginEnvironment();
|
|
24
|
+
return environment.layout === "compact" ? <CompactTasks /> : <WideTasks />;
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
platform 区分 desktop/android/ios/web/unknown;layout 为 compact/wide/unknown;input 区分 touch/finePointer。宿主更新布局/输入后 hook 刷新;不要将一次解构的快照当成一直变化的引用。platform 与能力集合在会话内固定,更换需重建会话。
|
|
29
|
+
|
|
30
|
+
能力词表由 SDK 的 `PLUGIN_CAPABILITIES`、`PluginCapability` 提供,当前包括 commands/storage/pages/navigation/settings/ui.dialog/editor.elements/editor.codecs/editor.source 的 `.v1` 版本。它表示接口可用性,不授予数据权限,也不是安全沙箱。
|
|
31
|
+
|
|
32
|
+
可选能力由作者显式检测:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
if (context.environment.capabilities.includes("settings.v1")) {
|
|
36
|
+
context.settings.register({ id: "preferences", title: "设置", component: Settings });
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
模板的设置页、Dialog 都是可选能力,核心计数不依赖它们。UI 组件能够导入,不表示宿主已经完成移动交互适配。
|
|
41
|
+
|
|
42
|
+
## 跨端清单
|
|
43
|
+
|
|
44
|
+
格式为 `formatVersion: 3`、`platform: portable`、`profile: web-v1`、`apiVersion: 1`、CJS 单入口。targets 至少包含 desktop/android/ios 中一个,每个平台声明:
|
|
45
|
+
|
|
46
|
+
| 字段 | 含义 |
|
|
47
|
+
| ------------- | --------------------------------------------------------- |
|
|
48
|
+
| minAppVersion | 该端最低客户端版本 |
|
|
49
|
+
| required | 必需能力,缺少时在模块执行前拒绝 |
|
|
50
|
+
| optional | 可选能力,不能与 required 重复 |
|
|
51
|
+
| elements | 编辑器包按节点类型填写 none/render/edit,普通页面包不填写 |
|
|
52
|
+
|
|
53
|
+
宿主必须显式支持 web-v1,并同时满足平台、版本与必需能力。模板的最低版本用于开发矩阵,不是现有正式客户端已接线的承诺。
|
|
54
|
+
|
|
55
|
+
编辑器包每个目标必须列出全部节点并与实际贡献一致。none 不装配,render 仅展示,edit 允许编辑和插入;未声明默认 none。受控开发宿主在标准组件和提交 API 中执行等级限制;清单校验本身不改变编辑器行为。
|
|
56
|
+
|
|
57
|
+
构建工具从 `@tau/plugins/portable` 使用 validatePortableDistributionManifest:严格拒绝未知 required/optional、预发布插件版本和含移动目标的非空 permissions,失败保留上一有效产物。validatePortablePluginManifest 是基础严格校验;客户端 readPortablePluginManifest 返回 ReadablePortablePluginManifest,保留未来能力名,未知 required 在兼容检查拒绝,未知 optional 缺失允许降级;不删除这些名称后再做审核清单对账。结构、权限词表、profile 与节点等级仍严格。旧格式校验继续拒绝格式 3;不要改格式号绕过限制。
|
|
58
|
+
|
|
59
|
+
## 依赖与桌面特有能力
|
|
60
|
+
|
|
61
|
+
普通依赖打包;React、React DOM、SDK 根入口和 UI 由宿主提供。web-v1 不开放 whiteboard/sync 子入口、host/environment-host 或 Node 模块。构建检查只能发现部分错误,不能证明任意 JS 行为安全。
|
|
62
|
+
|
|
63
|
+
格式 3 不支持 backend、whiteboard 或 Skill 脚本。需要 Node 时明确选择旧桌面格式 2:移除 profile/targets,填写 platform: desktop 和顶层 minAppVersion,按[后台契约](backend.md)开发。
|
|
64
|
+
|
|
65
|
+
构建器仍支持旧格式 1/2。`__PLUGIN_PORTABLE__` 是按格式注入的构建常量:跨端默认示例使用 navigation/环境 hook,显式旧桌面格式使用 sidebar/基础页面,没有运行失败后的自动回退。跨端三端产物仍是同一文件。
|
|
66
|
+
|
|
67
|
+
## 验证口径
|
|
68
|
+
|
|
69
|
+
同一模板提供 `examples/editor.tsx`。需要编辑器起点时,将 src/index.tsx 改为导出该文件的 default,manifest 添加 editor: true,并在各目标声明 editor.elements.v1 与 `elements: { "example.note": "edit" }`(只展示的平台用 render)。不要为手机另造节点类型;未适配的写入保护与交互仍须宿主验收。
|
|
70
|
+
|
|
71
|
+
仓库外构建证明类型闭包、依赖与产物;兼容矩阵证明声明校验,不代表真机运行。宿主提供页面守卫、标准浮层返回、节点提交保护和原生包事务。移动源码组件使用草稿保存/取消,复杂手势与真机行为分别验收;桌面格式 3 正式安装、未接移动业务 API、最低系统和完整发行签名等必须独立验证,不能以 SDK 发布替代。
|
package/docs/release.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# 发布与更新
|
|
2
2
|
|
|
3
|
+
模板使用 SDK 0.36.0 与 UI 0.4.0。格式 3 可经工作流上传待审,必须提交每个声明平台的人工验收证据,CI 不会自动批准。移动安装需 Android/iOS 0.2.1 及中心兼容选版;桌面正式客户端仍使用旧格式,格式 3 只供显式桌面开发目录验证。install:local 不把格式 3 写入旧正式目录,不要改格式号绕过限制。
|
|
4
|
+
|
|
3
5
|
插件写好之后,发布到[插件中心](https://plugins.taunote.app),用户就能在 Tau 中搜索、安装和更新它。这一篇介绍发布前的准备、第一次发布、之后的版本更新,以及如何升级 SDK。
|
|
4
6
|
|
|
5
7
|
## 发布前的准备
|
package/docs/ui.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# 界面
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
跨端开发包的通用入口用 `context.navigation.registerEntry`,不使用桌面 sidebar API。页面注销会回收相关入口,展示位置由宿主决定;环境与可选能力见[跨端契约](portability.md)。下面的侧边栏、通知等桌面能力不自动包含在 web-v1 中。
|
|
4
|
+
|
|
5
|
+
下述四种位置描述桌面呈现。移动只有页面/语义入口和插件自己的设置页;commands.v1 提供注册与回收,不自动增加手机命令面板;通知、旧 sidebar、首页/对象/详情扩展未接。具体见 [API 支持矩阵](api-support.md)。
|
|
6
|
+
|
|
7
|
+
桌面插件可以通过四种方式出现在界面里:
|
|
4
8
|
|
|
5
9
|
- **命令**:出现在 Ctrl+K 命令面板中,用户搜索后执行。
|
|
6
10
|
- **页面**:一个完整的 React 页面,和 Tau 自己的页面一样参与前进、后退。
|
package/docs/user-data.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# 用户数据
|
|
2
2
|
|
|
3
|
+
本篇业务授权、data/content、实体/记录/关联/事务与宿主动作适用于桌面;移动宿主尚未接线,即使是无需业务权限的插件自有实体也不能直接使用。移动当前只提供私有 KV,含移动目标的 permissions 必须为空。先查 [API 支持矩阵](api-support.md)。
|
|
4
|
+
|
|
3
5
|
插件可以读取和修改用户在 Tau 中的内容:卡片、文章、项目文档、待办和日程,也可以创建属于插件自己的内容。这一篇按以下顺序介绍:
|
|
4
6
|
|
|
5
7
|
1. [权限](#权限):访问用户数据前必须了解的授权方式。
|
|
@@ -259,6 +261,7 @@ try {
|
|
|
259
261
|
### 写入后
|
|
260
262
|
|
|
261
263
|
- 打开中的页面、其他窗口、搜索和云同步都会自动更新,插件不需要做任何通知。
|
|
264
|
+
- 插件新建的卡片、文章、项目文档、白板和项目,和用户在 `pick` 中选择的一样:之后不需要读取权限也能用 `describe` 读标题、用 `<EntityRef>` 显示、`open` 打开、`links.add` 关联。
|
|
262
265
|
- 插件删除的内容,用户可以在 7 天内从插件详情页的「权限 → 最近删除」中恢复。
|
|
263
266
|
- 项目只能删除空项目,里面还有文档时会被拒绝。
|
|
264
267
|
- 项目文档会从它挂载的所有位置删除,有子文档时会被拒绝,视频笔记不能由插件删除。恢复时挂回仍然存在的原位置。
|
|
@@ -266,7 +269,7 @@ try {
|
|
|
266
269
|
|
|
267
270
|
## 正文输入
|
|
268
271
|
|
|
269
|
-
新建卡片、文章、插件内容,以及修改正文时,正文都用同一种写法 `content
|
|
272
|
+
新建卡片、文章、插件内容,以及修改正文时,正文都用同一种写法 `content`,从下面几种里选一种:
|
|
270
273
|
|
|
271
274
|
```ts
|
|
272
275
|
// Markdown:适合 AI 生成或外部导入的文字
|
|
@@ -278,6 +281,9 @@ await context.data.cards.create({ content: { nodes: source!.nodes! } });
|
|
|
278
281
|
|
|
279
282
|
// 复制一份已有正文:Tau 内部整份复制,插件拿不到正文内容
|
|
280
283
|
await context.data.articles.create({ title: "副本", content: { copyOf: card.contentRef } });
|
|
284
|
+
|
|
285
|
+
// 共用本插件内容的正文:新卡片与插件内容是同一份正文,改一处另一处同步变化
|
|
286
|
+
await context.data.cards.create({ content: { shareOf: answer.contentRef } });
|
|
281
287
|
```
|
|
282
288
|
|
|
283
289
|
| 写法 | 什么时候用 | 注意 |
|
|
@@ -285,12 +291,15 @@ await context.data.articles.create({ title: "副本", content: { copyOf: card.co
|
|
|
285
291
|
| `markdown` | 写入纯文字、AI 输出、外部导入 | 高亮、颜色、白板嵌入等 Markdown 表达不了的格式会丢失 |
|
|
286
292
|
| `nodes` | 把读到的正文改写后写回,或在多份正文之间搬运内容 | 结构不对时报错并给出出错节点的路径 |
|
|
287
293
|
| `copyOf` | 把一份正文完整复制到新卡片、新文章或插件内容里,例如「把这条笔记存为卡片」 | 只需要目标的写入权限,不需要来源的读取权限 |
|
|
294
|
+
| `shareOf` | 让插件内容同时也是一张卡片、一篇文章或一篇项目文档,在哪里改都是同一份正文 | 只用于新建卡片、文章、项目文档与「插入到项目」 |
|
|
288
295
|
|
|
289
296
|
- `nodes` 只检查结构:顶层是元素,元素有 `type` 和非空的 `children`,文字节点有 `text`。Tau 不认识的节点类型(例如来自未安装的插件)原样保存,安装对应插件后即可正常显示。
|
|
290
297
|
- `content.read({ format: "nodes" })` 的结果带 `schemaVersion`。节点结构有不兼容的变化时它会增加,插件可以与 `EDITOR_NODE_SCHEMA_VERSION` 比较,判断自己是否认得这些节点。
|
|
291
298
|
- 正文中的待办勾选项由 Tau 维护身份,复制或搬运后各自独立,不需要插件处理。
|
|
292
299
|
- `copyOf` 的来源可以是卡片、文章、项目文档或任一插件内容的正文。复制的是当前内容,之后两份互不影响。
|
|
300
|
+
- `shareOf` 的来源只能是本插件内容的正文。用户在卡片、文章或项目文档里修改,插件内容同步变化,反之亦然;删除其中一处,另一处照常保留。一份正文最多是一张卡片、一篇文章,已经有了再新建会报错,可以先用 `content.read` 返回的 `owners` 判断。插件内容自己(`entities.create`)和修改正文(`content.edit`)不能用 `shareOf`。
|
|
293
301
|
- 新建时省略 `content` 得到空正文。
|
|
302
|
+
- 正文有大小上限:`markdown` 最多 200 万字;`nodes` 转成 JSON 后最多 800 万字,嵌套最多 30 层。超出时报错,上限可从 `CONTENT_INPUT_LIMITS` 读取。
|
|
294
303
|
|
|
295
304
|
## 读写正文
|
|
296
305
|
|
|
@@ -487,14 +496,14 @@ function CardRow({ card }: { card: PluginCard }) {
|
|
|
487
496
|
| `content.present` | `ref` | 全屏演示 | 无 |
|
|
488
497
|
| `content.share` | `ref` | 打开「内容协作」窗口,由用户确认发起共享 | 无 |
|
|
489
498
|
| `card.create` | `content?`(见[正文输入](#正文输入))、`tags?` | 打开新建卡片窗口并预填,用户可修改后保存 | 新卡片的引用 `{ kind: "card", id }` |
|
|
490
|
-
| `project.insertDocument` | `content`、`title?`(默认「未命名文档」) |
|
|
499
|
+
| `project.insertDocument` | `content`、`title?`(默认「未命名文档」) | 打开「插入到项目」窗口,用户选择项目与位置后新建文档 | 新文档的引用 `{ kind: "document", id }` |
|
|
491
500
|
| `notebook.create` | `title`、`sources?`(最多 200 项)、`from?` | 确认后新建 Notebook,`sources` 作为资料带入,`from` 记为来源 | Notebook 的引用 `{ kind: "notebook", id }` |
|
|
492
501
|
| `chat.start` | `prompt?`、`context?`(最多 20 项)、`placement?`:`page`(默认)、`dock` | 在对话页或右侧停靠栏开一个新对话,预填输入框与引用,由用户发送 | 对话的引用 `{ kind: "chat-session", id }` |
|
|
493
502
|
|
|
494
503
|
- 不需要数据权限:界面和确认都由 Tau 提供,用户在界面里确认即同意。插件拿不到正文。新建类返回的引用和用户在 `pick` 中选择的一样:不需要权限就能用 `describe` 读标题、用 `<EntityRef>` 显示、`open` 打开、`links.add` 关联;读取正文仍需要对应的读取权限(如 `cards:read`)。
|
|
495
504
|
- 用户关闭界面后才返回:导出、演示、协作在窗口关闭或演示结束时返回;新建类在保存后返回新内容的引用,用户取消时返回 `null`。插件停用时界面会被撤下。
|
|
496
505
|
- 只能在用户操作之后调用;同一时间只能打开一个,前一个还没关闭时抛错。内容已删除时抛出「内容不存在」。
|
|
497
|
-
- `copyOf` 只复制正文,不会改动来源。`project.insertDocument`
|
|
506
|
+
- `copyOf` 只复制正文,不会改动来源。`project.insertDocument` 的 `content` 用 `shareOf` 时,新文档与插件内容共用正文;其他写法都是新的一份正文。`card.create` 的窗口里用户可以修改预填内容,不接受 `shareOf`。
|
|
498
507
|
- `notebook.create` 的资料一次性带入,之后原内容的修改不会同步:卡片、文章、项目文档、日记和插件内容成为笔记资料;划线与 PDF 标注合并为一份,剪藏各一份;其他类型和已删除的内容不带入,确认框里会告诉用户数量。
|
|
499
508
|
- `from` 是这个 Notebook 由什么立项,显示在 Notebook 页顶部,用户点击可以打开。可以是卡片、文章、项目文档、日记、材料、对话、Notebook 或插件内容(`PLUGIN_NOTEBOOK_FROM_KINDS`),不存在时抛出「来源不存在」。
|
|
500
509
|
- `chat.start` 不会替用户发送:`prompt` 进入输入框,`context` 作为引用插在后面,用户可以修改。用户发出第一条消息后才返回对话的引用;没发送就切到别的对话、离开对话页、收起停靠栏或插件停用时返回 `null`。`context` 只支持卡片、文章、项目文档(`PLUGIN_CHAT_CONTEXT_KINDS`),其他内容请写进 `prompt`。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiongtao.xt/tau-plugins",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
"types": "./types/packages/plugins/src/package.d.ts",
|
|
23
23
|
"default": "./package.js"
|
|
24
24
|
},
|
|
25
|
+
"./portable": {
|
|
26
|
+
"types": "./types/packages/plugins/src/portable.d.ts",
|
|
27
|
+
"default": "./portable.js"
|
|
28
|
+
},
|
|
25
29
|
"./backend": {
|
|
26
30
|
"types": "./types/packages/plugins/src/backend.d.ts",
|
|
27
31
|
"default": "./runtime.js"
|
package/portable.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PORTABLE_PLATFORMS,
|
|
3
|
+
PORTABLE_SHARED_MODULES,
|
|
4
|
+
assertPortableElementDeclarations,
|
|
5
|
+
assertPortablePluginCompatibility,
|
|
6
|
+
getPortableElementSupport,
|
|
7
|
+
readPortablePluginManifest,
|
|
8
|
+
validatePortableDistributionManifest,
|
|
9
|
+
validatePortablePluginManifest
|
|
10
|
+
} from "./client/chunk-D4PV3N7Q.js";
|
|
11
|
+
import "./client/chunk-FZTR4KOY.js";
|
|
12
|
+
export {
|
|
13
|
+
PORTABLE_PLATFORMS,
|
|
14
|
+
PORTABLE_SHARED_MODULES,
|
|
15
|
+
assertPortableElementDeclarations,
|
|
16
|
+
assertPortablePluginCompatibility,
|
|
17
|
+
getPortableElementSupport,
|
|
18
|
+
readPortablePluginManifest,
|
|
19
|
+
validatePortableDistributionManifest,
|
|
20
|
+
validatePortablePluginManifest
|
|
21
|
+
};
|
package/publish-artifacts.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "./client/chunk-D4PV3N7Q.js";
|
|
1
2
|
import {
|
|
2
3
|
PLUGIN_SHARED_MODULES,
|
|
3
4
|
validatePluginManifest
|
|
@@ -64,16 +65,19 @@ function assertPluginEditorExtension(extension) {
|
|
|
64
65
|
var PLUGIN_RENDER_VERSION = 1;
|
|
65
66
|
function evaluatePluginPackage(artifact, modules) {
|
|
66
67
|
const manifest = validatePluginManifest(artifact.manifest);
|
|
68
|
+
return evaluateModule(manifest, artifact.code, modules, PLUGIN_SHARED_MODULES);
|
|
69
|
+
}
|
|
70
|
+
function evaluateModule(manifest, code, modules, allowed) {
|
|
67
71
|
const module = { exports: {} };
|
|
68
72
|
new Function(
|
|
69
73
|
"require",
|
|
70
74
|
"module",
|
|
71
75
|
"exports",
|
|
72
|
-
'"use strict";\n' +
|
|
76
|
+
'"use strict";\n' + code + `
|
|
73
77
|
//# sourceURL=tau-plugin://${manifest.id}/${manifest.version}/main.js`
|
|
74
78
|
)(
|
|
75
79
|
(id) => {
|
|
76
|
-
if (!
|
|
80
|
+
if (!allowed.includes(id) || !Object.hasOwn(modules, id))
|
|
77
81
|
throw new Error(`\u63D2\u4EF6\u4F7F\u7528\u4E86\u672A\u63D0\u4F9B\u7684\u5BBF\u4E3B\u6A21\u5757\uFF1A${id}`);
|
|
78
82
|
return modules[id];
|
|
79
83
|
},
|
package/publish-client.js
CHANGED
|
@@ -108,7 +108,7 @@ function createClient({ manifestUrl }) {
|
|
|
108
108
|
);
|
|
109
109
|
keys.add(item.key);
|
|
110
110
|
assert(
|
|
111
|
-
["home", "card", "article", "doc", "
|
|
111
|
+
["home", "card", "article", "doc", "list"].includes(String(item.type)) && typeof item.title === "string",
|
|
112
112
|
"INVALID_DATA",
|
|
113
113
|
"\u6570\u636E\u7C7B\u578B\u6216\u6807\u9898\u65E0\u6548"
|
|
114
114
|
);
|
|
@@ -158,7 +158,7 @@ function createClient({ manifestUrl }) {
|
|
|
158
158
|
"\u641C\u7D22 key \u672A\u95ED\u5408\u6216\u91CD\u590D"
|
|
159
159
|
);
|
|
160
160
|
assert(
|
|
161
|
-
["card", "article", "doc"
|
|
161
|
+
["card", "article", "doc"].includes(String(document.type)),
|
|
162
162
|
"INVALID_DATA",
|
|
163
163
|
"\u641C\u7D22\u7C7B\u578B\u9519\u8BEF"
|
|
164
164
|
);
|
|
@@ -57,3 +57,4 @@ export type { Plugin } from "../utils/plugin";
|
|
|
57
57
|
export { BLOCK_DRAG_GROUP, DragHandle, type DragHandleProps } from "../components/BlockDrag/index";
|
|
58
58
|
export { panAroundAnchor, pointFromCenter, type Point as ZoomPanPoint } from "../utils/zoomPan";
|
|
59
59
|
export { FloatingToolbar, ToolbarDivider, ToolbarIconButton } from "../components/FloatingToolbar/index";
|
|
60
|
+
export { IElementEditingPolicy, type ElementEditingPolicy } from "../services/elementEditingPolicy";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** 宿主按场景限制节点编辑,未注册时沿用编辑器自身只读状态。 */
|
|
2
|
+
export interface ElementEditingPolicy {
|
|
3
|
+
canEdit(type: string): boolean;
|
|
4
|
+
sourcePresentation?: "pointer" | "touch";
|
|
5
|
+
}
|
|
6
|
+
export declare const IElementEditingPolicy: import("../../../../shared/service-contract").ServiceIdentifier<ElementEditingPolicy>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** 能力版本表示接口可用性,不代表业务数据授权。 */
|
|
2
|
+
export declare const PLUGIN_CAPABILITIES: readonly ["commands.v1", "storage.v1", "pages.v1", "navigation.v1", "settings.v1", "ui.dialog.v1", "editor.elements.v1", "editor.codecs.v1", "editor.source.v1"];
|
|
3
|
+
export type PluginCapability = (typeof PLUGIN_CAPABILITIES)[number];
|
|
4
|
+
/** 消费者保留未来版本的能力名,但不把它们声明为本宿主已实现。 */
|
|
5
|
+
export declare function readPluginCapabilityNames(value: unknown): readonly string[];
|
|
6
|
+
export declare function isPluginCapability(value: unknown): value is PluginCapability;
|
|
7
|
+
export declare function readPluginCapabilities(value: unknown): readonly PluginCapability[];
|
|
@@ -18,6 +18,13 @@ export type PluginContentInput =
|
|
|
18
18
|
/** 整份复制一份已有正文:只需要目标的写入权限,插件拿不到正文 */
|
|
19
19
|
| {
|
|
20
20
|
copyOf: PluginContentRef;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 与本插件的一项内容共用同一份正文,任一处的修改在另一处实时可见;只能用于新建卡片、文章、
|
|
24
|
+
* 项目文档与「插入到项目」。删除其中一处不影响另一处。
|
|
25
|
+
*/
|
|
26
|
+
| {
|
|
27
|
+
shareOf: PluginContentRef;
|
|
21
28
|
};
|
|
22
29
|
export declare const CONTENT_INPUT_LIMITS: Readonly<{
|
|
23
30
|
markdown: 2000000;
|
|
@@ -28,7 +35,11 @@ export declare const CONTENT_INPUT_LIMITS: Readonly<{
|
|
|
28
35
|
}>;
|
|
29
36
|
/** 节点结构校验:顶层为元素;元素有 type 与非空 children;文本节点有 text、没有 children。 */
|
|
30
37
|
export declare function assertContentNodes(value: unknown): asserts value is Descendant[];
|
|
31
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* 读取并复制插件传入的正文输入;allowEmpty 为 false 时拒绝空 Markdown 与空节点数组,
|
|
40
|
+
* share 为 true 时才接受 shareOf(新建宿主内容的入口)。
|
|
41
|
+
*/
|
|
32
42
|
export declare function readContentInput(value: unknown, options: {
|
|
33
43
|
allowEmpty: boolean;
|
|
44
|
+
share?: boolean;
|
|
34
45
|
}): PluginContentInput;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { PluginPages } from "./pages";
|
|
2
|
+
import type { PluginEnvironment } from "./environment";
|
|
3
|
+
import type { PluginNavigation } from "./navigation";
|
|
2
4
|
import type { PluginAI, PluginAIFeature } from "./ai";
|
|
3
5
|
import type { WhiteboardExtension } from "./whiteboard";
|
|
4
6
|
import type { PluginServices } from "./services";
|
|
@@ -47,6 +49,8 @@ export interface PluginCommand {
|
|
|
47
49
|
run(input: JsonValue): JsonValue | Promise<JsonValue>;
|
|
48
50
|
}
|
|
49
51
|
export interface PluginContext {
|
|
52
|
+
readonly environment: PluginEnvironment;
|
|
53
|
+
readonly navigation: PluginNavigation;
|
|
50
54
|
readonly backend: PluginBackendClient;
|
|
51
55
|
readonly pluginId: string;
|
|
52
56
|
readonly workspaceId: string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type PluginCapability } from "./capabilities";
|
|
3
|
+
export interface PluginEnvironment {
|
|
4
|
+
readonly platform: "desktop" | "android" | "ios" | "web" | "unknown";
|
|
5
|
+
readonly layout: "compact" | "wide" | "unknown";
|
|
6
|
+
readonly input: Readonly<{
|
|
7
|
+
touch: boolean;
|
|
8
|
+
finePointer: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
/** 可用能力,不代表数据授权或代码隔离。 */
|
|
11
|
+
readonly capabilities: readonly PluginCapability[];
|
|
12
|
+
}
|
|
13
|
+
export interface PluginEnvironmentSource {
|
|
14
|
+
getSnapshot(): PluginEnvironment;
|
|
15
|
+
subscribe(listener: () => void): () => void;
|
|
16
|
+
}
|
|
17
|
+
export declare function createPluginEnvironmentStore(initial: PluginEnvironment): Readonly<{
|
|
18
|
+
getSnapshot: () => PluginEnvironment;
|
|
19
|
+
subscribe: (listener: () => void) => () => void;
|
|
20
|
+
update(patch: Partial<Pick<PluginEnvironment, "layout" | "input">>): void;
|
|
21
|
+
}>;
|
|
22
|
+
/** 由宿主显式选择平台;媒体查询只描述布局和输入,不用于猜测操作系统。 */
|
|
23
|
+
export declare function createBrowserPluginEnvironment(platform: PluginEnvironment["platform"], capabilities: readonly PluginCapability[], viewport: Window): {
|
|
24
|
+
connect(): () => void;
|
|
25
|
+
getSnapshot: () => PluginEnvironment;
|
|
26
|
+
subscribe: (listener: () => void) => () => void;
|
|
27
|
+
update: (patch: Partial<Pick<PluginEnvironment, "layout" | "input">>) => void;
|
|
28
|
+
};
|
|
29
|
+
export declare function PluginEnvironmentProvider(props: {
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
} & ({
|
|
32
|
+
source: PluginEnvironmentSource;
|
|
33
|
+
value?: never;
|
|
34
|
+
} | {
|
|
35
|
+
value: PluginEnvironment;
|
|
36
|
+
source?: never;
|
|
37
|
+
})): import("react").FunctionComponentElement<import("react").ProviderProps<PluginEnvironmentSource | undefined>>;
|
|
38
|
+
/** 静态内容组件也由宿主注入环境,不依赖插件 activate。 */
|
|
39
|
+
export declare function usePluginEnvironment(): PluginEnvironment;
|
|
40
|
+
export declare function snapshotPluginEnvironment(value: PluginEnvironment): PluginEnvironment;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { PluginDefinition } from "./contract";
|
|
2
|
+
export { usePluginEnvironment } from "./environment";
|
|
3
|
+
export type { PluginEnvironment } from "./environment";
|
|
4
|
+
export { PLUGIN_CAPABILITIES, isPluginCapability } from "./capabilities";
|
|
5
|
+
export type { PluginCapability } from "./capabilities";
|
|
6
|
+
export type { PluginNavigation, PluginNavigationEntry } from "./navigation";
|
|
2
7
|
export type { PluginBackendClient, BackendStatus, BackendState } from "./backend";
|
|
3
8
|
export type * from "./upload";
|
|
4
9
|
export type * from "./tts";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Disposable } from "./contract";
|
|
2
|
+
import type { PluginIcon } from "./icons";
|
|
3
|
+
import type { PluginPageHandle, PluginPageParams } from "./pages";
|
|
4
|
+
export interface PluginNavigationEntry {
|
|
5
|
+
id: string;
|
|
6
|
+
title: string;
|
|
7
|
+
icon?: PluginIcon;
|
|
8
|
+
page: PluginPageHandle;
|
|
9
|
+
params?: PluginPageParams;
|
|
10
|
+
}
|
|
11
|
+
export interface PluginNavigation {
|
|
12
|
+
/** 功能入口的具体位置由宿主决定,与页面注册分离。 */
|
|
13
|
+
registerEntry(entry: PluginNavigationEntry): Disposable;
|
|
14
|
+
}
|
|
@@ -11,6 +11,8 @@ export interface PluginPageContext {
|
|
|
11
11
|
* 这里供命令等 effect 之外的回调判断。
|
|
12
12
|
*/
|
|
13
13
|
isActive(): boolean;
|
|
14
|
+
/** 离开前返回 false 阻止导航;组件卸载或插件失活时自动失效。 */
|
|
15
|
+
registerLeaveGuard(guard: () => boolean | Promise<boolean>): Disposable;
|
|
14
16
|
/**
|
|
15
17
|
* 登记一个浮层(抽屉、弹出面板)的关闭函数:用户按 Esc 时 Tau 先关最后登记的浮层,
|
|
16
18
|
* 不会后退页面。只在本页显示时生效。@tau/ui 的模态 Dialog / Drawer 已自带,不必登记;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type PluginManifest } from "./package";
|
|
2
|
+
import { type PluginCapability } from "./capabilities";
|
|
3
|
+
import type { PluginEnvironment } from "./environment";
|
|
4
|
+
export declare const PORTABLE_PLATFORMS: readonly ["desktop", "android", "ios"];
|
|
5
|
+
export type PortablePlatform = (typeof PORTABLE_PLATFORMS)[number];
|
|
6
|
+
export type PluginElementSupport = "none" | "render" | "edit";
|
|
7
|
+
export declare const PORTABLE_SHARED_MODULES: readonly ["@tau/plugins", "@tau/ui", "react", "react-dom", "react-dom/client", "react/jsx-runtime", "react/jsx-dev-runtime"];
|
|
8
|
+
export interface PortablePluginTarget<Capability extends string = PluginCapability> {
|
|
9
|
+
readonly minAppVersion: string;
|
|
10
|
+
readonly required: readonly Capability[];
|
|
11
|
+
readonly optional: readonly Capability[];
|
|
12
|
+
readonly elements?: Readonly<Record<string, PluginElementSupport>>;
|
|
13
|
+
}
|
|
14
|
+
export interface PortablePluginManifest<Capability extends string = PluginCapability> extends Omit<PluginManifest, "formatVersion" | "platform" | "backend" | "whiteboard" | "skills" | "minAppVersion"> {
|
|
15
|
+
readonly formatVersion: 3;
|
|
16
|
+
readonly platform: "portable";
|
|
17
|
+
readonly profile: "web-v1";
|
|
18
|
+
readonly targets: Readonly<Partial<Record<PortablePlatform, PortablePluginTarget<Capability>>>>;
|
|
19
|
+
}
|
|
20
|
+
export type ReadablePortablePluginManifest = PortablePluginManifest<string>;
|
|
21
|
+
export interface PortablePluginHost {
|
|
22
|
+
readonly environment: PluginEnvironment;
|
|
23
|
+
readonly appVersion: string;
|
|
24
|
+
readonly profiles: readonly string[];
|
|
25
|
+
}
|
|
26
|
+
/** 作者与上传入口严格校验能力词表,避免拼写错误被当作可选降级。 */
|
|
27
|
+
export declare function validatePortablePluginManifest(value: unknown): PortablePluginManifest;
|
|
28
|
+
/** 客户端只放宽能力名称的前向读取,结构、格式、权限与摘要声明仍严格校验。 */
|
|
29
|
+
export declare function readPortablePluginManifest(value: unknown): ReadablePortablePluginManifest;
|
|
30
|
+
/** 构建器与中心共用发行范围;不代表中心已开放批准发布。 */
|
|
31
|
+
export declare function validatePortableDistributionManifest(value: unknown): PortablePluginManifest;
|
|
32
|
+
export declare function assertPortablePluginCompatibility(manifest: ReadablePortablePluginManifest, host: PortablePluginHost): PortablePluginTarget<string>;
|
|
33
|
+
export declare function getPortableElementSupport(manifest: ReadablePortablePluginManifest, platform: PortablePlatform, type: string): PluginElementSupport;
|
|
34
|
+
/** 定义求值后对账节点归属;调用方仍须按支持等级装配渲染与提交保护。 */
|
|
35
|
+
export declare function assertPortableElementDeclarations(manifest: ReadablePortablePluginManifest, nodeTypes: readonly string[]): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** 发布数据协议不包含公开路由、DOM、组件或宿主生命周期。 */
|
|
2
|
-
export type DataKind = "home" | "card" | "article" | "doc" | "
|
|
2
|
+
export type DataKind = "home" | "card" | "article" | "doc" | "list";
|
|
3
3
|
export interface ContentRef {
|
|
4
4
|
key: string;
|
|
5
5
|
type: DataKind;
|
|
@@ -10,7 +10,7 @@ export interface ResourceRef {
|
|
|
10
10
|
integrity: string;
|
|
11
11
|
}
|
|
12
12
|
export interface ManifestItem extends ContentRef {
|
|
13
|
-
collectionType?: "card" | "article" | "doc"
|
|
13
|
+
collectionType?: "card" | "article" | "doc";
|
|
14
14
|
title: string;
|
|
15
15
|
projectId?: number;
|
|
16
16
|
data: string;
|
|
@@ -123,58 +123,8 @@ export interface DocData {
|
|
|
123
123
|
createTime: number;
|
|
124
124
|
updateTime: number;
|
|
125
125
|
}
|
|
126
|
-
export type QuestStatus = "not_started" | "in_progress" | "resolved";
|
|
127
|
-
export interface QuestAnswer {
|
|
128
|
-
id: number;
|
|
129
|
-
createTime: number;
|
|
130
|
-
updateTime: number;
|
|
131
|
-
content?: ContentNode[];
|
|
132
|
-
source?: {
|
|
133
|
-
type: "card" | "article" | "project-item" | "custom";
|
|
134
|
-
id?: number;
|
|
135
|
-
contentId: number;
|
|
136
|
-
target?: ContentRef;
|
|
137
|
-
title?: string;
|
|
138
|
-
published: boolean;
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
export interface QuestMaterial {
|
|
142
|
-
index: number;
|
|
143
|
-
kind: string;
|
|
144
|
-
group: "external" | "note" | "discussion";
|
|
145
|
-
title: string;
|
|
146
|
-
meta: string;
|
|
147
|
-
excerpt: string;
|
|
148
|
-
note?: string;
|
|
149
|
-
target?: ContentRef;
|
|
150
|
-
url?: string;
|
|
151
|
-
citeKey?: string;
|
|
152
|
-
}
|
|
153
|
-
export interface QuestTrail {
|
|
154
|
-
time: number;
|
|
155
|
-
tone: "start" | "milestone" | "plain" | "note" | "done";
|
|
156
|
-
text: string;
|
|
157
|
-
refs: number[];
|
|
158
|
-
}
|
|
159
|
-
export interface QuestData {
|
|
160
|
-
id: number;
|
|
161
|
-
title: string;
|
|
162
|
-
summary: string;
|
|
163
|
-
target: ContentRef;
|
|
164
|
-
groupId: number;
|
|
165
|
-
groupTitle: string;
|
|
166
|
-
groupColor?: string;
|
|
167
|
-
status: QuestStatus;
|
|
168
|
-
answers: QuestAnswer[];
|
|
169
|
-
materials: QuestMaterial[];
|
|
170
|
-
trail: QuestTrail[];
|
|
171
|
-
description?: ContentNode[];
|
|
172
|
-
createTime: number;
|
|
173
|
-
updateTime: number;
|
|
174
|
-
resolvedTime?: number | null;
|
|
175
|
-
}
|
|
176
126
|
export interface TimelineItem {
|
|
177
|
-
type: "card" | "article" | "doc"
|
|
127
|
+
type: "card" | "article" | "doc";
|
|
178
128
|
id: number;
|
|
179
129
|
title?: string;
|
|
180
130
|
summary: string;
|
|
@@ -199,15 +149,10 @@ export interface ListItem {
|
|
|
199
149
|
target: ContentRef;
|
|
200
150
|
tags: string[];
|
|
201
151
|
createTime: number;
|
|
202
|
-
updateTime?: number;
|
|
203
|
-
groupId?: number;
|
|
204
|
-
groupTitle?: string;
|
|
205
|
-
status?: QuestStatus;
|
|
206
|
-
answerCount?: number;
|
|
207
152
|
}
|
|
208
153
|
export interface ListData {
|
|
209
154
|
title: string;
|
|
210
|
-
type: "card" | "article" | "doc"
|
|
155
|
+
type: "card" | "article" | "doc";
|
|
211
156
|
items: ListItem[];
|
|
212
157
|
tags?: {
|
|
213
158
|
name: string;
|
|
@@ -228,7 +173,7 @@ export interface CardTagTree {
|
|
|
228
173
|
export interface PublishedCommon {
|
|
229
174
|
version: 1;
|
|
230
175
|
key: string;
|
|
231
|
-
/**
|
|
176
|
+
/** 本文正文里已发布的站内链接目标,键为 `${contentType}:${refId}`;未发布的链接不在其中。 */
|
|
232
177
|
links?: Record<string, ContentRef>;
|
|
233
178
|
pluginRenderers?: import("./render-artifact").PublishedPluginRender[];
|
|
234
179
|
contentStyles?: ResourceRef[];
|
|
@@ -244,7 +189,6 @@ export type PublishedData = {
|
|
|
244
189
|
card: CardData;
|
|
245
190
|
article: ArticleData;
|
|
246
191
|
doc: DocData;
|
|
247
|
-
quest: QuestData;
|
|
248
192
|
list: ListData;
|
|
249
193
|
}[K];
|
|
250
194
|
};
|
|
@@ -256,7 +200,7 @@ export interface DataResult {
|
|
|
256
200
|
settings?: PublishSettings;
|
|
257
201
|
}
|
|
258
202
|
export interface SearchDocument extends ContentRef {
|
|
259
|
-
type: "card" | "article" | "doc"
|
|
203
|
+
type: "card" | "article" | "doc";
|
|
260
204
|
title: string;
|
|
261
205
|
summary: string;
|
|
262
206
|
content: string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type UiRegisterDismiss = (dismiss: () => void) => () => void;
|
|
3
|
+
/** 宿主负责返回仲裁,UI 不依赖任何页面框架。 */
|
|
4
|
+
export declare function UiHostProvider({ registerDismiss, children, }: {
|
|
5
|
+
registerDismiss: UiRegisterDismiss;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
/** 子模态先消费返回,避免同批挂载时子 effect 先执行而颠倒退场顺序。 */
|
|
9
|
+
export declare function UiDismissBoundary({ open, dismiss, children, }: {
|
|
10
|
+
open: boolean;
|
|
11
|
+
dismiss: () => void;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -9,6 +9,7 @@ export { EDIT_TEXT_PLACEHOLDER } from "./primitives/editTextClasses";
|
|
|
9
9
|
export * from "./hooks/index";
|
|
10
10
|
export { isEditableTarget } from "./hooks/isEditableTarget";
|
|
11
11
|
export * from "./UiProvider";
|
|
12
|
+
export { UiHostProvider, type UiRegisterDismiss } from "./UiHostProvider";
|
|
12
13
|
export * from "./primitives/Button";
|
|
13
14
|
export * from "./primitives/IconButton";
|
|
14
15
|
export * from "./primitives/Loading";
|