reactive-md 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG-ch.md +18 -0
- package/CHANGELOG.md +18 -0
- package/README-ch.md +7 -6
- package/README-en.md +8 -6
- package/README.md +8 -6
- package/dist-library/reactive-md-react.js +1661 -1630
- package/dist-library/reactive-md.js +323 -307
- package/dist-library/{runtime-CXBdLQ3A.js → runtime-UiQPz5ZV.js} +5327 -4925
- package/dist-library/types/local/LocalDocumentView.d.ts +10 -2
- package/dist-library/types/local/diagnostics.d.ts +40 -0
- package/dist-library/types/local/html-names.d.ts +6 -0
- package/dist-library/types/local/index.d.ts +1 -1
- package/dist-library/types/local/limits.d.ts +8 -0
- package/dist-library/types/local/options.d.ts +6 -1
- package/dist-library/types/local/render-types.d.ts +11 -0
- package/dist-library/types/local/types.d.ts +18 -0
- package/dist-library/types/local/worker.d.ts +4 -1
- package/dist-library/types/react/index.d.ts +1 -1
- package/dist-standalone/reactive-md-standalone.js +32 -32
- package/docs/compatibility-ch.md +7 -5
- package/docs/compatibility-en.md +7 -5
- package/docs/component-development-ch.md +4 -4
- package/docs/component-development-en.md +3 -3
- package/docs/component-protocol-ch.md +48 -11
- package/docs/component-protocol-en.md +48 -11
- package/docs/local-integration-ch.md +26 -2
- package/docs/local-integration-en.md +26 -2
- package/docs/release-0.5.2-ch.md +35 -0
- package/docs/release-0.5.2-en.md +35 -0
- package/docs/releasing-ch.md +7 -7
- package/docs/releasing-en.md +8 -8
- package/examples/conformance/README.md +1 -1
- package/package.json +1 -1
package/docs/compatibility-ch.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# 版本与兼容性
|
|
2
2
|
|
|
3
|
-
Reactive MD 目前是 0.x 预览版。本页说明包版本、语法版本、可持久化的内容、诊断契约和当前平台范围。显式修订声明、迁移 API 与 `reactive-md migrate` 见[源码修订与迁移](source-versioning-ch.md),公开 API 与样式接入见[本地模式集成](local-integration-ch.md),当前预览见[0.5.
|
|
3
|
+
Reactive MD 目前是 0.x 预览版。本页说明包版本、语法版本、可持久化的内容、诊断契约和当前平台范围。显式修订声明、迁移 API 与 `reactive-md migrate` 见[源码修订与迁移](source-versioning-ch.md),公开 API 与样式接入见[本地模式集成](local-integration-ch.md),当前预览见[0.5.2 发布说明](release-0.5.2-ch.md),该 minor 系列见[0.4.0 发布与迁移](release-0.4.0-ch.md)。
|
|
4
4
|
|
|
5
5
|
## 版本对应
|
|
6
6
|
|
|
7
7
|
| 项目 | 当前值 | 说明 |
|
|
8
8
|
| --- | --- | --- |
|
|
9
|
-
| 包版本 | `0.5.
|
|
10
|
-
| 分发标签 | `latest` → `0.4.0`;`next` → `0.5.
|
|
9
|
+
| 包版本 | `0.5.2` | 0.x 预览版;0.5.2 面向 `next`,`latest` 仍为 `0.4.0` |
|
|
10
|
+
| 分发标签 | `latest` → `0.4.0`;`next` → `0.5.2`(预览目标) | 默认安装使用 `latest` |
|
|
11
11
|
| 语法版本 | `local-draft-2` | `LOCAL_SYNTAX_VERSION`;当前构建只接受这一修订 |
|
|
12
12
|
| 源码修订指令 | 可选 `<!-- reactive-md: local-draft-2 -->` | 文档前导区中的一行;无指令源码继续按当前修订解析 |
|
|
13
|
-
| 组块协议 | `component-protocol-
|
|
13
|
+
| 组块协议 | `component-protocol-2` | 贡献与验收契约,见[组块协议](component-protocol-ch.md);不是运行时版本选择参数 |
|
|
14
14
|
| 核心入口 | `reactive-md` | 编译、表达式与运行时,不加载 React |
|
|
15
15
|
| React 入口 | `reactive-md/react` | `LocalReactiveDocument`、`LocalDocumentView` |
|
|
16
16
|
| 编辑器入口 | `reactive-md/editor` | `ReactiveMarkdownEditor` 及其类型;需要 React 19 |
|
|
@@ -50,6 +50,8 @@ Reactive MD 目前是 0.x 预览版。本页说明包版本、语法版本、可
|
|
|
50
50
|
|
|
51
51
|
`0.5.0` 新增 `reactive-md/editor` 入口及其独立样式表;`0.5.1` 新增编辑器视图、主题配色和 HTML 兼容。`local-draft-2`、`component-protocol-1` 和 `reactive-md-theme-1` 保持不变。现有 `reactive-md`、`reactive-md/react` 和 `reactive-md/styles.css` 导入继续有效,为 0.4.x 编写的文档无需迁移。编辑器需要 React 19;历史与渲染边界见[编辑器指南](editor-ch.md)。
|
|
52
52
|
|
|
53
|
+
`0.5.2` 新增可选的宿主组件扩展轴,并把组块协议提升到 `component-protocol-2`。语法修订和主题协议保持不变,现有导入继续有效,为 0.5.x 编写的文档无需迁移。见[0.5.2 发布说明](release-0.5.2-ch.md)。
|
|
54
|
+
|
|
53
55
|
`0.4.0` 新增[条件、校验与本地集合](constraints-collections-ch.md):`LocalRuntime.validate()`、可序列化的 `LocalValidation` 规则、数字数组及生成表格。自行实现运行时适配器的宿主需补充 `validate()`,值类型穷举需加入 `number-array`;与 `sum`、`average`、`minOf`、`maxOf` 同名的旧绑定应重命名。
|
|
54
56
|
|
|
55
57
|
`0.4.0` 新增[命名计算与格式化函数](computations-formatting-ch.md)。`computed`/`const` 使用现有本地标签形式;新函数名成为保留字,使用本版本前需重命名冲突的输入绑定并同步修改引用。`document.bindings` 和 `initialState` 继续只包含可写控件,快照同时提供成功求值的计算结果。
|
|
@@ -104,4 +106,4 @@ Node 端消费指在 Node 中导入 `reactive-md`、调用 `compileLocal` 和 `c
|
|
|
104
106
|
语言范围见[语法规范](local-interaction-syntax-ch.md),安全边界与宿主责任见[安全策略](../SECURITY-ch.md)。
|
|
105
107
|
|
|
106
108
|
|
|
107
|
-
新增组块、颜色、槽位状态与迁移规则见[local-draft-2 扩展说明](local-components-v2-ch.md),升级清单见[0.4.0 发布与迁移](release-0.4.0-ch.md)。0.5.
|
|
109
|
+
新增组块、颜色、槽位状态与迁移规则见[local-draft-2 扩展说明](local-components-v2-ch.md),升级清单见[0.4.0 发布与迁移](release-0.4.0-ch.md)。0.5.2 预览版面向 `next`,`latest` 仍为 `0.4.0`。
|
package/docs/compatibility-en.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# Versions and compatibility
|
|
2
2
|
|
|
3
|
-
Reactive MD is currently a 0.x preview. This page covers package versions, syntax versions, what can be persisted, the diagnostics contract and the current platform scope. See [Source revisions and migration](source-versioning-en.md) for explicit revision declarations, the migration API and `reactive-md migrate`, [Local mode integration](local-integration-en.md) for the public API and style integration, [0.5.
|
|
3
|
+
Reactive MD is currently a 0.x preview. This page covers package versions, syntax versions, what can be persisted, the diagnostics contract and the current platform scope. See [Source revisions and migration](source-versioning-en.md) for explicit revision declarations, the migration API and `reactive-md migrate`, [Local mode integration](local-integration-en.md) for the public API and style integration, [0.5.2 release notes](release-0.5.2-en.md) for the current preview, and [0.4.0 release and migration](release-0.4.0-en.md) for that minor series.
|
|
4
4
|
|
|
5
5
|
## Version mapping
|
|
6
6
|
|
|
7
7
|
| Item | Current value | Notes |
|
|
8
8
|
| --- | --- | --- |
|
|
9
|
-
| Package version | `0.5.
|
|
10
|
-
| Distribution tags | `latest` → `0.4.0`; `next` → `0.5.
|
|
9
|
+
| Package version | `0.5.2` | 0.x preview; 0.5.2 targets `next`, while `latest` remains `0.4.0` |
|
|
10
|
+
| Distribution tags | `latest` → `0.4.0`; `next` → `0.5.2` (preview target) | Default installs use `latest` |
|
|
11
11
|
| Syntax version | `local-draft-2` | `LOCAL_SYNTAX_VERSION`; the current build accepts only this revision |
|
|
12
12
|
| Source revision directive | Optional `<!-- reactive-md: local-draft-2 -->` | One line in the document prologue; unversioned source keeps current-revision behavior |
|
|
13
|
-
| Component protocol | `component-protocol-
|
|
13
|
+
| Component protocol | `component-protocol-2` | Contribution and acceptance contract, see [Component protocol](component-protocol-en.md); not a runtime version selection parameter |
|
|
14
14
|
| Core entry | `reactive-md` | Compilation, expressions and runtime, without loading React |
|
|
15
15
|
| React entry | `reactive-md/react` | `LocalReactiveDocument`, `LocalDocumentView` |
|
|
16
16
|
| Editor entry | `reactive-md/editor` | `ReactiveMarkdownEditor` and its types; requires React 19 |
|
|
@@ -50,6 +50,8 @@ Regression data in [the historical corpus](../examples/conformance/history/v0.3.
|
|
|
50
50
|
|
|
51
51
|
`0.5.0` added the `reactive-md/editor` entry and its independent stylesheet. `0.5.1` adds editor views, theme palettes and HTML compatibility. They keep `local-draft-2`, `component-protocol-1` and `reactive-md-theme-1`. Existing `reactive-md`, `reactive-md/react` and `reactive-md/styles.css` imports keep working, and documents written for 0.4.x need no migration. The editor requires React 19; see the [editor guide](editor-en.md) for its history and rendering boundaries.
|
|
52
52
|
|
|
53
|
+
`0.5.2` adds the opt-in host component extension axis and raises the component protocol to `component-protocol-2`. The syntax revision and theme protocol remain unchanged, existing imports keep working, and documents written for 0.5.x need no migration. See the [0.5.2 release notes](release-0.5.2-en.md).
|
|
54
|
+
|
|
53
55
|
`0.4.0` adds [constraints and collections](constraints-collections-en.md): `LocalRuntime.validate()`, serializable `LocalValidation` rules, numeric arrays and generated tables. Hosts implementing a runtime adapter need the new `validate()` method; exhaustive value-kind checks need `number-array`. Rename bindings colliding with `sum`, `average`, `minOf` or `maxOf`.
|
|
54
56
|
|
|
55
57
|
`0.4.0` adds [named calculations and formatting functions](computations-formatting-en.md). `computed`/`const` use the existing local tag syntax. The new built-in function names become reserved; rename colliding input bindings and their references before using this release. `document.bindings` and `initialState` still contain writable controls; snapshots also expose successful calculated values.
|
|
@@ -104,4 +106,4 @@ Node-side consumption means importing `reactive-md` in Node and calling `compile
|
|
|
104
106
|
See the [syntax specification](local-interaction-syntax-en.md) for the language scope, and the [security policy](../SECURITY.md) for the security boundary and host responsibilities.
|
|
105
107
|
|
|
106
108
|
|
|
107
|
-
See [local-draft-2 components and migration](local-components-v2-en.md) for new tags, colors and slot state, and [0.4.0 release and migration](release-0.4.0-en.md) for the upgrade checklist. The 0.5.
|
|
109
|
+
See [local-draft-2 components and migration](local-components-v2-en.md) for new tags, colors and slot state, and [0.4.0 release and migration](release-0.4.0-en.md) for the upgrade checklist. The 0.5.2 preview targets `next`; `latest` remains `0.4.0`.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
本指南面向为 Reactive MD 新增或修改组件的贡献者。组块包括输入控件、容器、可视化和结构子项。共同契约见[组块协议](component-protocol-ch.md),作者写法见[本地交互语法规范](local-interaction-syntax-ch.md)。
|
|
4
4
|
|
|
5
|
-
当前协议为 `component-protocol-
|
|
5
|
+
当前协议为 `component-protocol-2`,适用语法为 `local-draft-2`,当前包版本为 `0.5.2`,即发布在 `next` 渠道的预览版。这三个版本分别表示贡献契约、作者语法和 npm 发布。协议文档更新不自动改变语法或公开 API。
|
|
6
6
|
|
|
7
7
|
## 1. 提交什么
|
|
8
8
|
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
|
|
50
50
|
新标签还有一项迁移影响:旧实现会把完整的未知区域按惰性原文显示,新实现识别该名称后可能开始执行内部内容。必须在提案中记录这一点,并给出前后用例。名称是否加入核心组件集由维护者评审;不得覆盖现有名称的含义或偷偷添加别名。
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
本协议自身不新增作者标签或属性,因此保持 `local-draft-2` 和当前包版本。
|
|
53
53
|
|
|
54
54
|
## 4. 用现有组块填写声明
|
|
55
55
|
|
|
@@ -121,7 +121,7 @@ $$ y = a \sin x $$
|
|
|
121
121
|
| --- | --- |
|
|
122
122
|
| 包版本 | 当前值、目标值和理由 |
|
|
123
123
|
| 语法修订 | 当前值、目标值和迁移影响 |
|
|
124
|
-
| 协议修订 | component-protocol-
|
|
124
|
+
| 协议修订 | component-protocol-2,或说明新修订 |
|
|
125
125
|
| 名称 | 小写 kebab-case;冲突检查和维护者决定 |
|
|
126
126
|
| 形态 | leaf / inline / container |
|
|
127
127
|
| 父级、直接子项 | 允许范围、数量、嵌套及空白规则 |
|
|
@@ -207,4 +207,4 @@ $$ y = a \sin x $$
|
|
|
207
207
|
在 PR 中列出实际运行的命令和观察结果。未运行、失败、不适用分别写明,不把清单勾选当成验证证据。
|
|
208
208
|
|
|
209
209
|
|
|
210
|
-
新增组块、颜色、槽位状态与迁移规则见[local-draft-2 扩展说明](local-components-v2-ch.md)。`0.
|
|
210
|
+
新增组块、颜色、槽位状态与迁移规则见[local-draft-2 扩展说明](local-components-v2-ch.md)。`0.5.2` 是 `next` 渠道的预览版。
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
This guide is for contributors adding or changing components in Reactive MD. Components include input controls, containers, visualizations and structural children. The shared contract is in the [component protocol](component-protocol-en.md); the author syntax is in the [local interaction syntax specification](local-interaction-syntax-en.md).
|
|
4
4
|
|
|
5
|
-
The current protocol is `component-protocol-
|
|
5
|
+
The current protocol is `component-protocol-2`, the applicable syntax is `local-draft-2`, and the current package version is `0.5.2`, the preview release on the `next` channel. These three versions represent the contribution contract, the author syntax and the npm release. Updating the protocol document does not automatically change the syntax or public API.
|
|
6
6
|
|
|
7
7
|
## 1. What to submit
|
|
8
8
|
|
|
@@ -121,7 +121,7 @@ Copy the following into an issue, a PR description or a standalone design docume
|
|
|
121
121
|
| --- | --- |
|
|
122
122
|
| Package version | Current value, target value and rationale |
|
|
123
123
|
| Syntax revision | Current value, target value and migration impact |
|
|
124
|
-
| Protocol revision | component-protocol-
|
|
124
|
+
| Protocol revision | component-protocol-2, or describe the new revision |
|
|
125
125
|
| Name | Lowercase kebab-case; conflict check and maintainer decision |
|
|
126
126
|
| Shape | leaf / inline / container |
|
|
127
127
|
| Parent, direct children | Allowed scope, count, nesting and whitespace rules |
|
|
@@ -207,4 +207,4 @@ Browser checks must record the specific environment and actions. Check real keyb
|
|
|
207
207
|
List the commands actually run and observations in the PR. State not run, failed and not applicable separately; do not treat checked boxes as verification evidence.
|
|
208
208
|
|
|
209
209
|
|
|
210
|
-
See [local-draft-2 components and migration](local-components-v2-en.md) for new tags, colors and slot state. `0.
|
|
210
|
+
See [local-draft-2 components and migration](local-components-v2-en.md) for new tags, colors and slot state. `0.5.2` is the preview release on the `next` channel.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Reactive MD 组块协议
|
|
2
2
|
|
|
3
|
-
协议修订 `component-protocol-
|
|
3
|
+
协议修订 `component-protocol-2` · 适用语法 `local-draft-2` · 当前包版本 `0.5.2`(预览)
|
|
4
4
|
|
|
5
5
|
Reactive MD 的组块就是语言中的组件。本协议规定组块在贡献、实现和验收中的共同契约,连接作者语法、编译器、运行时、React 参考适配器和机器验收数据。作者写文档时以[本地交互语法规范](local-interaction-syntax-ch.md)为准;宿主接入以[本地模式集成](local-integration-ch.md)为准;本文供贡献者、评审和测试使用。
|
|
6
6
|
|
|
@@ -20,9 +20,9 @@ Reactive MD 分别维护以下版本轴:
|
|
|
20
20
|
|
|
21
21
|
| 版本轴 | 当前值 | 决定什么 |
|
|
22
22
|
| --- | --- | --- |
|
|
23
|
-
| 包版本 | `0.
|
|
23
|
+
| 包版本 | `0.5.2` | npm 发布、核心与 React 入口、升级兼容规则 |
|
|
24
24
|
| 语法修订 | `local-draft-2` | 作者可以写出的标签、属性和表达式 |
|
|
25
|
-
| 协议修订 | `component-protocol-
|
|
25
|
+
| 协议修订 | `component-protocol-2` | 组块贡献要求、验收门槛和机器数据语义 |
|
|
26
26
|
| 主题协议 | `reactive-md-theme-1` | 主题登记、样式变量、深浅模式与主题验收 |
|
|
27
27
|
|
|
28
28
|
协议修订独立于包版本和语法版本。一个包版本只接受一个语法修订。协议修订可以在不改变作者语法的前提下提高贡献和验收要求;语法修订变化也不必自动提升协议修订。
|
|
@@ -458,7 +458,7 @@ range-slider 和 coordinate 的每个数值槽位也独占拥有绑定;范围
|
|
|
458
458
|
|
|
459
459
|
### CP-SEC-05 扩展信任边界(边界)
|
|
460
460
|
|
|
461
|
-
本语言不为可信宿主扩展代码提供沙箱。若宿主自行注册或包装组块,安全边界由宿主负责,不能把作者文档中的 `disabled
|
|
461
|
+
本语言不为可信宿主扩展代码提供沙箱。若宿主自行注册或包装组块,安全边界由宿主负责,不能把作者文档中的 `disabled`、条件显示或客户端状态当作权限控制。`hostComponents` 选项只为单次编译登记纯 schema 数据,不携带可执行代码。宿主 renderer 是文档沙箱之外的可信宿主代码,安全边界仍由宿主负责;更完整的 SDK 需要单独定义信任模型。
|
|
462
462
|
|
|
463
463
|
## 9. 核心与渲染器分离
|
|
464
464
|
|
|
@@ -493,7 +493,7 @@ range-slider 和 coordinate 的每个数值槽位也独占拥有绑定;范围
|
|
|
493
493
|
|
|
494
494
|
### CP-CORE-05 扩展接口边界(边界)
|
|
495
495
|
|
|
496
|
-
|
|
496
|
+
当前修订没有运行时可装载的组块实现、`registerComponent` API、全局注册器或作者插件入口。`LOCAL_COMPONENTS` 是内部冻结表。`hostComponents` 选项(第 14 节)只为单次编译接受纯 schema 数据;组块实现留在宿主代码中,绝不从文档内容装载。未来 SDK 若提供通用注册接口,需要新的协议修订,并明确信任模型、版本协商、预算和验收方式。
|
|
497
497
|
|
|
498
498
|
## 10. 兼容、名称治理、修订和迁移
|
|
499
499
|
|
|
@@ -563,7 +563,7 @@ range-slider 和 coordinate 的每个数值槽位也独占拥有绑定;范围
|
|
|
563
563
|
|
|
564
564
|
### CP-ACCEPT-02 机器验收数据(要求)
|
|
565
565
|
|
|
566
|
-
机器验收集的根对象只包含 `protocolVersion`、`syntaxVersion` 和非空 `cases
|
|
566
|
+
机器验收集的根对象只包含 `protocolVersion`、`syntaxVersion` 和非空 `cases`。现有作者组块集把前两者固定为 `component-protocol-1` 和 `local-draft-2`,并作为第 14 节所述的 v1 冻结基线;包版本由 `package.json` 标识,不从这两个字段推断。
|
|
567
567
|
|
|
568
568
|
每个 case 至少包含唯一字符串 `id`、组块名 `component`、源码 `source`、布尔 `ok` 和去重诊断码集合 `codes`。可选字段 `initial`、`bindingNames`、`actions`、`reset`、`text`、`expectedText`、`htmlIncludes`、`htmlExcludes` 按[语言验收数据说明](../examples/conformance/README.md)和仓库附带的 JSON Schema 使用。完整格式以该说明和 Schema 为准,本协议只规定语义门槛。
|
|
569
569
|
|
|
@@ -578,7 +578,7 @@ range-slider 和 coordinate 的每个数值槽位也独占拥有绑定;范围
|
|
|
578
578
|
|
|
579
579
|
`initial` 和 `reset.expectedState` 做部分匹配;`bindingNames` 检查完整公开绑定名集合;`text` 与 `expectedText` 必须成对。
|
|
580
580
|
|
|
581
|
-
|
|
581
|
+
冻结的作者组块集覆盖 `slider`、`tabs`、`plot` 的代表性用例和至少一个完整未知标签降级用例。它仍是代表性门槛,不是 48 个标签名的全面认证;宿主组块没有可移植机器用例。
|
|
582
582
|
|
|
583
583
|
### CP-ACCEPT-03 组件级证据(要求)
|
|
584
584
|
|
|
@@ -634,7 +634,7 @@ range-slider 和 coordinate 的每个数值槽位也独占拥有绑定;范围
|
|
|
634
634
|
|
|
635
635
|
### CP-IMPL-03 扩展接口(边界)
|
|
636
636
|
|
|
637
|
-
|
|
637
|
+
除第 14 节的编译期 schema 和 React renderer 扩展轴外,更完整的 SDK 还需要单独定义:
|
|
638
638
|
|
|
639
639
|
- 组块声明的机器格式和版本协商。
|
|
640
640
|
- 宿主注册 API 的信任模型和沙箱边界。
|
|
@@ -652,7 +652,7 @@ range-slider 和 coordinate 的每个数值槽位也独占拥有绑定;范围
|
|
|
652
652
|
| 项目 | 填写内容 |
|
|
653
653
|
| --- | --- |
|
|
654
654
|
| 组块名 | `<name>`(小写 kebab-case) |
|
|
655
|
-
| 协议修订 | `component-protocol-
|
|
655
|
+
| 协议修订 | `component-protocol-2` |
|
|
656
656
|
| 用途 | 解决什么问题,读者如何使用 |
|
|
657
657
|
| 非目标 | 本组块不承担的能力 |
|
|
658
658
|
| 版本影响 | 包版本、语法修订、协议修订 |
|
|
@@ -700,11 +700,48 @@ range-slider 和 coordinate 的每个数值槽位也独占拥有绑定;范围
|
|
|
700
700
|
| CP-COMPAT-01 至 05 | 兼容说明、迁移示例 | 通过/待补 |
|
|
701
701
|
| CP-ACCEPT-01 至 05 | 验收矩阵和命令结果 | 通过/待补 |
|
|
702
702
|
|
|
703
|
-
## 14.
|
|
703
|
+
## 14. 宿主组件扩展轴
|
|
704
|
+
|
|
705
|
+
### CP-HOST-01 宿主组件是可选扩展(现有)
|
|
706
|
+
|
|
707
|
+
`compileLocal(source, { hostComponents })` 为编译器增加一条宿主拥有的扩展轴。不传 `hostComponents` 时,作者行为不变:48 个作者标签名照常解析,集合之外的标签仍是未知标签,并按 CP-DIAG-03 降级为原文。该选项只改变本次调用识别的标签名,不增加作者语法。语法修订仍为 `local-draft-2`,协议修订变为 `component-protocol-2`。
|
|
708
|
+
|
|
709
|
+
### CP-HOST-02 宿主 Schema 是普通数据(要求)
|
|
710
|
+
|
|
711
|
+
`LocalHostComponentSchema` 是宿主提供的普通、可结构化克隆的数据,不含函数、类实例或运行时句柄。
|
|
712
|
+
|
|
713
|
+
| 字段 | 内容 |
|
|
714
|
+
| --- | --- |
|
|
715
|
+
| `name` | 小写 kebab-case,在集合内唯一,不能是 48 个作者标签名、P0 HTML 标签名或主题声明名 `theme` |
|
|
716
|
+
| `form` | `'leaf'`;宿主组块没有正文 |
|
|
717
|
+
| `props` | 宿主属性表;属性名使用小写 kebab-case |
|
|
718
|
+
|
|
719
|
+
每次编译最多接受 32 个宿主组块 Schema。每个属性声明 `kind`(`string`、`number`、`boolean` 或 `enum`)、`required`、`static`、`enum` 和 `pattern`。`enum` 用于 `enum` 属性,`pattern` 用于 `string` 属性。P0 HTML 标签名保留给解析器优先处理的 HTML,不得复用。`pattern` 限制在线性时间安全子集内:拒绝反向引用、环视、命名组、嵌套量词和被量词修饰的分支。非法 Schema 以 `local.options.invalid` 诊断拒绝;编译失败,该集合不会部分生效。
|
|
720
|
+
|
|
721
|
+
### CP-HOST-03 宿主组块不是作者语法(边界)
|
|
722
|
+
|
|
723
|
+
宿主组块不属于 `local-draft-2`,不能当作可移植的作者语法。使用它们的文档只有在登记了相同名称和兼容 Schema 的宿主中才能渲染;普通读者会把每个名称当作未知组块,按 CP-DIAG-03 的既有降级处理。作者不能假定宿主组块一定存在,面向可移植的文档不应使用它们。
|
|
724
|
+
|
|
725
|
+
### CP-HOST-04 属性校验与预算(要求)
|
|
726
|
+
|
|
727
|
+
编译器按登记的 Schema 校验每个宿主属性:必填属性必须存在,`enum` 值必须属于声明的集合,`pattern` 必须匹配字面字符串值,字面值必须符合声明的 `kind`,声明为 `static` 的属性拒绝 `{{ ... }}`。声明了 `pattern` 的属性,非静态值只能用恰好一个完整插值代替字面值;混合字面文本与插值会被拒绝。其他字符串属性可以混合字面文本和插值。校验失败在属性位置产生 `local.host.attribute` 诊断。
|
|
728
|
+
|
|
729
|
+
合法宿主节点在既有语法节点预算中只计为一个语法节点;属性、props 和 leaf 形态不增加更多节点,也不改变其他预算的计算。
|
|
730
|
+
|
|
731
|
+
### CP-HOST-05 React 分发与宿主数据(要求)
|
|
732
|
+
|
|
733
|
+
React 视图把 `hostComponent` 节点分发给 `hostRenderer(node, data, ctx)`。`data` 从 `hostData` 读取,后者是 JSON 安全的宿主数据,按节点属性中的 `${kind}:${ref}` 索引。这两个 props 都留在宿主/React 一侧:渲染函数不进入 worker,`hostData` 也不进入 worker,因为编译只需要 Schema。
|
|
734
|
+
|
|
735
|
+
缺少渲染器、缺少 `${kind}:${ref}` 键或渲染器抛出异常时,显示可见的诊断占位,不得让异常冒出文档或使其余内容变空白。`mode === 'static'` 走同一分发路径,因此宿主未提供渲染器或数据时,静态渲染显示相同的占位。
|
|
736
|
+
|
|
737
|
+
可移植的机器用例仍是 `examples/conformance/component-protocol-1.json`,它作为 48 个作者组块的基线保持冻结。宿主组块不提供可移植验收用例,因为渲染由宿主拥有,普通读者只能看到未知组块降级。
|
|
738
|
+
|
|
739
|
+
## 15. 修订记录
|
|
704
740
|
|
|
705
741
|
| 修订 | 日期 | 说明 |
|
|
706
742
|
| --- | --- | --- |
|
|
743
|
+
| `component-protocol-2` | 2026-10-25 | 新增宿主组件扩展轴;作者语法仍为 `local-draft-2`。 |
|
|
707
744
|
| `component-protocol-1` | 2026-10-23 | 初版;最初适用于 `local-draft-1` 和包版本 `0.3.0`,定义组块贡献、验收和扩展边界。现在适用于 `local-draft-2` 和 `0.4.0` 预览版,MUST 条款和机器格式不变。 |
|
|
708
745
|
|
|
709
746
|
|
|
710
|
-
新增组块、颜色、槽位状态与迁移规则见[local-draft-2 扩展说明](local-components-v2-ch.md),升级清单见[0.4.0 发布与迁移](release-0.4.0-ch.md)。`0.
|
|
747
|
+
新增组块、颜色、槽位状态与迁移规则见[local-draft-2 扩展说明](local-components-v2-ch.md),升级清单见[0.4.0 发布与迁移](release-0.4.0-ch.md)。`0.5.2` 是 `next` 渠道的预览版。
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Reactive MD component protocol
|
|
2
2
|
|
|
3
|
-
Protocol revision `component-protocol-
|
|
3
|
+
Protocol revision `component-protocol-2` · applicable syntax `local-draft-2` · current package version `0.5.2` (preview)
|
|
4
4
|
|
|
5
5
|
Components are the building blocks of the Reactive MD language. This protocol defines the shared contract for contribution, implementation and acceptance, connecting author syntax, the compiler, the runtime, the React reference adapter and machine conformance data. Authors writing documents follow the [local interaction syntax specification](local-interaction-syntax-en.md); hosts integrating follow [local mode integration](local-integration-en.md); this document is for contributors, reviewers and tests.
|
|
6
6
|
|
|
@@ -20,9 +20,9 @@ Reactive MD maintains the following independent version axes:
|
|
|
20
20
|
|
|
21
21
|
| Version axis | Current value | Determines |
|
|
22
22
|
| --- | --- | --- |
|
|
23
|
-
| Package version | `0.
|
|
23
|
+
| Package version | `0.5.2` | npm release, core and React entries, upgrade compatibility rules |
|
|
24
24
|
| Syntax revision | `local-draft-2` | Tags, attributes and expressions authors can write |
|
|
25
|
-
| Protocol revision | `component-protocol-
|
|
25
|
+
| Protocol revision | `component-protocol-2` | Component contribution requirements, acceptance gates and machine data semantics |
|
|
26
26
|
| Theme protocol | `reactive-md-theme-1` | Theme registration, style variables, color schemes and theme acceptance |
|
|
27
27
|
|
|
28
28
|
The protocol revision is independent of the package version and syntax version. One package version accepts only one syntax revision. A protocol revision may raise contribution and acceptance requirements without changing author syntax; a syntax revision change does not automatically require a protocol revision.
|
|
@@ -458,7 +458,7 @@ The host decides who may write, submit and share documents; limits request size,
|
|
|
458
458
|
|
|
459
459
|
### CP-SEC-05 Extension trust boundary (boundary)
|
|
460
460
|
|
|
461
|
-
This language does not provide a sandbox for trusted host extension code. If the host registers or wraps components itself, the host is responsible for the security boundary; `disabled`, conditional visibility or client state in author documents must not be treated as permission control.
|
|
461
|
+
This language does not provide a sandbox for trusted host extension code. If the host registers or wraps components itself, the host is responsible for the security boundary; `disabled`, conditional visibility or client state in author documents must not be treated as permission control. The `hostComponents` option registers plain schema data for one compilation only and carries no executable code. A host renderer is trusted host code outside the document sandbox, so the host remains responsible for its security boundary; a fuller SDK would need a separately defined trust model.
|
|
462
462
|
|
|
463
463
|
## 9. Core and renderer separation
|
|
464
464
|
|
|
@@ -493,7 +493,7 @@ Adding only a `schema.ts` entry does not automatically provide parsing, validati
|
|
|
493
493
|
|
|
494
494
|
### CP-CORE-05 Extension interface boundary (boundary)
|
|
495
495
|
|
|
496
|
-
This revision has no runtime-loadable component
|
|
496
|
+
This revision has no runtime-loadable component implementation, `registerComponent` API, global registrar or author plugin entry point. `LOCAL_COMPONENTS` is an internal frozen table. The `hostComponents` option (section 14) accepts plain schema data for a single compile; component implementations stay in host code and are never loaded from document content. A future SDK that provides a general registration interface needs a new protocol revision that defines the trust model, version negotiation, budgets and acceptance methods.
|
|
497
497
|
|
|
498
498
|
## 10. Compatibility, name governance, revisions and migration
|
|
499
499
|
|
|
@@ -563,7 +563,7 @@ Persist only the original `.reactive.md` source and the syntax revision used. `L
|
|
|
563
563
|
|
|
564
564
|
### CP-ACCEPT-02 Machine conformance data (required)
|
|
565
565
|
|
|
566
|
-
The root object of a machine conformance set contains only `protocolVersion`, `syntaxVersion` and a non-empty `cases` array. The
|
|
566
|
+
The root object of a machine conformance set contains only `protocolVersion`, `syntaxVersion` and a non-empty `cases` array. The current author-component set fixes them to `component-protocol-1` and `local-draft-2`; it remains the frozen v1 baseline described in section 14. The package version is identified by `package.json` and is not inferred from these fields.
|
|
567
567
|
|
|
568
568
|
Each case contains at least a unique string `id`, component name `component`, source `source`, boolean `ok` and a deduplicated diagnostic code set `codes`. Optional fields `initial`, `bindingNames`, `actions`, `reset`, `text`, `expectedText`, `htmlIncludes` and `htmlExcludes` follow the [language conformance data notes](../examples/conformance/README.md) and the JSON Schema shipped with the repository. The full format follows that document and the Schema; this protocol defines only the semantic gates.
|
|
569
569
|
|
|
@@ -578,7 +578,7 @@ The runner must:
|
|
|
578
578
|
|
|
579
579
|
`initial` and `reset.expectedState` use partial matching; `bindingNames` checks the complete public binding name set; `text` and `expectedText` must appear in pairs.
|
|
580
580
|
|
|
581
|
-
The
|
|
581
|
+
The frozen author-component set covers representative `slider`, `tabs` and `plot` cases and at least one complete unknown-tag fallback case. It remains a representative gate, not full certification of the 48 tag names; host components have no portable machine cases.
|
|
582
582
|
|
|
583
583
|
### CP-ACCEPT-03 Component-level evidence (required)
|
|
584
584
|
|
|
@@ -634,7 +634,7 @@ The current implementation covers parsing, declarations, compilation, runtime, R
|
|
|
634
634
|
|
|
635
635
|
### CP-IMPL-03 Extension interfaces (boundary)
|
|
636
636
|
|
|
637
|
-
|
|
637
|
+
Beyond the compile-time schema and React renderer axis in section 14, a fuller SDK would need separately defined:
|
|
638
638
|
|
|
639
639
|
- Machine format and version negotiation for component declarations.
|
|
640
640
|
- Trust model and sandbox boundary for the host registration API.
|
|
@@ -652,7 +652,7 @@ The tables below are for review. See the [component development guide](component
|
|
|
652
652
|
| Item | Content |
|
|
653
653
|
| --- | --- |
|
|
654
654
|
| Component name | `<name>` (lowercase kebab-case) |
|
|
655
|
-
| Protocol revision | `component-protocol-
|
|
655
|
+
| Protocol revision | `component-protocol-2` |
|
|
656
656
|
| Purpose | What problem it solves and how readers use it |
|
|
657
657
|
| Non-goals | Capabilities this component does not take on |
|
|
658
658
|
| Version impact | Package version, syntax revision, protocol revision |
|
|
@@ -700,11 +700,48 @@ The tables below are for review. See the [component development guide](component
|
|
|
700
700
|
| CP-COMPAT-01 to 05 | Compatibility notes, migration examples | Pass/outstanding |
|
|
701
701
|
| CP-ACCEPT-01 to 05 | Acceptance matrix and command results | Pass/outstanding |
|
|
702
702
|
|
|
703
|
-
## 14.
|
|
703
|
+
## 14. Host component extension axis
|
|
704
|
+
|
|
705
|
+
### CP-HOST-01 Host components are opt-in (existing)
|
|
706
|
+
|
|
707
|
+
`compileLocal(source, { hostComponents })` adds a host-owned extension axis to the compiler. Without the `hostComponents` option, author behavior is unchanged: the 48 author tag names parse as before, and a tag outside that set remains unknown and falls back to source under CP-DIAG-03. The option changes only which tag names the compiler recognizes for that call; it does not add author syntax. The syntax revision remains `local-draft-2`; the protocol revision becomes `component-protocol-2`.
|
|
708
|
+
|
|
709
|
+
### CP-HOST-02 Host schemas are plain data (required)
|
|
710
|
+
|
|
711
|
+
`LocalHostComponentSchema` is plain, structured-clone-safe data supplied by the host. It contains no functions, class instances or runtime handles.
|
|
712
|
+
|
|
713
|
+
| Field | Content |
|
|
714
|
+
| --- | --- |
|
|
715
|
+
| `name` | Lowercase kebab-case, unique within the set, not one of the 48 author tag names, a P0 HTML tag name or the theme declaration name |
|
|
716
|
+
| `form` | `'leaf'`; host components have no body |
|
|
717
|
+
| `props` | A table of host properties; property names use lowercase kebab-case |
|
|
718
|
+
|
|
719
|
+
One compilation accepts at most 32 host component schemas. Each property declares `kind` (`string`, `number`, `boolean` or `enum`), `required`, `static`, `enum` and `pattern`. `enum` applies to `enum` properties, and `pattern` applies to `string` properties. P0 HTML tag names are reserved because the parser handles them before component tags. `pattern` is restricted to a linear-time-safe subset: backreferences, lookarounds, named groups, nested quantifiers and quantified alternation are rejected. Invalid schemas are rejected with a `local.options.invalid` diagnostic; compilation fails and no host component from that set is partially registered.
|
|
720
|
+
|
|
721
|
+
### CP-HOST-03 Host components are not author syntax (boundary)
|
|
722
|
+
|
|
723
|
+
Host components are not part of `local-draft-2` and cannot be used as portable author syntax. A document that uses them is portable only with a host that registers the same names and compatible schemas; a plain reader treats each name as an unknown component and applies the existing fallback in CP-DIAG-03. Authors cannot rely on host components being present, so documents intended to be portable must not use them.
|
|
724
|
+
|
|
725
|
+
### CP-HOST-04 Attribute validation and budget (required)
|
|
726
|
+
|
|
727
|
+
The compiler validates every host attribute against the registered schema: required properties must be present, `enum` values must belong to the declared set, `pattern` must match literal string values, literal values must match the declared `kind`, and a property declared `static` rejects `{{ ... }}`. For a property with a `pattern`, a non-static value may be exactly one full interpolation in place of the literal; mixed literal text with interpolation is rejected. Other string properties may mix literals and interpolations. Failures produce a `local.host.attribute` diagnostic at the attribute location.
|
|
728
|
+
|
|
729
|
+
A valid host node counts as exactly one syntax node in the existing syntax-node budget; its attributes, props and leaf form add no further nodes and do not change other budget accounting.
|
|
730
|
+
|
|
731
|
+
### CP-HOST-05 React dispatch and host-owned data (required)
|
|
732
|
+
|
|
733
|
+
The React view dispatches a `hostComponent` node to `hostRenderer(node, data, ctx)`. `data` is read from `hostData`, JSON-safe host data indexed by `${kind}:${ref}` from the node attributes. Both props stay on the host/React side: the renderer function never enters a worker, and `hostData` never enters the worker either, because compilation needs only the schemas.
|
|
734
|
+
|
|
735
|
+
A missing renderer, a missing `${kind}:${ref}` key or a renderer that throws renders a visible diagnostic placeholder. It must not throw out of the document or blank the rest of the content. `mode === 'static'` goes through the same dispatch, so static rendering shows the same placeholder when the host has not supplied a renderer or data.
|
|
736
|
+
|
|
737
|
+
Portable machine cases remain `examples/conformance/component-protocol-1.json`, frozen as the baseline for the 48 author components. Host components get no portable conformance cases, because rendering is host-owned and a plain reader only sees the unknown-component fallback.
|
|
738
|
+
|
|
739
|
+
## 15. Revision history
|
|
704
740
|
|
|
705
741
|
| Revision | Date | Notes |
|
|
706
742
|
| --- | --- | --- |
|
|
743
|
+
| `component-protocol-2` | 2026-10-25 | Added the host component extension axis; author syntax remains `local-draft-2`. |
|
|
707
744
|
| `component-protocol-1` | 2026-10-23 | Initial version; originally applied to `local-draft-1` and package version `0.3.0`, defining component contribution, acceptance and extension boundaries. It now applies to `local-draft-2` and the `0.4.0` preview release without changing its MUST clauses or machine format. |
|
|
708
745
|
|
|
709
746
|
|
|
710
|
-
See [local-draft-2 components and migration](local-components-v2-en.md) for new tags, colors and slot state, and [0.4.0 release and migration](release-0.4.0-en.md) for the upgrade checklist. `0.
|
|
747
|
+
See [local-draft-2 components and migration](local-components-v2-en.md) for new tags, colors and slot state, and [0.4.0 release and migration](release-0.4.0-en.md) for the upgrade checklist. `0.5.2` is the preview release on the `next` channel.
|
|
@@ -44,7 +44,7 @@ export function Article() {
|
|
|
44
44
|
| 属性 | 类型 | 组件 | 说明 |
|
|
45
45
|
| --- | --- | --- | --- |
|
|
46
46
|
| `source` | `string` | `LocalReactiveDocument` | 源码变化时重新编译并创建新运行时;旧实例状态不保留。见[源码变化时保留参数](#源码变化时保留参数) |
|
|
47
|
-
| `compileOptions` | `LocalCompileOptions` | `LocalReactiveDocument` |
|
|
47
|
+
| `compileOptions` | `LocalCompileOptions` | `LocalReactiveDocument` | 单次编译预算、HTML 能力开关和宿主组件 schema;省略时使用默认 ReactiveMD 模式 |
|
|
48
48
|
| `document` | `LocalDocument` | `LocalDocumentView` | 已编译文档;由宿主编译一次 |
|
|
49
49
|
| `runtime` | `LocalRuntime` | `LocalDocumentView` | 宿主创建并负责销毁 |
|
|
50
50
|
| `onDiagnostics` | `(diagnostics: Diagnostic[]) => void` | 两者 | 接收编译诊断和控件写入被拒绝时的运行时诊断 |
|
|
@@ -52,6 +52,8 @@ export function Article() {
|
|
|
52
52
|
| `locale` | `'en' \| 'zh'` | 两者 | 内置控件、标签和诊断显示的语言,默认 `'en'`;回调保留原始结构化诊断 |
|
|
53
53
|
| `themes` | `readonly LocalThemeDefinition[]` | 两者 | 宿主登记的主题;CSS 单独加载,内置 `default` 始终可用 |
|
|
54
54
|
| `colorScheme` | `'light' \| 'dark' \| 'auto'` | 两者 | 默认 `auto`,跟随最近祖先的显式模式或系统偏好 |
|
|
55
|
+
| `hostData` | `Readonly<Record<string, unknown>>` | 两者 | 按 `${kind}:${ref}` 索引的 JSON 安全宿主数据,用于 `hostComponent` 节点;不进入 worker |
|
|
56
|
+
| `hostRenderer` | `LocalHostRenderer` | 两者 | `hostComponent` 的客户端渲染函数;缺少 renderer 或数据时显示占位 |
|
|
55
57
|
|
|
56
58
|
两个组件都没有 `className`、`style` 或插槽属性。`LocalReactiveDocument` 渲染 `<article class="md-document local-document">`;`LocalDocumentView` 使用同样的文档容器。样式覆盖见下文。
|
|
57
59
|
|
|
@@ -117,6 +119,28 @@ const result = compileLocal(source, options);
|
|
|
117
119
|
|
|
118
120
|
需要在 React 中使用自定义预算时,先调用 `compileLocal`,再把编译文档和运行时交给 `LocalDocumentView`。`LocalReactiveDocument` 和 Playground 的编译线程使用默认预算。提高节点预算后,宿主应结合实际文档测量内存和预览渲染耗时。
|
|
119
121
|
|
|
122
|
+
### 宿主组件
|
|
123
|
+
|
|
124
|
+
宿主可以为单次编译登记叶子标签,不改变 `local-draft-2` 语法修订:
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
import { compileLocal, type LocalHostComponentSchema } from 'reactive-md';
|
|
128
|
+
|
|
129
|
+
const hostComponents: LocalHostComponentSchema[] = [
|
|
130
|
+
{
|
|
131
|
+
name: 'host-weather',
|
|
132
|
+
form: 'leaf',
|
|
133
|
+
props: {
|
|
134
|
+
kind: { kind: 'enum', required: true, enum: ['weather'] },
|
|
135
|
+
ref: { kind: 'string', required: true, pattern: '^[a-z-]+$' },
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
const result = compileLocal(source, { hostComponents });
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
不传 `hostComponents` 时,这些标签仍是未知标签并按原文降级。名称必须是唯一的小写 kebab-case,且不得复用 48 个作者标签名、P0 HTML 标签名或 `theme`;一次最多接受 32 个 schema。`pattern` 只接受线性时间安全的正则子集(拒绝反向引用、环视、命名组、嵌套量词和被量词修饰的分支)。schema 不合法返回 `local.options.invalid`,作者写出的属性不合法返回 `local.host.attribute`。一个合法宿主节点计为一个语法节点。把 `hostData`(按 `${kind}:${ref}` 索引)和 `hostRenderer` 传给 `LocalDocumentView`;两者都不进入 worker。缺少 renderer、缺少数据或 renderer 抛错时显示可见占位,不会让整个文档失败。`mode="static"` 走同一分派,并把 `ctx.mode` 传给 renderer。
|
|
143
|
+
|
|
120
144
|
### 版本查看与迁移
|
|
121
145
|
|
|
122
146
|
三个纯函数在不创建运行时的情况下检查和迁移源码,均从 `reactive-md` 导出:
|
|
@@ -281,7 +305,7 @@ scheduler.schedule(source);
|
|
|
281
305
|
- 源码修订:`inspectLocalSourceVersion`、`checkLocalUpgrade` 和 `migrateLocalSource`;`LocalUpgradeOptions` 配置源修订和语义变化许可。
|
|
282
306
|
- 参数保留:`planLocalStateRetention` 和 `applyLocalStateRetention`。
|
|
283
307
|
- 后台编译:`LocalCompileScheduler`、`LOCAL_COMPILE_DELAY_MS` 和 `startLocalCompileWorker`。
|
|
284
|
-
- 类型导出:`Diagnostic`、`SourceRange`、`LocalValue`、`LocalValueKind`、`LocalNode`、`LocalBinding`、`LocalComputation`、`LocalValidation`、`LocalDocument`、`LocalCompileLimits`、`LocalCompileOptions`、`LocalCompileResult`、`LocalUpgradeOptions`、`LocalRuntime`、`LocalSnapshot`、`LocalStateFile`、`LocalStateGenerator`、`LocalStateParseResult`、`LocalStateResolution`、`LocalRetainedState`、`LocalStateRetentionReason`、`LocalStateRetentionDrop`、`LocalStateRetentionInput`、`LocalStateRetentionResult`、`LocalCompileWorker`、`LocalCompileWorkerScope`、`LocalCompileRequest`、`LocalCompileResponse`、`LocalCompileOutcome`、`LocalCompileMode`、`LocalCompileSchedulerOptions`。
|
|
308
|
+
- 类型导出:`Diagnostic`、`SourceRange`、`LocalValue`、`LocalValueKind`、`LocalNode`、`LocalBinding`、`LocalComputation`、`LocalValidation`、`LocalDocument`、`LocalCompileLimits`、`LocalCompileOptions`、`LocalCompileResult`、`LocalHostPropKind`、`LocalHostPropSchema`、`LocalHostComponentSchema`、`LocalUpgradeOptions`、`LocalRuntime`、`LocalSnapshot`、`LocalStateFile`、`LocalStateGenerator`、`LocalStateParseResult`、`LocalStateResolution`、`LocalRetainedState`、`LocalStateRetentionReason`、`LocalStateRetentionDrop`、`LocalStateRetentionInput`、`LocalStateRetentionResult`、`LocalCompileWorker`、`LocalCompileWorkerScope`、`LocalCompileRequest`、`LocalCompileResponse`、`LocalCompileOutcome`、`LocalCompileMode`、`LocalCompileSchedulerOptions`。
|
|
285
309
|
|
|
286
310
|
`compileExpression`、`compileLatex` 和 `samplePlot` 是较低层的工具,稳定级别与核心 API 相同;通常只需要 `compileLocal` 和 `createLocalRuntime`。
|
|
287
311
|
|
|
@@ -44,7 +44,7 @@ export function Article() {
|
|
|
44
44
|
| Prop | Type | Component | Notes |
|
|
45
45
|
| --- | --- | --- | --- |
|
|
46
46
|
| `source` | `string` | `LocalReactiveDocument` | Recompiles and creates a new runtime when the source changes; old instance state is not kept. See [Keeping values when source changes](#keeping-values-when-source-changes) |
|
|
47
|
-
| `compileOptions` | `LocalCompileOptions` | `LocalReactiveDocument` | Per-compilation limits
|
|
47
|
+
| `compileOptions` | `LocalCompileOptions` | `LocalReactiveDocument` | Per-compilation limits, HTML capability flags and host component schemas; omitted options use the default ReactiveMD path |
|
|
48
48
|
| `document` | `LocalDocument` | `LocalDocumentView` | Compiled document; compiled once by the host |
|
|
49
49
|
| `runtime` | `LocalRuntime` | `LocalDocumentView` | Created by the host, which is responsible for disposal |
|
|
50
50
|
| `onDiagnostics` | `(diagnostics: Diagnostic[]) => void` | Both | Receives compile diagnostics and runtime diagnostics when control writes are rejected |
|
|
@@ -52,6 +52,8 @@ export function Article() {
|
|
|
52
52
|
| `locale` | `'en' \| 'zh'` | Both | Language for built-in labels, controls and displayed diagnostics; defaults to `'en'`. Callbacks keep structured diagnostics |
|
|
53
53
|
| `themes` | `readonly LocalThemeDefinition[]` | Both | Host registrations; CSS loads separately; built-in `default` is always available |
|
|
54
54
|
| `colorScheme` | `'light' \| 'dark' \| 'auto'` | Both | Defaults to `auto`, following the nearest explicit ancestor preference or the system |
|
|
55
|
+
| `hostData` | `Readonly<Record<string, unknown>>` | Both | JSON-safe host data keyed `${kind}:${ref}` for `hostComponent` nodes; never enters the worker |
|
|
56
|
+
| `hostRenderer` | `LocalHostRenderer` | Both | Client-only renderer for `hostComponent` nodes; a missing renderer or data renders a visible placeholder |
|
|
55
57
|
|
|
56
58
|
Neither component has `className`, `style` or slot props. `LocalReactiveDocument` renders `<article class="md-document local-document">`; `LocalDocumentView` uses the same document container. See below for style overrides.
|
|
57
59
|
|
|
@@ -117,6 +119,28 @@ The budget counts `LocalNode` instances created cumulatively during parsing, inc
|
|
|
117
119
|
|
|
118
120
|
To use a custom budget in React, call `compileLocal` first and pass the compiled document and runtime to `LocalDocumentView`. `LocalReactiveDocument` and the Playground compilation thread use the default budget. After raising the node budget, hosts should measure memory and preview rendering time with their actual documents.
|
|
119
121
|
|
|
122
|
+
### Host components
|
|
123
|
+
|
|
124
|
+
A host can register leaf tags for one compilation without changing the `local-draft-2` syntax revision:
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
import { compileLocal, type LocalHostComponentSchema } from 'reactive-md';
|
|
128
|
+
|
|
129
|
+
const hostComponents: LocalHostComponentSchema[] = [
|
|
130
|
+
{
|
|
131
|
+
name: 'host-weather',
|
|
132
|
+
form: 'leaf',
|
|
133
|
+
props: {
|
|
134
|
+
kind: { kind: 'enum', required: true, enum: ['weather'] },
|
|
135
|
+
ref: { kind: 'string', required: true, pattern: '^[a-z-]+$' },
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
const result = compileLocal(source, { hostComponents });
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Without `hostComponents`, those tags remain unknown and fall back to source. Names must be unique lowercase kebab-case and cannot reuse one of the 48 author tag names, a P0 HTML tag name or `theme`; at most 32 schemas are accepted. `pattern` accepts only a linear-time-safe regex subset (no backreferences, lookarounds, named groups, nested quantifiers or quantified alternation). An invalid schema returns `local.options.invalid`, and an invalid authored attribute returns `local.host.attribute`. A valid host node counts as one syntax node. Pass `hostData`, keyed `${kind}:${ref}`, and `hostRenderer` to `LocalDocumentView`; neither enters the worker. A missing renderer, missing data or a throwing renderer renders a visible placeholder instead of failing the document. `mode="static"` uses the same dispatch and passes `ctx.mode` to the renderer.
|
|
143
|
+
|
|
120
144
|
### Version inspection and migration
|
|
121
145
|
|
|
122
146
|
Three pure functions inspect and migrate source without creating a runtime. They are exported from `reactive-md`:
|
|
@@ -281,7 +305,7 @@ scheduler.schedule(source);
|
|
|
281
305
|
- Source revisions: `inspectLocalSourceVersion`, `checkLocalUpgrade` and `migrateLocalSource`; `LocalUpgradeOptions` configures the source revision and semantic-change allowance.
|
|
282
306
|
- Retention: `planLocalStateRetention` and `applyLocalStateRetention`.
|
|
283
307
|
- Background compilation: `LocalCompileScheduler`, `LOCAL_COMPILE_DELAY_MS` and `startLocalCompileWorker`.
|
|
284
|
-
- Type exports: `Diagnostic`, `SourceRange`, `LocalValue`, `LocalValueKind`, `LocalNode`, `LocalBinding`, `LocalComputation`, `LocalValidation`, `LocalDocument`, `LocalCompileLimits`, `LocalCompileOptions`, `LocalCompileResult`, `LocalUpgradeOptions`, `LocalRuntime`, `LocalSnapshot`, `LocalStateFile`, `LocalStateGenerator`, `LocalStateParseResult`, `LocalStateResolution`, `LocalRetainedState`, `LocalStateRetentionReason`, `LocalStateRetentionDrop`, `LocalStateRetentionInput`, `LocalStateRetentionResult`, `LocalCompileWorker`, `LocalCompileWorkerScope`, `LocalCompileRequest`, `LocalCompileResponse`, `LocalCompileOutcome`, `LocalCompileMode`, `LocalCompileSchedulerOptions`.
|
|
308
|
+
- Type exports: `Diagnostic`, `SourceRange`, `LocalValue`, `LocalValueKind`, `LocalNode`, `LocalBinding`, `LocalComputation`, `LocalValidation`, `LocalDocument`, `LocalCompileLimits`, `LocalCompileOptions`, `LocalCompileResult`, `LocalHostPropKind`, `LocalHostPropSchema`, `LocalHostComponentSchema`, `LocalUpgradeOptions`, `LocalRuntime`, `LocalSnapshot`, `LocalStateFile`, `LocalStateGenerator`, `LocalStateParseResult`, `LocalStateResolution`, `LocalRetainedState`, `LocalStateRetentionReason`, `LocalStateRetentionDrop`, `LocalStateRetentionInput`, `LocalStateRetentionResult`, `LocalCompileWorker`, `LocalCompileWorkerScope`, `LocalCompileRequest`, `LocalCompileResponse`, `LocalCompileOutcome`, `LocalCompileMode`, `LocalCompileSchedulerOptions`.
|
|
285
309
|
|
|
286
310
|
`compileExpression`, `compileLatex` and `samplePlot` are lower-level utilities with the same stability level as the core API; usually only `compileLocal` and `createLocalRuntime` are needed.
|
|
287
311
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# 0.5.2 预览版发布
|
|
2
|
+
|
|
3
|
+
`reactive-md@0.5.2` 是面向 `next` 渠道的 0.x 预览版。语法修订仍为 `local-draft-2`,主题协议仍为 `reactive-md-theme-1`;因新增宿主组件扩展轴,组块协议提升到 `component-protocol-2`。现有 0.5.x 导入和文档无需迁移。`latest` 仍为 `0.4.0`。
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install reactive-md@next
|
|
7
|
+
# 或固定预览版
|
|
8
|
+
npm install reactive-md@0.5.2
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
离线安装可使用 [npm tarball](https://registry.npmjs.org/reactive-md/-/reactive-md-0.5.2.tgz)。
|
|
12
|
+
|
|
13
|
+
## 宿主组件
|
|
14
|
+
|
|
15
|
+
`compileLocal(source, { hostComponents })` 增加一条可选的宿主叶子标签扩展轴。Schema 是普通数据:名称、`form: 'leaf'`,以及声明 `kind`、`required`、`static`、`enum` 和 `pattern` 的属性表。名称必须是唯一的小写 kebab-case,不能复用 48 个作者标签名、P0 HTML 标签名或主题名;单次编译最多接受 32 个 Schema。
|
|
16
|
+
|
|
17
|
+
不传 `hostComponents` 时行为不变:标签仍是未知标签并按原文降级。传入后,解析器生成 `hostComponent` 叶子节点,编译器校验其属性。属性失败使用 `local.host.attribute`,Schema 非法使用 `local.options.invalid`。合法宿主节点计为一个语法节点,宿主属性同样受共享字符串长度预算约束。`pattern` 限制在线性时间安全子集内,拒绝反向引用、环视、命名组、嵌套量词和被量词修饰的分支。
|
|
18
|
+
|
|
19
|
+
`LocalDocumentView` 和 `LocalReactiveDocument` 接受 `hostData`(按 `${kind}:${ref}` 索引的 JSON 安全数据)与仅客户端的 `hostRenderer(node, data, ctx)`。缺少 renderer、缺少数据或 renderer 抛错时显示可见占位,不会让文档失败。`mode="static"` 走同一分派。Schema 会随编译请求进入 worker;renderer 和宿主数据不会。
|
|
20
|
+
|
|
21
|
+
完整契约见[本地模式集成](local-integration-ch.md#宿主组件)与[组块协议](component-protocol-ch.md)。
|
|
22
|
+
|
|
23
|
+
## 协议修订
|
|
24
|
+
|
|
25
|
+
组块协议现为 `component-protocol-2`。语法修订仍为 `local-draft-2`,机器验收基线 `component-protocol-1.json` 继续冻结,用于 48 个作者组块。宿主组件不提供可移植机器用例,因为渲染由宿主拥有。
|
|
26
|
+
|
|
27
|
+
## 兼容性
|
|
28
|
+
|
|
29
|
+
现有 `reactive-md`、`reactive-md/react`、`reactive-md/editor`、`reactive-md/styles.css` 和 `reactive-md/editor/styles.css` 导入继续有效。为 `0.5.x` 编写的文档无需修改;宿主扩展为可选能力。核心入口仍不依赖 React。详见[变更日志](../CHANGELOG-ch.md)与[版本与兼容性](compatibility-ch.md)。
|
|
30
|
+
|
|
31
|
+
## 验证与限制
|
|
32
|
+
|
|
33
|
+
发布门槛覆盖类型检查、完整测试套件、文档链接、包构建和打包安装冒烟检查。单文件导出之外的通用 SSR 水合、Firefox 和 WebKit 仍未验证。
|
|
34
|
+
|
|
35
|
+
项目仍是 0.x 预览版。安全边界与宿主责任见[SECURITY-ch.md](../SECURITY-ch.md)。
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# 0.5.2 preview release
|
|
2
|
+
|
|
3
|
+
`reactive-md@0.5.2` is a 0.x preview that targets the `next` channel. It keeps syntax revision `local-draft-2` and theme protocol `reactive-md-theme-1`, and raises the component protocol to `component-protocol-2` for the host component extension axis. Existing 0.5.x imports and documents need no migration. `latest` remains `0.4.0`.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install reactive-md@next
|
|
7
|
+
# or pin the preview
|
|
8
|
+
npm install reactive-md@0.5.2
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
For offline installation, use the [npm tarball](https://registry.npmjs.org/reactive-md/-/reactive-md-0.5.2.tgz).
|
|
12
|
+
|
|
13
|
+
## Host components
|
|
14
|
+
|
|
15
|
+
`compileLocal(source, { hostComponents })` adds an opt-in extension axis for host-defined leaf tags. A schema is plain data: a name, `form: 'leaf'` and a property table declaring `kind`, `required`, `static`, `enum` and `pattern`. Names must be unique lowercase kebab-case and cannot reuse the 48 author tag names, P0 HTML tag names or the theme name; one compilation accepts at most 32 schemas.
|
|
16
|
+
|
|
17
|
+
Without `hostComponents`, behavior is unchanged: the tag remains unknown and falls back to source. With the option, the parser produces a `hostComponent` leaf node and the compiler validates its attributes. Attribute failures use `local.host.attribute`; invalid schemas use `local.options.invalid`. A valid host node counts as one syntax node, and host attributes obey the shared string-length budget. `pattern` is restricted to a linear-time-safe regex subset that rejects backreferences, lookarounds, named groups, nested quantifiers and quantified alternation.
|
|
18
|
+
|
|
19
|
+
`LocalDocumentView` and `LocalReactiveDocument` accept `hostData`, JSON-safe data keyed `${kind}:${ref}`, and a client-only `hostRenderer(node, data, ctx)`. A missing renderer, missing data or a throwing renderer renders a visible placeholder instead of failing the document. `mode="static"` uses the same dispatch. Schemas travel through the compile worker; the renderer and host data never do.
|
|
20
|
+
|
|
21
|
+
See [Local mode integration](local-integration-en.md#host-components) and [Component protocol](component-protocol-en.md) for the full contract.
|
|
22
|
+
|
|
23
|
+
## Protocol revision
|
|
24
|
+
|
|
25
|
+
The component protocol is now `component-protocol-2`. The syntax revision remains `local-draft-2`, and the machine conformance baseline `component-protocol-1.json` stays frozen for the 48 author components. Host components have no portable machine cases because rendering is host-owned.
|
|
26
|
+
|
|
27
|
+
## Compatibility
|
|
28
|
+
|
|
29
|
+
Existing `reactive-md`, `reactive-md/react`, `reactive-md/editor`, `reactive-md/styles.css` and `reactive-md/editor/styles.css` imports keep working. Documents written for `0.5.x` need no edit; the host extension is opt-in. The core entry still does not depend on React. See the [changelog](../CHANGELOG.md) and [Versions and compatibility](compatibility-en.md).
|
|
30
|
+
|
|
31
|
+
## Validation and limits
|
|
32
|
+
|
|
33
|
+
The release gate covers type checking, the full test suite, documentation links, the package build and a packed-package smoke check. General SSR hydration outside exported HTML, Firefox and WebKit remain unverified.
|
|
34
|
+
|
|
35
|
+
The project remains a 0.x preview. Security boundaries and host responsibilities are documented in [SECURITY.md](../SECURITY.md).
|