reactive-md 0.3.1 → 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 +82 -39
- package/CONTRIBUTING-ch.md +62 -0
- package/CONTRIBUTING.md +64 -65
- package/README-ch.md +122 -0
- package/README-en.md +146 -0
- package/README.md +146 -89
- package/SECURITY-ch.md +80 -0
- package/SECURITY.md +58 -49
- 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 +3425 -1647
- 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/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 +13 -2
- 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 +32 -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 +112 -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.md → component-development-ch.md} +210 -206
- package/docs/component-development-en.md +210 -0
- package/docs/{component-protocol.md → component-protocol-ch.md} +710 -685
- 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} +28 -8
- 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} +66 -20
- package/docs/local-interaction-syntax-en.md +483 -0
- package/docs/{performance.md → performance-ch.md} +12 -3
- 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 +33 -31
- package/examples/conformance/component-protocol-1.json +482 -194
- package/examples/conformance/component-protocol-1.schema.json +76 -76
- 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-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 +64 -58
- package/examples/local/catalog.reactive.md +14 -14
- package/examples/local/charts.reactive.md +34 -34
- 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 +16 -3
- package/README.en.md +0 -76
- package/dist-library/runtime-CPzMEMcW.js +0 -11111
- package/docs/compatibility.md +0 -68
- package/docs/local-integration.md +0 -218
- package/docs/releasing.md +0 -92
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# 新增组块与迁移:local-draft-2
|
|
2
|
+
|
|
3
|
+
本页说明 `0.4.0` 的新增组块与 `local-draft-2` 语法。它是[本地交互语法规范](local-interaction-syntax-ch.md)的补充。贡献与验收继续使用 `component-protocol-1`,机器格式保持不变。
|
|
4
|
+
|
|
5
|
+
## 跳转与正文颜色
|
|
6
|
+
|
|
7
|
+
```markdown
|
|
8
|
+
<jump to="result" appearance="button" color="#2563eb">查看结果</jump>
|
|
9
|
+
|
|
10
|
+
<section color="#45536f">
|
|
11
|
+
普通正文,<text color="#a2273a">**重点提醒**</text>。
|
|
12
|
+
|
|
13
|
+
第二段继承外层颜色,支持 {{ count }} 等插值。
|
|
14
|
+
</section>
|
|
15
|
+
|
|
16
|
+
<anchor id="result">
|
|
17
|
+
|
|
18
|
+
## 结果
|
|
19
|
+
|
|
20
|
+
结果显示在这里。
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
本例中的 `count` 需由一个控件声明,例如 `<counter bind="count" label="数量">`。
|
|
24
|
+
|
|
25
|
+
| 组块 | 形态 | 属性与规则 |
|
|
26
|
+
| --- | --- | --- |
|
|
27
|
+
| jump | 行内、成对标签 | `to` 必填,为静态文档内目标名;`appearance=link/button`,默认 link;可选 color;正文为行内 Markdown |
|
|
28
|
+
| anchor | 无正文标签 | `id` 必填,匹配 `[A-Za-z_][A-Za-z0-9_-]*`,当前文档内唯一 |
|
|
29
|
+
| text | 行内、成对标签 | color 必填,正文为行内 Markdown 与插值 |
|
|
30
|
+
| section | 块容器、成对标签 | color 必填,内部继续解析 Markdown;不添加边框和背景 |
|
|
31
|
+
|
|
32
|
+
jump 可以指向自动生成的标题锚点或显式 anchor,不写前导 `#`。普通 Markdown 链接仍使用 `[结果](#result)`。实际 DOM ID 按文档实例隔离;显式 ID 与标题锚点冲突、跳转目标不存在时编译失败。点击后滚动并移动焦点,隐藏目标显示局部提示,保留读者已填写的参数。
|
|
33
|
+
|
|
34
|
+
color 是静态颜色名或 `#RGB`、`#RRGGBB`。它不接受表达式、CSS 函数、变量或声明。颜色名由共享校验表限定;无效值给出编译诊断。text/section 的 color 控制文字,内层显式颜色覆盖继承;链接和交互控件保留自身配色。jump/badge 使用文字或强调色;progress 使用填充色;slider、toggle、checkbox、select、choices、radio-group、checklist 以及新输入组块使用激活色。省略时沿用主题。tone 的语义保持不变。
|
|
35
|
+
|
|
36
|
+
## 待办与多选
|
|
37
|
+
|
|
38
|
+
checklist 继续接受原有 Markdown 任务列表。勾选后仅该项正文加删除线并变淡,取消勾选后恢复;初始 `[x]` 也呈现完成样式。绑定、隐藏与面板重置保持原有规则。
|
|
39
|
+
|
|
40
|
+
```markdown
|
|
41
|
+
<multi-select bind="subjects" label="主题" max-selected="2" initial="math">
|
|
42
|
+
<option value="math">数学</option>
|
|
43
|
+
<option value="physics">物理</option>
|
|
44
|
+
<option value="chemistry">化学</option>
|
|
45
|
+
</multi-select>
|
|
46
|
+
|
|
47
|
+
已选择 {{ len(subjects) }} 项。
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
multi-select 是有正文容器,只接受 option 子项,label 必填;bind 可省略。公开值为按源码顺序排列的字符串数组,默认空数组;initial 为逗号分隔的静态 value。value 非空、唯一,且不含逗号。max-selected 为非负整数,默认选项数。组件内置搜索、清空,达到上限仍可取消已选项;disabled 可以使用布尔表达式。该绑定为独占 family,保留已有数组大小和字符串预算。
|
|
51
|
+
|
|
52
|
+
## 区间与二维坐标
|
|
53
|
+
|
|
54
|
+
```markdown
|
|
55
|
+
<range-slider label="观察区间" bind-start="low" bind-end="high"
|
|
56
|
+
initial-start="20" initial-end="80" min="0" max="100" step="1">
|
|
57
|
+
|
|
58
|
+
区间宽度:{{ high - low }}。
|
|
59
|
+
|
|
60
|
+
<coordinate label="坐标点" bind-x="px" bind-y="py"
|
|
61
|
+
initial-x="1" initial-y="2"
|
|
62
|
+
x-min="-5" x-max="5" y-min="-5" y-max="5" step="1">
|
|
63
|
+
|
|
64
|
+
坐标:({{ px }}, {{ py }})。
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
这两个组块均为无正文标签,label 必填,支持 color 与动态 disabled。范围和步长都是静态有限数,step 必须为正。
|
|
68
|
+
|
|
69
|
+
- range-slider 默认 min=0、max=100、step=1;起点默认 min,终点默认不超过 max 的最大合法步长值。始终满足起点不大于终点,交叉写入被拒绝,不交换端点。
|
|
70
|
+
- coordinate 默认两个轴范围均为 -5 到 5,step=1;各轴初值取最接近零的合法值。支持拖动、键盘和数值输入,指针输入吸附到合法步长。
|
|
71
|
+
- 每个绑定名独立可选,省略时仍有内部状态;首版各槽位独占拥有绑定,不能与其他控件共享。`x`、`y` 仍是保留名,示例使用 px、py。
|
|
72
|
+
- 所有槽位在编译时初始化;多值写入和重置均为原子更新,拒绝写入时状态与 revision 保持不变。
|
|
73
|
+
|
|
74
|
+
宿主 API 扩展:`runtime.get(node, slot?)`、`runtime.set(node, value, slot?)` 保留原调用方式,新增 `runtime.setMany(node, values)`。range-slider 的 slot 为 start/end,coordinate 为 x/y;setMany 使用 slot 名作为对象键。运行时根据已登记的节点和槽位校验,调用方提供的伪造属性不改变权限或约束。
|
|
75
|
+
|
|
76
|
+
## 练习与分步阅读
|
|
77
|
+
|
|
78
|
+
```markdown
|
|
79
|
+
<quiz type="choice" label="2 + 3 等于多少?" answer="b" explanation="相加得到 5。">
|
|
80
|
+
<option value="a">4</option>
|
|
81
|
+
<option value="b">5</option>
|
|
82
|
+
</quiz>
|
|
83
|
+
|
|
84
|
+
<quiz type="number" label="圆周率近似值" answer="3.14" tolerance="0.01">
|
|
85
|
+
</quiz>
|
|
86
|
+
|
|
87
|
+
<steps label="学习路线" bind="lesson">
|
|
88
|
+
<step label="观察" value="observe">
|
|
89
|
+
调整参数,观察结果。
|
|
90
|
+
</step>
|
|
91
|
+
<step label="练习" value="practice">
|
|
92
|
+
检查一道练习题。
|
|
93
|
+
</step>
|
|
94
|
+
</steps>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
quiz 的 type 默认 choice,label/answer 必填;choice 接受 option,answer 必须是现有 value。number 的正文为空,answer 为有限数,tolerance 默认为 0 且非负。explanation 可选,可含文本插值。组件内置检查答案、反馈与重试,首版不公开 bind;答案随源码提供,适合自学练习。隐藏后保留草稿与反馈,面板重置清除它们。
|
|
98
|
+
|
|
99
|
+
steps 只接受一个或多个 step。steps.label 可选,bind 可选且独占;initial 默认第一步 value。step.label 必填,value 可省略,按顺序生成 step-1、step-2 等,同组唯一。组件提供上一步、下一步和当前位置;仅当前内容显示,所有子控件仍参与编译和初始化。切换保留内容状态,隐藏计时器暂停;面板重置恢复初始步骤和子内容。
|
|
100
|
+
|
|
101
|
+
## 表格与图表选择
|
|
102
|
+
|
|
103
|
+
```markdown
|
|
104
|
+
<table bind="project" key="项目" initial="内容">
|
|
105
|
+
| 项目 | 费用 |
|
|
106
|
+
| --- | ---: |
|
|
107
|
+
| 内容 | 120 |
|
|
108
|
+
| 视觉 | 230 |
|
|
109
|
+
</table>
|
|
110
|
+
|
|
111
|
+
<chart bind="project" key="项目">
|
|
112
|
+
| 项目 | 费用 |
|
|
113
|
+
| --- | ---: |
|
|
114
|
+
| 内容 | 120 |
|
|
115
|
+
| 视觉 | 230 |
|
|
116
|
+
</chart>
|
|
117
|
+
|
|
118
|
+
当前项目:{{ project }}。
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
key 指定静态标识列,值必须非空、唯一且没有插值。提供 key 才启用选择状态,bind/initial 要求同时提供 key。默认空字符串表示未选;显式 initial 必须是现有标识。表格和图表可以共享 selection family,前提是标识集合与顺序一致,且最多一处显式 initial。
|
|
122
|
+
|
|
123
|
+
点击或键盘选择写入稳定标识,排序、搜索、分页和隐藏图例都保留选择。表格搜索仍只影响该表。省略 key 的旧文档保持原行为,不增加隐含绑定。
|
|
124
|
+
|
|
125
|
+
## 兼容、迁移与验收
|
|
126
|
+
|
|
127
|
+
local-draft-1 中已支持的写法继续有效。本扩展引入 10 个新组块名:jump、anchor、text、section、multi-select、range-slider、coordinate、quiz、steps、step。同一版本还增加声明标签 computed、const、validation 和结构标签 data-table、column,`local-draft-2` 的完整集合为 48 个标签名;开头的 `<theme>` 声明是元数据,不计入组块。新名称以前会作为未知源码惰性显示,现在开始解释其中的受支持内容;若原文用于演示标签,放进代码围栏或行内代码。checklist 的完成样式是可见变化。
|
|
128
|
+
|
|
129
|
+
机器验收沿用 component-protocol-1 的格式,syntaxVersion 更新为 local-draft-2;旧 local-draft-1.json 留作历史数据,新构建运行 local-draft-2.json。新组件另有核心、渲染和可视化用例。错误仍使用带源码位置的 Diagnostic,未知标签、脚注、安全与资源预算保持已有契约。同一版本还新增表达式函数保留名;完整重命名清单见[0.4.0 发布与迁移](release-0.4.0-ch.md)。
|
|
130
|
+
|
|
131
|
+
| 协议条款 | 实现与证据入口 |
|
|
132
|
+
| --- | --- |
|
|
133
|
+
| CP-SYNTAX、CP-DIAG、CP-SEC | parser/schema/compiler/colors;local-v2-core 与 local-v2-acceptance 测试 |
|
|
134
|
+
| CP-STATE、CP-LIFE、CP-VIS | runtime 的规范槽位、数组校验、原子写入与重置;核心测试、浏览器检查 |
|
|
135
|
+
| CP-A11Y、CP-STYLE | LocalDocumentView、visuals 及相应样式;SSR 与浏览器检查 |
|
|
136
|
+
| CP-CORE、CP-COMPAT、CP-ACCEPT | 独立 core/React 构建、机器验收、打包和本页迁移说明 |
|
|
137
|
+
|
|
138
|
+
双语可运行示例分布在[六个场景](../examples/local/showcase/README.md):函数场景包含区间、坐标与数值题;表单场景包含多选;统计场景包含表格与图表选择联动;布局场景包含跳转与正文颜色;流程场景包含分步阅读与选择题;清单场景包含待办与计时。自动检查命令为 `npm test`、`npm run test:components`、`npm run build:demo`、`npm run test:docs`;浏览器检查和完整发布门禁使用 `npm run verify:release`,见[贡献指南](../CONTRIBUTING-ch.md)。实际结果以该门禁的执行记录为准,不要沿用旧脚本名。
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# New components and migration: local-draft-2
|
|
2
|
+
|
|
3
|
+
This page describes the new components in `0.4.0` and the `local-draft-2` syntax. It supplements the [syntax reference](local-interaction-syntax-en.md). The contribution protocol remains component-protocol-1; its portable fixture format is unchanged.
|
|
4
|
+
|
|
5
|
+
## Navigation and text color
|
|
6
|
+
|
|
7
|
+
```markdown
|
|
8
|
+
<jump to="result" appearance="button" color="#2563eb">View results</jump>
|
|
9
|
+
|
|
10
|
+
<section color="#45536f">
|
|
11
|
+
Ordinary prose with <text color="#a2273a">**an important reminder**</text>.
|
|
12
|
+
|
|
13
|
+
Another paragraph inherits the section color.
|
|
14
|
+
</section>
|
|
15
|
+
|
|
16
|
+
<anchor id="result">
|
|
17
|
+
|
|
18
|
+
## Results
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
jump and text are paired inline components with inline Markdown children. section is a paired block container with no extra border or background. anchor is a leaf. jump.to is a static heading slug or explicit anchor ID without a leading #. appearance is link (default) or button. Explicit IDs match `[A-Za-z_][A-Za-z0-9_-]*`; duplicates, heading collisions and missing targets are compile errors. DOM IDs are namespaced per rendered document. Jumps scroll and move focus; hidden targets show local feedback. Existing Markdown fragment links also resolve explicit anchors.
|
|
22
|
+
|
|
23
|
+
text/section require color. Other supported components accept an optional color: jump, badge, progress, slider, toggle, checkbox, select, choices, radio-group, checklist, multi-select, range-slider and coordinate. Static named colors from the shared table and #RGB/#RRGGBB are accepted. Expressions, CSS functions, variables and declarations are rejected. Text containers set foreground color; inner values override inheritance. Links and controls keep their own appearance. Other components use color for their accent, selected state or progress fill; tone keeps its semantic meaning. Omitted values use the theme.
|
|
24
|
+
|
|
25
|
+
## Todo lists and multiple selection
|
|
26
|
+
|
|
27
|
+
Existing checklist syntax is unchanged. Checked item text is struck through and muted, including initial `[x]` items; unchecking restores it. Only the checked item changes.
|
|
28
|
+
|
|
29
|
+
```markdown
|
|
30
|
+
<multi-select bind="subjects" label="Subjects" max-selected="2" initial="math">
|
|
31
|
+
<option value="math">Math</option>
|
|
32
|
+
<option value="physics">Physics</option>
|
|
33
|
+
</multi-select>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
multi-select requires a label and one or more option children; bind is optional. Its exclusive string-array binding defaults to empty. initial is a comma-separated list of static values; values must be nonempty, unique and comma-free. max-selected is a nonnegative integer, defaulting to the option count. Writes normalize to source order and obey existing array budgets. Search and Clear are built in. Selected items remain removable at the limit. disabled may be dynamic; reset clears local search and restores initial selection, while hiding preserves them.
|
|
37
|
+
|
|
38
|
+
## Range and coordinate inputs
|
|
39
|
+
|
|
40
|
+
```markdown
|
|
41
|
+
<range-slider label="Interval" bind-start="low" bind-end="high"
|
|
42
|
+
initial-start="20" initial-end="80" min="0" max="100" step="1">
|
|
43
|
+
|
|
44
|
+
<coordinate label="Point" bind-x="px" bind-y="py"
|
|
45
|
+
initial-x="1" initial-y="2"
|
|
46
|
+
x-min="-5" x-max="5" y-min="-5" y-max="5" step="1">
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Both are leaves with required label, optional color and dynamic disabled. Bounds and positive step are static finite numbers. range-slider defaults to 0/100/1, with start=min and end=the largest valid step not exceeding max. Crossing is rejected rather than swapping endpoints. coordinate defaults to -5…5 on both axes, step 1, and the nearest legal zero per axis. It supports pointer dragging, keyboard control and numeric alternatives.
|
|
50
|
+
|
|
51
|
+
Each optional bind names one exclusive numeric slot; omitted names use internal state. x/y remain reserved parameter names. Slots initialize at compile time and reset atomically. Host APIs extend to `runtime.get(node, slot?)`, `runtime.set(node, value, slot?)` and `runtime.setMany(node, values)`. Slots are start/end for ranges and x/y for coordinates. Every write validates canonical registered slots; invalid batches preserve the entire snapshot and revision. Existing one-value calls remain valid.
|
|
52
|
+
|
|
53
|
+
## Questions and guided reading
|
|
54
|
+
|
|
55
|
+
```markdown
|
|
56
|
+
<quiz type="choice" label="What is 2 + 3?" answer="b" explanation="The sum is 5.">
|
|
57
|
+
<option value="a">4</option>
|
|
58
|
+
<option value="b">5</option>
|
|
59
|
+
</quiz>
|
|
60
|
+
|
|
61
|
+
<quiz type="number" label="Approximate pi" answer="3.14" tolerance="0.01">
|
|
62
|
+
</quiz>
|
|
63
|
+
|
|
64
|
+
<steps label="Learning path" bind="lesson">
|
|
65
|
+
<step label="Observe" value="observe">
|
|
66
|
+
Change a parameter.
|
|
67
|
+
</step>
|
|
68
|
+
<step label="Practice" value="practice">
|
|
69
|
+
Check an answer.
|
|
70
|
+
</step>
|
|
71
|
+
</steps>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
quiz requires label/answer. type defaults to choice, with option children and a matching answer. Numeric quizzes have an empty body, finite answer and nonnegative absolute tolerance (default 0). explanation is optional and supports text interpolation. Check answer, feedback and Try again are built in. Draft and feedback stay internal; this revision has no quiz bind. Hiding preserves them and panel reset clears them. Answers are supplied in source for self-study.
|
|
75
|
+
|
|
76
|
+
steps accepts one or more step children, optional label and exclusive string bind. initial defaults to the first step. Each step requires label; omitted values become step-1, step-2 and so on. Values are unique within a group. Previous/Next and position are built in. Only active content is visible; all bindings still initialize, state persists between steps, and hidden timers pause. Reset restores the initial step and its subtree.
|
|
77
|
+
|
|
78
|
+
## Table and chart selection
|
|
79
|
+
|
|
80
|
+
```markdown
|
|
81
|
+
<table bind="project" key="Project" initial="Content">
|
|
82
|
+
| Project | Cost |
|
|
83
|
+
| --- | ---: |
|
|
84
|
+
| Content | 120 |
|
|
85
|
+
| Visual | 230 |
|
|
86
|
+
</table>
|
|
87
|
+
|
|
88
|
+
<chart bind="project" key="Project">
|
|
89
|
+
| Project | Cost |
|
|
90
|
+
| --- | ---: |
|
|
91
|
+
| Content | 120 |
|
|
92
|
+
| Visual | 230 |
|
|
93
|
+
</chart>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
key names a column of static, nonempty, unique text identifiers. Selection is enabled only when key is present; bind/initial require key. Empty string means no selection by default. Explicit initial must match a row. Table/chart can share a selection binding only with identical ordered keys and at most one explicit initial. Mouse or keyboard selection writes row identity. Sorting, searching, pagination and hidden legends preserve selection; table filters still affect only that table. Existing components without key gain no implicit binding.
|
|
97
|
+
|
|
98
|
+
## Compatibility and acceptance
|
|
99
|
+
|
|
100
|
+
Previously supported local-draft-1 source remains valid. Ten new names arrive with this extension: jump, anchor, text, section, multi-select, range-slider, coordinate, quiz, steps and step. The same release also adds the declaration tags computed, const and validation and the structural tags data-table and column, for 48 tag names in the complete `local-draft-2` set; the leading `<theme>` declaration is metadata, not a component. Old builds displayed these unknown regions as inert source; this build interprets their supported content. Put literal examples inside code spans or fences. Checklist completion appearance changes visibly.
|
|
101
|
+
|
|
102
|
+
Portable fixture syntaxVersion advances to local-draft-2; component-protocol-1 and its data format stay unchanged. local-draft-1.json is retained as historical data. New tests cover compiler/runtime, SSR rendering and visual selection. Canonical state, atomic rejection/reset, instance isolation, hidden-state retention, positioned diagnostics, existing resource budgets and the core/React boundary follow the component protocol. The same release also reserves new expression function names; see [0.4.0 release and migration](release-0.4.0-en.md) for the full rename list.
|
|
103
|
+
|
|
104
|
+
Run `npm test`, `npm run test:components`, `npm run build:demo` and `npm run test:docs`. Browser checks and the complete release gate use `npm run verify:release`; see the [contributing guide](../CONTRIBUTING.md). Record actual run results with the gate rather than copying an old script name. The bilingual [six scenarios](../examples/local/showcase/README.md) cover all components: ranges, coordinates and numeric questions in Functions; multiple selection in Forms; linked selection in Data; jumps and prose colors in Layout; steps and choice questions in Flow; todos and timing in Checklists.
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
这份指南面向会写 Markdown、见过一点 HTML、但没有接触过 Reactive MD 的读者。读完之后,你应该能独立写出带输入控件、实时计算、条件内容、图表和图解的本地交互文档。
|
|
4
4
|
|
|
5
|
-
本文讲的是 `local-draft-
|
|
5
|
+
本文讲的是 `local-draft-2` 本地交互语法。完整规则见 [本地交互语法规范](local-interaction-syntax-ch.md),可以直接运行的完整文档见 [示例目录](../examples/local/README.md)。更完整的组件和表达式细节以规范为准。包版本、语法修订和迁移规则见 [版本与兼容性](compatibility-ch.md)。
|
|
6
6
|
|
|
7
7
|
## 目录
|
|
8
8
|
|
|
9
|
+
需要复用中间结果或格式化输出时,可读[复用计算与格式化数值](computations-formatting-ch.md),其中附有完整账单示例。
|
|
10
|
+
|
|
9
11
|
- [1. 先建立直觉](#1-先建立直觉)
|
|
10
12
|
- [2. 五分钟:第一份交互文档](#2-五分钟第一份交互文档)
|
|
11
13
|
- [3. 标签怎么写](#3-标签怎么写)
|
|
@@ -132,7 +134,7 @@ npm run dev
|
|
|
132
134
|
|
|
133
135
|
无正文组件固定为:
|
|
134
136
|
|
|
135
|
-
`input`、`textarea`、`number`、`slider`、`toggle`、`checkbox`、`date`、`counter`、`timer`、`progress`、`edge
|
|
137
|
+
`input`、`textarea`、`number`、`slider`、`range-slider`、`coordinate`、`toggle`、`checkbox`、`date`、`counter`、`timer`、`progress`、`anchor`、`edge`。声明标签 `computed`、`const`、`validation` 以及结构子项 `column` 也没有正文。
|
|
136
138
|
|
|
137
139
|
其余组件使用成对标签。特别提醒:`textarea` 的文本通过 `initial` 设置,所以它没有正文;不要写成 `<textarea>内容</textarea>`。
|
|
138
140
|
|
|
@@ -259,7 +261,12 @@ HTML 注释 `<!-- ... -->` 会被忽略,不产生组件或变量。原始 HTML
|
|
|
259
261
|
| `counter` | 数字 | 范围内最接近 0 的合法步长值 |
|
|
260
262
|
| `toggle`、`checkbox` | 布尔值 | `false` |
|
|
261
263
|
| `select`、`choices`、`radio-group` | 选项字符串 | 第一个选项的 value |
|
|
264
|
+
| `multi-select` | 已选选项 value 的字符串数组 | 空数组 |
|
|
265
|
+
| `range-slider` | 两个数字,`start` / `end` | start=min;end=范围内不超过 max 的最大合法步长值 |
|
|
266
|
+
| `coordinate` | 两个数字,`x` / `y` | 各轴最接近 0 的合法步长值 |
|
|
267
|
+
| 带 `key` 的 `table`、`chart` | 稳定行标识字符串 | 空字符串(未选) |
|
|
262
268
|
| `tabs` | 页面字符串 | 第一个 tab 的 value |
|
|
269
|
+
| `steps` | 步骤字符串 | 第一步的 value |
|
|
263
270
|
| `diagram` | 节点 ID 字符串 | 第一个节点的 id |
|
|
264
271
|
| `checklist` | 已勾选条目 ID 的字符串数组 | 由任务列表的勾选标记决定 |
|
|
265
272
|
| `timer` | 剩余秒数 | `duration`,默认 60 |
|
|
@@ -289,7 +296,7 @@ HTML 注释 `<!-- ... -->` 会被忽略,不产生组件或变量。原始 HTML
|
|
|
289
296
|
- 两个控件的数值范围、步长必须一致。
|
|
290
297
|
- 文本、数字、布尔、日期、选择等不同家族不能共用一个变量。
|
|
291
298
|
- 选择器共享变量时,选项的 value 和顺序必须完全一致。
|
|
292
|
-
- `timer`、`checklist`、`tabs`、`diagram`
|
|
299
|
+
- `timer`、`checklist`、`tabs`、`diagram`、`multi-select`、`steps` 的公开状态只能由一个组件拥有,不能共享。`range-slider` 与 `coordinate` 的槽位也独占;表格和图表只有在有序 `key` 完全一致时才能共享选择绑定。
|
|
293
300
|
|
|
294
301
|
### 4.5 不写 bind 的组件
|
|
295
302
|
|
|
@@ -439,6 +446,8 @@ HTML 注释 `<!-- ... -->` 会被忽略,不产生组件或变量。原始 HTML
|
|
|
439
446
|
|
|
440
447
|
### 6.3 函数
|
|
441
448
|
|
|
449
|
+
数组索引与数字聚合、跨字段提示及本地表格生成见[条件、校验与本地集合](constraints-collections-ch.md)。其中的工作坊示例展示了如何在编辑过程中检查关联字段。
|
|
450
|
+
|
|
442
451
|
| 函数 | 作用 |
|
|
443
452
|
| --- | --- |
|
|
444
453
|
| `abs(x)` | 绝对值 |
|
|
@@ -582,6 +591,8 @@ HTML 注释 `<!-- ... -->` 会被忽略,不产生组件或变量。原始 HTML
|
|
|
582
591
|
|
|
583
592
|
`alert` 的 `tone` 可选 `info`、`success`、`warning`。`badge` 的 `tone` 可选 `neutral`、`success`、`warning`。`badge` 和 `tooltip` 是行内组件,可以嵌在句子里。
|
|
584
593
|
|
|
594
|
+
本预览还增加 `jump`、`anchor`、`text`、`section` 用于跳转和受控正文颜色,`multi-select`、`range-slider`、`coordinate` 用于输入,`quiz`、`steps`、`step` 用于练习和分步阅读,`computed`/`const` 用于命名值,`validation` 用于跨字段提示,`data-table`/`column` 用于生成表格行。规则见[扩展说明](local-components-v2-ch.md)、[计算说明](computations-formatting-ch.md)和[集合说明](constraints-collections-ch.md)。
|
|
595
|
+
|
|
585
596
|
## 8. 清单、进度、计时与时间轴
|
|
586
597
|
|
|
587
598
|
### 8.1 可勾选清单
|
|
@@ -627,7 +638,7 @@ HTML 注释 `<!-- ... -->` 会被忽略,不产生组件或变量。原始 HTML
|
|
|
627
638
|
</timeline>
|
|
628
639
|
```
|
|
629
640
|
|
|
630
|
-
表头必须包含
|
|
641
|
+
表头必须包含 `事项`、`开始`、`时长`(可选 `说明`),或使用 `Task`、`Start`、`Duration`(可选 `Notes`)。开始时间和时长是非负数,允许区间重叠。按开始时间稳定排序。
|
|
631
642
|
|
|
632
643
|
## 9. 表格与图表
|
|
633
644
|
|
|
@@ -830,6 +841,9 @@ $$
|
|
|
830
841
|
| `edge` 指向不存在的节点 | `to` 的 id 拼错 | 统一节点 id |
|
|
831
842
|
| 绘图提示不支持积分 | 公式超出首版计算范围 | 换成支持的函数,或只排版不绘图 |
|
|
832
843
|
| 表格里的 `\|\|` 出错 | GFM 表格把竖线当成列分隔 | 写成 `\|\|` |
|
|
844
|
+
| `sum` 等绑定被拒绝 | 该名称是新增保留函数名 | 重命名绑定并同步修改引用 |
|
|
845
|
+
| 两个 anchor 或跳转目标冲突 | 显式 ID 重复或与标题锚点冲突 | 使用唯一的 `anchor.id` 与匹配的 `jump.to` |
|
|
846
|
+
| 生成表格提示缺少列 | `data-table` 至少需要一个 `column` | 添加带静态 label 和 value 表达式的 `column` |
|
|
833
847
|
| 标签被当成文字显示 | 位于代码围栏或反斜杠转义后 | 这是正常的原文显示 |
|
|
834
848
|
| `textarea` 正文不生效 | `textarea` 是无正文组件 | 用 `initial="..."` 设置文本 |
|
|
835
849
|
| 成对组件写成 `/>` | `<card ... />` 不会自动闭合 | 改成开始标签加结束标签 |
|
|
@@ -921,8 +935,8 @@ Playground 的左侧编辑器和右侧诊断区会同时定位问题。未知标
|
|
|
921
935
|
## 13. 下一步
|
|
922
936
|
|
|
923
937
|
- 想先看成品:打开 [示例目录](../examples/local/README.md),从计数器、方案计算器和交互图解开始。
|
|
924
|
-
- 想了解全部组件和边界:阅读 [本地交互语法规范](local-interaction-syntax.md)。
|
|
925
|
-
- 想嵌入自己的 React 应用:阅读 [本地模式集成](local-integration.md)。
|
|
938
|
+
- 想了解全部组件和边界:阅读 [本地交互语法规范](local-interaction-syntax-ch.md)。
|
|
939
|
+
- 想嵌入自己的 React 应用:阅读 [本地模式集成](local-integration-ch.md)。
|
|
926
940
|
- 想看错误示例:打开 [diagnostics.reactive.md](../examples/local/diagnostics.reactive.md),对照诊断理解常见问题。
|
|
927
941
|
- 想启动 Playground:在仓库根目录执行 `npm run dev`,或访问线上演示 [yaozi.raricy.com](https://yaozi.raricy.com/)。
|
|
928
942
|
|
|
@@ -930,12 +944,18 @@ Playground 的左侧编辑器和右侧诊断区会同时定位问题。未知标
|
|
|
930
944
|
|
|
931
945
|
| 用途 | 组件 |
|
|
932
946
|
| --- | --- |
|
|
933
|
-
| 参数输入 | `input`、`textarea`、`number`、`slider`、`toggle`、`checkbox`、`date`、`select`、`choices`、`radio-group`、`option` |
|
|
947
|
+
| 参数输入 | `input`、`textarea`、`number`、`slider`、`range-slider`、`coordinate`、`toggle`、`checkbox`、`date`、`select`、`choices`、`radio-group`、`multi-select`、`option` |
|
|
934
948
|
| 自带操作 | `counter`、`timer`、`checklist`、`progress` |
|
|
935
949
|
| 组织内容 | `panel`、`card`、`grid`、`tabs`、`tab`、`accordion`、`disclosure`、`if` |
|
|
950
|
+
| 跳转与正文 | `jump`、`anchor`、`text`、`section` |
|
|
951
|
+
| 练习与分步 | `quiz`、`steps`、`step` |
|
|
936
952
|
| 提示 | `alert`、`badge`、`tooltip` |
|
|
953
|
+
| 声明与生成数据 | `computed`、`const`、`validation`、`data-table`、`column` |
|
|
937
954
|
| 可视化 | `table`、`chart`、`plot`、`timeline`、`diagram`、`node`、`edge` |
|
|
938
955
|
|
|
939
|
-
其中 `option`、`tab`、`disclosure`、`node`、`edge`
|
|
956
|
+
其中 `option`、`tab`、`disclosure`、`node`、`edge`、`step`、`column` 是父组件的结构子项,不能单独放在任意位置。`computed`、`const`、`validation` 是文档声明,不是可见控件。
|
|
940
957
|
|
|
941
958
|
大多数文章只需要 Markdown,加上两三个输入组件和一个展示组件。先把参数和正文连接起来,再按需要引入图表、图解和 LaTeX 曲线。
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
新增组块、颜色、槽位状态与迁移规则见[local-draft-2 扩展说明](local-components-v2-ch.md),升级清单见[0.4.0 发布与迁移](release-0.4.0-ch.md)。`0.4.0` 是 `next` 渠道的预览版。
|