@xiongtao.xt/tau-plugins 0.35.0 → 0.37.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 (39) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/client/chunk-PZ6FG7OR.js +289 -0
  3. package/docs/README.md +4 -2
  4. package/docs/api-support.md +71 -0
  5. package/docs/editor.md +3 -3
  6. package/docs/getting-started.md +25 -117
  7. package/docs/plugin-basics.md +11 -9
  8. package/docs/portability.md +107 -0
  9. package/docs/release.md +2 -0
  10. package/docs/storage-and-network.md +2 -0
  11. package/docs/ui.md +5 -1
  12. package/docs/user-data.md +2 -0
  13. package/package.json +5 -1
  14. package/portable.js +27 -0
  15. package/publish-artifacts.js +68 -4
  16. package/types/packages/editor/src/core/api/index.d.ts +4 -1
  17. package/types/packages/editor/src/core/components/EditorContextMenu/types.d.ts +35 -0
  18. package/types/packages/editor/src/core/components/ExtensionLayers/index.d.ts +17 -0
  19. package/types/packages/editor/src/core/hooks/useDragHandlerMenu.d.ts +39 -0
  20. package/types/packages/editor/src/core/kit/EditorKit.d.ts +39 -0
  21. package/types/packages/editor/src/core/kit/ExtensionAssembly.d.ts +81 -0
  22. package/types/packages/editor/src/core/kit/context.d.ts +21 -0
  23. package/types/packages/editor/src/core/menu/resolveMenu.d.ts +19 -0
  24. package/types/packages/editor/src/core/services/elementEditingPolicy.d.ts +6 -0
  25. package/types/packages/editor/src/core/utils/nodeOperations.d.ts +2 -2
  26. package/types/packages/plugins/src/capabilities.d.ts +7 -0
  27. package/types/packages/plugins/src/contract.d.ts +4 -0
  28. package/types/packages/plugins/src/environment.d.ts +37 -0
  29. package/types/packages/plugins/src/index.d.ts +3 -0
  30. package/types/packages/plugins/src/navigation.d.ts +14 -0
  31. package/types/packages/plugins/src/pages.d.ts +2 -0
  32. package/types/packages/plugins/src/portable.d.ts +67 -0
  33. package/types/packages/plugins/src/publish-artifacts.d.ts +8 -3
  34. package/types/packages/plugins/src/render-artifact.d.ts +2 -1
  35. package/types/packages/plugins/src/rendering.d.ts +78 -0
  36. package/types/packages/themes/src/themes/paper.theme.d.ts +1 -1
  37. package/types/packages/ui/src/UiHostProvider.d.ts +13 -0
  38. package/types/packages/ui/src/index.d.ts +1 -0
  39. package/types/packages/ui/src/primitives/Tabs.d.ts +3 -1
@@ -1,5 +1,7 @@
1
1
  # 插件的组成
2
2
 
3
+ 默认模板维护作者清单,构建器生成格式 3 发行清单;平台和节点声明见[跨端契约](portability.md)。作者不手写包格式、入口或摘要。
4
+
3
5
  一个 Tau 插件由以下几部分组成:
4
6
 
5
7
  - **manifest.json**:插件是谁、需要什么。Tau 不运行代码就能读到它。
@@ -15,18 +17,17 @@
15
17
 
16
18
  ```json
17
19
  {
18
- "formatVersion": 1,
19
20
  "id": "example.external-counter",
20
21
  "name": "计数器示例",
21
22
  "description": "在侧边栏记录并保存计数。",
22
23
  "categories": ["page"],
23
24
  "keywords": ["计数", "打卡"],
24
25
  "version": "1.0.0",
25
- "minAppVersion": "0.59.0",
26
- "apiVersion": 1,
27
- "platform": "desktop",
28
- "format": "cjs",
29
- "main": "main.js"
26
+ "targets": {
27
+ "desktop": { "minAppVersion": "0.59.2" },
28
+ "android": { "minAppVersion": "0.2.3" },
29
+ "ios": { "minAppVersion": "0.2.3" }
30
+ }
30
31
  }
31
32
  ```
32
33
 
@@ -38,11 +39,11 @@
38
39
  | `name` | 插件名称,显示在插件页和插件中心 |
39
40
  | `description` | 一句话简介,1 至 160 字 |
40
41
  | `version` | 插件版本,格式为 `主版本.次版本.修订号`,可带预发布后缀,如 `1.2.0-beta.1` |
