@xiongtao.xt/tau-plugins 0.36.0 → 0.38.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 (41) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/client/{chunk-D4PV3N7Q.js → chunk-BKZ7HC6P.js} +127 -18
  3. package/docs/README.md +2 -2
  4. package/docs/api-support.md +38 -34
  5. package/docs/editor.md +2 -2
  6. package/docs/getting-started.md +5 -5
  7. package/docs/plugin-basics.md +8 -9
  8. package/docs/portability.md +86 -38
  9. package/docs/providers/README.md +2 -1
  10. package/docs/providers/upload.md +1 -1
  11. package/docs/release.md +2 -2
  12. package/docs/storage-and-network.md +1 -1
  13. package/docs/ui.md +1 -1
  14. package/package.json +1 -1
  15. package/portable.js +7 -1
  16. package/publish-artifacts.js +63 -3
  17. package/types/packages/editor/src/core/api/index.d.ts +4 -1
  18. package/types/packages/editor/src/core/components/EditorContextMenu/types.d.ts +35 -0
  19. package/types/packages/editor/src/core/components/ExtensionLayers/index.d.ts +17 -0
  20. package/types/packages/editor/src/core/hooks/useDragHandlerMenu.d.ts +39 -0
  21. package/types/packages/editor/src/core/kit/EditorKit.d.ts +39 -0
  22. package/types/packages/editor/src/core/kit/ExtensionAssembly.d.ts +81 -0
  23. package/types/packages/editor/src/core/kit/context.d.ts +21 -0
  24. package/types/packages/editor/src/core/menu/resolveMenu.d.ts +19 -0
  25. package/types/packages/editor/src/core/services/interaction.d.ts +12 -0
  26. package/types/packages/editor/src/core/utils/nodeOperations.d.ts +2 -2
  27. package/types/packages/markdown/src/index.d.ts +1 -1
  28. package/types/packages/markdown/src/markdown-helper.d.ts +5 -1
  29. package/types/packages/markdown/src/markdownSerializerRegistry.d.ts +1 -0
  30. package/types/packages/markdown/src/processor.d.ts +8 -1
  31. package/types/packages/plugins/src/capabilities.d.ts +3 -3
  32. package/types/packages/plugins/src/environment.d.ts +7 -10
  33. package/types/packages/plugins/src/index.d.ts +0 -2
  34. package/types/packages/plugins/src/portable.d.ts +33 -1
  35. package/types/packages/plugins/src/publish-artifacts.d.ts +8 -3
  36. package/types/packages/plugins/src/render-artifact.d.ts +2 -1
  37. package/types/packages/plugins/src/rendering.d.ts +78 -0
  38. package/types/packages/themes/src/themes/paper.theme.d.ts +1 -1
  39. package/types/packages/ui/src/index.d.ts +1 -0
  40. package/types/packages/ui/src/patterns/ConfigurationPanel.d.ts +21 -0
  41. package/types/packages/ui/src/primitives/Tabs.d.ts +3 -1
@@ -1,71 +1,119 @@
1
- # 跨端开发契约
1
+ <!-- 由 scripts/plugins/sync-author-docs.mjs 从 packages/plugins/docs/portability.md 生成,请勿单独编辑。 -->
2
2
 
3
- 模板使用 SDK 0.36.0、UI 0.4.0 与格式 3。先读 [API 支持矩阵](api-support.md),再按[快速开始](getting-started.md)安装依赖。移动正式安装要求 Android/iOS 客户端至少 0.2.1,且中心允许该平台及版本;桌面格式 3 仍只在显式开发目录装配,不用旧公开客户端冒充支持。
3
+ # 多端插件作者契约
4
4
 
5
- ## 页面与入口
5
+ 一个 SDK、一套模板、同一插件 ID/版本对应同一 ZIP。普通页面直接使用公共 API;宿主在加载前检查兼容性。具体宿主实现范围见 [API 支持矩阵](api-support.md),SDK 类型存在不等于所有接口都已在移动端接入。
6
6
 
7
- 同一个 main.js 可以支持 desktop/android/ios,公共数据模型与业务逻辑保持一致:
7
+ ## 作者清单
8
+
9
+ 作者维护 manifest.json 的身份、目标平台、最低版本和额外需求。包格式、入口、摘要与内部要求由构建器生成。
10
+
11
+ ```json
12
+ {
13
+ "id": "example.counter",
14
+ "name": "计数器",
15
+ "description": "保存当前工作区的计数。",
16
+ "version": "1.0.0",
17
+ "categories": ["page"],
18
+ "targets": {
19
+ "desktop": { "minAppVersion": "0.59.2" },
20
+ "android": { "minAppVersion": "0.2.3" },
21
+ "ios": { "minAppVersion": "0.2.3" }
22
+ }
23
+ }
24
+ ```
25
+
26
+ 版本填写实际验证过的下限。声明平台不代表已在该平台通过设备验收,也不控制生产中心的分发开关。
27
+
28
+ 公共应用基础包含 commands、storage、pages、navigation、settings、dialogs,不要求作者逐项填写或调用前查字符串。行为遵循支持矩阵:移动命令注册不自动生成命令面板,通用设置与领域设置共用注册方式,领域设置另声明对应功能。
29
+
30
+ 额外功能写 requires:sourceEditor、media、runtimeStyles、fetch、sync、upload。编辑器声明使用 editor: { elements: { "abc": "edit" } },构建器补齐 editor/editorCodecs。每个实际节点必须明确列出;edit 支持显示、插入和编辑,render 只显示,none 不装配但保留原始数据。
31
+
32
+ 根级 requires、optional、editor.elements 为公共声明。目标平台不写时继承;写了就整组替换,空数组清空该组额外需求,不能取消公共基础要求。节点映射也是完整替换,不深合并。必需与可选不能重叠,未知名称在构建时拒绝;省略平台表示不允许该平台应用安装。
33
+
34
+ ## 页面和入口
8
35
 
