reactive-md 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG-ch.md +96 -0
- package/CHANGELOG.md +96 -40
- package/CONTRIBUTING-ch.md +62 -0
- package/CONTRIBUTING.md +64 -61
- package/README-ch.md +122 -0
- package/README-en.md +146 -0
- package/README.md +146 -88
- package/SECURITY-ch.md +80 -0
- package/SECURITY.md +80 -68
- package/THIRD_PARTY_NOTICES.md +85 -1
- package/bin/reactive-md.mjs +40 -0
- package/cli/args.mjs +181 -0
- package/cli/assets.mjs +390 -0
- package/cli/build.mjs +268 -0
- package/cli/document.mjs +130 -0
- package/cli/errors.mjs +61 -0
- package/cli/fs-utils.mjs +133 -0
- package/cli/glob.mjs +203 -0
- package/cli/help.mjs +138 -0
- package/cli/lint.mjs +177 -0
- package/cli/main.mjs +55 -0
- package/cli/migrate.mjs +368 -0
- package/cli/package.mjs +209 -0
- package/dist-library/reactive-md-react.js +3603 -1690
- package/dist-library/reactive-md.css +1 -1
- package/dist-library/reactive-md.js +1798 -4
- package/dist-library/runtime-DtjdPXxJ.js +15410 -0
- package/dist-library/types/index.d.ts +1 -0
- package/dist-library/types/local/LocalDocumentView.d.ts +66 -3
- package/dist-library/types/local/authoring.d.ts +63 -0
- package/dist-library/types/local/collection-functions.d.ts +4 -0
- package/dist-library/types/local/colors.d.ts +2 -0
- package/dist-library/types/local/compiler.d.ts +3 -3
- package/dist-library/types/local/computations.d.ts +53 -0
- package/dist-library/types/local/data-functions.d.ts +22 -0
- package/dist-library/types/local/data-table.d.ts +65 -0
- package/dist-library/types/local/dates.d.ts +2 -0
- package/dist-library/types/local/dependencies.d.ts +31 -0
- package/dist-library/types/local/diagnostics.d.ts +1450 -0
- package/dist-library/types/local/expression.d.ts +13 -3
- package/dist-library/types/local/formatting.d.ts +41 -0
- package/dist-library/types/local/heading-anchors.d.ts +17 -0
- package/dist-library/types/local/i18n.d.ts +18 -0
- package/dist-library/types/local/index.d.ts +18 -1
- package/dist-library/types/local/limits.d.ts +33 -1
- package/dist-library/types/local/locale.d.ts +1 -0
- package/dist-library/types/local/math.d.ts +6 -1
- package/dist-library/types/local/parser.d.ts +10 -4
- package/dist-library/types/local/render-types.d.ts +5 -1
- package/dist-library/types/local/retention.d.ts +23 -0
- package/dist-library/types/local/schema.d.ts +25 -3
- package/dist-library/types/local/source-migration.d.ts +35 -0
- package/dist-library/types/local/state.d.ts +80 -0
- package/dist-library/types/local/text-length.d.ts +13 -0
- package/dist-library/types/local/theme.d.ts +30 -0
- package/dist-library/types/local/types.d.ts +120 -4
- package/dist-library/types/local/validation.d.ts +32 -0
- package/dist-library/types/local/version.d.ts +1 -1
- package/dist-library/types/local/worker.d.ts +82 -0
- package/dist-library/types/react/index.d.ts +4 -1
- package/dist-library/types/shareable.d.ts +64 -0
- package/dist-standalone/reactive-md-standalone.css +2 -0
- package/dist-standalone/reactive-md-standalone.js +57 -0
- package/docs/author-tools-ch.md +56 -0
- package/docs/author-tools-en.md +56 -0
- package/docs/compatibility-ch.md +103 -0
- package/docs/compatibility-en.md +103 -0
- package/docs/component-development-ch.md +210 -0
- package/docs/component-development-en.md +210 -0
- package/docs/component-protocol-ch.md +710 -0
- package/docs/component-protocol-en.md +710 -0
- package/docs/computations-formatting-ch.md +87 -0
- package/docs/computations-formatting-en.md +87 -0
- package/docs/constraints-collections-ch.md +84 -0
- package/docs/constraints-collections-en.md +84 -0
- package/docs/diagnostics-counting-ch.md +84 -0
- package/docs/diagnostics-counting-en.md +84 -0
- package/docs/local-components-v2-ch.md +138 -0
- package/docs/local-components-v2-en.md +104 -0
- package/docs/{local-guide.md → local-guide-ch.md} +961 -936
- package/docs/local-guide-en.md +961 -0
- package/docs/local-integration-ch.md +363 -0
- package/docs/local-integration-en.md +363 -0
- package/docs/{local-interaction-syntax.md → local-interaction-syntax-ch.md} +485 -437
- package/docs/local-interaction-syntax-en.md +483 -0
- package/docs/performance-ch.md +76 -0
- package/docs/performance-en.md +76 -0
- package/docs/release-0.4.0-ch.md +89 -0
- package/docs/release-0.4.0-en.md +89 -0
- package/docs/releasing-ch.md +101 -0
- package/docs/releasing-en.md +101 -0
- package/docs/shareable-export-ch.md +205 -0
- package/docs/shareable-export-en.md +207 -0
- package/docs/source-versioning-ch.md +159 -0
- package/docs/source-versioning-en.md +159 -0
- package/docs/theme-protocol-ch.md +107 -0
- package/docs/theme-protocol-en.md +107 -0
- package/examples/conformance/README.md +53 -11
- package/examples/conformance/component-protocol-1.json +482 -0
- package/examples/conformance/component-protocol-1.schema.json +76 -0
- package/examples/conformance/history/v0.3.1/catalog.reactive.md +20 -0
- package/examples/conformance/history/v0.3.1/charts.reactive.md +73 -0
- package/examples/conformance/history/v0.3.1/checklist.reactive.md +32 -0
- package/examples/conformance/history/v0.3.1/comparison.reactive.md +47 -0
- package/examples/conformance/history/v0.3.1/components.reactive.md +44 -0
- package/examples/conformance/history/v0.3.1/counter.reactive.md +7 -0
- package/examples/conformance/history/v0.3.1/diagnostics.reactive.md +54 -0
- package/examples/conformance/history/v0.3.1/diagram.reactive.md +44 -0
- package/examples/conformance/history/v0.3.1/gallery.reactive.md +61 -0
- package/examples/conformance/history/v0.3.1/local-draft-1.json +50 -0
- package/examples/conformance/history/v0.3.1/parameters.reactive.md +36 -0
- package/examples/conformance/history/v0.3.1/planning.reactive.md +24 -0
- package/examples/conformance/history/v0.3.1/pricing.reactive.md +20 -0
- package/examples/conformance/history/v0.3.1/provenance.json +72 -0
- package/examples/conformance/local-draft-1.json +50 -49
- package/examples/conformance/local-draft-2.json +212 -0
- package/examples/integration/README.md +45 -29
- package/examples/integration/core/index.mjs +32 -19
- package/examples/integration/react/index.html +1 -1
- package/examples/integration/react/main.jsx +5 -5
- package/examples/integration/worker/index.html +19 -0
- package/examples/integration/worker/main.js +61 -0
- package/examples/integration/worker/package.json +13 -0
- package/examples/integration/worker/worker.js +3 -0
- package/examples/local/README.md +72 -66
- package/examples/local/catalog.reactive.md +14 -14
- package/examples/local/charts.reactive.md +73 -73
- package/examples/local/checklist.reactive.md +19 -19
- package/examples/local/comparison.reactive.md +23 -23
- package/examples/local/components.reactive.md +20 -20
- package/examples/local/counter.reactive.md +4 -4
- package/examples/local/diagnostics.reactive.md +25 -25
- package/examples/local/diagram.reactive.md +20 -20
- package/examples/local/gallery.reactive.md +31 -31
- package/examples/local/parameters.reactive.md +19 -19
- package/examples/local/planning.reactive.md +15 -15
- package/examples/local/pricing.reactive.md +10 -10
- package/examples/local/recipes/invoice-zh.reactive.md +36 -0
- package/examples/local/recipes/invoice.reactive.md +36 -0
- package/examples/local/recipes/workshop-zh.reactive.md +33 -0
- package/examples/local/recipes/workshop.reactive.md +33 -0
- package/examples/local/showcase/README.md +25 -0
- package/examples/local/showcase/explore.reactive.md +102 -0
- package/examples/local/showcase/flow.reactive.md +86 -0
- package/examples/local/showcase/forms.reactive.md +126 -0
- package/examples/local/showcase/functions.reactive.md +119 -0
- package/examples/local/showcase/layout.reactive.md +100 -0
- package/examples/local/showcase/statistics.reactive.md +108 -0
- package/examples/local/showcase/tasks.reactive.md +89 -0
- package/examples/local/showcase/zh/explore.reactive.md +102 -0
- package/examples/local/showcase/zh/flow.reactive.md +86 -0
- package/examples/local/showcase/zh/forms.reactive.md +126 -0
- package/examples/local/showcase/zh/functions.reactive.md +119 -0
- package/examples/local/showcase/zh/layout.reactive.md +100 -0
- package/examples/local/showcase/zh/statistics.reactive.md +108 -0
- package/examples/local/showcase/zh/tasks.reactive.md +89 -0
- package/examples/local/zh/catalog.reactive.md +20 -0
- package/examples/local/zh/charts.reactive.md +73 -0
- package/examples/local/zh/checklist.reactive.md +32 -0
- package/examples/local/zh/comparison.reactive.md +47 -0
- package/examples/local/zh/components.reactive.md +44 -0
- package/examples/local/zh/counter.reactive.md +7 -0
- package/examples/local/zh/diagnostics.reactive.md +54 -0
- package/examples/local/zh/diagram.reactive.md +44 -0
- package/examples/local/zh/gallery.reactive.md +61 -0
- package/examples/local/zh/parameters.reactive.md +36 -0
- package/examples/local/zh/planning.reactive.md +24 -0
- package/examples/local/zh/pricing.reactive.md +20 -0
- package/package.json +90 -75
- package/README.en.md +0 -75
- package/dist-library/runtime-D4phFXOr.js +0 -10937
- package/docs/compatibility.md +0 -67
- package/docs/local-integration.md +0 -193
- package/docs/performance.md +0 -30
- package/docs/releasing.md +0 -92
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# 作者工具
|
|
2
|
+
|
|
3
|
+
[English](author-tools-en.md)
|
|
4
|
+
|
|
5
|
+
作者工具包含在 `0.4.0` 源码树中。本地使用前先构建语言包:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm ci
|
|
9
|
+
npm run build
|
|
10
|
+
npm run lint -- examples/local/planning.reactive.md
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 命令行检查
|
|
14
|
+
|
|
15
|
+
语言包提供 `reactive-md lint`。可以传入多个文件,或用 `-` 读取标准输入:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
reactive-md lint "my document.reactive.md" other.reactive.md
|
|
19
|
+
reactive-md lint --json --warnings-as-errors document.reactive.md
|
|
20
|
+
reactive-md lint --locale zh document.reactive.md
|
|
21
|
+
cat document.reactive.md | reactive-md lint -
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
文本输出包含文件、行、列、严重程度和诊断代码。JSON 输出为 `{ file, ok, diagnostics }` 报告数组。诊断沿用编译器的 UTF-16 源码范围,行列从 1 开始。检查过程保留原文件。
|
|
25
|
+
|
|
26
|
+
`--locale en|zh` 选择诊断消息语言,默认英文。切换语言保留诊断码、严重程度和位置。兼容契约与预算单位见[诊断与计数规则](diagnostics-counting-ch.md)。
|
|
27
|
+
|
|
28
|
+
| 退出码 | 含义 |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| 0 | 没有错误;默认允许警告 |
|
|
31
|
+
| 1 | 存在编译错误,或启用 `--warnings-as-errors` 后存在警告 |
|
|
32
|
+
| 2 | 参数错误或文件读取失败 |
|
|
33
|
+
|
|
34
|
+
## 接入编辑器
|
|
35
|
+
|
|
36
|
+
核心入口提供与 DOM 无关的函数:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import {
|
|
40
|
+
analyzeLocalSource, completeLocalSource,
|
|
41
|
+
renameLocalBinding, formatLocalSource,
|
|
42
|
+
} from 'reactive-md';
|
|
43
|
+
|
|
44
|
+
const analysis = analyzeLocalSource(source);
|
|
45
|
+
const suggestions = completeLocalSource(source, cursorOffset);
|
|
46
|
+
const renamed = renameLocalBinding(source, 'people', 'attendees');
|
|
47
|
+
const formatted = formatLocalSource(renamed.source);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
分析结果包含按位置排序的高亮 token、绑定声明和引用范围,以及编译诊断。补全项包含 `label`、`kind`、`insertText` 和待替换的 `range`。应用编辑时,应使用生成这些范围的同一版本源码。
|
|
51
|
+
|
|
52
|
+
重命名修改生效的绑定声明、表达式引用和绘图参数,保留普通文字与展示公式。绘图参数在重命名后写为 `\mathrm{newName}`。非法名称和名称冲突会抛出错误。格式化整理已识别组件标签内的空白,保留 Markdown 排版、引号内容、公式、代码与降级区域的源码。编辑器应持续保存原始文档。
|
|
53
|
+
|
|
54
|
+
## Playground
|
|
55
|
+
|
|
56
|
+
运行 `npm run dev`,选择“显示源码”。编辑器提供高亮、补全、绑定定位、重命名、格式化、诊断跳转与实时预览。通过补全按钮或 Ctrl+Space 打开建议列表,方向键选择,Enter 插入,Escape 关闭。重命名与格式化均可撤销、重做。
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Author tools
|
|
2
|
+
|
|
3
|
+
[中文](author-tools-ch.md)
|
|
4
|
+
|
|
5
|
+
These tools are included in the `0.4.0` source tree. Build the package before using them locally:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm ci
|
|
9
|
+
npm run build
|
|
10
|
+
npm run lint -- examples/local/planning.reactive.md
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Command line
|
|
14
|
+
|
|
15
|
+
The package provides `reactive-md lint`. Pass one or more document paths, or `-` to read stdin:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
reactive-md lint "my document.reactive.md" other.reactive.md
|
|
19
|
+
reactive-md lint --json --warnings-as-errors document.reactive.md
|
|
20
|
+
reactive-md lint --locale zh document.reactive.md
|
|
21
|
+
cat document.reactive.md | reactive-md lint -
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Text output includes the file, line, column, severity and diagnostic code. JSON output is an array of `{ file, ok, diagnostics }` reports. Diagnostics use the compiler's original UTF-16 source ranges and one-based line/column positions. The command reads documents without changing them.
|
|
25
|
+
|
|
26
|
+
`--locale en|zh` selects diagnostic messages and defaults to English. Codes, severity and locations stay identical across languages. See [Diagnostics and counting rules](diagnostics-counting-en.md) for the compatibility contract and budget units.
|
|
27
|
+
|
|
28
|
+
| Exit code | Meaning |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| 0 | No errors; warnings are allowed by default |
|
|
31
|
+
| 1 | Compiler errors, or warnings with `--warnings-as-errors` |
|
|
32
|
+
| 2 | Invalid arguments or a file-read failure |
|
|
33
|
+
|
|
34
|
+
## Editor integration
|
|
35
|
+
|
|
36
|
+
The core entry exposes DOM-independent functions:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import {
|
|
40
|
+
analyzeLocalSource, completeLocalSource,
|
|
41
|
+
renameLocalBinding, formatLocalSource,
|
|
42
|
+
} from 'reactive-md';
|
|
43
|
+
|
|
44
|
+
const analysis = analyzeLocalSource(source);
|
|
45
|
+
const suggestions = completeLocalSource(source, cursorOffset);
|
|
46
|
+
const renamed = renameLocalBinding(source, 'people', 'attendees');
|
|
47
|
+
const formatted = formatLocalSource(renamed.source);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Analysis returns ordered highlight tokens, bindings with declaration/reference ranges, and compiler diagnostics. Completions contain `label`, `kind`, `insertText` and the `range` to replace. Apply edits against the same source version that produced their ranges.
|
|
51
|
+
|
|
52
|
+
Rename updates active binding declarations, expression references and computed plot parameters, preserving literal text and display formulas. Plot parameters use `\mathrm{newName}` after a rename. Invalid names and collisions throw an error. Formatting normalizes spacing inside recognized component tags; Markdown layout, quoted content, formulas, code and fallback regions retain their source. Keep the original source as the editable document.
|
|
53
|
+
|
|
54
|
+
## Playground
|
|
55
|
+
|
|
56
|
+
Run `npm run dev` and choose **Show source**. The source editor provides highlighting, completion, binding locations, rename, formatting, diagnostic navigation and a live preview. Use the completion button or Ctrl+Space, arrow keys and Enter to insert a suggestion, and Escape to close the list. Rename and formatting participate in editor undo/redo.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# 版本与兼容性
|
|
2
|
+
|
|
3
|
+
Reactive MD 目前是 0.x 预览版。本页说明包版本、语法版本、可持久化的内容、诊断契约和当前平台范围。显式修订声明、迁移 API 与 `reactive-md migrate` 见[源码修订与迁移](source-versioning-ch.md),公开 API 与样式接入见[本地模式集成](local-integration-ch.md),本次发布的升级摘要见[0.4.0 发布与迁移](release-0.4.0-ch.md)。
|
|
4
|
+
|
|
5
|
+
## 版本对应
|
|
6
|
+
|
|
7
|
+
| 项目 | 当前值 | 说明 |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| 包版本 | `0.4.0` | 预览版,发布在 `next` 分发渠道 |
|
|
10
|
+
| 分发标签 | `next` → `0.4.0`;`latest` → `0.3.1` | `0.3.1` 保持稳定通道,直到另行决定提升 |
|
|
11
|
+
| 语法版本 | `local-draft-2` | `LOCAL_SYNTAX_VERSION`;当前构建只接受这一修订 |
|
|
12
|
+
| 源码修订指令 | 可选 `<!-- reactive-md: local-draft-2 -->` | 文档前导区中的一行;无指令源码继续按当前修订解析 |
|
|
13
|
+
| 组块协议 | `component-protocol-1` | 贡献与验收契约,见[组块协议](component-protocol-ch.md);不是运行时版本选择参数 |
|
|
14
|
+
| 核心入口 | `reactive-md` | 编译、表达式与运行时,不加载 React |
|
|
15
|
+
| React 入口 | `reactive-md/react` | `LocalReactiveDocument`、`LocalDocumentView` |
|
|
16
|
+
| 样式入口 | `reactive-md/styles.css` | 一份全局样式表,由宿主显式引入 |
|
|
17
|
+
|
|
18
|
+
一个包版本只对应一个语法修订。升级包之前,记录应用使用的 `LOCAL_SYNTAX_VERSION`。如果文档源码来自另一个语法修订,保留旧包版本渲染,或按下面的迁移说明改写。`compileLocal(source, options?)` 不提供语法版本参数;宿主可以通过 `options.limits.maxSyntaxNodes` 调整单次编译的语法节点预算,见[本地模式集成](local-integration-ch.md)。
|
|
19
|
+
|
|
20
|
+
## 显式源码修订
|
|
21
|
+
|
|
22
|
+
源码可以在前导区用一行 `<!-- reactive-md: local-draft-2 -->` 声明修订。无指令源码按当前修订读取,不新增警告。显式 `local-draft-1` 或未知修订会以 `local.version.*` 诊断拒绝,不创建运行时;声明旧修订不会选择旧解析器。格式错误、重复和位置错误的指令同样被拒绝。
|
|
23
|
+
|
|
24
|
+
在这一指令出现之前构建的读者(包括 `0.3.1`)会把它当作普通注释,不执行这项检查。依赖检查前请先迁移旧文档。`inspectLocalSourceVersion`、`checkLocalUpgrade` 和 `migrateLocalSource` 在编译器之外读取声明,`reactive-md migrate` 对单份源码执行元数据迁移。见[源码修订与迁移](source-versioning-ch.md)。
|
|
25
|
+
|
|
26
|
+
## 0.x 的兼容规则
|
|
27
|
+
|
|
28
|
+
- 次版本(`0.3` 到 `0.4`)可能包含破坏性变更;补丁版本只做兼容修复和安全修复。
|
|
29
|
+
- 0.x 阶段不承诺固定弃用周期。每项破坏性变更都会写入 [变更记录](../CHANGELOG-ch.md),说明旧写法、新写法和迁移步骤。
|
|
30
|
+
- 1.0 之前,把每次升级都当成可能需要修改文档源码或宿主代码。
|
|
31
|
+
- 应用应固定包版本,保留原始 `.reactive.md` 源码,并在升级后用自己的文档和示例重新运行编译与渲染检查。
|
|
32
|
+
|
|
33
|
+
## 核心语义兼容范围
|
|
34
|
+
|
|
35
|
+
同一语法修订内,兼容的包更新保留已接受源码的含义:
|
|
36
|
+
|
|
37
|
+
- 控件的公开值类型、初值规则、同名绑定约束和校验规则保持一致。隐藏控件仍会初始化,再次显示不会自动重置其值。
|
|
38
|
+
- 表达式保持严格操作数类型、运算符优先级、短路求值和有限数值规则。局部计算失败不替换有效输入,也不阻止无关内容更新。
|
|
39
|
+
- 非法参数写入保留上一次有效状态;多值写入原子提交。面板重置自己的控件与组件状态,依赖这些值的内容同步更新。
|
|
40
|
+
- 正文、公式和可视化读取相同的参数值;代码与惰性降级区域保持原文。源码位置仍从 1 开始,按 UTF-16 单元和半开区间定位。
|
|
41
|
+
- 渲染内容、控件标签和交互行为属于语义输出;生成的节点/DOM ID、内部 `@` 键、AST 布局、缓存、像素排版和诊断措辞不属于稳定的源码契约。
|
|
42
|
+
|
|
43
|
+
从 `local-draft-1` 升级到 `local-draft-2` 时,这一承诺适用于通过升级检查的共同语言子集。新增保留名和新激活标签需要人工修改源码;文本长度计数是必须显式接受的兼容例外,清单完成样式属于视觉例外。超出这些已记录例外的语义变化需要新的语法修订与迁移说明。
|
|
44
|
+
|
|
45
|
+
[历史语料](../examples/conformance/history/v0.3.1/provenance.json) 保留实际 `v0.3.1` 源码、来源提交和 SHA256。回归测试检查原一致性预期、公开值、非法写入拒绝、初始化、重置和迁移渲染;比较中明确排除内部 ID。
|
|
46
|
+
|
|
47
|
+
## 破坏性变更与迁移
|
|
48
|
+
|
|
49
|
+
`0.4.0` 新增[条件、校验与本地集合](constraints-collections-ch.md):`LocalRuntime.validate()`、可序列化的 `LocalValidation` 规则、数字数组及生成表格。自行实现运行时适配器的宿主需补充 `validate()`,值类型穷举需加入 `number-array`;与 `sum`、`average`、`minOf`、`maxOf` 同名的旧绑定应重命名。
|
|
50
|
+
|
|
51
|
+
`0.4.0` 新增[命名计算与格式化函数](computations-formatting-ch.md)。`computed`/`const` 使用现有本地标签形式;新函数名成为保留字,使用本版本前需重命名冲突的输入绑定并同步修改引用。`document.bindings` 和 `initialState` 继续只包含可写控件,快照同时提供成功求值的计算结果。
|
|
52
|
+
|
|
53
|
+
`0.4.0` 建立 `local-draft-2`。使用受支持 `local-draft-1` 写法的无指令源码继续有效;显式 `local-draft-1` 声明在迁移前会被拒绝。构建新增识别 15 个标签名:十个 `local-draft-2` 组块,以及 `computed`、`const`、`validation`、`data-table`、`column`。以前作为未知标签或普通文字显示的内容现在会解析为组块或声明;字面示例应移入行内代码或代码围栏。开头的 `<theme>` 声明是文档元数据,不计入组块。完整的重命名与升级清单见[0.4.0 发布与迁移](release-0.4.0-ch.md)。
|
|
54
|
+
|
|
55
|
+
作者可见的语法变化会建立新的语法修订,例如本次的 `local-draft-2`,并提升次版本、更新 `LOCAL_SYNTAX_VERSION`。核心或 React API 的变化也会记录在变更记录中。项目不自动改写文档正文。`reactive-md migrate` 迁移单份源码的元数据声明,并阻止正文级冲突;升级后由作者或宿主按记录完成其余源码修改。
|
|
56
|
+
|
|
57
|
+
旧版配置语法不属于 `local-draft-2`。常见替换如下:
|
|
58
|
+
|
|
59
|
+
| 旧写法 | `local-draft-2` 中的做法 |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `:::card`、`:::row` 等 directive | `<card>`、`<grid>` 等标签 |
|
|
62
|
+
| YAML `state:` 声明参数 | 控件上的 `bind` 与 `initial` |
|
|
63
|
+
| YAML `computed:` | 正文中的 `{{ 表达式 }}` |
|
|
64
|
+
| `actions:`、按钮动作、`on-*` 事件 | 没有等价入口;使用组件自带的交互和面板重置 |
|
|
65
|
+
| `data:` 或外部接口数据 | 直接写在正文的 Markdown 表格;参数由控件声明 |
|
|
66
|
+
| 持久化运行状态 | 宿主保存原始源码;公开参数还可以导出为经过校验的 `reactive-md-state/v1` 文件。该文件绑定源码摘要、语法修订和完整公开参数集合,不是文档格式。 |
|
|
67
|
+
|
|
68
|
+
## 持久化什么
|
|
69
|
+
|
|
70
|
+
持久化原始 `.reactive.md` 源码。`reactive-md-state/v1` 文件可以为同一源码和语法修订保存公开参数值;摘要、修订或参数集合不一致时会拒绝整个文件。迁移会改变源码摘要,迁移后应重新导出状态文件;迁移不会改写状态文件。不要持久化 `LocalDocument`、`LocalNode`、`node.id`、`initialState`、`LocalSnapshot` 或内部 `@` 运行时键:它们属于当前运行时对象,跨版本不保证结构,也不保证字段含义。`node.id` 在源码变化后会重新生成。诊断中的行号、列号和偏移量用于定位当前源码,不是稳定的持久化标识。
|
|
71
|
+
|
|
72
|
+
## 诊断契约
|
|
73
|
+
|
|
74
|
+
`Diagnostic` 包含 `code`、`message`、`severity`、`range`、`line` 和 `column`。
|
|
75
|
+
|
|
76
|
+
- `line` 和 `column` 从 1 开始;列和 `range` 均按原始源码的 UTF-16 代码单元计数,范围为半开区间。
|
|
77
|
+
- `line`、`column` 和 `range` 可以用于程序定位和编辑器跳转。
|
|
78
|
+
- `code` 是字符串标识,例如 `local.type`、`expression-type`、`latex-plot-range`。同一 0.x minor 系列内,现有诊断码的含义保持稳定;可以新增码,删除、改名或改变含义须在新 minor 版本中说明迁移。
|
|
79
|
+
- `message` 是默认英文显示文本,使用 `formatLocalDiagnostic(diagnostic, 'zh')` 可取得中文。文案可以改进;不要解析 message 或按完整文本做业务判断。语言切换保留机器字段。
|
|
80
|
+
- `severity` 为 `warning` 或 `error`。结构完整的未知标签和脚注保留源码并给出降级警告,编译仍可成功;编译错误会让 `result.ok` 为 `false` 并停用预览。运行时局部错误只影响对应内容。
|
|
81
|
+
|
|
82
|
+
完整规则和资源单位见[诊断与计数规则](diagnostics-counting-ch.md)。
|
|
83
|
+
|
|
84
|
+
## 平台与运行环境
|
|
85
|
+
|
|
86
|
+
| 环境 | 当前状态 |
|
|
87
|
+
| --- | --- |
|
|
88
|
+
| Node.js 22.12+ | 开发和 Node 端消费的最低版本;CI 目标为 22.12 与 24 |
|
|
89
|
+
| ESM | 唯一模块格式;不提供 CommonJS 入口 |
|
|
90
|
+
| React 19 | `reactive-md/react` 的要求;核心入口不依赖 React |
|
|
91
|
+
| Microsoft Edge(Chromium 内核) | 本地浏览器验证使用 Edge |
|
|
92
|
+
| Playwright Chromium | Linux CI 浏览器目标 |
|
|
93
|
+
| Firefox、Safari/WebKit | 未验证,不作支持声明 |
|
|
94
|
+
| 可分享状态格式 | `reactive-md-state/v1`:公开参数、语法版本与源码摘要;见[可分享文档](shareable-export-ch.md) |
|
|
95
|
+
| 单文件 HTML 格式 | `reactive-md-html/v1`:交互或静态导出;仅交互模式内嵌独立运行时 |
|
|
96
|
+
| SSR | `react-dom/server` 静态渲染由 packed 检查覆盖。单文件导出的静态首屏水合已在 Playwright Chromium/Edge 验证;通用 SSR 水合未验证,使用前需自行检查 |
|
|
97
|
+
|
|
98
|
+
Node 端消费指在 Node 中导入 `reactive-md`、调用 `compileLocal` 和 `createLocalRuntime`,不需要 DOM。React 渲染要求浏览器环境或宿主自行处理服务端输出。
|
|
99
|
+
|
|
100
|
+
语言范围见[语法规范](local-interaction-syntax-ch.md),安全边界与宿主责任见[安全策略](../SECURITY-ch.md)。
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
新增组块、颜色、槽位状态与迁移规则见[local-draft-2 扩展说明](local-components-v2-ch.md),升级清单见[0.4.0 发布与迁移](release-0.4.0-ch.md)。`0.4.0` 是 `next` 渠道的预览版,`0.3.1` 仍为 `latest`。
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Versions and compatibility
|
|
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, and [0.4.0 release and migration](release-0.4.0-en.md) for this release's upgrade summary.
|
|
4
|
+
|
|
5
|
+
## Version mapping
|
|
6
|
+
|
|
7
|
+
| Item | Current value | Notes |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| Package version | `0.4.0` | Preview release, published on the `next` distribution channel |
|
|
10
|
+
| Distribution tags | `next` → `0.4.0`; `latest` → `0.3.1` | `0.3.1` remains the stable channel until a separate promotion decision |
|
|
11
|
+
| Syntax version | `local-draft-2` | `LOCAL_SYNTAX_VERSION`; the current build accepts only this revision |
|
|
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-1` | Contribution and acceptance contract, see [Component protocol](component-protocol-en.md); not a runtime version selection parameter |
|
|
14
|
+
| Core entry | `reactive-md` | Compilation, expressions and runtime, without loading React |
|
|
15
|
+
| React entry | `reactive-md/react` | `LocalReactiveDocument`, `LocalDocumentView` |
|
|
16
|
+
| Style entry | `reactive-md/styles.css` | One global stylesheet, explicitly imported by the host |
|
|
17
|
+
|
|
18
|
+
One package version corresponds to exactly one syntax revision. Before upgrading the package, record the `LOCAL_SYNTAX_VERSION` your application uses. If document sources come from another syntax revision, keep rendering them with the old package version or rewrite them according to the migration notes below. `compileLocal(source, options?)` has no syntax version parameter; hosts can adjust the syntax node budget for a single compilation through `options.limits.maxSyntaxNodes`, see [Local mode integration](local-integration-en.md).
|
|
19
|
+
|
|
20
|
+
## Explicit source revisions
|
|
21
|
+
|
|
22
|
+
A source may declare its revision with one `<!-- reactive-md: local-draft-2 -->` line in the prologue. Unversioned source is read as the current revision, without a new warning. An explicit `local-draft-1` or unknown revision is rejected with a `local.version.*` diagnostic and no runtime is created; declaring an old revision does not select an old parser. Malformed, duplicate and misplaced directives are rejected the same way.
|
|
23
|
+
|
|
24
|
+
Readers built before this directive existed, including `0.3.1`, treat it as an ordinary comment and do not enforce the check. Migrate old documents before relying on it. `inspectLocalSourceVersion`, `checkLocalUpgrade` and `migrateLocalSource` expose the declaration outside the compiler, and `reactive-md migrate` performs the single-source metadata migration. See [Source revisions and migration](source-versioning-en.md).
|
|
25
|
+
|
|
26
|
+
## Compatibility rules for 0.x
|
|
27
|
+
|
|
28
|
+
- Minor versions (`0.3` to `0.4`) may contain breaking changes; patch versions contain only compatibility and security fixes.
|
|
29
|
+
- The 0.x phase does not promise a fixed deprecation period. Every breaking change is recorded in the [changelog](../CHANGELOG.md), with the old form, new form and migration steps.
|
|
30
|
+
- Before 1.0, treat every upgrade as potentially requiring changes to document sources or host code.
|
|
31
|
+
- Applications should pin the package version, keep the original `.reactive.md` sources, and rerun compile and render checks with their own documents and examples after upgrading.
|
|
32
|
+
|
|
33
|
+
## Core semantic compatibility
|
|
34
|
+
|
|
35
|
+
Within a syntax revision, compatible package updates preserve the meaning of accepted source:
|
|
36
|
+
|
|
37
|
+
- Controls keep their public value types, initial-value rules, shared-binding constraints and validation rules. Hidden controls still initialize, and showing them again does not reset their values.
|
|
38
|
+
- Expressions keep strict operand types, operator precedence, short-circuit evaluation and finite-number rules. A failed local calculation does not replace a valid input or stop unrelated content.
|
|
39
|
+
- Invalid parameter writes leave the last valid state unchanged; multi-value writes commit atomically. Panel reset restores its own controls and component state, and dependent content updates consistently.
|
|
40
|
+
- Prose, formulas and visualizations read the same parameter values. Code and inert fallback regions stay literal. Source locations remain one-based with UTF-16 offsets and half-open ranges.
|
|
41
|
+
- Rendered content, control labels and interactions are semantic outputs. Generated node/DOM IDs, internal `@` keys, AST layout, caches, pixel layout and diagnostic wording are outside the stable source contract.
|
|
42
|
+
|
|
43
|
+
From `local-draft-1` to `local-draft-2`, this promise covers the common supported language after upgrade checks. New reserved identifiers and newly active tags require manual source changes. Text-length counting is an explicit compatibility exception that the migrator requires you to accept; completed-checklist styling is a visual exception. A semantic change outside these recorded exceptions requires a syntax revision and migration notes.
|
|
44
|
+
|
|
45
|
+
Regression data in [the historical corpus](../examples/conformance/history/v0.3.1/provenance.json) preserves actual `v0.3.1` sources, their source commit and SHA256 digests. The regression suite checks the original conformance expectations, public values, rejected writes, initialization, resets and migration rendering. Internal IDs are excluded from comparisons.
|
|
46
|
+
|
|
47
|
+
## Breaking changes and migration
|
|
48
|
+
|
|
49
|
+
`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`.
|
|
50
|
+
|
|
51
|
+
`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.
|
|
52
|
+
|
|
53
|
+
`0.4.0` establishes `local-draft-2`. Unversioned source that uses supported `local-draft-1` forms remains valid; an explicit `local-draft-1` declaration is rejected until migrated. The build now recognizes 15 additional tag names: the ten `local-draft-2` components plus `computed`, `const`, `validation`, `data-table` and `column`. Text that previously displayed as an unknown or literal tag now parses as a component or declaration; move literal examples into code spans or fences. The leading `<theme>` declaration is document metadata and is not counted as a component. See [0.4.0 release and migration](release-0.4.0-en.md) for the complete rename and upgrade checklist.
|
|
54
|
+
|
|
55
|
+
Author-visible syntax changes establish a new syntax revision, such as `local-draft-2`, and raise the minor version and update `LOCAL_SYNTAX_VERSION`. Changes to the core or React API are also recorded in the changelog. The project does not rewrite document bodies automatically. `reactive-md migrate` moves one source's metadata declaration and blocks body-level conflicts; after upgrading, authors or hosts complete any remaining source changes according to the record.
|
|
56
|
+
|
|
57
|
+
Legacy configuration syntax is not part of `local-draft-2`. Common replacements:
|
|
58
|
+
|
|
59
|
+
| Old form | What to do in `local-draft-2` |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| Directives such as `:::card`, `:::row` | Tags such as `<card>`, `<grid>` |
|
|
62
|
+
| YAML `state:` declaring parameters | `bind` and `initial` on controls |
|
|
63
|
+
| YAML `computed:` | `{{ expression }}` in the prose |
|
|
64
|
+
| `actions:`, button actions, `on-*` events | No equivalent entry point; use component built-in interactions and panel reset |
|
|
65
|
+
| `data:` or external API data | Markdown tables written directly in the prose; parameters are declared by controls |
|
|
66
|
+
| Persisted runtime state | The host saves the original source. Public parameters may additionally be exported as a validated `reactive-md-state/v1` file; it is tied to the source digest, syntax revision and exact public parameter set and is not a document format. |
|
|
67
|
+
|
|
68
|
+
## What to persist
|
|
69
|
+
|
|
70
|
+
Persist the original `.reactive.md` source. A `reactive-md-state/v1` file may preserve public parameter values for the same source and syntax revision; it is rejected when the digest, revision or parameter set differs. Migration changes the source digest, so export a fresh state file after migrating; migration never rewrites state files. Do not persist `LocalDocument`, `LocalNode`, `node.id`, `initialState`, `LocalSnapshot` or internal `@` runtime keys: they belong to the current runtime object and their structure and field meanings are not guaranteed across versions. `node.id` is regenerated when the source changes. Diagnostic line numbers, columns and offsets locate the current source and are not stable persistence identifiers.
|
|
71
|
+
|
|
72
|
+
## Diagnostics contract
|
|
73
|
+
|
|
74
|
+
`Diagnostic` contains `code`, `message`, `severity`, `range`, `line` and `column`.
|
|
75
|
+
|
|
76
|
+
- Lines and columns are one-based. Columns and half-open ranges count UTF-16 code units in the original source.
|
|
77
|
+
- `line`, `column` and `range` can be used for programmatic location and editor jumps.
|
|
78
|
+
- `code` is a string identifier, such as `local.type`, `expression-type` or `latex-plot-range`. Existing codes keep their meaning within one 0.x minor series. New codes may be added; removal, renaming or a change of meaning requires a new minor version and migration notes.
|
|
79
|
+
- `message` contains default English display text. Use `formatLocalDiagnostic(diagnostic, 'zh')` for Chinese. Wording may improve; do not parse messages or make business decisions based on their complete text. Language changes preserve machine fields.
|
|
80
|
+
- `severity` is `warning` or `error`. Structurally complete unknown tags and footnotes keep their source and produce fallback warnings, and compilation can still succeed; compile errors make `result.ok` `false` and disable the preview. Runtime local errors affect only the corresponding content.
|
|
81
|
+
|
|
82
|
+
See [Diagnostics and counting rules](diagnostics-counting-en.md) for units and resource-budget scopes.
|
|
83
|
+
|
|
84
|
+
## Platforms and runtimes
|
|
85
|
+
|
|
86
|
+
| Environment | Current status |
|
|
87
|
+
| --- | --- |
|
|
88
|
+
| Node.js 22.12+ | Minimum for development and Node-side consumption; CI targets both 22.12 and 24 |
|
|
89
|
+
| ESM | The only module format; no CommonJS entry |
|
|
90
|
+
| React 19 | Required by `reactive-md/react`; the core entry does not depend on React |
|
|
91
|
+
| Microsoft Edge (Chromium-based) | Local browser verification has used Edge |
|
|
92
|
+
| Playwright Chromium | Linux CI browser target |
|
|
93
|
+
| Firefox, Safari/WebKit | Unverified; no support claim |
|
|
94
|
+
| Shareable state format | `reactive-md-state/v1`: public parameter values with a syntax version and source digest; see [Shareable documents](shareable-export-en.md) |
|
|
95
|
+
| Single-file HTML format | `reactive-md-html/v1`: interactive or static export, with an inline standalone runtime only in interactive mode |
|
|
96
|
+
| SSR | `react-dom/server` static rendering is covered by the packed check. Static-first hydration of the single-file export is covered in Playwright Chromium/Edge; general SSR hydration is unverified and should be checked before use |
|
|
97
|
+
|
|
98
|
+
Node-side consumption means importing `reactive-md` in Node and calling `compileLocal` and `createLocalRuntime` without a DOM. React rendering requires a browser environment, or the host must handle server output itself.
|
|
99
|
+
|
|
100
|
+
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.
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
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.4.0` is the preview release on `next`; `0.3.1` remains `latest`.
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# 组块开发指南
|
|
2
|
+
|
|
3
|
+
本指南面向为 Reactive MD 新增或修改组件的贡献者。组块包括输入控件、容器、可视化和结构子项。共同契约见[组块协议](component-protocol-ch.md),作者写法见[本地交互语法规范](local-interaction-syntax-ch.md)。
|
|
4
|
+
|
|
5
|
+
当前协议为 `component-protocol-1`,适用语法为 `local-draft-2`,当前包版本为 `0.4.0`,即发布在 `next` 渠道的预览版。这三个版本分别表示贡献契约、作者语法和 npm 发布。协议文档更新不自动改变语法或公开 API。
|
|
6
|
+
|
|
7
|
+
## 1. 提交什么
|
|
8
|
+
|
|
9
|
+
一次完整的组块贡献包括声明、实现、示例和验收证据。先用第 5 节的模板说明行为,再按受影响的实现面修改代码。评审需要能回答:作者可以怎样写,读者怎样操作,错误时怎样表现,以及旧文档升级后会发生什么。
|
|
10
|
+
|
|
11
|
+
当前项目通过仓库内代码扩展组块。没有公开的运行时注册器、可装载组件 JSON 或作者导入语法;`LocalComponentSchema`、`LOCAL_COMPONENTS` 和渲染器内部上下文也不是稳定的插件 SDK。验收 JSON 是源码与预期结果,不是组件安装包。
|
|
12
|
+
|
|
13
|
+
组块继续遵守本地简单交互范围。输入通过 `bind` 命名,输出通过表达式读取。网络服务、作者脚本、任意 HTML、事件处理器、作者 CSS 和持久化状态不属于当前作者语言。图片与链接使用宿主控制的 URL 策略,详见[安全策略](../SECURITY-ch.md)。
|
|
14
|
+
|
|
15
|
+
## 2. 从提案到验收
|
|
16
|
+
|
|
17
|
+
1. 提交第 5 节的声明模板,写清用途、语法、状态、错误、预算和版本影响。与现有组块重叠时,说明现有组件或 Markdown 组合还缺少什么。
|
|
18
|
+
2. 标出适用的 `CP-*` 条款。没有绑定、计时或计算的组块可把相应项标为“不适用”,同时说明理由。
|
|
19
|
+
3. 检查下表中的实现位置。复用已有通用逻辑时,说明为何无需新增分支;需要新分支时,同步检查编译器和运行时的消费者。
|
|
20
|
+
4. 添加最小正常示例、非法输入和边界用例。涉及状态时检查初始化、拒绝写入、共享、隐藏和重置;涉及计算时检查预算。
|
|
21
|
+
5. 按第 6 节执行受影响的检查。保留命令、结果和浏览器观察记录,明确待补项。
|
|
22
|
+
6. 更新语法、兼容说明、变更记录和相关示例。PR 中附声明与证据,由维护者核对版本和迁移影响。
|
|
23
|
+
|
|
24
|
+
| 实现面 | 位置 | 检查内容 |
|
|
25
|
+
| --- | --- | --- |
|
|
26
|
+
| 标签解析 | `src/local/parser.ts` | `VOID`、`PAIRED`、`INLINE` 及由其生成的 `KNOWN`;形态、嵌套、代码隔离和未知区域降级 |
|
|
27
|
+
| 组块声明 | `src/local/schema.ts` | 名称、`form`、`childRule`、父级、属性类型与默认值、`binding`、`initialRule` |
|
|
28
|
+
| 编译 | `src/local/compiler.ts` | 属性与子内容、表达式类型、绑定 family、共享约束、初值和预算 |
|
|
29
|
+
| 状态运行时 | `src/local/runtime.ts` | 规范控件查找、写入类型与约束、原子提交、数组副本、重置和销毁 |
|
|
30
|
+
| 控件与布局 | `src/local/LocalDocumentView.tsx` | `COMPONENTS`、输入草稿、可访问名称、键盘、可见性、重置 token 和 effect 清理 |
|
|
31
|
+
| 可视化 | `src/local/visuals.tsx`、`src/local/math.ts` | `VISUAL_COMPONENTS`、绘图或表格语义、局部错误、计算预算、读数和重置 |
|
|
32
|
+
| 样式 | `src/local/local.css`、`src/local/visuals.css`、`src/theme.css` | 主题变量、类名前缀、焦点、窄屏和文档外样式影响 |
|
|
33
|
+
| 预算与类型 | `src/local/limits.ts`、`src/local/types.ts`、`src/local/render-types.ts` | 新增资源的边界;核心类型不依赖 React;内部节点不成为持久化格式 |
|
|
34
|
+
| 证据与文档 | `tests/`、[验收数据](../examples/conformance/README.md)、[语法规范](local-interaction-syntax-ch.md) | 具体行为用例、可复制示例、迁移和检查记录 |
|
|
35
|
+
|
|
36
|
+
新增声明不会自动同步解析器、运行时和渲染器。反过来,已有通用校验足够时,也无需为了凑齐文件清单而添加分支。
|
|
37
|
+
|
|
38
|
+
## 3. 怎样判断兼容性
|
|
39
|
+
|
|
40
|
+
按[兼容说明](compatibility-ch.md)和协议 CP-COMPAT 条款判断。项目当前要求作者可见的语法变化建立新语法修订,并提升包次版本;“旧的合法写法仍可用”不等于可以在原语法修订内增加新标签。
|
|
41
|
+
|
|
42
|
+
| 变化 | 处理 |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| 新标签、新的作者可见属性 | 记录为能力新增,建立新语法修订,更新 `LOCAL_SYNTAX_VERSION`、包次版本、语法和验收数据 |
|
|
45
|
+
| 改名、删除、改变默认值、绑定类型、子项或初值规则 | 记录破坏性变化,提供旧写法、新写法、影响范围和迁移检查 |
|
|
46
|
+
| 实现修复、优化或样式调整,保持既有语义、可访问性和资源边界 | 按实际影响补回归证据;公开 API 或作者语义变化另行分类 |
|
|
47
|
+
| 诊断码变化 | 更新对应验收数据和变更记录;遵守 0.x 的诊断码兼容约定,不依赖 message 文本 |
|
|
48
|
+
| 改变本协议的 MUST 条款、必填声明或机器格式语义 | 提升协议修订;是否改变语法或 API 单独判断 |
|
|
49
|
+
|
|
50
|
+
新标签还有一项迁移影响:旧实现会把完整的未知区域按惰性原文显示,新实现识别该名称后可能开始执行内部内容。必须在提案中记录这一点,并给出前后用例。名称是否加入核心组件集由维护者评审;不得覆盖现有名称的含义或偷偷添加别名。
|
|
51
|
+
|
|
52
|
+
协议格式保持 component-protocol-1;此次能力新增将语法提升到 local-draft-2,包版本提升到 0.4.0。
|
|
53
|
+
|
|
54
|
+
## 4. 用现有组块填写声明
|
|
55
|
+
|
|
56
|
+
下面三种现有组块分别展示控件、容器和计算型可视化的契约。它们是可执行示例,不是新 API 的设计稿。
|
|
57
|
+
|
|
58
|
+
### slider:一个数值控件
|
|
59
|
+
|
|
60
|
+
```markdown
|
|
61
|
+
<slider bind="seats" label="人数" initial="2" min="1" max="20">
|
|
62
|
+
|
|
63
|
+
当前费用:{{ seats * 100 }} 元。
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
声明重点:无正文,数值 family,可共享绑定;`min/max/step` 是静态约束,缺省为 `0/100/1`;省略 `initial` 时取 `min`。同名数值控件必须有一致约束,且最多出现一次显式初值。
|
|
67
|
+
|
|
68
|
+
验收应证明初值为 2、合法写入改变费用、越界和不在步长上的写入被拒、拒绝时完整快照与 revision 不变、共享控件读取同一值。无 `bind` 时应检查独立的内部状态。面板重置恢复编译初值;真实拖动和键盘步进需要浏览器证据。对应协议 CP-STATE-03、04、06、08、10。
|
|
69
|
+
|
|
70
|
+
### tabs:有状态的容器
|
|
71
|
+
|
|
72
|
+
```markdown
|
|
73
|
+
<panel title="方案">
|
|
74
|
+
<tabs bind="page" label="方案页" initial="basic">
|
|
75
|
+
<tab label="基本" value="basic">
|
|
76
|
+
<slider bind="a" label="基本数量" initial="2" min="0" max="10">
|
|
77
|
+
</tab>
|
|
78
|
+
<tab label="高级" value="advanced">
|
|
79
|
+
<slider bind="b" label="高级数量" initial="7" min="0" max="10">
|
|
80
|
+
</tab>
|
|
81
|
+
</tabs>
|
|
82
|
+
</panel>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
声明重点:`tabs` 只接受 `tab` 子项,公开值为字符串,绑定独占。`tab.value` 唯一;省略时按源码顺序生成 `tab-1`、`tab-2`。未写 `initial` 时选择第一项。无 `bind` 时选择保留在组件内部。
|
|
86
|
+
|
|
87
|
+
验收应证明非活动页的 `b` 仍初始化为 7、切换保留子内容状态、未知页面值被拒、第二个组块不能声明同名绑定、面板重置恢复页面和子控件。方向键、Home/End、焦点,以及隐藏计时器暂停后需由读者再次启动,须有相应浏览器检查。对应协议 CP-STATE-11、CP-VIS 和 CP-LIFE。
|
|
88
|
+
|
|
89
|
+
### plot:受预算约束的计算
|
|
90
|
+
|
|
91
|
+
```markdown
|
|
92
|
+
<slider bind="a" label="振幅" initial="1" min="0" max="3" step="0.5">
|
|
93
|
+
<slider bind="high" label="右边界" initial="3" min="1" max="10">
|
|
94
|
+
|
|
95
|
+
<plot label="正弦波" min="-2" max="{{ high }}">
|
|
96
|
+
$$ y = a \sin x $$
|
|
97
|
+
</plot>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
声明重点:正文为一个或多个独立公式块,每块写 `y = 表达式`;`min/max` 可以动态,要求 `min < max`;`samples` 是静态整数,默认 200,范围 2 至 2000。公式参数必须是已声明的数字绑定。
|
|
101
|
+
|
|
102
|
+
验收应覆盖合法 LaTeX、参数变化、动态范围、非数字参数和非法范围。每图最多 16 条曲线,整份文档请求的采样点累计最多 20,000,计算共享 2,000,000 步预算,隐藏区域也计入。出现无效采样应断开曲线;空数据和局部错误要有明确显示。指针与键盘读数、窄屏和图例交互另做浏览器检查。对应协议 CP-STATE-12、CP-DIAG-04、CP-SEC-03。
|
|
103
|
+
|
|
104
|
+
## 5. 可复制的提案模板
|
|
105
|
+
|
|
106
|
+
把下面内容复制到 issue、PR 正文或独立设计文档中。占位符必须替换成实际决定,不适用项说明原因。属性声明是评审材料,不是运行时可装载的 Schema。
|
|
107
|
+
|
|
108
|
+
```markdown
|
|
109
|
+
# 组块提案:<名称>
|
|
110
|
+
|
|
111
|
+
## 用途和边界
|
|
112
|
+
|
|
113
|
+
- 要解决的具体文档需求:
|
|
114
|
+
- 读者触发的操作与可观察结果:
|
|
115
|
+
- 现有组件或 Markdown 组合缺少的能力:
|
|
116
|
+
- 本组块的非目标:
|
|
117
|
+
|
|
118
|
+
## 版本与名称
|
|
119
|
+
|
|
120
|
+
| 项目 | 决定 |
|
|
121
|
+
| --- | --- |
|
|
122
|
+
| 包版本 | 当前值、目标值和理由 |
|
|
123
|
+
| 语法修订 | 当前值、目标值和迁移影响 |
|
|
124
|
+
| 协议修订 | component-protocol-1,或说明新修订 |
|
|
125
|
+
| 名称 | 小写 kebab-case;冲突检查和维护者决定 |
|
|
126
|
+
| 形态 | leaf / inline / container |
|
|
127
|
+
| 父级、直接子项 | 允许范围、数量、嵌套及空白规则 |
|
|
128
|
+
|
|
129
|
+
## 语法
|
|
130
|
+
|
|
131
|
+
给出最小可运行文档,以及一个必须被拒绝的写法。
|
|
132
|
+
|
|
133
|
+
## 属性
|
|
134
|
+
|
|
135
|
+
| 属性 | 类型与单位 | 静态或动态 | 必填 | 默认值 | 约束及失败诊断 |
|
|
136
|
+
| --- | --- | --- | --- | --- | --- |
|
|
137
|
+
| 待填 | string/number/boolean/enum | 是否允许插值、如何保留类型 | 是/否 | 具体值或无 | 范围、枚举、长度、code |
|
|
138
|
+
|
|
139
|
+
## 状态
|
|
140
|
+
|
|
141
|
+
- 是否有 bind;值类型与 family;是否独占:
|
|
142
|
+
- 显式初值与缺省初值如何产生:
|
|
143
|
+
- 同名绑定允许共享的条件:
|
|
144
|
+
- 合法写入、非法写入、原子性与订阅:
|
|
145
|
+
- 输入草稿与内部 UI 状态:
|
|
146
|
+
- 面板重置的作用范围、共享值及内部状态:
|
|
147
|
+
- 隐藏、再次显示、源码变化、实例隔离:
|
|
148
|
+
- 计时器、订阅、事件监听与销毁:
|
|
149
|
+
|
|
150
|
+
## 诊断与降级
|
|
151
|
+
|
|
152
|
+
| 触发条件 | 阶段 | severity 与 code | 定位 | 预期结果 |
|
|
153
|
+
| --- | --- | --- | --- | --- |
|
|
154
|
+
| 待填 | 编译/运行/渲染 | warning/error,具体 code | 源码范围 | 拒绝、保留旧状态或局部显示 |
|
|
155
|
+
|
|
156
|
+
说明旧实现把未知标签按原文显示时的行为,以及新增识别后发生的变化。
|
|
157
|
+
|
|
158
|
+
## 安全、预算与表现
|
|
159
|
+
|
|
160
|
+
- 不可信输入如何校验;宿主可信代码的责任:
|
|
161
|
+
- 输入长度、集合规模、计算次数、递归或采样的预算:
|
|
162
|
+
- 预算由谁设置、在哪些阶段检查、超限结果:
|
|
163
|
+
- 可访问名称、角色、状态、键盘和焦点:
|
|
164
|
+
- 375px、触控目标、深色主题与样式作用域:
|
|
165
|
+
- 新增或修改的样式文件及主题变量:
|
|
166
|
+
|
|
167
|
+
## 兼容与迁移
|
|
168
|
+
|
|
169
|
+
- 变化分类和理由:
|
|
170
|
+
- 旧写法、旧结果:
|
|
171
|
+
- 新写法、新结果:
|
|
172
|
+
- 受影响的源码、宿主 API、诊断、预算或渲染行为:
|
|
173
|
+
- 迁移方法和升级后的验证方式:
|
|
174
|
+
|
|
175
|
+
## 文件与验收
|
|
176
|
+
|
|
177
|
+
| 适用 CP-* 条款 | 要改的文件 | 用例或检查 | 实际结果及证据 |
|
|
178
|
+
| --- | --- | --- | --- |
|
|
179
|
+
| 待填 | 真实路径;无需修改则说明复用原因 | 正常、非法、边界、状态或浏览器检查 | 通过/失败/未运行 |
|
|
180
|
+
|
|
181
|
+
- 可移植验收数据与组件专属测试:
|
|
182
|
+
- 实际运行的命令及结果:
|
|
183
|
+
- 浏览器、视口、具体操作与观察结果:
|
|
184
|
+
- 待补证据;SHOULD 偏离的理由和替代证据:
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
提案必须满足适用的 MUST 条款。SHOULD 的偏离记录理由、影响和替代证据。已有组件不因模板出现而自动取得“已认证”状态。
|
|
188
|
+
|
|
189
|
+
## 6. 按影响选择检查
|
|
190
|
+
|
|
191
|
+
在根目录安装现有依赖后执行检查,环境和完整命令见[贡献指南](../CONTRIBUTING-ch.md)。行为变更必须有直接覆盖该行为的测试;以下选择用于确定检查范围。
|
|
192
|
+
|
|
193
|
+
| 改动 | 最小有用检查 |
|
|
194
|
+
| --- | --- |
|
|
195
|
+
| 仅协议、指南或链接 | `npm run test:docs`;核对规则与当前语法、安全和兼容说明 |
|
|
196
|
+
| 验收数据或运行器 | `npm run test:components`、`npm run typecheck` |
|
|
197
|
+
| 解析、编译、绑定或运行时 | 对应组件的针对性测试、`npm run test:components`、`npm run build`;共享逻辑变化再跑相关回归或 `npm test` |
|
|
198
|
+
| React、样式或交互 | 对应渲染器测试、`npm run build:demo`,以及受影响的浏览器操作 |
|
|
199
|
+
| 公开入口、类型或分发文件 | 构建后执行 `npm run test:package`、`npm run test:packed` |
|
|
200
|
+
| 文档、语法、示例或版本 | `npm run test:docs`,对应示例编译及迁移核对 |
|
|
201
|
+
| 完整发布门禁 | `npm run verify:release`;覆盖 Node 端与浏览器检查、真实 tarball 消费和组合文档行为。发布前或改动横跨多行时使用 |
|
|
202
|
+
|
|
203
|
+
`npm run test:components` 执行协议的 `slider`、`tabs`、`plot` 代表性用例和原有语言验收数据。文件格式、字段含义和运行顺序见[验收说明](../examples/conformance/README.md)。新增组块继续补自己的用例;这个命令不证明全部 48 个标签名或全部浏览器行为已经认证。新增的 `tests/**/*.test.ts` 或 `.tsx` 也会由已有 `npm test` 和 CI 运行。
|
|
204
|
+
|
|
205
|
+
浏览器检查须记录具体环境和操作。按组件适用性检查真实键盘与焦点、输入法草稿、375px 布局、触控、主题、重置、隐藏与再次显示、计时暂停和卸载清理。已有自动浏览器检查可以提供对应行为的证据;读屏体验等尚未覆盖的项目需要人工检查。静态 SSR 只能证明服务器输出,不能证明真实输入、effect 生命周期或水合。
|
|
206
|
+
|
|
207
|
+
在 PR 中列出实际运行的命令和观察结果。未运行、失败、不适用分别写明,不把清单勾选当成验证证据。
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
新增组块、颜色、槽位状态与迁移规则见[local-draft-2 扩展说明](local-components-v2-ch.md)。`0.4.0` 是 `next` 渠道的预览版。
|