41
- | `minAppVersion` | 需要的最低 Tau 版本,如 `0.59.0`。写完整版本号,不写 `>=`、`^` 之类的范围。客户端版本低于它时不会加载插件 |
42
+ | `targets` | 各平台最低应用版本;填写完整版本号,不写范围。省略平台表示不支持安装 |
42
43
  | `categories` | 插件中心的分类,可多选,也可以不写,见下表 |
43
44
  | `keywords` | 插件中心的搜索词,最多 5 个,每个不超过 20 字。例如 S3 插件可以写 `MinIO`、`R2` |
44
45
  | `permissions` | 插件可能申请的用户数据权限,见[用户数据 · 权限](user-data.md#权限)和 [AI](ai.md) |
45
- | `editor` | 声明了编辑器扩展时写 `true`,见[编辑器扩展](editor.md) |
46
+ | `editor` | 作者清单填写 elements 支持等级;发行包的 editor 标记由工具生成,见[跨端契约](portability.md) |
46
47
  | `whiteboard` | 声明了白板扩展时写 `true`,见[白板扩展](whiteboard.md) |
47
48
  | `backend` | 需要本机后台时填写,同时把 `formatVersion` 改为 `2`,见[本机后台](backend.md) |
48
49
 
@@ -64,7 +65,7 @@
64
65
 
65
66
  ### 保持模板值的字段
66
67
 
67
- `formatVersion`、`apiVersion`、`platform`、`format`、`main` 保持模板里的值。`styles`、`skills` 和 `integrity`(文件摘要)由 `pnpm build` 自动写入构建产物,不要手写,也不要直接修改 ZIP 里的文件。
68
+ `formatVersion`、`apiVersion`、`platform`、`profile`、`format`、`main` 按所选协议保持一致。`styles` 和 `integrity` 由构建生成;skills 仅旧桌面格式支持。不要直接修改 ZIP。
68
69
 
69
70
  ## 入口与插件定义
70
71
 
@@ -139,6 +140,7 @@ create: () => ({
139
140
  | ----------------------------------------------------- | -------------------------------------------- | --------------------------------------------- |
140
141
  | `pluginId`、`workspaceId` | 当前插件 ID 与工作区 ID(不要解析工作区 ID) | |
141
142
  | `signal` | 本次运行结束时中止 | [取消与清理](#取消与清理) |
143
+ | `environment`、`navigation` | 当前环境与语义功能入口 | [跨端契约](portability.md) |
142
144
  | `register` | 托管需要清理的资源 | [取消与清理](#取消与清理) |
143
145
  | `commands` | 注册命令 | [界面](ui.md#命令) |
144
146
  | `pages`、`sidebar` | 注册页面与侧边栏入口 | [界面](ui.md#页面) |
@@ -0,0 +1,107 @@
1
+ <!-- 由 scripts/plugins/sync-author-docs.mjs 从 packages/plugins/docs/portability.md 生成,请勿单独编辑。 -->
2
+
3
+ # 多端插件作者契约
4
+
5
+ 一个 SDK、一套模板、同一插件 ID/版本对应同一 ZIP。普通页面直接使用公共 API;宿主在加载前检查兼容性。具体宿主实现范围见 [API 支持矩阵](api-support.md),SDK 类型存在不等于所有接口都已在移动端接入。
6
+
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。编辑器声明使用 editor: { elements: { "abc": "edit" } },构建器补齐 editor/editorCodecs。每个实际节点必须明确列出;edit 支持显示、插入和编辑,render 只显示,none 不装配但保留原始数据。
31
+
32
+ 根级 requires、optional、editor.elements 为公共声明。目标平台不写时继承;写了就整组替换,空数组清空该组额外需求,不能取消公共基础要求。节点映射也是完整替换,不深合并。必需与可选不能重叠,未知名称在构建时拒绝;省略平台表示不允许该平台应用安装。
33
+
34
+ ## 页面和入口
35
+
36
+ ```tsx
37
+ const page = context.pages.register({
38
+ id: "tasks",
39
+ title: "任务管理",
40
+ component: TasksPage,
41
+ });
42
+ context.navigation.registerEntry({ id: "tasks", title: "任务管理", page });
43
+ context.settings.register({ id: "preferences", title: "设置", component: Settings });
44
+ ```
45
+
46
+ 页面不自动创建入口。桌面侧栏、移动插件功能列表消费同一语义声明;作者不操作宿主 history,不导入宿主路由。详情页可没有入口。页面句柄的 open 仅接收标量参数,页面注销后入口回收。
47
+
48
+ Dialog/Drawer 直接使用公共 UI。宿主负责浮层返回、层级与安全区。页面组件通过 pageContext.registerLeaveGuard 登记离开守卫,并在 effect 清理时注销;系统终止进程不保证调用守卫或 deactivate,重要数据应及时保存。
49
+
50
+ context.storage 为当前工作区的插件私有 JSON 存储,不等于业务实体数据库。异步任务处理 signal 与工作区失效;资源通过 context.register 或组件 effect 回收。
51
+
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
+ };
61
+ }
62
+ ```
63
+
64
+ React 组件使用 usePluginEnvironment(),非 React 调用每次读取 context.environment,二者是同一宿主源的不可变快照。平台在会话内固定,输入变化自动通知组件;未注入环境是装配错误,不假定某个平台。
65
+
66
+ coarsePointer 对应 (any-pointer: coarse),finePointer 对应 (any-pointer: fine):只表达 WebView 报告的指针精度,二者可以同时为真。它们不识别手机、平板、当前事件来源、键盘或悬停能力;一次手势的来源看 PointerEvent。普通插件一般不需要读取环境。
67
+
68
+ 环境没有 layout 或能力清单。布局用 CSS 与容器宽度,不能用系统平台推导宽窄。Android 平板沿用 android,未来 iPad 宿主沿用 SDK 的 ios 家族标识;分屏时重排布局,接入鼠标时增强操作而不删除触摸按钮。平板支持还需要宿主和设备验收,不能从平台声明推断已通过。
69
+
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"]
86
+ }
87
+ ```
88
+
89
+ 通过 useSourceBlock(element).compiler(行内源码为 useInlineSource)读取编译器,宿主未提供时得到 undefined;作者使用随包基础样式完成降级。若动态样式是内容正确呈现的必要条件,就必须放在 requires。调用异常仍应显示错误,不能以可选为由吞掉失败。
90
+
91
+ 跨端应用模块按清单装配具体服务:未声明的功能访问明确报错;一个插件的可选需求不影响另一个插件。不增加 hasCapability/getCapability 通用查询器,不在环境对象里列宿主能力。
92
+
93
+ 媒体解析与展示需要 requires: ["media"]。useResourceUpload() 在只读或没有资源存储的作用域返回 undefined,表示当前不能上传,并不表示媒体宿主整体缺失;不能通过链接输入绕过只读限制。功能存在、用户授权、当前作用域允许与网络请求成功是四件不同的事。
94
+
95
+ ## 构建和分发
96
+
97
+ buildPortablePluginManifest(authorManifest, output) 接收作者清单和构建器提供的 main/styles/integrity/skills,输出格式 3、apiVersion 1、profile web-v1、CJS 单入口的发行清单。targets 展开为各端 required/optional/elements,插件中心只消费规范化结果,不执行作者源码。
98
+
99
+ 宿主内部 PortablePluginHost 的 capabilities 与作者环境分离。客户端同时校验平台、版本、profile 与必需功能;未知必需项拒绝,未知可选项不授予功能。构建器只推导明确规则,不声称能推断任意 JS 的全部依赖。
100
+
101
+ 纯 Markdown Skill 由目录收集,桌面读取,移动校验保存但不执行;脚本与后台不因此成为移动能力。现有桌面领域插件保持其真实支持范围。移动业务数据权限未接时,不允许发行声明这些权限的移动目标。
102
+
103
+ React、SDK 与公共 UI 由宿主提供,其他浏览器依赖随包构建;不引用宿主 src,不导入 host/environment-host 等内部装配入口。可信插件与宿主共享 JS 环境,能力检查、完整性摘要和用户权限不构成恶意代码沙箱。
104
+
105
+ ## 验证
106
+
107
+ 仓库外构建验证依赖闭包、类型和包格式;设备联调验证安装、启用、插入、编辑、保存、取消、只读与重启恢复。两者分别记录,模拟器不能替代真机、最低系统、平板与性能验收。发布 SDK、插件和客户端分别遵循明确发行授权。
package/docs/release.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # 发布与更新
2
2
 
3
+ 模板使用 SDK 0.36.0 与 UI 0.4.0。格式 3 可经工作流发布;OIDC 推送者与插件所有者一致、本人有审核权限且仓库已绑定时自动批准,其他提交进入人工审核。作者负责声明平台的适配和测试;审核者只做上架审核,不要求平台测试或验证记录。移动安装需 Android/iOS 0.2.1 及中心兼容选版;桌面 0.59.1 支持格式 3 正式安装;旧桌面继续使用旧格式版本。install:local 不把格式 3 写入旧正式目录,不要改格式号绕过限制。
4
+
3
5
  插件写好之后,发布到[插件中心](https://plugins.taunote.app),用户就能在 Tau 中搜索、安装和更新它。这一篇介绍发布前的准备、第一次发布、之后的版本更新,以及如何升级 SDK。
4
6
 
5
7
  ## 发布前的准备
@@ -1,5 +1,7 @@
1
1
  # 存储与网络
2
2
 
3
+ 平台范围:context.storage 的私有 KV 已接桌面与 Android/iOS 调试宿主;下文 context.fetch 的原生网络适配仅桌面已接。插件中心的原生下载不等于插件网络 API。结构化 records/entities/transaction 也不是 KV 的别名,移动尚未接入。详见 [API 支持矩阵](api-support.md)。
4
+
3
5
  ## 私有存储
4
6
 
5
7
  `context.storage` 是插件自己的键值存储,适合保存设置、进度、缓存等小块数据。
package/docs/ui.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # 界面
2
2
 
3
- 插件可以通过四种方式出现在 Tau 的界面里:
3
+ 跨端开发包的通用入口用 `context.navigation.registerEntry`,不使用桌面 sidebar API。页面注销会回收相关入口,展示位置由宿主决定;环境与可选能力见[跨端契约](portability.md)。下面的侧边栏、通知等桌面能力不自动包含在 web-v1 中。
4
+
5
+ 下述四种位置描述桌面呈现。移动只有页面/语义入口和插件自己的设置页;commands 提供注册与回收,不自动增加手机命令面板;通知、旧 sidebar、首页/对象/详情扩展未接。具体见 [API 支持矩阵](api-support.md)。
6
+
7
+ 桌面插件可以通过四种方式出现在界面里:
4
8
 
5
9
  - **命令**:出现在 Ctrl+K 命令面板中,用户搜索后执行。
6
10
  - **页面**:一个完整的 React 页面,和 Tau 自己的页面一样参与前进、后退。
package/docs/user-data.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # 用户数据
2
2
 
3
+ 本篇业务授权、data/content、实体/记录/关联/事务与宿主动作适用于桌面;移动宿主尚未接线,即使是无需业务权限的插件自有实体也不能直接使用。移动当前只提供私有 KV,含移动目标的 permissions 必须为空。先查 [API 支持矩阵](api-support.md)。
4
+
3
5
  插件可以读取和修改用户在 Tau 中的内容:卡片、文章、项目文档、待办和日程,也可以创建属于插件自己的内容。这一篇按以下顺序介绍:
4
6
 
5
7
  1. [权限](#权限):访问用户数据前必须了解的授权方式。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiongtao.xt/tau-plugins",
3
- "version": "0.35.0",
3
+ "version": "0.37.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,6 +22,10 @@
22
22
  "types": "./types/packages/plugins/src/package.d.ts",
23
23
  "default": "./package.js"
24
24
  },
25
+ "./portable": {
26
+ "types": "./types/packages/plugins/src/portable.d.ts",
27
+ "default": "./portable.js"
28
+ },
25
29
  "./backend": {
26
30
  "types": "./types/packages/plugins/src/backend.d.ts",
27
31
  "default": "./runtime.js"
package/portable.js ADDED
@@ -0,0 +1,27 @@
1
+ import {
2
+ PLUGIN_BASE_REQUIREMENTS,
3
+ PORTABLE_PLATFORMS,
4
+ PORTABLE_SHARED_MODULES,
5
+ assertPortableElementDeclarations,
6
+ assertPortablePluginCompatibility,
7
+ buildPortablePluginManifest,
8
+ getPortableElementSupport,
9
+ isPluginCapability,
10
+ readPortablePluginManifest,
11
+ validatePortableDistributionManifest,
12
+ validatePortablePluginManifest
13
+ } from "./client/chunk-PZ6FG7OR.js";
14
+ import "./client/chunk-FZTR4KOY.js";
15
+ export {
16
+ PLUGIN_BASE_REQUIREMENTS,
17
+ PORTABLE_PLATFORMS,
18
+ PORTABLE_SHARED_MODULES,
19
+ assertPortableElementDeclarations,
20
+ assertPortablePluginCompatibility,
21
+ buildPortablePluginManifest,
22
+ getPortableElementSupport,
23
+ isPluginCapability,
24
+ readPortablePluginManifest,
25
+ validatePortableDistributionManifest,
26
+ validatePortablePluginManifest
27
+ };
@@ -1,3 +1,9 @@
1
+ import {
2
+ PORTABLE_SHARED_MODULES,
3
+ assertPortableElementDeclarations,
4
+ getPortableElementSupport,
5
+ readPortablePluginManifest
6
+ } from "./client/chunk-PZ6FG7OR.js";
1
7
  import {
2
8
  PLUGIN_SHARED_MODULES,
3
9
  validatePluginManifest
@@ -62,18 +68,76 @@ function assertPluginEditorExtension(extension) {
62
68
 
63
69
  // packages/plugins/src/rendering.ts
64
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
+ }
65
83
  function evaluatePluginPackage(artifact, modules) {
66
84
  const manifest = validatePluginManifest(artifact.manifest);
85
+ return evaluateModule(manifest, artifact.code, modules, PLUGIN_SHARED_MODULES);
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
+ }
130
+ function evaluateModule(manifest, code, modules, allowed) {
67
131
  const module = { exports: {} };
68
132
  new Function(
69
133
  "require",
70
134
  "module",
71
135
  "exports",
72
- '"use strict";\n' + artifact.code + `
136
+ '"use strict";\n' + code + `
73
137
  //# sourceURL=tau-plugin://${manifest.id}/${manifest.version}/main.js`
74
138
  )(
75
139
  (id) => {
76
- if (!PLUGIN_SHARED_MODULES.some((name) => name === id) || !Object.hasOwn(modules, id))
140
+ if (!allowed.includes(id) || !Object.hasOwn(modules, id))
77
141
  throw new Error(`\u63D2\u4EF6\u4F7F\u7528\u4E86\u672A\u63D0\u4F9B\u7684\u5BBF\u4E3B\u6A21\u5757\uFF1A${id}`);
78
142
  return modules[id];
79
143
  },
@@ -159,7 +223,7 @@ function assertRenderTypes(definition, expected) {
159
223
  // packages/plugins/src/publish-artifacts.ts
160
224
  var PLUGIN_RENDER_VERSION2 = PLUGIN_RENDER_VERSION;
161
225
  function evaluatePluginPackage2(artifact, modules) {
162
- return evaluatePluginPackage(artifact, modules);
226
+ return evaluatePublishedPluginPackage(artifact, modules);
163
227
  }
164
228
  function assertRenderTypes2(definition, types) {
165
229
  assertRenderTypes(definition, types);
@@ -169,5 +233,5 @@ export {
169
233
  PLUGIN_SHARED_MODULES,
170
234
  assertRenderTypes2 as assertRenderTypes,
171
235
  evaluatePluginPackage2 as evaluatePluginPackage,
172
- validatePluginManifest
236
+ readPublishedPluginManifest as validatePluginManifest
173
237
  };
@@ -35,13 +35,15 @@ 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";
@@ -57,3 +59,4 @@ export type { Plugin } from "../utils/plugin";
57
59
  export { BLOCK_DRAG_GROUP, DragHandle, type DragHandleProps } from "../components/BlockDrag/index";
58
60
  export { panAroundAnchor, pointFromCenter, type Point as ZoomPanPoint } from "../utils/zoomPan";
59
61
  export { FloatingToolbar, ToolbarDivider, ToolbarIconButton } from "../components/FloatingToolbar/index";
62
+ export { IElementEditingPolicy, type ElementEditingPolicy } from "../services/elementEditingPolicy";
@@ -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;
@@ -0,0 +1,19 @@
1
+ import type { EditorMenuContext, EditorMenuContribution } from "../api/menu";
2
+ import type { ContextMenuItem } from "../components/EditorContextMenu/types";
3
+ /**
4
+ * 把各扩展贡献的菜单声明求值成渲染件条目(01 §5.4)。
5
+ * when 决定条目是否出现;disabled 决定灰显;执行统一走 `editor.commands.execute`
6
+ * (与热键共享命令的 enablement 与熔断)。求值错误只丢出错的条目,不波及其他扩展。
7
+ * 顶层条目按 id 去重,后声明的覆盖先声明的——扩展可以覆盖内核默认条目。
8
+ */
9
+ /** 一个扩展贡献的菜单来源;owner 用于日志,并写入条目的 owner 字段供宿主区分来源 */
10
+ export interface MenuContributionSource {
11
+ readonly owner: string;
12
+ readonly menu: EditorMenuContribution;
13
+ /**
14
+ * 贡献者注册的元素类型:条目默认只出现在这些类型上(特有菜单不进别的块的菜单)。
15
+ * 不注册元素的扩展(内核默认菜单、preview 菜单)为全局条目,靠自身 when 限定范围。
16
+ */
17
+ readonly types?: readonly string[];
18
+ }
19
+ export declare function resolveBlockMenuItems(sources: readonly MenuContributionSource[], ctx: EditorMenuContext, extras?: readonly ContextMenuItem[]): ContextMenuItem[];