9
36
  ```tsx
10
- const page = context.pages.register({ id: "tasks", title: "任务管理", component: TasksPage });
37
+ const page = context.pages.register({
38
+ id: "tasks",
39
+ title: "任务管理",
40
+ component: TasksPage,
41
+ });
11
42
  context.navigation.registerEntry({ id: "tasks", title: "任务管理", page });
43
+ context.settings.register({ id: "preferences", title: "设置", component: Settings });
12
44
  ```
13
45
 
14
- 页面声明不自动创建入口。宿主决定入口位于桌面侧栏还是移动功能列表;作者不导入宿主路由或修改 history。页面注销会回收其入口,旧句柄不能继续打开。页面可在 effect 中登记 pageContext.registerLeaveGuard,返回 false 阻止离开,清理时调用返回句柄的 dispose。
46
+ 页面不自动创建入口。桌面侧栏、移动插件功能列表消费同一语义声明;作者不操作宿主 history,不导入宿主路由。详情页可没有入口。页面句柄的 open 仅接收标量参数,页面注销后入口回收。
15
47
 
16
- ## 环境与能力
48
+ Dialog/Drawer 直接使用公共 UI。宿主负责浮层返回、层级与安全区。页面组件通过 pageContext.registerLeaveGuard 登记离开守卫,并在 effect 清理时注销;系统终止进程不保证调用守卫或 deactivate,重要数据应及时保存。
17
49
 
18
- `context.environment` 每次读取取得当前不可变快照。React 页面和静态编辑器组件通过 `usePluginEnvironment()` 订阅环境变化,不依赖 activate:
50
+ context.storage 为当前工作区的插件私有 JSON 存储,不等于业务实体数据库。异步任务处理 signal 与工作区失效;资源通过 context.register 或组件 effect 回收。
19
51
 
20
- ```tsx
21
- import { usePluginEnvironment } from "@tau/plugins";
22
- function TasksView() {
23
- const environment = usePluginEnvironment();
24
- return environment.layout === "compact" ? <CompactTasks /> : <WideTasks />;
52
+ ## 环境与平板
53
+
54
+ ```ts
55
+ interface PluginEnvironment {
56
+ readonly platform: "desktop" | "android" | "ios" | "web";
57
+ readonly input: {
58
+ readonly coarsePointer: boolean;
59
+ readonly finePointer: boolean;
60
+ };
25
61
  }
