@xiongtao.xt/tau-plugins 0.46.0 → 0.48.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 +13 -0
- package/LICENSE +21 -21
- package/docs/README.md +49 -49
- package/docs/ai.md +172 -172
- package/docs/api-support.md +28 -28
- package/docs/backend.md +168 -168
- package/docs/content-metrics.md +43 -43
- package/docs/editor-collaboration.md +185 -185
- package/docs/editor.md +635 -635
- package/docs/excerpts.md +126 -126
- package/docs/flashcards.md +127 -127
- package/docs/getting-started.md +46 -46
- package/docs/mcp.md +173 -173
- package/docs/plugin-basics.md +211 -211
- package/docs/portability.md +114 -114
- package/docs/providers/README.md +111 -111
- package/docs/providers/asr.md +50 -43
- package/docs/providers/images.md +69 -65
- package/docs/providers/publish.md +146 -144
- package/docs/providers/sync.md +120 -114
- package/docs/providers/tts.md +48 -77
- package/docs/providers/upload.md +116 -116
- package/docs/providers/video.md +118 -118
- package/docs/release.md +132 -132
- package/docs/services.md +159 -159
- package/docs/site-data.md +90 -90
- package/docs/skills.md +128 -128
- package/docs/storage-and-network.md +68 -68
- package/docs/ui.md +568 -568
- package/docs/user-data.md +714 -714
- package/docs/websocket.md +37 -37
- package/docs/whiteboard-collaboration.md +65 -65
- package/docs/whiteboard.md +337 -337
- package/package.json +1 -1
- package/types/packages/plugins/src/provider-form.d.ts +38 -3
- package/types/packages/plugins/src/settings.d.ts +8 -3
|
@@ -1,187 +1,187 @@
|
|
|
1
1
|
<!-- 由 scripts/plugins/sync-author-docs.mjs 从 packages/plugins/docs/editor-collaboration.md 生成,请勿单独编辑。 -->
|
|
2
2
|
|
|
3
|
-
# 编辑器节点的同步与协作
|
|
4
|
-
|
|
5
|
-
本页对应 SDK 0.45.0 的作者契约。运行时由 Tau 客户端提供,升级 npm 依赖不会更新用户的客户端;插件最低宿主版本须以实际通过验收的发行版为准。
|
|
6
|
-
|
|
7
|
-
## 从旧 SDK 升级
|
|
8
|
-
|
|
9
|
-
1. 将 `@tau/plugins` 别名依赖固定为 `npm:@xiongtao.xt/tau-plugins@0.45.0`,重新生成锁文件并执行类型检查。
|
|
10
|
-
2. 为节点声明 `dataVersion`,把需要并发编辑的字符串列入 `collaboration.textFields`;资源字段沿用 `resources`。
|
|
11
|
-
3. 将源码编辑改为 `SourceBlockEditor` 的 `element + field` 或 `useTextField`,移除 `initValue/onChange` 及通过普通属性补丁整段覆盖源码的写法。
|
|
12
|
-
4. 无损传递正文时同时保留 `nodes` 和 `contracts`;需要保留的折叠、标签等本机视图状态使用 `view/updateView`。
|
|
13
|
-
5. 保存形状变化须声明精确的 `previousVersions` 和 `migrations`,由宿主显式执行转换。只升级插件包不改写已有文档。
|
|
14
|
-
|
|
15
|
-
## 声明与源码编辑
|
|
16
|
-
|
|
17
|
-
```tsx
|
|
18
|
-
const diagram = defineEditorElement<DiagramElement>({
|
|
19
|
-
type: "example.diagram",
|
|
20
|
-
dataVersion: 1,
|
|
21
|
-
kind: "block",
|
|
22
|
-
isVoid: true,
|
|
23
|
-
collaboration: { textFields: ["source"] },
|
|
24
|
-
resources: [{ path: "images[].url", kind: "image" }],
|
|
25
|
-
render: ({ element, attributes, children }) => (
|
|
26
|
-
<div {...attributes}>
|
|
27
|
-
<SourceBlockEditor element={element} field="source" mode="text" title="图表" icon={Code}>
|
|
28
|
-
<DiagramPreview source={element.source} />
|
|
29
|
-
</SourceBlockEditor>
|
|
30
|
-
{children}
|
|
31
|
-
</div>
|
|
32
|
-
),
|
|
33
|
-
});
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
`DiagramElement`、`Code` 和 `DiagramPreview` 是插件自己的节点类型、图标与预览组件。`textFields` 只列不重复的顶层字符串属性。字段不能与宿主身份、结构属性或资源地址重叠。正文其它属性默认同步,对象和数组按整个属性更新。
|
|
37
|
-
|
|
38
|
-
源码使用 `SourceBlockEditor` 的 `element + field`;不要再传 `initValue/onChange`,也不要通过 `useElement().update` 整段覆盖声明的源码字段。预览与编译可以防抖,输入提交不防抖。
|
|
39
|
-
|
|
40
|
-
自定义原生输入复用同一文本句柄:
|
|
41
|
-
|
|
42
|
-
```tsx
|
|
43
|
-
const source = useTextField(element, "source");
|
|
44
|
-
return <textarea ref={source.inputRef} defaultValue={source.value} readOnly={source.readOnly} />;
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
`inputRef` 处理输入法、远端更新、选区、撤销和卸载冲刷,不要再给该输入传受控 `value/onChange`。其它输入组件使用 `edit({ offset, remove, text })` 或 `editBatch`;操作携带句柄读取时的修订,冲突后保留待应用输入。`error` 表示未确认保存,不能当成功关闭并丢弃输入。宿主的原生绑定在失败时保留输入框草稿并停止写入。
|
|
48
|
-
|
|
49
|
-
普通属性仍使用 `useElement(element).update(patch)`。需要重启保留的本机标签、折叠等状态使用同一接口的 `view / updateView(patch)`;临时弹窗放组件状态。编译产物放可重建缓存,不写正文。`activeKey`、`isFold`、`svg` 等名字没有全局过滤规则,插件不得依赖宿主替自己过滤数据。
|
|
50
|
-
|
|
51
|
-
附件沿用 `resources`。没有 `resourceRefs`、`localFields`、`private` 或 `sync` 第二套声明。资源声明只说明位置,上传、解析、访问权限仍由宿主资源能力处理。
|
|
52
|
-
|
|
53
|
-
## 版本升级
|
|
54
|
-
|
|
55
|
-
首次声明用 `dataVersion: 1`。只改渲染、菜单或修复实现不升数据版本;改变源码字段、资源字段或持久化形状时升数据版本。宿主生成契约摘要,作者不编写摘要或客户端兼容范围。
|
|
56
|
-
|
|
57
|
-
以下完整入口使用 `lucide-react` 图标;在插件工程先执行 `pnpm add lucide-react`。
|
|
58
|
-
|
|
59
|
-
```tsx
|
|
60
|
-
import {
|
|
61
|
-
definePlugin,
|
|
62
|
-
defineEditorExtension,
|
|
63
|
-
defineEditorElement,
|
|
64
|
-
SourceBlockEditor,
|
|
65
|
-
type EditorElementRenderProps,
|
|
66
|
-
} from "@tau/plugins";
|
|
67
|
-
import { Code } from "lucide-react";
|
|
68
|
-
|
|
69
|
-
interface DiagramV1 {
|
|
70
|
-
type: "example.diagram";
|
|
71
|
-
source: string;
|
|
72
|
-
title?: string;
|
|
73
|
-
children: { type: "formatted"; text: string }[];
|
|
74
|
-
}
|
|
75
|
-
interface DiagramV2 {
|
|
76
|
-
type: "example.diagram";
|
|
77
|
-
code: string;
|
|
78
|
-
title?: string;
|
|
79
|
-
children: { type: "formatted"; text: string }[];
|
|
80
|
-
}
|
|
81
|
-
declare module "@tau/plugins" {
|
|
82
|
-
interface EditorElementMap {
|
|
83
|
-
"example.diagram": DiagramV1 | DiagramV2;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
declare const __PLUGIN_META__: { id: string; name: string; version: string };
|
|
87
|
-
|
|
88
|
-
function DiagramV1View({ attributes, element, children }: EditorElementRenderProps<DiagramV1>) {
|
|
89
|
-
return (
|
|
90
|
-
<div {...attributes}>
|
|
91
|
-
<SourceBlockEditor
|
|
92
|
-
element={element}
|
|
93
|
-
field="source"
|
|
94
|
-
mode="text"
|
|
95
|
-
title={element.title ?? "图表"}
|
|
96
|
-
icon={Code}
|
|
97
|
-
>
|
|
98
|
-
<pre contentEditable={false}>{element.source}</pre>
|
|
99
|
-
{children}
|
|
100
|
-
</SourceBlockEditor>
|
|
101
|
-
</div>
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
function DiagramV2View({ attributes, element, children }: EditorElementRenderProps<DiagramV2>) {
|
|
105
|
-
return (
|
|
106
|
-
<div {...attributes}>
|
|
107
|
-
<SourceBlockEditor
|
|
108
|
-
element={element}
|
|
109
|
-
field="code"
|
|
110
|
-
mode="text"
|
|
111
|
-
title={element.title ?? "图表"}
|
|
112
|
-
icon={Code}
|
|
113
|
-
>
|
|
114
|
-
<pre contentEditable={false}>{element.code}</pre>
|
|
115
|
-
{children}
|
|
116
|
-
</SourceBlockEditor>
|
|
117
|
-
</div>
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const v1 = defineEditorElement<DiagramV1>({
|
|
122
|
-
type: "example.diagram",
|
|
123
|
-
dataVersion: 1,
|
|
124
|
-
kind: "block",
|
|
125
|
-
isVoid: true,
|
|
126
|
-
collaboration: { textFields: ["source"] },
|
|
127
|
-
render: DiagramV1View,
|
|
128
|
-
});
|
|
129
|
-
const v2 = defineEditorElement<DiagramV2>({
|
|
130
|
-
type: "example.diagram",
|
|
131
|
-
dataVersion: 2,
|
|
132
|
-
kind: "block",
|
|
133
|
-
isVoid: true,
|
|
134
|
-
collaboration: { textFields: ["code"] },
|
|
135
|
-
render: DiagramV2View,
|
|
136
|
-
previousVersions: [{ element: v1, access: "edit" }],
|
|
137
|
-
migrations: [
|
|
138
|
-
{
|
|
139
|
-
from: 1,
|
|
140
|
-
migrate(data) {
|
|
141
|
-
if (typeof data.source !== "string") throw new Error("旧版源码字段无效");
|
|
142
|
-
if (Object.hasOwn(data, "code")) throw new Error("目标字段已存在,请保留两份内容后处理");
|
|
143
|
-
const { source, ...rest } = data;
|
|
144
|
-
return { ...rest, code: source };
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
],
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
export default definePlugin({
|
|
151
|
-
...__PLUGIN_META__,
|
|
152
|
-
editorExtensions: [
|
|
153
|
-
defineEditorExtension({
|
|
154
|
-
id: "example.diagram",
|
|
155
|
-
elements: [v2],
|
|
156
|
-
blockPanel: [
|
|
157
|
-
{
|
|
158
|
-
icon: Code,
|
|
159
|
-
title: "源码图表",
|
|
160
|
-
description: "插入可协作编辑的源码图表",
|
|
161
|
-
keywords: ["图表", "源码"],
|
|
162
|
-
onClick: editor =>
|
|
163
|
-
editor.insertNode({
|
|
164
|
-
type: "example.diagram",
|
|
165
|
-
code: "",
|
|
166
|
-
children: [{ type: "formatted", text: "" }],
|
|
167
|
-
}),
|
|
168
|
-
},
|
|
169
|
-
],
|
|
170
|
-
}),
|
|
171
|
-
],
|
|
172
|
-
});
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
上例是 v2 的完整相关入口,`__PLUGIN_META__` 由模板注入。v1 发布时注册 `v1`,创建动作写 `source`;升级后只注册 `v2`,旧定义放在 `previousVersions`,不并列注册同名类型。新增可选 `title` 不改变文本或资源解释,仍可使用数据版本 1。安装 v2 不改写已有节点;共享文档的字段改名由宿主显式转换并切换基线。
|
|
176
|
-
|
|
177
|
-
`previousVersions` 按需保留准确的旧声明和渲染,`access` 选 `read` 或 `edit`。省略旧版本时宿主保留原数据并禁写,不把旧节点交给新版渲染器猜测。`migrations` 是旧版本到当前版本的直接转换,不需要维护任意版本之间的图。
|
|
178
|
-
|
|
179
|
-
转换函数同步返回完整业务属性,保留未知属性;不能访问网络、数据库、时间或随机数。`type`、`children` 与宿主身份由宿主保留,转换函数不能修改。宿主在用户选择升级后备份、校验并安装,不在打开文档或规范化时偷偷转换。
|
|
180
|
-
|
|
181
|
-
旧、新 Markdown 导出器用现有 `editorCodecs` 的 `dataVersion` 区分。普通 Markdown 只使用当前导入语法;导出按节点保存的精确契约分发,没有匹配导出器或导出失败时保留带契约的无损载荷。不能让旧 codec 抢占新版导入语法。
|
|
182
|
-
|
|
183
|
-
## 正文传递与旧数据
|
|
184
|
-
|
|
185
|
-
`content.read({ format: "nodes" })` 返回 `nodes` 与 `contracts`,无损写回应一起传回 `{ nodes, contracts }`。创建已声明的新节点可省略字典,由宿主准备;复制未知节点必须保留来源字典,或直接使用已有的 `copyOf`。`shareOf` 继续表示共用同一份正文。
|
|
186
|
-
|
|
187
|
-
缺插件、声明冲突或新版本不受支持时,原节点和资源声明仍随文档保存;插件不要用空节点替换读取失败的数据。旧 private blocks 只由升级入口收集与保全,普通正文不再按设备替换真身。旧私有内容进入共享正文需要持有者提供和所有者确认,不能借升级自动公开。
|
|
3
|
+
# 编辑器节点的同步与协作
|
|
4
|
+
|
|
5
|
+
本页对应 SDK 0.45.0 的作者契约。运行时由 Tau 客户端提供,升级 npm 依赖不会更新用户的客户端;插件最低宿主版本须以实际通过验收的发行版为准。
|
|
6
|
+
|
|
7
|
+
## 从旧 SDK 升级
|
|
8
|
+
|
|
9
|
+
1. 将 `@tau/plugins` 别名依赖固定为 `npm:@xiongtao.xt/tau-plugins@0.45.0`,重新生成锁文件并执行类型检查。
|
|
10
|
+
2. 为节点声明 `dataVersion`,把需要并发编辑的字符串列入 `collaboration.textFields`;资源字段沿用 `resources`。
|
|
11
|
+
3. 将源码编辑改为 `SourceBlockEditor` 的 `element + field` 或 `useTextField`,移除 `initValue/onChange` 及通过普通属性补丁整段覆盖源码的写法。
|
|
12
|
+
4. 无损传递正文时同时保留 `nodes` 和 `contracts`;需要保留的折叠、标签等本机视图状态使用 `view/updateView`。
|
|
13
|
+
5. 保存形状变化须声明精确的 `previousVersions` 和 `migrations`,由宿主显式执行转换。只升级插件包不改写已有文档。
|
|
14
|
+
|
|
15
|
+
## 声明与源码编辑
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
const diagram = defineEditorElement<DiagramElement>({
|
|
19
|
+
type: "example.diagram",
|
|
20
|
+
dataVersion: 1,
|
|
21
|
+
kind: "block",
|
|
22
|
+
isVoid: true,
|
|
23
|
+
collaboration: { textFields: ["source"] },
|
|
24
|
+
resources: [{ path: "images[].url", kind: "image" }],
|
|
25
|
+
render: ({ element, attributes, children }) => (
|
|
26
|
+
<div {...attributes}>
|
|
27
|
+
<SourceBlockEditor element={element} field="source" mode="text" title="图表" icon={Code}>
|
|
28
|
+
<DiagramPreview source={element.source} />
|
|
29
|
+
</SourceBlockEditor>
|
|
30
|
+
{children}
|
|
31
|
+
</div>
|
|
32
|
+
),
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`DiagramElement`、`Code` 和 `DiagramPreview` 是插件自己的节点类型、图标与预览组件。`textFields` 只列不重复的顶层字符串属性。字段不能与宿主身份、结构属性或资源地址重叠。正文其它属性默认同步,对象和数组按整个属性更新。
|
|
37
|
+
|
|
38
|
+
源码使用 `SourceBlockEditor` 的 `element + field`;不要再传 `initValue/onChange`,也不要通过 `useElement().update` 整段覆盖声明的源码字段。预览与编译可以防抖,输入提交不防抖。
|
|
39
|
+
|
|
40
|
+
自定义原生输入复用同一文本句柄:
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
const source = useTextField(element, "source");
|
|
44
|
+
return <textarea ref={source.inputRef} defaultValue={source.value} readOnly={source.readOnly} />;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`inputRef` 处理输入法、远端更新、选区、撤销和卸载冲刷,不要再给该输入传受控 `value/onChange`。其它输入组件使用 `edit({ offset, remove, text })` 或 `editBatch`;操作携带句柄读取时的修订,冲突后保留待应用输入。`error` 表示未确认保存,不能当成功关闭并丢弃输入。宿主的原生绑定在失败时保留输入框草稿并停止写入。
|
|
48
|
+
|
|
49
|
+
普通属性仍使用 `useElement(element).update(patch)`。需要重启保留的本机标签、折叠等状态使用同一接口的 `view / updateView(patch)`;临时弹窗放组件状态。编译产物放可重建缓存,不写正文。`activeKey`、`isFold`、`svg` 等名字没有全局过滤规则,插件不得依赖宿主替自己过滤数据。
|
|
50
|
+
|
|
51
|
+
附件沿用 `resources`。没有 `resourceRefs`、`localFields`、`private` 或 `sync` 第二套声明。资源声明只说明位置,上传、解析、访问权限仍由宿主资源能力处理。
|
|
52
|
+
|
|
53
|
+
## 版本升级
|
|
54
|
+
|
|
55
|
+
首次声明用 `dataVersion: 1`。只改渲染、菜单或修复实现不升数据版本;改变源码字段、资源字段或持久化形状时升数据版本。宿主生成契约摘要,作者不编写摘要或客户端兼容范围。
|
|
56
|
+
|
|
57
|
+
以下完整入口使用 `lucide-react` 图标;在插件工程先执行 `pnpm add lucide-react`。
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import {
|
|
61
|
+
definePlugin,
|
|
62
|
+
defineEditorExtension,
|
|
63
|
+
defineEditorElement,
|
|
64
|
+
SourceBlockEditor,
|
|
65
|
+
type EditorElementRenderProps,
|
|
66
|
+
} from "@tau/plugins";
|
|
67
|
+
import { Code } from "lucide-react";
|
|
68
|
+
|
|
69
|
+
interface DiagramV1 {
|
|
70
|
+
type: "example.diagram";
|
|
71
|
+
source: string;
|
|
72
|
+
title?: string;
|
|
73
|
+
children: { type: "formatted"; text: string }[];
|
|
74
|
+
}
|
|
75
|
+
interface DiagramV2 {
|
|
76
|
+
type: "example.diagram";
|
|
77
|
+
code: string;
|
|
78
|
+
title?: string;
|
|
79
|
+
children: { type: "formatted"; text: string }[];
|
|
80
|
+
}
|
|
81
|
+
declare module "@tau/plugins" {
|
|
82
|
+
interface EditorElementMap {
|
|
83
|
+
"example.diagram": DiagramV1 | DiagramV2;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
declare const __PLUGIN_META__: { id: string; name: string; version: string };
|
|
87
|
+
|
|
88
|
+
function DiagramV1View({ attributes, element, children }: EditorElementRenderProps<DiagramV1>) {
|
|
89
|
+
return (
|
|
90
|
+
<div {...attributes}>
|
|
91
|
+
<SourceBlockEditor
|
|
92
|
+
element={element}
|
|
93
|
+
field="source"
|
|
94
|
+
mode="text"
|
|
95
|
+
title={element.title ?? "图表"}
|
|
96
|
+
icon={Code}
|
|
97
|
+
>
|
|
98
|
+
<pre contentEditable={false}>{element.source}</pre>
|
|
99
|
+
{children}
|
|
100
|
+
</SourceBlockEditor>
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
function DiagramV2View({ attributes, element, children }: EditorElementRenderProps<DiagramV2>) {
|
|
105
|
+
return (
|
|
106
|
+
<div {...attributes}>
|
|
107
|
+
<SourceBlockEditor
|
|
108
|
+
element={element}
|
|
109
|
+
field="code"
|
|
110
|
+
mode="text"
|
|
111
|
+
title={element.title ?? "图表"}
|
|
112
|
+
icon={Code}
|
|
113
|
+
>
|
|
114
|
+
<pre contentEditable={false}>{element.code}</pre>
|
|
115
|
+
{children}
|
|
116
|
+
</SourceBlockEditor>
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const v1 = defineEditorElement<DiagramV1>({
|
|
122
|
+
type: "example.diagram",
|
|
123
|
+
dataVersion: 1,
|
|
124
|
+
kind: "block",
|
|
125
|
+
isVoid: true,
|
|
126
|
+
collaboration: { textFields: ["source"] },
|
|
127
|
+
render: DiagramV1View,
|
|
128
|
+
});
|
|
129
|
+
const v2 = defineEditorElement<DiagramV2>({
|
|
130
|
+
type: "example.diagram",
|
|
131
|
+
dataVersion: 2,
|
|
132
|
+
kind: "block",
|
|
133
|
+
isVoid: true,
|
|
134
|
+
collaboration: { textFields: ["code"] },
|
|
135
|
+
render: DiagramV2View,
|
|
136
|
+
previousVersions: [{ element: v1, access: "edit" }],
|
|
137
|
+
migrations: [
|
|
138
|
+
{
|
|
139
|
+
from: 1,
|
|
140
|
+
migrate(data) {
|
|
141
|
+
if (typeof data.source !== "string") throw new Error("旧版源码字段无效");
|
|
142
|
+
if (Object.hasOwn(data, "code")) throw new Error("目标字段已存在,请保留两份内容后处理");
|
|
143
|
+
const { source, ...rest } = data;
|
|
144
|
+
return { ...rest, code: source };
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
export default definePlugin({
|
|
151
|
+
...__PLUGIN_META__,
|
|
152
|
+
editorExtensions: [
|
|
153
|
+
defineEditorExtension({
|
|
154
|
+
id: "example.diagram",
|
|
155
|
+
elements: [v2],
|
|
156
|
+
blockPanel: [
|
|
157
|
+
{
|
|
158
|
+
icon: Code,
|
|
159
|
+
title: "源码图表",
|
|
160
|
+
description: "插入可协作编辑的源码图表",
|
|
161
|
+
keywords: ["图表", "源码"],
|
|
162
|
+
onClick: editor =>
|
|
163
|
+
editor.insertNode({
|
|
164
|
+
type: "example.diagram",
|
|
165
|
+
code: "",
|
|
166
|
+
children: [{ type: "formatted", text: "" }],
|
|
167
|
+
}),
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
}),
|
|
171
|
+
],
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
上例是 v2 的完整相关入口,`__PLUGIN_META__` 由模板注入。v1 发布时注册 `v1`,创建动作写 `source`;升级后只注册 `v2`,旧定义放在 `previousVersions`,不并列注册同名类型。新增可选 `title` 不改变文本或资源解释,仍可使用数据版本 1。安装 v2 不改写已有节点;共享文档的字段改名由宿主显式转换并切换基线。
|
|
176
|
+
|
|
177
|
+
`previousVersions` 按需保留准确的旧声明和渲染,`access` 选 `read` 或 `edit`。省略旧版本时宿主保留原数据并禁写,不把旧节点交给新版渲染器猜测。`migrations` 是旧版本到当前版本的直接转换,不需要维护任意版本之间的图。
|
|
178
|
+
|
|
179
|
+
转换函数同步返回完整业务属性,保留未知属性;不能访问网络、数据库、时间或随机数。`type`、`children` 与宿主身份由宿主保留,转换函数不能修改。宿主在用户选择升级后备份、校验并安装,不在打开文档或规范化时偷偷转换。
|
|
180
|
+
|
|
181
|
+
旧、新 Markdown 导出器用现有 `editorCodecs` 的 `dataVersion` 区分。普通 Markdown 只使用当前导入语法;导出按节点保存的精确契约分发,没有匹配导出器或导出失败时保留带契约的无损载荷。不能让旧 codec 抢占新版导入语法。
|
|
182
|
+
|
|
183
|
+
## 正文传递与旧数据
|
|
184
|
+
|
|
185
|
+
`content.read({ format: "nodes" })` 返回 `nodes` 与 `contracts`,无损写回应一起传回 `{ nodes, contracts }`。创建已声明的新节点可省略字典,由宿主准备;复制未知节点必须保留来源字典,或直接使用已有的 `copyOf`。`shareOf` 继续表示共用同一份正文。
|
|
186
|
+
|
|
187
|
+
缺插件、声明冲突或新版本不受支持时,原节点和资源声明仍随文档保存;插件不要用空节点替换读取失败的数据。旧 private blocks 只由升级入口收集与保全,普通正文不再按设备替换真身。旧私有内容进入共享正文需要持有者提供和所有者确认,不能借升级自动公开。
|