@xiongtao.xt/tau-plugins 0.43.0 → 0.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/client/chunk-UTVEXGFI.js +30 -0
  3. package/client/{fuse-M2Z6NNAT.js → fuse-KWYBABFA.js} +2 -0
  4. package/docs/README.md +3 -1
  5. package/docs/api-support.md +6 -2
  6. package/docs/content-metrics.md +45 -0
  7. package/docs/editor.md +4 -0
  8. package/docs/getting-started.md +2 -2
  9. package/docs/plugin-basics.md +1 -0
  10. package/docs/portability.md +1 -1
  11. package/docs/providers/asr.md +1 -1
  12. package/package.js +1 -0
  13. package/package.json +1 -1
  14. package/portable.js +1 -0
  15. package/publish-artifacts.js +114 -4
  16. package/publish-client.js +3 -1
  17. package/types/packages/db-schema/content-contracts.d.ts +80 -0
  18. package/types/packages/db-schema/content-metrics.d.ts +30 -0
  19. package/types/packages/db-schema/content-resources.d.ts +4 -0
  20. package/types/packages/editor/contracts.d.ts +2 -2
  21. package/types/packages/editor/source-contracts.d.ts +67 -3
  22. package/types/packages/editor/src/core/api/elementVersions.d.ts +12 -0
  23. package/types/packages/editor/src/core/api/extension.d.ts +15 -0
  24. package/types/packages/editor/src/core/api/index.d.ts +3 -0
  25. package/types/packages/editor/src/core/api/useTextFieldBinding.d.ts +9 -0
  26. package/types/packages/editor/src/core/kit/ExtensionAssembly.d.ts +5 -1
  27. package/types/packages/markdown/src/codec.d.ts +2 -0
  28. package/types/packages/markdown/src/index.d.ts +1 -0
  29. package/types/packages/markdown/src/markdown-helper.d.ts +3 -0
  30. package/types/packages/markdown/src/markdownSerializerRegistry.d.ts +8 -2
  31. package/types/packages/markdown/src/positionMapper.d.ts +1 -0
  32. package/types/packages/markdown/src/processor.d.ts +3 -0
  33. package/types/packages/markdown/src/unknownNode.d.ts +24 -0
  34. package/types/packages/plugins/src/contract.d.ts +3 -0
  35. package/types/packages/plugins/src/editor.d.ts +4 -0
  36. package/types/packages/plugins/src/index.d.ts +2 -2
  37. package/types/packages/plugins/src/rendering.d.ts +1 -1
  38. package/types/packages/plugins/src/source-editor.d.ts +2 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # 更新记录
2
2
 
3
+ ## 0.44.0
4
+
5
+ - 新增 EditorMetricRule 与静态 editorMetrics 声明,扩展拥有自己的文本字段规则。
6
+ - 字数算法与子树遍历统一,桌面进程只接收可序列化规则,移动日记沿用同一结果。
7
+ - 空文档判断与字数分离,零字数的媒体、结构块和未知节点不会被自动清理。
8
+
3
9
  ## 0.43.0
4
10
 
5
11
  - 新增统一 ASR 提供方契约、流式会话、取消与最终结果规则。
@@ -0,0 +1,30 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ export {
28
+ __commonJS,
29
+ __toESM
30
+ };
@@ -1,3 +1,5 @@
1
+ import "./chunk-UTVEXGFI.js";
2
+
1
3
  // node_modules/.pnpm/fuse.js@7.4.1/node_modules/fuse.js/dist/fuse.mjs