26
62
  ```
27
63
 
28
- platform 区分 desktop/android/ios/web/unknown;layout 为 compact/wide/unknown;input 区分 touch/finePointer。宿主更新布局/输入后 hook 刷新;不要将一次解构的快照当成一直变化的引用。platform 与能力集合在会话内固定,更换需重建会话。
64
+ React 组件使用 usePluginEnvironment(),非 React 调用每次读取 context.environment,二者是同一宿主源的不可变快照。平台在会话内固定,输入变化自动通知组件;未注入环境是装配错误,不假定某个平台。
29
65
 
30
- 能力词表由 SDK 的 `PLUGIN_CAPABILITIES`、`PluginCapability` 提供,当前包括 commands/storage/pages/navigation/settings/ui.dialog/editor.elements/editor.codecs/editor.source 的 `.v1` 版本。它表示接口可用性,不授予数据权限,也不是安全沙箱。
66
+ coarsePointer 对应 (any-pointer: coarse),finePointer 对应 (any-pointer: fine):只表达 WebView 报告的指针精度,二者可以同时为真。它们不识别手机、平板、当前事件来源、键盘或悬停能力;一次手势的来源看 PointerEvent。普通插件一般不需要读取环境。
31
67
 
32
- 可选能力由作者显式检测:
68
+ 环境没有 layout 或能力清单。布局用 CSS 与容器宽度,不能用系统平台推导宽窄。Android 平板沿用 android,未来 iPad 宿主沿用 SDK 的 ios 家族标识;分屏时重排布局,接入鼠标时增强操作而不删除触摸按钮。平板支持还需要宿主和设备验收,不能从平台声明推断已通过。
33
69
 
34
- ```ts
35
- if (context.environment.capabilities.includes("settings.v1")) {
36
- context.settings.register({ id: "preferences", title: "设置", component: Settings });
70
+ ## 编辑器插件
71
+
72
+ 节点结构、codec、校验和渲染共用;静态 editorExtensions/editorCodecs 直接交给 definePlugin,不依赖 activate 或缓存全局 context。博客由自己的宿主提供 web/只读环境,不能启动应用插件生命周期。
73
+
74
+ 优先使用 SourceBlockEditor/useSourceBlock 与公开的节点 API。标准插入、选区、源码草稿保存/取消、只读和迟到提交保护由宿主负责;节点允许移动不等于所有平台都采用鼠标拖拽。
75
+
76
+ 图册排序、绘图等专有交互仍由作者实现。基础操作保留可点击/可聚焦按钮,拖拽与悬停只作增强;布局按实际容器调整,共享编辑状态和提交函数,方向或输入变化不能丢失草稿。不能为手机另建一套节点类型。
77
+
78
+ ## 可选功能
79
+
80
+ 只有具备具体可选访问器和完整替代流程的功能才能标记 optional。当前作者 optional 词表仅允许 runtimeStyles,且 requires 必须包含 sourceEditor:
81
+
82
+ ```json
83
+ {
84
+ "requires": ["sourceEditor"],
85
+ "optional": ["runtimeStyles"]
37
86
  }
38
87
  ```
39
88
 
40
- 模板的设置页、Dialog 都是可选能力,核心计数不依赖它们。UI 组件能够导入,不表示宿主已经完成移动交互适配。
89
+ 通过 useSourceBlock(element).compiler(行内源码为 useInlineSource)读取编译器,宿主未提供时得到 undefined;作者使用随包基础样式完成降级。若动态样式是内容正确呈现的必要条件,就必须放在 requires。调用异常仍应显示错误,不能以可选为由吞掉失败。
90
+
91
+ 跨端应用模块按清单装配具体服务:未声明的功能访问明确报错;一个插件的可选需求不影响另一个插件。不增加 hasCapability/getCapability 通用查询器,不在环境对象里列宿主能力。
92
+
93
+ 媒体解析与展示需要 requires: ["media"]。useResourceUpload() 在只读或没有资源存储的作用域返回 undefined,表示当前不能上传,并不表示媒体宿主整体缺失;不能通过链接输入绕过只读限制。功能存在、用户授权、当前作用域允许与网络请求成功是四件不同的事。
41
94
 
42
- ## 跨端清单
95
+ ## 同步与资源上传
43
96
 
44
- 格式为 `formatVersion: 3`、`platform: portable`、`profile: web-v1`、`apiVersion: 1`、CJS 单入口。targets 至少包含 desktop/android/ios 中一个,每个平台声明:
97
+ 桌面、Android 和 iOS 使用同一套 context.sync、context.upload、context.fetch 和 settings.register API。同步提供方声明 requires: ["fetch", "sync"],上传提供方声明 requires: ["fetch", "upload"];同包同时提供两者时声明三项。API 的存在由宿主加载前检查,作者不写平台能力查询。
45
98
 
46
- | 字段 | 含义 |
47
- | ------------- | --------------------------------------------------------- |
48
- | minAppVersion | 该端最低客户端版本 |
49
- | required | 必需能力,缺少时在模块执行前拒绝 |
50
- | optional | 可选能力,不能与 required 重复 |
51
- | elements | 编辑器包按节点类型填写 none/render/edit,普通页面包不填写 |
99
+ 领域表单仍接收 syncConfig/uploadConfig 的 value 与 save(value)。save 表达保存配置的意图:持久化、选用、测试和切换确认由宿主编排。当前桌面显式保存并选用,移动字段失焦保存后在服务页显式选用;作者不调用原生存储或宿主路由。保存失败保留输入,不把调用成功等同于网络测试通过。
52
100
 
53
- 宿主必须显式支持 web-v1,并同时满足平台、版本与必需能力。模板的最低版本用于开发矩阵,不是现有正式客户端已接线的承诺。
101
+ 同一插件可以保留桌面设置视图和移动设置视图,共用配置字段、校验和存储业务代码。环境只用于选择交互视图,不分叉 API。ConfigurationPanel 是公共 UI 的账号卡、位置字段和选择弹层组合,可用于迁移已有移动表单。
54
102
 
55
- 编辑器包每个目标必须列出全部节点并与实际贡献一致。none 不装配,render 仅展示,edit 允许编辑和插入;未声明默认 none。受控开发宿主在标准组件和提交 API 中执行等级限制;清单校验本身不改变编辑器行为。
103
+ 同步与上传的完整配置分别归各插件,不做统一账号共享;不要把凭据存入 context.storage。宿主在任务开始固定配置,停用/切库后不交付迟到结果。两端网络为原生 HTTP(S) 流式传输,取消覆盖响应体消费阶段;不承诺浏览器 Cookie、后台续传或进程终止后继续任务。
56
104
 
57
- 构建工具从 `@tau/plugins/portable` 使用 validatePortableDistributionManifest:严格拒绝未知 required/optional、预发布插件版本和含移动目标的非空 permissions,失败保留上一有效产物。validatePortablePluginManifest 是基础严格校验;客户端 readPortablePluginManifest 返回 ReadablePortablePluginManifest,保留未来能力名,未知 required 在兼容检查拒绝,未知 optional 缺失允许降级;不删除这些名称后再做审核清单对账。结构、权限词表、profile 与节点等级仍严格。旧格式校验继续拒绝格式 3;不要改格式号绕过限制。
105
+ 同步提供方继续实现相同的 `Uint8Array` 对象接口。宿主统一管理数据库、资源和会话的分块、校验与重组,作者无需增加移动分支或专用分片。对象名由宿主决定,提供方应原样存取字节,不依赖数据库后缀、目录布局或清单内容。公网直链上传仍接收完整资源并返回真实 HTTP(S) URL,其内存与远端服务约束保持原样。
58
106
 
59
- ## 依赖与桌面特有能力
107
+ ## 构建和分发
60
108
 
61
- 普通依赖打包;React、React DOM、SDK 根入口和 UI 由宿主提供。web-v1 不开放 whiteboard/sync 子入口、host/environment-host 或 Node 模块。构建检查只能发现部分错误,不能证明任意 JS 行为安全。
109
+ buildPortablePluginManifest(authorManifest, output) 接收作者清单和构建器提供的 main/styles/integrity/skills,输出格式 3、apiVersion 1、profile web-v1、CJS 单入口的发行清单。targets 展开为各端 required/optional/elements,插件中心只消费规范化结果,不执行作者源码。
62
110
 
63
- 格式 3 不支持 backend、whiteboard 或 Skill 脚本。需要 Node 时明确选择旧桌面格式 2:移除 profile/targets,填写 platform: desktop 和顶层 minAppVersion,按[后台契约](backend.md)开发。
111
+ 宿主内部 PortablePluginHost 的 capabilities 与作者环境分离。客户端同时校验平台、版本、profile 与必需功能;未知必需项拒绝,未知可选项不授予功能。构建器只推导明确规则,不声称能推断任意 JS 的全部依赖。
64
112
 
65
- 构建器仍支持旧格式 1/2。`__PLUGIN_PORTABLE__` 是按格式注入的构建常量:跨端默认示例使用 navigation/环境 hook,显式旧桌面格式使用 sidebar/基础页面,没有运行失败后的自动回退。跨端三端产物仍是同一文件。
113
+ 纯 Markdown Skill 由目录收集,桌面读取,移动校验保存但不执行;脚本与后台不因此成为移动能力。现有桌面领域插件保持其真实支持范围。移动业务数据权限未接时,不允许发行声明这些权限的移动目标。
66
114
 
67
- ## 验证口径
115
+ React、SDK 与公共 UI 由宿主提供,其他浏览器依赖随包构建;不引用宿主 src,不导入 host/environment-host 等内部装配入口。可信插件与宿主共享 JS 环境,能力检查、完整性摘要和用户权限不构成恶意代码沙箱。
68
116
 
69
- 同一模板提供 `examples/editor.tsx`。需要编辑器起点时,将 src/index.tsx 改为导出该文件的 default,manifest 添加 editor: true,并在各目标声明 editor.elements.v1 与 `elements: { "example.note": "edit" }`(只展示的平台用 render)。不要为手机另造节点类型;未适配的写入保护与交互仍须宿主验收。
117
+ ## 验证
70
118
 
71
- 仓库外构建证明类型闭包、依赖与产物;兼容矩阵证明声明校验,不代表真机运行。宿主提供页面守卫、标准浮层返回、节点提交保护和原生包事务。移动源码组件使用草稿保存/取消,复杂手势与真机行为分别验收;桌面格式 3 正式安装、未接移动业务 API、最低系统和完整发行签名等必须独立验证,不能以 SDK 发布替代。
119
+ 仓库外构建验证依赖闭包、类型和包格式;设备联调验证安装、启用、插入、编辑、保存、取消、只读与重启恢复。两者分别记录,模拟器不能替代真机、最低系统、平板与性能验收。发布 SDK、插件和客户端分别遵循明确发行授权。
@@ -76,7 +76,8 @@ context.settings.register({
76
76
 
77
77
  - 配置属性是可选的,使用前先检查是否存在。
78
78
  - `value` 是之前保存的 JSON 值,用户还没保存过时可能为空。读取后自己校验结构,缺失的字段用默认值。
79
- - `save` 失败时保留用户的输入并显示错误;成功后再提示已保存。
79
+ - `save` 表达保存配置意图,持久化、选用与确认由宿主处理;两端不新增不同的作者接口。失败时保留用户输入,成功后再提示已保存。
80
+ - 同步、上传分别声明 sync/upload 和 fetch;两端可保留独立 UI,共用配置与业务代码。账号归各插件独立配置,不做统一共享。
80
81
  - 配置由 Tau 保存,**不要再存一份到 `context.storage`**:`storage` 会随笔记库同步,不适合放凭据。
81
82
  - `create(config)` 收到的就是这里保存的值。
82
83
 
@@ -51,7 +51,7 @@ context.settings.register({
51
51
  });
52
52
  ```
53
53
 
54
- 组件从 `uploadConfig.value` 读取配置,用户保存时调用 `await uploadConfig.save(config)`。保存后,Tau 会把你的插件选为当前的上传目标。
54
+ 组件从 `uploadConfig.value` 读取配置,用户保存时调用 `await uploadConfig.save(config)`。save 表达保存意图;当前桌面保存并选用,移动保存后由服务页显式选用,作者无需操作宿主设置。
55
55
 
56
56
  ## 职责划分
57
57
 
package/docs/release.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # 发布与更新
2
2
 
3
- 模板使用 SDK 0.36.0 与 UI 0.4.0。格式 3 可经工作流上传待审,必须提交每个声明平台的人工验收证据,CI 不会自动批准。移动安装需 Android/iOS 0.2.1 及中心兼容选版;桌面正式客户端仍使用旧格式,格式 3 只供显式桌面开发目录验证。install:local 不把格式 3 写入旧正式目录,不要改格式号绕过限制。
3
+ 模板使用 SDK 0.38.0 与 UI 0.5.0,当前清单要求桌面至少 0.59.2、Android/iOS 至少 0.2.3。格式 3 可经工作流发布;OIDC 推送者与插件所有者一致、本人有审核权限且仓库已绑定时自动批准,其他提交进入人工审核。作者负责声明平台的适配和测试;审核者只做上架审核,不要求平台测试或验证记录。实际安装还须通过中心兼容选版和平台分发开关。install:local 不把格式 3 写入旧正式目录,不要改格式号绕过限制。
4
4
 
5
5
  插件写好之后,发布到[插件中心](https://plugins.taunote.app),用户就能在 Tau 中搜索、安装和更新它。这一篇介绍发布前的准备、第一次发布、之后的版本更新,以及如何升级 SDK。
6
6
 
@@ -124,7 +124,7 @@ pnpm build
124
124
  各版本的变化见已安装包中的 `node_modules/@tau/plugins/CHANGELOG.md`。
125
125
 
126
126
  - React 保持模板锁定的版本,它由 Tau 提供,版本不一致可能导致插件无法运行。
127
- - 新能力需要用户的 Tau 版本支持时,同时提高 manifest 的 `minAppVersion`。
127
+ - 新能力需要用户的 Tau 版本支持时,同时提高对应 `targets.<平台>.minAppVersion`;显式桌面旧格式使用顶层 `minAppVersion`。
128
128
  - 升级后在 Tau 中重新验证一遍主要功能。
129
129
 
130
130
  ### 同步模板的更新
@@ -1,6 +1,6 @@
1
1
  # 存储与网络
2
2
 
3
- 平台范围:context.storage 的私有 KV 已接桌面与 Android/iOS 调试宿主;下文 context.fetch 的原生网络适配仅桌面已接。插件中心的原生下载不等于插件网络 API。结构化 records/entities/transaction 也不是 KV 的别名,移动尚未接入。详见 [API 支持矩阵](api-support.md)。
3
+ 平台范围:context.storage 与声明 fetch 的原生网络适配已接桌面、Android 和 iOS。移动请求与响应各限 128 MiB,不承诺后台续传。结构化 records/entities/transaction 也不是 KV 的别名,移动尚未接入。详见 [API 支持矩阵](api-support.md)。
4
4
 
5
5
  ## 私有存储
6
6
 
package/docs/ui.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  跨端开发包的通用入口用 `context.navigation.registerEntry`,不使用桌面 sidebar API。页面注销会回收相关入口,展示位置由宿主决定;环境与可选能力见[跨端契约](portability.md)。下面的侧边栏、通知等桌面能力不自动包含在 web-v1 中。
4
4
 
5
- 下述四种位置描述桌面呈现。移动只有页面/语义入口和插件自己的设置页;commands.v1 提供注册与回收,不自动增加手机命令面板;通知、旧 sidebar、首页/对象/详情扩展未接。具体见 [API 支持矩阵](api-support.md)。
5
+ 下述四种位置描述桌面呈现。移动只有页面/语义入口和插件自己的设置页;commands 提供注册与回收,不自动增加手机命令面板;通知、旧 sidebar、首页/对象/详情扩展未接。具体见 [API 支持矩阵](api-support.md)。
6
6
 
7
7
  桌面插件可以通过四种方式出现在界面里:
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiongtao.xt/tau-plugins",
3
- "version": "0.36.0",
3
+ "version": "0.38.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
package/portable.js CHANGED
@@ -1,20 +1,26 @@
1
1
  import {
2
+ PLUGIN_BASE_REQUIREMENTS,
2
3
  PORTABLE_PLATFORMS,
3
4
  PORTABLE_SHARED_MODULES,
4
5
  assertPortableElementDeclarations,
5
6
  assertPortablePluginCompatibility,
7
+ buildPortablePluginManifest,
6
8
  getPortableElementSupport,
9
+ isPluginCapability,
7
10
  readPortablePluginManifest,
8
11
  validatePortableDistributionManifest,
9
12
  validatePortablePluginManifest
10
- } from "./client/chunk-D4PV3N7Q.js";
13
+ } from "./client/chunk-BKZ7HC6P.js";
11
14
  import "./client/chunk-FZTR4KOY.js";
12
15
  export {
16
+ PLUGIN_BASE_REQUIREMENTS,
13
17
  PORTABLE_PLATFORMS,
14
18
  PORTABLE_SHARED_MODULES,
15
19
  assertPortableElementDeclarations,
16
20
  assertPortablePluginCompatibility,
21
+ buildPortablePluginManifest,
17
22
  getPortableElementSupport,
23
+ isPluginCapability,
18
24
  readPortablePluginManifest,
19
25
  validatePortableDistributionManifest,
20
26
  validatePortablePluginManifest
@@ -1,4 +1,9 @@
1
- import "./client/chunk-D4PV3N7Q.js";
1
+ import {
2
+ PORTABLE_SHARED_MODULES,
3
+ assertPortableElementDeclarations,
4
+ getPortableElementSupport,
5
+ readPortablePluginManifest
6
+ } from "./client/chunk-BKZ7HC6P.js";
2
7
  import {
3
8
  PLUGIN_SHARED_MODULES,
4
9
  validatePluginManifest
@@ -63,10 +68,65 @@ function assertPluginEditorExtension(extension) {
63
68
 
64
69
  // packages/plugins/src/rendering.ts
65
70
  var PLUGIN_RENDER_VERSION = 1;
71
+ function readPublishedPluginManifest(value) {
72
+ return value?.formatVersion === 3 ? readPortablePluginManifest(value) : validatePluginManifest(value);
73
+ }
74
+ function evaluatePublishedPluginPackage(artifact, modules) {
75
+ const manifest = readPublishedPluginManifest(artifact.manifest);
76
+ if (manifest.formatVersion !== 3)
77
+ return evaluatePluginPackage({ ...artifact, manifest }, modules);
78
+ if (!manifest.editor || !manifest.targets.desktop) throw new Error("\u535A\u5BA2\u6E32\u67D3\u9700\u8981\u684C\u9762\u7F16\u8F91\u5668\u8D21\u732E");
79
+ const definition = evaluateModule(manifest, artifact.code, modules, PORTABLE_SHARED_MODULES);
80
+ assertPortableElementDeclarations(manifest, getPluginNodeTypes(definition));
81
+ return adaptPortablePluginDefinition(definition, manifest, "desktop").definition;
82
+ }
66
83
  function evaluatePluginPackage(artifact, modules) {
67
84
  const manifest = validatePluginManifest(artifact.manifest);
68
85
  return evaluateModule(manifest, artifact.code, modules, PLUGIN_SHARED_MODULES);
69
86
  }
87
+ function adaptPortablePluginDefinition(definition, manifest, platform) {
88
+ const support = Object.freeze(
89
+ Object.fromEntries(
90
+ getPluginNodeTypes(definition).map((type) => [
91
+ type,
92
+ getPortableElementSupport(manifest, platform, type)
93
+ ])
94
+ )
95
+ );
96
+ const extensions = definition.editorExtensions?.flatMap((extension) => {
97
+ const elements = extension.elements?.filter((element) => support[element.type] !== "none").map(
98
+ (element) => support[element.type] === "edit" ? element : { ...element, behaviors: void 0 }
99
+ );
100
+ if (!elements?.length) return [];
101
+ const types = new Set(elements.map((element) => element.type));
102
+ const editable = elements.every((element) => support[element.type] === "edit");
103
+ return [
104
+ {
105
+ ...extension,
106
+ elements,
107
+ styleSources: extension.styleSources?.filter((source) => types.has(source.type)),
108
+ htmlSerializers: extension.htmlSerializers?.filter(
109
+ (serializer) => types.has(serializer.type)
110
+ ),
111
+ ...editable ? {} : {
112
+ blockPanel: void 0,
113
+ commands: void 0,
114
+ hotkeys: void 0,
115
+ menu: void 0,
116
+ behaviorsFor: void 0
117
+ }
118
+ }
119
+ ];
120
+ });
121
+ return {
122
+ support,
123
+ definition: {
124
+ ...definition,
125
+ editorExtensions: extensions?.length ? extensions : void 0,
126
+ editorCodecs: definition.editorCodecs?.filter((codec) => support[codec.type] !== "none")
127
+ }
128
+ };
129
+ }
70
130
  function evaluateModule(manifest, code, modules, allowed) {
71
131
  const module = { exports: {} };
72
132
  new Function(
@@ -163,7 +223,7 @@ function assertRenderTypes(definition, expected) {
163
223
  // packages/plugins/src/publish-artifacts.ts
164
224
  var PLUGIN_RENDER_VERSION2 = PLUGIN_RENDER_VERSION;
165
225
  function evaluatePluginPackage2(artifact, modules) {
166
- return evaluatePluginPackage(artifact, modules);
226
+ return evaluatePublishedPluginPackage(artifact, modules);
167
227
  }
168
228
  function assertRenderTypes2(definition, types) {
169
229
  assertRenderTypes(definition, types);
@@ -173,5 +233,5 @@ export {
173
233
  PLUGIN_SHARED_MODULES,
174
234
  assertRenderTypes2 as assertRenderTypes,
175
235
  evaluatePluginPackage2 as evaluatePluginPackage,
176
- validatePluginManifest
236
+ readPublishedPluginManifest as validatePluginManifest
177
237
  };
@@ -35,18 +35,21 @@ export { default as InlineChromiumBugfix } from "../components/InlineChromiumBug
35
35
  export { default as useIsLastElement } from "../hooks/useIsLastElement";
36
36
  export { registerBlockNavigation, hasBlockNavigation, unregisterBlockNavigation, focusPreviousBlock, focusNextBlock, type BlockNavigationHandler, } from "../utils/blockNavigation";
37
37
  export { isCollapsed, getCurrentTextNode } from "../utils/editor";
38
- export { deleteVoidBlock } from "../utils/nodeOperations";
38
+ export { copyNodeToClipboard, deleteVoidBlock } from "../utils/nodeOperations";
39
39
  export { getSelectionSnapshot, isSelectionSnapshotUnchanged } from "../utils/selectionSnapshot";
40
40
  export { createParagraph, isParagraphElement, type ParagraphElement } from "../model/paragraph";
41
41
  export { insertParagraphAndFocus } from "../utils/editor";
42
42
  export { isAtParagraphStart, isParagraphAndEmpty } from "../utils/editor";
43
43
  export { isNodeEmpty } from "../kit/elementEmpty";
44
44
  export { createBlockConversionMenu } from "../menu/conversion";
45
+ export { resolveElementMenu } from "../hooks/useDragHandlerMenu";
46
+ export type { ContextMenuItem } from "../components/EditorContextMenu/types";
45
47
  export { getCommandElementPath } from "../utils/commandTarget";
46
48
  export { captureEditorSubmission, captureElementSubmission, captureInsertionSubmission, type Submission, type SubmissionOutcome, type SubmissionDiscardReason, } from "./submission";
47
49
  export { default as AddParagraph, type AddParagraphRef } from "../components/AddParagraph/index";
48
50
  export { IOverlayBackDismiss, type OverlayBackDismissProps, type OverlayBackDismissAdapter, } from "../services/overlayBackDismiss";
49
51
  export { default as OverlayBackDismiss } from "../components/OverlayBackDismiss/index";
52
+ export { IEditorInteraction, useTouchInteraction, isTouchInteraction, type EditorInteraction, } from "../services/interaction";
50
53
  export { getElementParent, getClosestCurrentElement } from "../utils/editor";
51
54
  export { getParentNodeByNode, getPreviousSiblingNode } from "../utils/element";
52
55
  export { getPrevPath } from "../utils/path";
@@ -0,0 +1,35 @@
1
+ import { ReactNode } from "react";
2
+ import { Editor, Path, Element } from "slate";
3
+ export interface ContextMenuItem {
4
+ key: string;
5
+ label: string;
6
+ icon?: ReactNode;
7
+ danger?: boolean;
8
+ disabled?: boolean;
9
+ children?: ContextMenuItem[];
10
+ onSelect?: () => void;
11
+ /** 该条目上方画一条组分隔线(由菜单聚合器在组边界标记) */
12
+ separator?: boolean;
13
+ /** 贡献该条目的扩展 id(MenuContributionSource.owner);合并子项的父项取首个来源 */
14
+ owner?: string;
15
+ }
16
+ export interface EditorContextMenuProps {
17
+ readonly?: boolean;
18
+ visible: boolean;
19
+ position: {
20
+ x: number;
21
+ y: number;
22
+ };
23
+ items: ContextMenuItem[];
24
+ onClose: () => void;
25
+ }
26
+ export interface BuildMenuParams<T extends Element> {
27
+ element: T;
28
+ editor: Editor;
29
+ path: Path;
30
+ }
31
+ export interface UseDragHandlerMenuOptions<T extends Element> {
32
+ element: T;
33
+ editor: Editor;
34
+ buildMenuItems: (params: BuildMenuParams<T>) => ContextMenuItem[];
35
+ }
@@ -0,0 +1,17 @@
1
+ import { type ComponentType } from "react";
2
+ import type { ExtensionLayerProps } from "../../api/extension";
3
+ export interface RegisteredLayer {
4
+ readonly owner: string;
5
+ readonly component: ComponentType<ExtensionLayerProps>;
6
+ }
7
+ interface Props {
8
+ layer: RegisteredLayer;
9
+ readOnly: boolean;
10
+ report: (owner: string, error: unknown) => void;
11
+ }
12
+ export default function ExtensionLayers({ layers, report, readOnly, }: {
13
+ layers: readonly RegisteredLayer[];
14
+ report: Props["report"];
15
+ readOnly: boolean;
16
+ }): import("react/jsx-runtime").JSX.Element;
17
+ export {};
@@ -0,0 +1,39 @@
1
+ import { Editor, Element, Path } from "slate";
2
+ import { ContextMenuItem } from "../components/EditorContextMenu/types";
3
+ import { useInheritedKit } from "../kit/context";
4
+ type Kit = ReturnType<typeof useInheritedKit>;
5
+ /** 按 kit 聚合的扩展菜单声明对目标元素求值(手柄菜单与媒体属性条「更多」共用) */
6
+ export declare function resolveElementMenu<T extends Element>(kit: Kit, editor: Editor, element: T, extraItems?: (params: {
7
+ element: T;
8
+ editor: Editor;
9
+ path: Path;
10
+ }) => ContextMenuItem[]): ContextMenuItem[];
11
+ export interface UseDragHandlerMenuOptions<T extends Element> {
12
+ element: T;
13
+ editor: Editor;
14
+ /** 过渡:宿主/组件补充的旧形态条目(extraMenuItemsBuilder),打开菜单时求值、追加在末尾 */
15
+ extraItems?: (params: {
16
+ element: T;
17
+ editor: Editor;
18
+ path: Path;
19
+ }) => ContextMenuItem[];
20
+ }
21
+ /**
22
+ * 手柄点击菜单:数据来自 kit 聚合的扩展菜单声明(01 §5.4),
23
+ * 打开时对目标元素求值一次(when / disabled / 动态标题都是那一刻的快照)。
24
+ */
25
+ export declare function useDragHandlerMenu<T extends Element>(options: UseDragHandlerMenuOptions<T>): {
26
+ menuProps: {
27
+ visible: boolean;
28
+ position: {
29
+ x: number;
30
+ y: number;
31
+ };
32
+ items: ContextMenuItem[];
33
+ onClose: () => void;
34
+ };
35
+ dragHandlerProps: {
36
+ onClick: (e: React.MouseEvent) => void;
37
+ };
38
+ };
39
+ export {};
@@ -0,0 +1,39 @@
1
+ import { type AnyExtension } from "../api/legacy";
2
+ import type { EditorExtension } from "../api/extension";
3
+ import type { ServiceRegistration, ServiceRegistry } from "../services/registry";
4
+ import type { ThemeService } from "../theme/ThemeService";
5
+ import { ExtensionAssembly } from "./ExtensionAssembly";
6
+ /**
7
+ * EditorKit:宿主显式声明「这个编辑器由什么组成」(docs/editor-refactor ER-004)。
8
+ *
9
+ * 一个 kit 创建一次、可给多个编辑器复用:扩展的插件、快捷键、工具条条目与 type 分发表
10
+ * 在 kit 上预计算并缓存。需要个别差异时用 `kit.extend()` 派生,不做隐式合并。
11
+ */
12
+ export interface EditorKit {
13
+ readonly registry: ServiceRegistry;
14
+ readonly extensions: readonly EditorExtension[];
15
+ /** 本 kit 能渲染的元素类型;跨端覆盖测试(CONTENT_ELEMENT_TYPES)按它断言 */
16
+ readonly elementTypes: readonly string[];
17
+ /** 内部用:扩展的预计算结果(插件、快捷键、工具条、type 分发表) */
18
+ readonly assembly: ExtensionAssembly;
19
+ /** 派生:追加扩展或覆盖服务;同 type 扩展需显式 override */
20
+ extend(options: EditorKitExtendOptions): EditorKit;
21
+ }
22
+ export interface EditorKitOptions {
23
+ /** 元素与功能扩展;同元素类型重复会报错,除非 `override: true` */
24
+ extensions?: readonly AnyExtension[];
25
+ /** 平台能力与 UI 插槽 */
26
+ services?: ServiceRegistration[];
27
+ /** 主题服务;等价于注册 IThemeService,缺省时编辑器读 DOM */
28
+ theme?: ThemeService;
29
+ /** 允许后来的扩展按 type 覆盖先前的功能扩展;核心段落不可替换。 */
30
+ override?: boolean;
31
+ }
32
+ export interface EditorKitExtendOptions {
33
+ extensions?: readonly AnyExtension[];
34
+ services?: ServiceRegistration[];
35
+ theme?: ThemeService;
36
+ override?: boolean;
37
+ }
38
+ /** 核心只提供基础段落,产品功能由调用方显式选择。 */
39
+ export declare function createEditorKit(options?: EditorKitOptions): EditorKit;
@@ -0,0 +1,81 @@
1
+ import { type ReactElement } from "react";
2
+ import type { ContentResourceDeclarations } from "../../../../db-schema/content-resources";
3
+ import type { Editor } from "slate";
4
+ import type { RenderElementProps } from "slate-react";
5
+ import type { EditorExtension, ElementBehaviors } from "../api/extension";
6
+ import { CommandRegistry, type EditorHotkey } from "../api/command";
7
+ import { type ElementDragSpec } from "../api/drag";
8
+ import type { ElementIngestSpec } from "../api/ingest";
9
+ import type { MenuContributionSource } from "../menu/resolveMenu";
10
+ import { type AnyExtension } from "../api/legacy";
11
+ import type { Plugin } from "../utils/plugin";
12
+ import type { IBlockPanelListItem, IConfigItem } from "../types";
13
+ import type { RegisteredCopy } from "../api/copy";
14
+ import type { RegisteredDecoration, RegisteredMark } from "../api/marks";
15
+ import type { RegisteredInputRule } from "../api/inputRules";
16
+ import type { RegisteredLayer } from "../components/ExtensionLayers/index";
17
+ /** 一个扩展贡献的插件:内核按扩展逐组应用,出错隔离到组(extensionGuard.ts) */
18
+ export interface ExtensionPluginGroup {
19
+ /** 扩展 id,熔断与上报按它计 */
20
+ readonly type: string;
21
+ readonly plugins: readonly Plugin[];
22
+ }
23
+ /** 某元素类型上的一组声明式行为及其来源扩展,由内核的行为分发器调用(extensionGuard.ts) */
24
+ export interface ElementBehaviorEntry {
25
+ readonly extension: string;
26
+ readonly behaviors: ElementBehaviors;
27
+ }
28
+ /** 一个扩展的内容注入声明;owner 用于隔离熔断与日志 */
29
+ export interface IngestSource {
30
+ readonly owner: string;
31
+ readonly files?: ElementIngestSpec["files"];
32
+ readonly text?: ElementIngestSpec["text"];
33
+ }
34
+ /**
35
+ * 扩展的预计算结果:插件链、快捷键、悬浮工具条条目与 type → 渲染的分发表。
36
+ *
37
+ * 一个 kit 一份(取代原先每个编辑器一个 PluginOptimizer):同一个 kit 的多个编辑器共享,
38
+ * 不必每次挂载都重新收集。扩展集合由 kit 在创建时定好,所以这里只算一次,无需缓存淘汰。
39
+ */
40
+ /** v2 热键声明及其来源扩展;执行经命令注册表,熔断按命令的 owner */
41
+ export interface CommandHotkeyEntry {
42
+ readonly hotkey: EditorHotkey;
43
+ readonly owner: string;
44
+ }
45
+ export declare class ExtensionAssembly {
46
+ readonly extensions: readonly EditorExtension[];
47
+ readonly plugins: readonly Plugin[];
48
+ readonly pluginGroups: readonly ExtensionPluginGroup[];
49
+ /** v2 命令热键(绑命令 id) */
50
+ readonly commandHotkeys: readonly CommandHotkeyEntry[];
51
+ readonly commands: CommandRegistry;
52
+ readonly hoveringBarElements: readonly IConfigItem[];
53
+ /** 手柄/右键菜单的贡献来源(按扩展顺序);求值在打开菜单时进行 */
54
+ readonly menuSources: readonly MenuContributionSource[];
55
+ /** 元素类型 → 拖拽声明;未收录的类型没有拖拽 chrome(BlockDragHost 查询) */
56
+ readonly dragSpecs: ReadonlyMap<string, ElementDragSpec>;
57
+ /** 内容注入声明(drop/paste 认领管线);相同 accept 重复声明在构造时抛错 */
58
+ readonly ingestSources: readonly IngestSource[];
59
+ /** 本装配能渲染的元素类型(按扩展顺序) */
60
+ readonly elementTypes: readonly string[];
61
+ /** 元素类型 → 资源字段声明 */
62
+ readonly resources: ContentResourceDeclarations;
63
+ /** 元素类型 → 行为列表:该类型自己的在前,其他扩展经 behaviorsFor 挂上来的按扩展顺序在后 */
64
+ readonly behaviors: ReadonlyMap<string, readonly ElementBehaviorEntry[]>;
65
+ readonly copyPolicies: ReadonlyMap<string, RegisteredCopy>;
66
+ readonly marks: readonly RegisteredMark[];
67
+ readonly decorations: readonly RegisteredDecoration[];
68
+ readonly inputRules: readonly RegisteredInputRule[];
69
+ readonly layers: readonly RegisteredLayer[];
70
+ private readonly renderers;
71
+ private readonly owners;
72
+ constructor(extensions: readonly AnyExtension[]);
73
+ /** 先把一个扩展的全部贡献收齐,中途抛错则整个扩展都不装,不留半截 */
74
+ private collect;
75
+ hasElement(type: string): boolean;
76
+ render(props: RenderElementProps): ReactElement | undefined;
77
+ /** 元素类型归哪个扩展(上报与熔断按扩展 id) */
78
+ getElementOwner(type: string): EditorExtension | undefined;
79
+ /** 块菜单条目:每次打开菜单求值;单个扩展出错只丢它自己的条目 */
80
+ getBlockPanelItems(editor: Editor): IBlockPanelListItem[];
81
+ }
@@ -0,0 +1,21 @@
1
+ import type { ReactNode } from "react";
2
+ import type { AnyExtension } from "../api/legacy";
3
+ import type { EditorKit } from "./EditorKit";
4
+ /** 内核用:把本编辑器的 kit 传给子树(含嵌套编辑器与扩展组件) */
5
+ export declare function EditorKitScope({ kit, children }: {
6
+ kit: EditorKit;
7
+ children: ReactNode;
8
+ }): import("react/jsx-runtime").JSX.Element;
9
+ /** 继承外层编辑器的 kit;没有外层则为 null */
10
+ export declare function useInheritedKit(): EditorKit | null;
11
+ /**
12
+ * 解析本编辑器最终使用的 kit:显式传入 > 继承外层。
13
+ * 需要 per-instance 扩展时在此派生,同一组输入返回同一个 kit 实例(否则编辑器会重建)。
14
+ */
15
+ export declare function useResolvedKit(explicit: EditorKit | undefined): EditorKit;
16
+ /**
17
+ * 在 kit 基础上叠加单个编辑器的扩展;无扩展时返回原 kit。
18
+ * per-instance 扩展按 type 覆盖 kit 的同名实现(沿用迁移前的 later-wins 语义),
19
+ * 相同扩展实例返回同一个派生 kit(kit.extend 内部按实例集合缓存),编辑器不会因此重建。
20
+ */
21
+ export declare function useKitWithExtensions(kit: EditorKit, extensions: readonly AnyExtension[] | undefined): EditorKit;