2
4
  function isArray(value) {
3
5
  return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
package/docs/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Tau 插件开发文档
2
2
 
3
- 默认模板使用 SDK 0.43.0、UI 0.5.0,生成格式 3 的同一插件包。中心 v2 支持上传待审,格式 3 普通提交人工批准,具审核权限的作者本人经已绑定仓库 CI 发布可自动批准;平台测试由作者负责,不要求审核者测试或填写验证记录。Android/iOS 正式安装要求客户端至少 0.2.4,并通过中心兼容选版。先读 [API 支持矩阵](api-support.md)、[跨端契约](portability.md)与[快速开始](getting-started.md)。下文桌面领域接口不表示移动端可用。
3
+ 默认模板使用 SDK 0.44.0、UI 0.5.0,生成格式 3 的同一插件包。中心 v2 支持上传待审,格式 3 普通提交人工批准,具审核权限的作者本人经已绑定仓库 CI 发布可自动批准;平台测试由作者负责,不要求审核者测试或填写验证记录。Android/iOS 正式安装要求客户端至少 0.2.4,并通过中心兼容选版。先读 [API 支持矩阵](api-support.md)、[跨端契约](portability.md)与[快速开始](getting-started.md)。下文桌面领域接口不表示移动端可用。
4
4
 
5
5
  Tau 插件用 TypeScript 和 React 编写,打包成一个 ZIP,按声明在兼容的 Tau 宿主运行。插件可以给 Tau 加页面和侧边栏入口,在文档里放自定义块,给 AI 提供工具,接入第三方存储、语音、视频等服务,或者读写用户的卡片和待办。
6
6
 
@@ -45,3 +45,5 @@ Tau 插件用 TypeScript 和 React 编写,打包成一个 ZIP,按声明在
45
45
  ## 给 AI 编程助手
46
46
 
47
47
  模板根目录的 `AGENTS.md` 是给 AI 编程助手看的项目指引。用 AI 写插件时,让它先读 `AGENTS.md` 和本目录下与任务相关的文档。
48
+
49
+ - [正文字数与空文档](content-metrics.md):声明节点文本字段,避免把零字数当成空正文。
@@ -39,9 +39,9 @@
39
39
 
40
40
  ## ASR 与 WebSocket
41
41
 
42
- SDK 0.43.0 的 `context.asr`、`context.websocket` 与 `settings target: "asr"` 已接桌面 0.59.5、Android/iOS 0.2.7 宿主源码。移动插件使用同一注册、配置和事件接口,音频由宿主采集,插件不访问麦克风。设备与真实云端账号验收单独记录;Windows 原生识别仍待验证,不影响插件契约。
42
+ SDK 0.43.0 的 `context.asr`、`context.websocket` 与 `settings target: "asr"` 已接桌面 0.59.5、Android/iOS 0.2.7 宿主源码。移动插件使用同一注册、配置和事件接口,音频由宿主采集,插件不访问麦克风。当前仅保留能力层,语音输入与整理的按钮、设置页和导航尚未挂载;ASR 表单可注册,open 返回入口不可用。设备与真实云端账号验收单独记录;Windows 原生识别仍待验证,不影响插件契约。
43
43
 
44
- ASR 支持能力探测、可取消的流式会话与可选文件任务;提供方必须真实声明能力,Seed 当前仅流式。WebSocket 的工厂仅扩展鉴权头和 signal,连接保留标准事件、状态、同步 send/close;详见 [WebSocket 契约](websocket.md)。聊天和搜索只在最终结果后写入草稿;桌面可选 AI 整理复用现有模型配置,移动暂使用原文。
44
+ ASR 支持能力探测、可取消的流式会话与可选文件任务;提供方必须真实声明能力,Seed 当前仅流式。WebSocket 的工厂仅扩展鉴权头和 signal,连接保留标准事件、状态、同步 send/close;详见 [WebSocket 契约](websocket.md)。桌面整理服务复用现有模型配置,保留原文和失败回退;输入目标及界面位置由后续接入方决定。
45
45
 
46
46
  ## 正文、UI 与交互
47
47
 
@@ -76,3 +76,7 @@ ASR 支持能力探测、可取消的流式会话与可选文件任务;提供
76
76
  5. SDK、模板、中心与宿主共用平台和版本契约;不保留重复能力声明或名称映射。普通提交人工批准,具审核权限的作者本人通过已绑定仓库 CI 发布可自动批准。平台适配与功能测试由作者负责,不要求审核者测试或填写验证记录。是否可安装由平台、客户端版本与中心开关共同决定,不能由 npm 版本推断。移动中心首次安装默认保存启用意图,下次打开生效;桌面新装默认停用,用户启用后重启内容插件;更新保留显式启停选择。任意开发 URL 安装仅限调试构建。
77
77
 
78
78
  已完成的自动测试与模拟器行为验证不替代真机、最低系统、完整 IPA、桌面原生安装包发行、未知旧作者迁移或应用商店验收。
79
+
80
+ ## 正文字数
81
+
82
+ SDK 0.44.0 的静态 editorMetrics 在桌面与移动内容注册表装配;桌面主进程只接收校验过的字段声明,不执行插件函数。动态工作台使用 metrics 字段。作者用法见[正文字数与空文档](content-metrics.md)。
@@ -0,0 +1,45 @@
1
+ <!-- 由 scripts/plugins/sync-author-docs.mjs 从 packages/plugins/docs/content-metrics.md 生成,请勿单独编辑。 -->
2
+
3
+ # 正文字数与空文档
4
+
5
+ SDK 0.44.0 提供 `EditorMetricRule`,在 `definePlugin` 的静态 `editorMetrics` 注册。它与 `editorCodecs` 并列,不依赖 Markdown 或 `activate`。
6
+
7
+ ## 声明字段
8
+
9
+ ```ts
10
+ import type { EditorMetricRule } from "@tau/plugins";
11
+
12
+ export const editorMetrics = [
13
+ { type: "example.quiz", textFields: ["question", "answers[].text"] },
14
+ ] as const satisfies readonly EditorMetricRule[];
15
+ ```
16
+
17
+ 将这份数组作为 `definePlugin({ ...meta, editorExtensions, editorMetrics })` 的字段;`editorExtensions` 必须注册 `example.quiz`。规则只能声明本插件拥有的节点类型,同类型只能声明一次。字段路径支持对象属性和数组项,例如 `answers[].text`;缺失或非字符串字段不计数。只声明正文,不声明 ID、URL、渲染缓存或编译产物。
18
+
19
+ 题目“天空是什么颜色”、答案“蓝色”合计 9 字。HTML、公式、乐谱等源码节点可声明对应源码字段,文字的分词算法仍由宿主统一执行。纯图片节点可用 `textFields: []` 明确不统计资源元信息。
20
+
21
+ ## 子树与口径
22
+
23
+ 普通 `children` 自动递归,文本叶子的 `text` 自动计数。不要在父节点重新声明 `children[].text`,否则会重复统计。表格、列表与容器的普通子树无需专门规则。正文在其他位置时才使用 `additionalChildren`:
24
+
25
+ ```ts
26
+ const foldedList = {
27
+ type: "example.folded-list",
28
+ textFields: [],
29
+ additionalChildren: [{ path: "allContent", when: "isFold", skip: 1 }],
30
+ } satisfies EditorMetricRule;
31
+ ```
32
+
33
+ `path` 指定附加节点或节点数组;`when` 要求当前节点的布尔字段为 true;`skip` 跳过开头指定项。包装数组可用 `childrenPath` 指定项内的正文;`exclude: { field, equalsField }` 排除项标识与父节点当前标识相同的项。这些声明用于仍有非 children 子树的模型,新增模型优先把全部正文放进 children。
34
+
35
+ 规则是纯数据,不能传入函数,不读取 DOM、网络或生命周期状态。宿主校验后冻结快照,桌面窗口、主进程、移动保存与协作投影使用同一算法。规则换代会失效字数缓存;开发台的动态贡献通过 `metrics` 字段传入,只作用于该工作台。
36
+
37
+ 缺少插件时只统计能解释的文本子树,不猜测私有字段、不把 JSON 序列化长度当字数;私有源码恢复插件后重新计入。规则按当前节点字段解释,不改变节点数据版本或正文。既有数据库 count 为派生缓存,正文再次保存时按当前规则重算。
38
+
39
+ ## 空文档
40
+
41
+ `wordCount === 0` 不能用于判空、复用草稿或自动删除。图片、分割线、未知节点、只有标点的正文都可能为零字数。宿主自动清理只识别空文本和空段落,结构块及损坏数据保守保留。编辑器的 `ElementSpec.isEmpty` 属于交互语义,继续控制扩展内部的退格和导航,不作为文档自动清理依据。
42
+
43
+ ## 验证
44
+
45
+ 为节点提供普通文本、空文本、嵌套子树及缺少插件的样例。核对页面字数与保存返回值一致,切换折叠不改变总字数,纯媒体保存后不会被当作空草稿复用或删除。构建通过不代表客户端或真机验收通过。
package/docs/editor.md CHANGED
@@ -626,3 +626,7 @@ defineEditorExtension({
626
626
  ```
627
627
 
628
628
  `toHtml` 返回 HTML 字符串,文本内容要自己转义。它只用于静态导出,博客里的显示仍然使用 `render`。
629
+
630
+ ## 正文字数与空文档
631
+
632
+ 自定义节点通过 SDK 0.44.0 的 `editorMetrics` 声明哪些字段参与统计,与 `editorExtensions`、`editorCodecs` 一起静态导出。代码示例、数组字段、容器遍历与空文档边界见[正文字数协议](content-metrics.md)。
@@ -12,7 +12,7 @@ pnpm install --frozen-lockfile
12
12
  pnpm build
13
13
  ```
14
14
 
15
- SDK 0.43.0 已发布到 npm,直接使用上述冻结安装与构建命令,无需本地 tarball。SDK 发布不代表插件或 APP 已发布;客户端要求以清单和支持矩阵为准。
15
+ 模板声明 SDK 0.44.0。候选阶段在仓库外复制模板并通过 use-local-sdk.mjs 注入生成的 SDK/UI tarball,运行 pnpm install、pnpm build;公开发布并更新正式锁文件后再使用上述冻结安装命令。SDK 发布不代表插件或 APP 已发布;客户端要求以清单和支持矩阵为准。
16
16
 
17
17
  3. 构建生成 `dist/<插件ID>-<版本>.zip`;再次安装可用 `pnpm install --frozen-lockfile`。
18
18
  4. 在目标宿主验证后按发布指南上传待审;格式 3 普通提交人工审核,具审核权限的作者本人通过已绑定仓库 CI 发布可自动批准。移动用户从应用内中心安装,首次安装保存启用意图,重开应用生效;桌面 0.59.1 支持格式 3 中心安装,首次安装后需在已安装页启用并重启。install:local 不把格式 3 写进旧桌面正式目录。
@@ -43,4 +43,4 @@ SDK 0.43.0 已发布到 npm,直接使用上述冻结安装与构建命令,
43
43
 
44
44
  ## 开发语音识别插件
45
45
 
46
- ASR 与标准 WebSocket 需要 SDK 0.43.0、桌面 0.59.5 或移动 0.2.7。模板已使用 npm 的 SDK 0.43.0;冻结安装、构建后再在目标宿主验证。接口见 [语音识别](providers/asr.md) 与 [WebSocket](websocket.md)。SDK 可安装不代表客户端已经发行,最低客户端版本与平台分发仍由插件清单控制。
46
+ ASR 与标准 WebSocket 需要 SDK 0.43.0、桌面 0.59.5 或移动 0.2.7。模板声明 SDK 0.44.0;按本页候选验证或正式安装流程构建后再在目标宿主验证。接口见 [语音识别](providers/asr.md) 与 [WebSocket](websocket.md)。SDK 可安装不代表客户端已经发行,最低客户端版本与平台分发仍由插件清单控制。
@@ -97,6 +97,7 @@ export default definePlugin({
97
97
  | ---------------------- | ---------- | --------------------------------------------------------------------- |
98
98
  | `create` | 运行时逻辑 | 每次启用时调用,返回本次运行的实例。只有静态声明的插件可以省略 |
99
99
  | `editorExtensions` | 静态声明 | 编辑器块,见[编辑器扩展](editor.md) |
100
+ | `editorMetrics` | 静态声明 | 自定义节点的统计字段,见[正文字数](content-metrics.md) |
100
101
  | `editorCodecs` | 静态声明 | 编辑器块的 Markdown 转换,见[编辑器扩展](editor.md#markdown-导入导出) |
101
102
  | `whiteboardExtensions` | 静态声明 | 白板元素与工具,见[白板扩展](whiteboard.md) |
102
103
  | `ai` | 静态声明 | 插件自定义的 AI 功能,见 [AI](ai.md#自定义-ai-功能) |
@@ -111,4 +111,4 @@ React、SDK 与公共 UI 由宿主提供,其他浏览器依赖随包构建;
111
111
 
112
112
  ## 语音输入提供方
113
113
 
114
- ASR 与语音合成是独立注册。语音输入插件使用 `context.asr.register` 和 `settings target: "asr"`,账号通过 `asrConfig.save(value, modelId)` 保存;麦克风、重采样、输入目标、提交守卫由宿主管理。SDK 0.43.0 要求 ASR 目标最低桌面 0.59.5、移动 0.2.7。`context.websocket.connect` 同步返回标准 WebSocket 接口形状,鉴权头和任务 signal 为第三参扩展;两端的发送背压、关闭握手和插件生命周期由宿主统一处理。详见 [WebSocket](websocket.md)。
114
+ ASR 与语音合成是独立注册。语音输入插件使用 `context.asr.register` 和 `settings target: "asr"`,账号通过 `asrConfig.save(value, modelId)` 保存;麦克风与重采样由宿主管理,输入目标及提交守卫由后续界面消费者负责。当前未挂载语音输入和整理入口,ASR 表单保留注册但不显示。SDK 0.43.0 要求 ASR 目标最低桌面 0.59.5、移动 0.2.7。`context.websocket.connect` 同步返回标准 WebSocket 接口形状,鉴权头和任务 signal 为第三参扩展;两端的发送背压、关闭握手和插件生命周期由宿主统一处理。详见 [WebSocket](websocket.md)。
@@ -1,6 +1,6 @@
1
1
  # 语音识别提供方
2
2
 
3
- 使用 SDK 0.43.0,目标最低桌面 0.59.5、Android/iOS 0.2.7。宿主版本与 SDK 的正式发布状态分开检查。默认模板使用 npm 的 SDK 0.43.0 和正式锁文件;直接冻结安装后开发,不需要本机 SDK 路径。
3
+ 使用 SDK 0.43.0,目标最低桌面 0.59.5、Android/iOS 0.2.7。宿主版本与 SDK 的正式发布状态分开检查。模板当前依赖与候选验证流程见[快速开始](/docs/getting-started.md)。
4
4
 
5
5
  ## 注册与配置
6
6
 
package/package.js CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  validateBackendManifest,
14
14
  validatePluginManifest
15
15
  } from "./client/chunk-M3YEVDN4.js";
16
+ import "./client/chunk-UTVEXGFI.js";
16
17
  export {
17
18
  PLUGIN_AI_CAPABILITIES,
18
19
  PLUGIN_CATEGORIES,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiongtao.xt/tau-plugins",
3
- "version": "0.43.0",
3
+ "version": "0.44.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
package/portable.js CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  validatePortablePluginManifest
9
9
  } from "./client/chunk-X6MBLKAL.js";
10
10
  import "./client/chunk-M3YEVDN4.js";
11
+ import "./client/chunk-UTVEXGFI.js";
11
12
  export {
12
13
  PORTABLE_PLATFORMS,
13
14
  PORTABLE_SHARED_MODULES,
@@ -6,6 +6,108 @@ import {
6
6
  PLUGIN_SHARED_MODULES,
7
7
  validatePluginManifest
8
8
  } from "./client/chunk-M3YEVDN4.js";
9
+ import {
10
+ __commonJS,
11
+ __toESM
12
+ } from "./client/chunk-UTVEXGFI.js";
13
+
14
+ // node_modules/.pnpm/words-count@2.0.2/node_modules/words-count/dist/index.js
15
+ var require_dist = __commonJS({
16
+ "node_modules/.pnpm/words-count@2.0.2/node_modules/words-count/dist/index.js"(exports, module) {
17
+ !(function(e, t) {
18
+ "object" == typeof exports && "object" == typeof module ? module.exports = t() : "function" == typeof define && define.amd ? define("words-count", [], t) : "object" == typeof exports ? exports["words-count"] = t() : e["words-count"] = t();
19
+ })(exports, (function() {
20
+ return (() => {
21
+ "use strict";
22
+ var e = { 314: (e2, t2, r2) => {
23
+ r2.r(t2), r2.d(t2, { default: () => a, wordsCount: () => c, wordsSplit: () => i, wordsDetect: () => u });
24
+ var o = [",", "\uFF0C", ".", "\u3002", ":", "\uFF1A", ";", "\uFF1B", "[", "]", "\u3010", "]", "\u3011", "{", "\uFF5B", "}", "\uFF5D", "(", "\uFF08", ")", "\uFF09", "<", "\u300A", ">", "\u300B", "$", "\uFFE5", "!", "\uFF01", "?", "\uFF1F", "~", "\uFF5E", "'", "\u2019", '"', "\u201C", "\u201D", "*", "/", "\\", "&", "%", "@", "#", "^", "\u3001", "\u3001", "\u3001", "\u3001"], n = { words: [], count: 0 }, u = function(e3) {
25
+ var t3 = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
26
+ if (!e3) return n;
27
+ var r3 = String(e3);
28
+ if ("" === r3.trim()) return n;
29
+ var u2 = t3.punctuationAsBreaker ? " " : "", c2 = t3.disableDefaultPunctuation ? [] : o, i2 = t3.punctuation || [], a2 = c2.concat(i2);
30
+ a2.forEach((function(e4) {
31
+ var t4 = new RegExp("\\" + e4, "g");
32
+ r3 = r3.replace(t4, u2);
33
+ })), r3 = (r3 = (r3 = (r3 = r3.replace(/[\uFF00-\uFFEF\u2000-\u206F]/g, "")).replace(/\s+/, " ")).split(" ")).filter((function(e4) {
34
+ return e4.trim();
35
+ }));
36
+ var d = "(\\d+)|[a-zA-Z\xC0-\xFF\u0100-\u017F\u0180-\u024F\u0250-\u02AF\u1E00-\u1EFF\u0400-\u04FF\u0500-\u052F\u0D00-\u0D7F]+|", f = "\u2E80-\u2EFF\u2F00-\u2FDF\u3000-\u303F\u31C0-\u31EF\u3200-\u32FF\u3300-\u33FF\u3400-\u3FFF\u4000-\u4DBF\u4E00-\u4FFF\u5000-\u5FFF\u6000-\u6FFF\u7000-\u7FFF\u8000-\u8FFF\u9000-\u9FFF\uF900-\uFAFF", p = "\u3040-\u309F\u30A0-\u30FF\u31F0-\u31FF\u3190-\u319F", s = "\u1100-\u11FF\u3130-\u318F\uA960-\uA97F\uAC00-\uAFFF\uB000-\uBFFF\uC000-\uCFFF\uD000-\uD7AF\uD7B0-\uD7FF", l = new RegExp(d + "[" + f + p + s + "]", "g"), v = [];
37
+ return r3.forEach((function(e4) {
38
+ var t4, r4 = [];
39
+ do {
40
+ (t4 = l.exec(e4)) && r4.push(t4[0]);
41
+ } while (t4);
42
+ 0 === r4.length ? v.push(e4) : v = v.concat(r4);
43
+ })), { words: v, count: v.length };
44
+ }, c = function(e3) {
45
+ var t3 = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, r3 = u(e3, t3), o2 = r3.count;
46
+ return o2;
47
+ }, i = function(e3) {
48
+ var t3 = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, r3 = u(e3, t3), o2 = r3.words;
49
+ return o2;
50
+ };
51
+ const a = c;
52
+ } }, t = {};
53
+ function r(o) {
54
+ if (t[o]) return t[o].exports;
55
+ var n = t[o] = { exports: {} };
56
+ return e[o](n, n.exports, r), n.exports;
57
+ }
58
+ return r.d = (e2, t2) => {
59
+ for (var o in t2) r.o(t2, o) && !r.o(e2, o) && Object.defineProperty(e2, o, { enumerable: true, get: t2[o] });
60
+ }, r.o = (e2, t2) => Object.prototype.hasOwnProperty.call(e2, t2), r.r = (e2) => {
61
+ "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e2, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e2, "__esModule", { value: true });
62
+ }, r(314);
63
+ })();
64
+ }));
65
+ }
66
+ });
67
+
68
+ // packages/db-schema/content-metrics.ts
69
+ var import_words_count = __toESM(require_dist());
70
+ var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
71
+ var field = (value) => typeof value === "string" && /^[A-Za-z_$][\w$-]*$/.test(value) && !["__proto__", "constructor", "prototype"].includes(value);
72
+ var validPath = (value) => typeof value === "string" && value.split(".").every((part) => field(part.replace(/\[\]$/, "")));
73
+ function normalizeContentMetricRules(value) {
74
+ if (!Array.isArray(value)) throw new Error("\u5B57\u6570\u7EDF\u8BA1\u89C4\u5219\u5FC5\u987B\u662F\u6570\u7EC4");
75
+ const types = /* @__PURE__ */ new Set();
76
+ return Object.freeze(
77
+ value.map((rule) => {
78
+ if (!record(rule) || typeof rule.type !== "string" || !rule.type || types.has(rule.type))
79
+ throw new Error("\u5B57\u6570\u7EDF\u8BA1\u8282\u70B9\u7C7B\u578B\u65E0\u6548\u6216\u91CD\u590D");
80
+ types.add(rule.type);
81
+ if (!Array.isArray(rule.textFields) || !rule.textFields.every(validPath) || new Set(rule.textFields).size !== rule.textFields.length)
82
+ throw new Error("\u5B57\u6570\u7EDF\u8BA1\u6587\u672C\u5B57\u6BB5\u65E0\u6548\u6216\u91CD\u590D");
83
+ if (rule.textFields.some((path) => path.split(".")[0].replace(/\[\]$/, "") === "children"))
84
+ throw new Error("\u5B57\u6570\u7EDF\u8BA1\u4E0D\u80FD\u91CD\u590D\u58F0\u660E children");
85
+ if (rule.additionalChildren !== void 0 && !Array.isArray(rule.additionalChildren))
86
+ throw new Error("\u5B57\u6570\u7EDF\u8BA1\u8865\u5145\u5B50\u6811\u65E0\u6548");
87
+ const additionalChildren = rule.additionalChildren?.map((source) => {
88
+ if (!record(source) || !validPath(source.path) || source.path.split(".")[0].replace(/\[\]$/, "") === "children" || source.when !== void 0 && !field(source.when) || source.skip !== void 0 && (!Number.isSafeInteger(source.skip) || Number(source.skip) < 0) || source.childrenPath !== void 0 && !validPath(source.childrenPath) || source.exclude !== void 0 && (!record(source.exclude) || !field(source.exclude.field) || !field(source.exclude.equalsField)))
89
+ throw new Error("\u5B57\u6570\u7EDF\u8BA1\u8865\u5145\u5B50\u6811\u65E0\u6548");
90
+ return Object.freeze({
91
+ path: source.path,
92
+ ...source.when === void 0 ? {} : { when: source.when },
93
+ ...source.skip === void 0 ? {} : { skip: source.skip },
94
+ ...source.childrenPath === void 0 ? {} : { childrenPath: source.childrenPath },
95
+ ...source.exclude === void 0 ? {} : {
96
+ exclude: Object.freeze({
97
+ field: source.exclude.field,
98
+ equalsField: source.exclude.equalsField
99
+ })
100
+ }
101
+ });
102
+ });
103
+ return Object.freeze({
104
+ type: rule.type,
105
+ textFields: Object.freeze([...rule.textFields]),
106
+ ...additionalChildren ? { additionalChildren: Object.freeze(additionalChildren) } : {}
107
+ });
108
+ })
109
+ );
110
+ }
9
111
 
10
112
  // packages/db-schema/content-resources.ts
11
113
  var CONTENT_RESOURCE_KINDS = [
@@ -17,8 +119,9 @@ var CONTENT_RESOURCE_KINDS = [
17
119
  var UNSAFE_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
18
120
  var SEGMENT = /^[A-Za-z_$][\w$-]*(\[\])?$/;
19
121
  var FIELD = /^[A-Za-z_$][\w$-]*$/;
20
- var MAX_SPECS = 16;
21
- var MAX_PATH_LENGTH = 128;
122
+ var CONTENT_RESOURCE_LIMITS = Object.freeze({ specs: 16, pathLength: 128 });
123
+ var MAX_SPECS = CONTENT_RESOURCE_LIMITS.specs;
124
+ var MAX_PATH_LENGTH = CONTENT_RESOURCE_LIMITS.pathLength;
22
125
  var isField = (value) => typeof value === "string" && FIELD.test(value) && !UNSAFE_SEGMENTS.has(value);
23
126
  function isValidPath(path) {
24
127
  if (typeof path !== "string" || !path || path.length > MAX_PATH_LENGTH) return false;
@@ -138,16 +241,23 @@ function getPluginNodeTypes(definition) {
138
241
  if (definition.editorExtensions?.length && !types.length)
139
242
  throw new Error("\u7F16\u8F91\u5668\u63D2\u4EF6\u5FC5\u987B\u58F0\u660E\u8282\u70B9\u7C7B\u578B");
140
243
  const htmlTypes = /* @__PURE__ */ new Set();
244
+ const declared = new Map(definition.editorExtensions?.flatMap((extension) => extension.elements ?? []).map((element) => [element.type, element]));
141
245
  for (const extension of definition.editorExtensions ?? []) {
142
246
  for (const source of extension.styleSources ?? [])
143
247
  if (!types.includes(source.type) || !source.field || !["html", "tsx"].includes(source.language))
144
248
  throw new Error("\u63D2\u4EF6\u6837\u5F0F\u6E90\u7801\u5FC5\u987B\u58F0\u660E\u672C\u63D2\u4EF6\u7684\u8282\u70B9\u5B57\u6BB5\u548C\u8BED\u8A00");
145
249
  for (const serializer of extension.htmlSerializers ?? []) {
146
- if (!types.includes(serializer.type) || htmlTypes.has(serializer.type) || typeof serializer.toHtml !== "function")
250
+ const element = declared.get(serializer.type);
251
+ const version = serializer.dataVersion ?? element?.dataVersion;
252
+ const key = JSON.stringify([serializer.type, version ?? null]);
253
+ const supported = element ? [element.dataVersion, ...(element.previousVersions ?? []).map((item) => item.element.dataVersion)] : [];
254
+ if (!types.includes(serializer.type) || htmlTypes.has(key) || serializer.dataVersion !== void 0 && !supported.includes(serializer.dataVersion) || typeof serializer.toHtml !== "function")
147
255
  throw new Error("\u63D2\u4EF6 HTML \u5BFC\u51FA\u7C7B\u578B\u91CD\u590D\u6216\u4E0D\u5C5E\u4E8E\u672C\u63D2\u4EF6");
148
- htmlTypes.add(serializer.type);
256
+ htmlTypes.add(key);
149
257
  }
150
258
  }
259
+ for (const rule of normalizeContentMetricRules(definition.editorMetrics ?? []))
260
+ if (!types.includes(rule.type)) throw new Error("\u5B57\u6570\u7EDF\u8BA1\u89C4\u5219\u53EA\u80FD\u58F0\u660E\u672C\u63D2\u4EF6\u7684\u8282\u70B9");
151
261
  return types;
152
262
  }
153
263
  function getPluginWhiteboardTypes(definition) {
package/publish-client.js CHANGED
@@ -1,3 +1,5 @@
1
+ import "./client/chunk-UTVEXGFI.js";
2
+
1
3
  // packages/plugins/src/publish-client.ts
2
4
  var DataError = class extends Error {
3
5
  constructor(code, message) {
@@ -222,7 +224,7 @@ function createClient({ manifestUrl }) {
222
224
  if (!normalized) return [];
223
225
  assert(Number.isInteger(limit) && limit > 0, "INVALID_DATA", "limit \u5FC5\u987B\u662F\u6B63\u6574\u6570");
224
226
  const [{ documents }, { default: Fuse }] = await waitFor(
225
- Promise.all([index(), import("./client/fuse-M2Z6NNAT.js")]),
227
+ Promise.all([index(), import("./client/fuse-KWYBABFA.js")]),
226
228
  signal
227
229
  );
228
230
  cancelled(signal);
@@ -0,0 +1,80 @@
1
+ import { type ContentResourceSpec } from "./content-resources";
2
+ export declare const CONTENT_CONTRACT_VERSION = 2;
3
+ export declare const NODE_CONTRACT_PROPERTY = "tauContract";
4
+ export declare const CONTENT_CONTRACT_LIMITS: Readonly<{
5
+ contracts: 1024;
6
+ fields: 32;
7
+ nameLength: 128;
8
+ contractBytes: number;
9
+ totalBytes: number;
10
+ }>;
11
+ export interface ContentCollaborationSpec {
12
+ textFields?: readonly string[];
13
+ structuredFields?: readonly string[];
14
+ }
15
+ export interface ContentContractDefinition {
16
+ type: string;
17
+ dataVersion: number;
18
+ kind: "block" | "inline";
19
+ isVoid?: boolean;
20
+ collaboration?: ContentCollaborationSpec;
21
+ resources?: readonly ContentResourceSpec[];
22
+ }
23
+ export interface WhiteboardStructure {
24
+ geometry: "rect" | "opaque";
25
+ container: "none" | "free" | "layout";
26
+ canBeContained: boolean;
27
+ joins: readonly "layout"[];
28
+ text: "none" | "plain" | "richtext";
29
+ reference: "none" | "entity";
30
+ }
31
+ /** 宿主契约输入;结构由宿主注册入口生成,不是新增作者槽位语言。 */
32
+ export interface WhiteboardContractDefinition {
33
+ type: string;
34
+ dataVersion: number;
35
+ structure?: Partial<WhiteboardStructure>;
36
+ collaboration?: {
37
+ textFields?: readonly string[];
38
+ };
39
+ resources?: readonly ContentResourceSpec[];
40
+ }
41
+ interface ContractBase {
42
+ format: typeof CONTENT_CONTRACT_VERSION;
43
+ owner: string;
44
+ type: string;
45
+ dataVersion: number;
46
+ textFields: readonly string[];
47
+ structuredFields: readonly string[];
48
+ resources: readonly ContentResourceSpec[];
49
+ }
50
+ export interface ContentContract extends ContractBase {
51
+ domain: "editor-node";
52
+ kind: "block" | "inline";
53
+ isVoid: boolean;
54
+ }
55
+ export interface WhiteboardElementContract extends ContractBase {
56
+ domain: "whiteboard-element";
57
+ structure: Readonly<WhiteboardStructure>;
58
+ }
59
+ export type DataContract = ContentContract | WhiteboardElementContract;
60
+ export interface PreparedContentContract {
61
+ id: string;
62
+ contract: ContentContract;
63
+ }
64
+ export interface PreparedWhiteboardContract {
65
+ id: string;
66
+ contract: WhiteboardElementContract;
67
+ }
68
+ export type ContentContractDictionary = Readonly<Record<string, DataContract>>;
69
+ export declare function normalizeContentContract(owner: string, definition: ContentContractDefinition): ContentContract;
70
+ export declare function normalizeWhiteboardContract(owner: string, definition: WhiteboardContractDefinition): WhiteboardElementContract;
71
+ export declare function canonicalContractJson(value: unknown): string;
72
+ export declare function prepareContentContract(owner: string, definition: ContentContractDefinition): Promise<PreparedContentContract>;
73
+ export declare function prepareWhiteboardContract(owner: string, definition: WhiteboardContractDefinition): Promise<PreparedWhiteboardContract>;
74
+ export declare function contentContractChecks(value: unknown): readonly {
75
+ id: string;
76
+ contract: DataContract;
77
+ canonical: string;
78
+ }[];
79
+ export declare function validateContentContracts(value: unknown): Promise<ContentContractDictionary>;
80
+ export {};
@@ -0,0 +1,30 @@
1
+ /** 字段路径支持对象属性与数组项,例如 answers[].text。 */
2
+ export interface ContentMetricChildren {
3
+ path: string;
4
+ /** 仅在节点的该布尔字段为 true 时补充子树。 */
5
+ when?: string;
6
+ skip?: number;
7
+ /** 排除标识与当前节点指定字段相同的项。 */
8
+ exclude?: {
9
+ field: string;
10
+ equalsField: string;
11
+ };
12
+ childrenPath?: string;
13
+ }
14
+ /** 扩展只声明内容字段;计数算法与普通 children 遍历由宿主统一执行。 */
15
+ export interface ContentMetricRule {
16
+ type: string;
17
+ textFields: readonly string[];
18
+ additionalChildren?: readonly ContentMetricChildren[];
19
+ }
20
+ /** 在进程边界重新校验,并复制为不可变快照;不携带插件可执行代码。 */
21
+ export declare function normalizeContentMetricRules(value: unknown): readonly ContentMetricRule[];
22
+ export declare const countTextWords: (text: string) => number;
23
+ export declare function createContentMetrics(initialRules?: readonly ContentMetricRule[]): {
24
+ count: (content: readonly unknown[]) => number;
25
+ readonly revision: number;
26
+ readonly rules: readonly ContentMetricRule[];
27
+ setRules(next: readonly ContentMetricRule[]): void;
28
+ };
29
+ /** 自动清理只认空段落与空文本;图片、结构块和未知节点始终保留。 */
30
+ export declare function isContentEmpty(content: unknown): boolean;
@@ -43,6 +43,10 @@ export declare const BUILTIN_CONTENT_RESOURCES: {
43
43
  readonly kind: "file";
44
44
  }];
45
45
  };
46
+ export declare const CONTENT_RESOURCE_LIMITS: Readonly<{
47
+ specs: 16;
48
+ pathLength: 128;
49
+ }>;
46
50
  export declare function isContentResourceSpec(value: unknown): value is ContentResourceSpec;
47
51
  /** 校验来自插件或其他设备的声明;形状不对时抛错 */
48
52
  export declare function assertContentResourceSpecs(value: unknown): asserts value is readonly ContentResourceSpec[];
@@ -1,3 +1,3 @@
1
1
  /** 无 React/DOM 运行时代码的声明入口,供应用 SDK 适配现有扩展协议。 */
2
- export { defineExtension, defineElement } from "./src/core/api/extension";
3
- export type { EditorExtension, ElementSpec, ElementRenderProps, ElementFrame, } from "./src/core/api/extension";
2
+ export { defineExtension, defineElement, assertElementVersions } from "./src/core/api/extension";
3
+ export type { EditorExtension, ElementSpec, ElementRenderProps, ElementFrame, ElementDataMigration, PreviousElementVersion, } from "./src/core/api/extension";
@@ -2,17 +2,79 @@ import type { MouseEvent, ReactNode, ReactElement } from "react";
2
2
  import type { LucideIcon } from "lucide-react";
3
3
  import type { Editor, Element, Path } from "slate";
4
4
  import type { ElementBehaviors, ParagraphElement, BlockElement } from "./api";
5
- export interface SourceBlockEditorProps {
5
+ export interface TextFieldSnapshot {
6
+ readonly value: string;
7
+ readonly revision: string;
8
+ }
9
+ export interface TextFieldDelta {
10
+ retain?: number;
11
+ delete?: number;
12
+ insert?: string;
13
+ }
14
+ export interface EditorTextField {
15
+ getSnapshot(): TextFieldSnapshot;
16
+ subscribe(listener: (event: {
17
+ delta: readonly TextFieldDelta[];
18
+ local: boolean;
19
+ }) => void): () => void;
20
+ edit(change: {
21
+ offset: number;
22
+ remove: number;
23
+ text: string;
24
+ revision: string;
25
+ }): void;
26
+ editBatch(changes: readonly {
27
+ offset: number;
28
+ remove: number;
29
+ text: string;
30
+ }[], revision: string): void;
31
+ /** 本机观察版本保护;共享文档的异步整段替换须经宿主条件提交,不能据此声称服务端 CAS。 */
32
+ replace(value: string, revision: string): void;
33
+ undo(): void;
34
+ redo(): void;
35
+ dispose(): void;
36
+ }
37
+ export interface EditorTextFields {
38
+ open(editor: Editor, element: Element, field: string): EditorTextField;
39
+ }
40
+ export declare const IEditorTextFields: import("../shared/service-contract").ServiceIdentifier<EditorTextFields>;
41
+ export interface TextFieldEditor {
42
+ readonly value: string;
43
+ readonly revision: string;
44
+ readonly readOnly: boolean;
45
+ readonly ready: boolean;
46
+ readonly error: string | null;
47
+ edit(change: {
48
+ offset: number;
49
+ remove: number;
50
+ text: string;
51
+ }): void;
52
+ editBatch(changes: readonly {
53
+ offset: number;
54
+ remove: number;
55
+ text: string;
56
+ }[]): void;
57
+ undo(): void;
58
+ redo(): void;
59
+ }
60
+ interface SourceBlockEditorBaseProps {
6
61
  mode: string;
7
62
  title: string;
8
63
  icon: LucideIcon;
9
- initValue: string;
10
- onChange(value: string): void;
11
64
  element: Element;
12
65
  center?: boolean;
13
66
  extend?: boolean;
14
67
  children?: ReactNode;
15
68
  }
69
+ export type SourceBlockEditorProps = SourceBlockEditorBaseProps & ({
70
+ field: string;
71
+ initValue?: never;
72
+ onChange?: never;
73
+ } | {
74
+ field?: never;
75
+ initValue: string;
76
+ onChange(value: string): void;
77
+ });
16
78
  export interface RuntimeStyleCompiler {
17
79
  compile(request: {
18
80
  source: string;
@@ -20,6 +82,7 @@ export interface RuntimeStyleCompiler {
20
82
  }): Promise<string>;
21
83
  }
22
84
  export interface SourceEditorRuntime {
85
+ useTextField(element: Element, field: string): TextFieldEditor;
23
86
  SourceBlockEditor(props: SourceBlockEditorProps): ReactElement;
24
87
  useSourceBlock(element: Element): {
25
88
  theme: {
@@ -85,3 +148,4 @@ export interface InlineSourceRuntime {
85
148
  insertInlineSource(editor: Editor, element: Element): void;
86
149
  InlineSourceBoundary(): ReactElement;
87
150
  }
151
+ export {};
@@ -0,0 +1,12 @@
1
+ import type { Editor, Element } from "slate";
2
+ import type { ElementSpec } from "./extension";
3
+ export interface ElementVersionAccess {
4
+ element: ElementSpec;
5
+ access: "read" | "edit" | "none";
6
+ }
7
+ export type ElementVersionResolver = (element: Element) => ElementVersionAccess | undefined;
8
+ export declare function bindElementDefinitions(editor: Editor, elements: readonly ElementSpec[]): void;
9
+ export declare const currentElementDefinition: (editor: Editor, type: string) => ElementSpec | undefined;
10
+ export declare function setElementVersionResolver(editor: Editor, resolver: ElementVersionResolver | undefined): void;
11
+ export declare const getElementVersionResolver: (editor: Editor) => ElementVersionResolver | undefined;
12
+ export declare function canEditElement(editor: Editor, element: Element): boolean;
@@ -11,6 +11,15 @@ import type { ElementCopy } from "./copy";
11
11
  import type { DecorationSpec, MarkSpec } from "./marks";
12
12
  import type { InputRule } from "./inputRules";
13
13
  import type { ContentResourceSpec } from "../../../../db-schema/content-resources";
14
+ import { type ContentCollaborationSpec } from "../../../../db-schema/content-contracts";
15
+ export interface ElementDataMigration {
16
+ from: number;
17
+ migrate(data: Readonly<Record<string, unknown>>): Record<string, unknown>;
18
+ }
19
+ export interface PreviousElementVersion {
20
+ element: ElementSpec;
21
+ access: "read" | "edit" | "none";
22
+ }
14
23
  /**
15
24
  * 扩展 API v2(01 §5.1):声明式描述「这个扩展贡献了什么」,内核负责装配、隔离与分发。
16
25
  * 所有扩展都是 defineExtension 的产物(旧 IExtension 适配层已删除,ER-019)。
@@ -50,6 +59,11 @@ export interface ElementFrame {
50
59
  export interface ElementSpec<E extends Element = Element> {
51
60
  /** 元素 type;内置类型沿用现有名字,兼容已有文档 */
52
61
  type: string;
62
+ /** 数据结构与同步语义版本;无版本的旧声明不能进入新契约文档。 */
63
+ dataVersion?: number;
64
+ collaboration?: ContentCollaborationSpec;
65
+ previousVersions?: readonly PreviousElementVersion[];
66
+ migrations?: readonly ElementDataMigration[];
53
67
  kind: "block" | "inline";
54
68
  isVoid?: boolean;
55
69
  /** 后代的方向键/退格导航由领域接管,核心不执行默认相邻块导航。 */
@@ -115,4 +129,5 @@ export type ExtensionDefinition = Omit<EditorExtension, "apiVersion"> & {
115
129
  export declare function defineExtension(definition: ExtensionDefinition): EditorExtension;
116
130
  /** 按元素类型收窄 render / behaviors 的参数类型;运行时原样返回 */
117
131
  export declare function defineElement<E extends Element>(spec: ElementSpec<E>): ElementSpec;
132
+ export declare function assertElementVersions(spec: ElementSpec): void;
118
133
  export declare const isEditorExtension: (value: unknown) => value is EditorExtension;
@@ -6,6 +6,7 @@
6
6
  */
7
7
  export { EXTENSION_API_VERSION, defineExtension, defineElement, type EditorExtension, type ExtensionDefinition, type ElementSpec, type ElementFrame, type ElementEmptyContext, type ElementBehaviors, type ElementRenderProps, type ExtensionLayerProps, } from "./extension";
8
8
  export type { AnyExtension } from "./legacy";
9
+ export { canEditElement, getElementVersionResolver, setElementVersionResolver, type ElementVersionAccess, type ElementVersionResolver, } from "./elementVersions";
9
10
  export type { CopyDecision, CopyContext, ElementCopy } from "./copy";
10
11
  export type { MarkSpec, MarkRenderProps, DecorationSpec } from "./marks";
11
12
  export type { InputRule, MarkInputRule, InlineInputRule } from "./inputRules";
@@ -62,3 +63,5 @@ export { panAroundAnchor, pointFromCenter, type Point as ZoomPanPoint } from "..
62
63
  export { FloatingToolbar, ToolbarDivider, ToolbarIconButton } from "../components/FloatingToolbar/index";
63
64
  export { IElementEditingPolicy, type ElementEditingPolicy } from "../services/elementEditingPolicy";
64
65
  export { IUnknownElementNotice, type UnknownElementNotice } from "../services/unknownElementNotice";
66
+ export type { EditorTextField } from "../../../source-contracts";
67
+ export { useTextFieldBinding } from "./useTextFieldBinding";
@@ -0,0 +1,9 @@
1
+ import type { Element } from "slate";
2
+ import { type EditorTextField } from "../../../source-contracts";
3
+ export declare function useTextFieldBinding(element: Element | undefined, field: string): {
4
+ binding: EditorTextField | null;
5
+ value: string;
6
+ revision: string;
7
+ readOnly: boolean;
8
+ error: string | null;
9
+ };
@@ -2,7 +2,7 @@ import { type ReactElement } from "react";
2
2
  import type { ContentResourceDeclarations } from "../../../../db-schema/content-resources";
3
3
  import type { Editor } from "slate";
4
4
  import type { RenderElementProps } from "slate-react";
5
- import type { EditorExtension, ElementBehaviors } from "../api/extension";
5
+ import type { EditorExtension, ElementBehaviors, ElementSpec } from "../api/extension";
6
6
  import { CommandRegistry, type EditorHotkey } from "../api/command";
7
7
  import { type ElementDragSpec } from "../api/drag";
8
8
  import type { ElementIngestSpec } from "../api/ingest";
@@ -24,6 +24,7 @@ export interface ExtensionPluginGroup {
24
24
  export interface ElementBehaviorEntry {
25
25
  readonly extension: string;
26
26
  readonly behaviors: ElementBehaviors;
27
+ readonly own?: boolean;
27
28
  }
28
29
  /** 一个扩展的内容注入声明;owner 用于隔离熔断与日志 */
29
30
  export interface IngestSource {
@@ -31,6 +32,8 @@ export interface IngestSource {
31
32
  readonly files?: ElementIngestSpec["files"];
32
33
  readonly text?: ElementIngestSpec["text"];
33
34
  }
35
+ type ElementRenderer = (props: RenderElementProps) => ReactElement | undefined;
36
+ export declare const renderElementSpec: (spec: ElementSpec) => ElementRenderer;
34
37
  /**
35
38
  * 扩展的预计算结果:插件链、快捷键、悬浮工具条条目与 type → 渲染的分发表。
36
39
  *
@@ -79,3 +82,4 @@ export declare class ExtensionAssembly {
79
82
  /** 块菜单条目:每次打开菜单求值;单个扩展出错只丢它自己的条目 */
80
83
  getBlockPanelItems(editor: Editor): IBlockPanelListItem[];
81
84
  }
85
+ export {};
@@ -33,6 +33,8 @@ export interface MarkdownImportContext {
33
33
  export interface MarkdownCodec {
34
34
  /** 元素 type */
35
35
  type: string;
36
+ /** 省略时归当前节点契约;历史版本只用于明确的导出分发。 */
37
+ dataVersion?: number;
36
38
  /** 导入:按 directive 名解析(container / leaf / text 三种都查),优先于内置分支 */
37
39
  directives?: Record<string, CustomDirectiveHandler>;
38
40
  /**
@@ -1,3 +1,4 @@
1
+ export { serializeUnknownBlock, serializeUnknownInline, isInlinePosition } from "./unknownNode";
1
2
  export { createMarkdownProcessor, type MarkdownProcessor, type MarkdownProcessorOptions, type MarkdownCachePolicy, } from "./processor";
2
3
  export type { MarkdownTextCodec, MarkdownTextRule, LeafSerializationResult } from "./textCodec";
3
4
  export type { MarkdownCodec, CustomDirectiveHandler, MarkdownImportNode, MarkdownImportContext, } from "./codec";
@@ -3,6 +3,7 @@ import type { CustomElement } from "./types";
3
3
  import type { MarkdownSerializerRegistry } from "./markdownSerializerRegistry";
4
4
  import { PositionMapper } from "./positionMapper";
5
5
  import type { MarkdownTextRegistry } from "./textCodec";
6
+ import type { MarkdownCodec } from "./codec";
6
7
  /** 处理器级导出配置:注册表 + void 类型表 + 子元素接续表(内置 + 宿主 codec) */
7
8
  export interface ExportConfig {
8
9
  textRegistry: MarkdownTextRegistry;
@@ -10,6 +11,8 @@ export interface ExportConfig {
10
11
  voidTypes: ReadonlySet<string>;
11
12
  /** 元素类型的子块级接续符(列表 / 表格为 "\n",缺省 "\n\n") */
12
13
  childSeparators: ReadonlyMap<string, "\n" | "\n\n">;
14
+ resolveCodec?: (element: CustomElement) => MarkdownCodec | undefined;
15
+ serializeUnknown?: (element: CustomElement, parent: CustomElement | null, error?: unknown) => string;
13
16
  }
14
17
  /** codec 的序列化器登记脚注(如 annotation 的 [^n]),由导出入口统一追加到文末 */
15
18
  export declare const addExportFootnote: (content: string) => number;
@@ -36,13 +36,19 @@ export declare class MarkdownSerializerRegistry {
36
36
  private blockTypes;
37
37
  private footnoteCounter;
38
38
  private footnoteDefinitions;
39
- constructor(serializers?: MarkdownSerializer[]);
39
+ private readonly resolve?;
40
+ constructor(serializers?: MarkdownSerializer[], resolve?: (element: CustomElement) => MarkdownSerializer | undefined);
40
41
  resetFootnotes(): void;
42
+ captureFootnotes(): {
43
+ counter: number;
44
+ definitions: Map<number, string>;
45
+ };
46
+ restoreFootnotes(snapshot: ReturnType<MarkdownSerializerRegistry["captureFootnotes"]>): void;
41
47
  getFootnoteCount(): number;
42
48
  addFootnote(content: string): number;
43
49
  getFootnoteDefinitions(): string;
44
50
  register(serializer: MarkdownSerializer): void;
45
51
  registerMany(serializers: MarkdownSerializer[]): void;
46
- getSerializer(type: string): MarkdownSerializer | undefined;
52
+ getSerializer(type: string, element?: CustomElement): MarkdownSerializer | undefined;
47
53
  isBlock(element: CustomElement): boolean;
48
54
  }
@@ -76,6 +76,7 @@ export declare class PositionMapper {
76
76
  * 清空映射表
77
77
  */
78
78
  clear(): void;
79
+ truncate(length: number): void;
79
80
  /**
80
81
  * Slate 位置 → Markdown 位置
81
82
  *
@@ -25,6 +25,9 @@ export interface MarkdownProcessorOptions {
25
25
  /** 元素类型的编解码(各扩展的 markdown.ts 提供);处理器只认这里的类型,其余走 ER-006 兜底 */
26
26
  codecs?: MarkdownCodec[];
27
27
  textCodecs?: readonly MarkdownTextCodec[];
28
+ /** 宿主按节点携带的契约选择导出器;undefined 表示该节点需保真回退。 */
29
+ resolveCodec?: (element: CustomElement) => MarkdownCodec | undefined;
30
+ serializeUnknown?: (element: CustomElement, parent: CustomElement | null, error?: unknown) => string;
28
31
  }
29
32
  /**
30
33
  * 创建 Markdown 处理器(01 §8.2):框架不带任何元素类型,全部经 codecs 注入,
@@ -0,0 +1,24 @@
1
+ /**
2
+ * 未知节点的 Markdown 兜底语法(ER-006 / ER-P3):没有 codec 的元素整节点原样存成 JSON,导入时还原。
3
+ *
4
+ * - 块级:`:::tau-node{type="x"}` 容器包一段 json 代码围栏,围栏里是整个节点(含 children)。
5
+ * - 行内:`:tau-node[正文]{type="x" json="…"}`,方括号里的正文只供阅读,还原以 json 为准。
6
+ *
7
+ * 块级 / 行内按 Slate 的结构判断:父元素含文本子节点时,它的元素子节点必然是行内的。
8
+ */
9
+ import type { Descendant } from "slate";
10
+ export declare const UNKNOWN_NODE_DIRECTIVE = "tau-node";
11
+ type NodeLike = {
12
+ type?: string;
13
+ text?: string;
14
+ children?: NodeLike[];
15
+ };
16
+ /** 该位置上的元素是否是行内的(父元素含文本子节点) */
17
+ export declare const isInlinePosition: (parent: NodeLike | null | undefined) => boolean;
18
+ export declare const serializeUnknownBlock: (element: NodeLike) => string;
19
+ export declare const serializeUnknownInline: (element: NodeLike) => string;
20
+ /** 元素沿用 children 协议,文本载体只接受基础 formatted 叶子。 */
21
+ export declare const parseUnknownNode: (json: string | undefined) => Descendant | null;
22
+ export declare const markRestored: <T extends object>(node: T) => T;
23
+ export declare const isRestoredNode: (node: unknown) => boolean;
24
+ export {};
@@ -6,6 +6,7 @@ import type { WhiteboardExtension } from "./whiteboard";
6
6
  import type { PluginServices } from "./services";
7
7
  import type { PluginEditor } from "./editor";
8
8
  import type { PluginEditorExtension } from "./editor";
9
+ import type { ContentMetricRule } from "../../db-schema/content-metrics";
9
10
  import type { MarkdownCodec } from "../../markdown/src/index";
10
11
  import type { PluginSettings } from "./settings";
11
12
  import type { PluginSync } from "./sync";
@@ -122,6 +123,8 @@ export interface PluginDefinition {
122
123
  readonly editorExtensions?: readonly PluginEditorExtension[];
123
124
  readonly whiteboardExtensions?: readonly WhiteboardExtension[];
124
125
  readonly editorCodecs?: readonly MarkdownCodec[];
126
+ /** 可序列化的统计字段,与 Markdown 转换独立;不执行插件回调。 */
127
+ readonly editorMetrics?: readonly ContentMetricRule[];
125
128
  readonly ai?: {
126
129
  readonly features: readonly PluginAIFeature[];
127
130
  };
@@ -1,9 +1,11 @@
1
+ import type { ContentMetricRule } from "../../db-schema/content-metrics";
1
2
  import type { EditorExtension as InternalExtension } from "../../editor/contracts";
2
3
  import type { MarkdownCodec } from "../../markdown/src/index";
3
4
  import type { Disposable } from "./index";
4
5
  import { type OpenEditorExtensionField } from "./editor-fields";
5
6
  export { defineElement as defineEditorElement } from "../../editor/contracts";
6
7
  export type { ElementRenderProps as EditorElementRenderProps } from "../../editor/contracts";
8
+ export type { ContentMetricRule as EditorMetricRule } from "../../db-schema/content-metrics";
7
9
  export type { MarkdownCodec as EditorMarkdownCodec } from "../../markdown/src/index";
8
10
  export type { ContentResourceSpec as EditorResourceSpec, ContentResourceKind as EditorResourceKind, } from "../../db-schema/content-resources";
9
11
  /** 作者通过模块增强登记自定义节点,无需引用编辑器内部包。 */
@@ -34,6 +36,7 @@ export type PluginEditorExtension = Pick<InternalExtension, OpenEditorExtensionF
34
36
  /** 静态 HTML/EPUB 导出;博客始终使用 elements.render,不经过这里。 */
35
37
  htmlSerializers?: readonly {
36
38
  type: string;
39
+ dataVersion?: number;
37
40
  toHtml(element: Record<string, unknown>): string;
38
41
  }[];
39
42
  };
@@ -44,6 +47,7 @@ export interface PluginEditorContribution {
44
47
  extension: PluginEditorExtension;
45
48
  /** 纯函数定义可由主进程独立导入,本次只在开发台装配。 */
46
49
  codecs?: readonly MarkdownCodec[];
50
+ metrics?: readonly ContentMetricRule[];
47
51
  }
48
52
  export interface PluginEditor {
49
53
  register(contribution: PluginEditorContribution): Disposable;
@@ -11,8 +11,8 @@ export type * from "./publish";
11
11
  export type { JsonValue, Disposable, PluginStorage, PluginCommand, PluginContext, PluginInstance, PluginDefinition, } from "./contract";
12
12
  export type { PluginSettings, PluginSettingsDefinition, PluginSettingsProps, PluginSettingsHandle, } from "./settings";
13
13
  export * from "./editor";
14
- export { SourceBlockEditor, useSourceBlock, useReportPreviewError, insertSourceBlock, sourceBlockParagraphBehavior, } from "./source-editor";
15
- export type { SourceBlockEditorProps, PluginRuntimeStyleCompiler } from "./source-editor";
14
+ export { SourceBlockEditor, useSourceBlock, useTextField, useReportPreviewError, insertSourceBlock, sourceBlockParagraphBehavior, } from "./source-editor";
15
+ export type { SourceBlockEditorProps, PluginRuntimeStyleCompiler, TextFieldEditor } from "./source-editor";
16
16
  export { useInlineSource, insertInlineSource, InlineSourceBoundary } from "./inline-source";
17
17
  export { ContentEditor, ContentPreview, EntityRef } from "./components";
18
18
  export { useElement, useMediaViewer, BlockToolbar, BlockToolbarButton, BlockToolbarGap, } from "./element";
@@ -4,7 +4,7 @@ import type { MarkdownCodec } from "../../markdown/src/index";
4
4
  import { type ReadablePortablePluginManifest, type PortablePluginHost } from "./portable";
5
5
  import { type DevelopmentPluginPackage, type PluginManifest } from "./package";
6
6
  export type { PublishedPluginRender } from "./render-artifact";
7
- export declare function assertUniqueEditorCodecs(codecs: readonly MarkdownCodec[]): void;
7
+ export declare function assertUniqueEditorCodecs(codecs: readonly MarkdownCodec[], versions?: ReadonlyMap<string, number | undefined>): void;
8
8
  export declare const PLUGIN_RENDER_VERSION = 1;
9
9
  /** 发布站只读取静态贡献;清单保持原格式,不启动应用插件生命周期。 */
10
10
  export declare function readPublishedPluginManifest(value: unknown): PluginManifest | import("./portable").PortablePluginManifest;
@@ -3,6 +3,8 @@ export type { SourceBlockEditorProps, RuntimeStyleCompiler as PluginRuntimeStyle
3
3
  export declare function configureSourceEditor(value: SourceEditorRuntime): void;
4
4
  export declare const SourceBlockEditor: SourceEditorRuntime["SourceBlockEditor"];
5
5
  export declare const useSourceBlock: SourceEditorRuntime["useSourceBlock"];
6
+ export declare const useTextField: SourceEditorRuntime["useTextField"];
7
+ export type { TextFieldEditor } from "../../editor/source-contracts";
6
8
  export declare const useReportPreviewError: SourceEditorRuntime["useReportPreviewError"];
7
9
  export declare const insertSourceBlock: SourceEditorRuntime["insertSourceBlock"];
8
10
  export declare const sourceBlockParagraphBehavior: SourceEditorRuntime["sourceBlockParagraphBehavior"];