reactive-md 0.6.0 → 0.6.1
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 +203 -194
- package/CHANGELOG.md +203 -194
- package/CONTRIBUTING-ch.md +67 -67
- package/CONTRIBUTING.md +69 -69
- package/README-ch.md +157 -157
- package/README-en.md +184 -184
- package/README.md +184 -184
- package/SECURITY-ch.md +81 -81
- package/SECURITY.md +81 -81
- package/THIRD_PARTY_NOTICES.md +313 -209
- package/bin/reactive-md.mjs +39 -39
- package/cli/args.mjs +181 -181
- package/cli/assets.mjs +390 -390
- package/cli/build.mjs +268 -268
- package/cli/document.mjs +130 -130
- package/cli/errors.mjs +61 -61
- package/cli/fs-utils.mjs +133 -133
- package/cli/glob.mjs +203 -203
- package/cli/help.mjs +138 -138
- package/cli/lint.mjs +177 -177
- package/cli/main.mjs +55 -55
- package/cli/migrate.mjs +368 -368
- package/cli/package.mjs +210 -210
- package/dist-library/{authoring-DSC0VsNK.js → authoring-BEVyth5X.js} +1 -1
- package/dist-library/compiler-Cm3ppMxG.js +46044 -0
- package/dist-library/{react-Dk94rcOp.js → react-Bh7_oxZp.js} +20110 -20113
- package/dist-library/reactive-md-authoring.js +2 -2
- package/dist-library/reactive-md-print.css +284 -284
- package/dist-library/reactive-md-react-unstyled.js +1 -1
- package/dist-library/reactive-md-react.js +1 -1
- package/dist-library/reactive-md.css +1 -1
- package/dist-library/reactive-md.js +3 -3
- package/dist-library/{runtime-D8KbnCd0.js → runtime-DlFYQ4s_.js} +1 -1
- package/dist-library/types/local/math-display.d.ts +22 -23
- package/dist-library/types/local/math-view.d.ts +6 -7
- package/dist-standalone/reactive-md-standalone.css +1 -1
- package/dist-standalone/reactive-md-standalone.js +318 -62
- package/docs/compatibility/compatibility-ch.md +121 -119
- package/docs/compatibility/compatibility-en.md +121 -119
- package/docs/compatibility/source-versioning-ch.md +159 -159
- package/docs/compatibility/source-versioning-en.md +159 -159
- package/docs/development/component-development-ch.md +210 -210
- package/docs/development/component-development-en.md +210 -210
- package/docs/development/component-protocol-ch.md +747 -747
- package/docs/development/component-protocol-en.md +747 -747
- package/docs/development/performance-ch.md +76 -76
- package/docs/development/performance-en.md +76 -76
- package/docs/development/releasing-ch.md +108 -108
- package/docs/development/releasing-en.md +108 -108
- package/docs/integration/author-tools-ch.md +62 -62
- package/docs/integration/author-tools-en.md +62 -62
- package/docs/integration/shareable-export-ch.md +209 -209
- package/docs/integration/shareable-export-en.md +211 -211
- package/docs/reference/computations-formatting-ch.md +87 -87
- package/docs/reference/computations-formatting-en.md +87 -87
- package/docs/reference/constraints-collections-ch.md +84 -84
- package/docs/reference/constraints-collections-en.md +84 -84
- package/docs/reference/diagnostics-counting-ch.md +104 -104
- package/docs/reference/diagnostics-counting-en.md +104 -104
- package/docs/reference/local-components-v2-ch.md +138 -138
- package/docs/reference/local-components-v2-en.md +104 -104
- package/docs/reference/local-interaction-syntax-ch.md +515 -511
- package/docs/reference/local-interaction-syntax-en.md +511 -507
- package/docs/reference/theme-protocol-ch.md +107 -107
- package/docs/reference/theme-protocol-en.md +107 -107
- package/docs/releases/release-0.4.0-ch.md +89 -89
- package/docs/releases/release-0.4.0-en.md +89 -89
- package/docs/releases/release-0.4.1-ch.md +23 -23
- package/docs/releases/release-0.4.1-en.md +23 -23
- package/docs/releases/release-0.6.1-ch.md +27 -0
- package/docs/releases/release-0.6.1-en.md +27 -0
- package/examples/conformance/README.md +53 -53
- package/examples/conformance/component-protocol-1.json +482 -482
- package/examples/conformance/component-protocol-1.schema.json +76 -76
- package/examples/conformance/local-draft-1.json +50 -50
- package/examples/conformance/local-draft-2.json +212 -212
- package/examples/integration/README.md +47 -47
- package/examples/integration/core/index.mjs +32 -32
- package/examples/integration/worker/index.html +19 -19
- package/examples/integration/worker/main.js +61 -61
- package/examples/integration/worker/package.json +13 -13
- package/examples/integration/worker/worker.js +3 -3
- package/examples/local/README.md +74 -74
- package/examples/local/charts.reactive.md +73 -73
- package/examples/local/recipes/invoice-zh.reactive.md +36 -36
- package/examples/local/recipes/invoice.reactive.md +36 -36
- package/examples/local/recipes/workshop-zh.reactive.md +33 -33
- package/examples/local/recipes/workshop.reactive.md +33 -33
- package/examples/local/showcase/README.md +25 -25
- package/examples/local/showcase/explore.reactive.md +102 -102
- package/examples/local/showcase/flow.reactive.md +86 -86
- package/examples/local/showcase/forms.reactive.md +126 -126
- package/examples/local/showcase/functions.reactive.md +119 -119
- package/examples/local/showcase/layout.reactive.md +100 -100
- package/examples/local/showcase/statistics.reactive.md +108 -108
- package/examples/local/showcase/tasks.reactive.md +89 -89
- package/examples/local/showcase/zh/explore.reactive.md +102 -102
- package/examples/local/showcase/zh/flow.reactive.md +86 -86
- package/examples/local/showcase/zh/forms.reactive.md +126 -126
- package/examples/local/showcase/zh/functions.reactive.md +119 -119
- package/examples/local/showcase/zh/layout.reactive.md +100 -100
- package/examples/local/showcase/zh/statistics.reactive.md +108 -108
- package/examples/local/showcase/zh/tasks.reactive.md +89 -89
- package/package.json +152 -152
- package/dist-library/compiler-CRD88BMt.js +0 -24964
|
@@ -1,210 +1,210 @@
|
|
|
1
|
-
# Component development guide
|
|
2
|
-
|
|
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](../reference/local-interaction-syntax-en.md).
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
## 1. What to submit
|
|
8
|
-
|
|
9
|
-
A complete component contribution includes a declaration, implementation, examples and acceptance evidence. Use the template in section 5 to describe the behavior first, then change code according to the implementation surfaces affected. Review needs to answer: how authors can write it, how readers operate it, how it behaves on errors, and what happens to existing documents after an upgrade.
|
|
10
|
-
|
|
11
|
-
The project currently extends components through repository code. There is no public runtime registrar, loadable component JSON or author import syntax; `LocalComponentSchema`, `LOCAL_COMPONENTS` and renderer-internal contexts are not a stable plugin SDK either. Conformance JSON contains source and expected results, not a component installation package.
|
|
12
|
-
|
|
13
|
-
Components continue to follow the simple local interaction scope. Inputs are named with `bind`, and outputs are read through expressions. Network services, author scripts, arbitrary HTML, event handlers, author CSS and persisted state are not part of the current author language. Images and links use the host-controlled URL policy; see the [security policy](../../SECURITY.md) for details.
|
|
14
|
-
|
|
15
|
-
## 2. From proposal to acceptance
|
|
16
|
-
|
|
17
|
-
1. Submit the declaration template in section 5, stating purpose, syntax, state, errors, budgets and version impact. When it overlaps existing components, explain what a combination of existing components or Markdown still lacks.
|
|
18
|
-
2. Mark the applicable `CP-*` clauses. A component without bindings, timing or computation may mark the corresponding items as "not applicable" and explain why.
|
|
19
|
-
3. Check the implementation locations in the table below. When reusing existing generic logic, explain why no new branch is needed; when a new branch is needed, check the compiler and runtime consumers together.
|
|
20
|
-
4. Add a minimal normal example, invalid input and boundary cases. For state, check initialization, rejected writes, sharing, hiding and reset; for computation, check budgets.
|
|
21
|
-
5. Run the affected checks from section 6. Keep the commands, results and browser observations, and state outstanding items clearly.
|
|
22
|
-
6. Update the syntax, compatibility notes, changelog and relevant examples. Attach the declaration and evidence in the PR so maintainers can verify version and migration impact.
|
|
23
|
-
|
|
24
|
-
| Implementation surface | Location | What to check |
|
|
25
|
-
| --- | --- | --- |
|
|
26
|
-
| Tag parsing | `src/local/parser.ts` | `VOID`, `PAIRED`, `INLINE` and the `KNOWN` set generated from them; shape, nesting, code isolation and unknown-region fallback |
|
|
27
|
-
| Component declaration | `src/local/schema.ts` | Name, `form`, `childRule`, parent, attribute types and defaults, `binding`, `initialRule` |
|
|
28
|
-
| Compilation | `src/local/compiler.ts` | Attributes and child content, expression types, binding family, shared constraints, initial values and budgets |
|
|
29
|
-
| State runtime | `src/local/runtime.ts` | Canonical control lookup, write types and constraints, atomic commits, array copies, reset and disposal |
|
|
30
|
-
| Controls and layout | `src/local/LocalDocumentView.tsx` | `COMPONENTS`, input drafts, accessible names, keyboard, visibility, reset tokens and effect cleanup |
|
|
31
|
-
| Visualization | `src/local/visuals.tsx`, `src/local/math.ts` | `VISUAL_COMPONENTS`, plot or table semantics, local errors, computation budgets, readouts and reset |
|
|
32
|
-
| Styles | `src/local/local.css`, `src/local/visuals.css`, `src/theme.css` | Theme variables, class prefixes, focus, narrow screens and styling effects outside the document |
|
|
33
|
-
| Budgets and types | `src/local/limits.ts`, `src/local/types.ts`, `src/local/render-types.ts` | Boundaries for new resources; core types do not depend on React; internal nodes do not become a persistence format |
|
|
34
|
-
| Evidence and documentation | `tests/`, [conformance data](../../examples/conformance/README.md), [syntax specification](../reference/local-interaction-syntax-en.md) | Concrete behavior cases, copyable examples, migration and check records |
|
|
35
|
-
|
|
36
|
-
A new declaration does not automatically synchronize the parser, runtime and renderer. Conversely, when existing generic validation is sufficient, there is no need to add branches just to complete the file checklist.
|
|
37
|
-
|
|
38
|
-
## 3. How to judge compatibility
|
|
39
|
-
|
|
40
|
-
Judge by the [compatibility notes](../compatibility/compatibility-en.md) and the CP-COMPAT clauses of the protocol. The project currently requires author-visible syntax changes to establish a new syntax revision and raise the package minor version; "the old valid form still works" does not mean a new tag can be added within the same syntax revision.
|
|
41
|
-
|
|
42
|
-
| Change | Handling |
|
|
43
|
-
| --- | --- |
|
|
44
|
-
| New tag, new author-visible attribute | Record it as a capability addition, establish a new syntax revision, update `LOCAL_SYNTAX_VERSION`, the package minor version, the syntax specification and conformance data |
|
|
45
|
-
| Rename, removal, changed default, binding type, child item or initial-value rule | Record as a breaking change and provide the old form, new form, affected scope and migration checks |
|
|
46
|
-
| Implementation fix, optimization or style adjustment that keeps existing semantics, accessibility and resource boundaries | Add regression evidence according to actual impact; classify public API or author semantics changes separately |
|
|
47
|
-
| Diagnostic code change | Update the corresponding conformance data and changelog; follow the 0.x diagnostic code compatibility convention and do not depend on message text |
|
|
48
|
-
| Change to a MUST clause, required declaration or machine format semantics of this protocol | Raise the protocol revision; judge separately whether syntax or API changes |
|
|
49
|
-
|
|
50
|
-
A new tag has one more migration impact: the old implementation displays the complete unknown region as inert source, while the new implementation may start executing inner content after recognizing the name. This must be recorded in the proposal with before/after cases. Whether a name joins the core component set is reviewed by maintainers; do not override the meaning of an existing name or quietly add an alias.
|
|
51
|
-
|
|
52
|
-
This protocol itself adds no author tags or attributes, so it keeps `local-draft-2` and the current package version.
|
|
53
|
-
|
|
54
|
-
## 4. Filling in a declaration with existing components
|
|
55
|
-
|
|
56
|
-
The three existing components below show the contracts for a control, a container and a computational visualization. They are executable examples, not design drafts for a new API.
|
|
57
|
-
|
|
58
|
-
### slider: a numeric control
|
|
59
|
-
|
|
60
|
-
```markdown
|
|
61
|
-
<slider bind="seats" label="People" initial="2" min="1" max="20">
|
|
62
|
-
|
|
63
|
-
Current cost: {{ seats * 100 }} USD.
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
Declaration points: no body, number family, shareable binding; `min/max/step` are static constraints with defaults `0/100/1`; omitting `initial` takes `min`. Same-name numeric controls must have identical constraints, and there can be at most one explicit initial value.
|
|
67
|
-
|
|
68
|
-
Acceptance should prove that the initial value is 2, valid writes change the cost, out-of-range and off-step writes are rejected, a rejected write leaves the unchanged complete snapshot and revision, and shared controls read the same value. Without `bind`, check the independent internal state. Panel reset restores compile-time initial values; real dragging and keyboard stepping need browser evidence. Corresponding protocol clauses: CP-STATE-03, 04, 06, 08, 10.
|
|
69
|
-
|
|
70
|
-
### tabs: a stateful container
|
|
71
|
-
|
|
72
|
-
```markdown
|
|
73
|
-
<panel title="Plan">
|
|
74
|
-
<tabs bind="page" label="Plan pages" initial="basic">
|
|
75
|
-
<tab label="Basic" value="basic">
|
|
76
|
-
<slider bind="a" label="Basic quantity" initial="2" min="0" max="10">
|
|
77
|
-
</tab>
|
|
78
|
-
<tab label="Advanced" value="advanced">
|
|
79
|
-
<slider bind="b" label="Advanced quantity" initial="7" min="0" max="10">
|
|
80
|
-
</tab>
|
|
81
|
-
</tabs>
|
|
82
|
-
</panel>
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Declaration points: `tabs` accepts only `tab` children, exposes a string value, and owns the binding exclusively. `tab.value` is unique; when omitted, `tab-1`, `tab-2` are generated in source order. Without `initial`, the first tab is selected. Without `bind`, selection stays inside the component.
|
|
86
|
-
|
|
87
|
-
Acceptance should prove that `b` on the inactive page still initializes to 7, switching preserves child content state, unknown page values are rejected, a second component cannot declare the same binding, and panel reset restores the page and child controls. Arrow keys, Home/End, focus, and the need for the reader to start a paused hidden timer again require corresponding browser checks. Corresponding protocol clauses: CP-STATE-11, CP-VIS and CP-LIFE.
|
|
88
|
-
|
|
89
|
-
### plot: budget-constrained computation
|
|
90
|
-
|
|
91
|
-
```markdown
|
|
92
|
-
<slider bind="a" label="Amplitude" initial="1" min="0" max="3" step="0.5">
|
|
93
|
-
<slider bind="high" label="Right bound" initial="3" min="1" max="10">
|
|
94
|
-
|
|
95
|
-
<plot label="Sine wave" min="-2" max="{{ high }}">
|
|
96
|
-
$$ y = a \sin x $$
|
|
97
|
-
</plot>
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Declaration points: the body is one or more standalone formula blocks, each written `y = expression`; `min/max` may be dynamic and require `min < max`; `samples` is a static integer, default 200, range 2 to 2000. Formula parameters must be declared numeric bindings.
|
|
101
|
-
|
|
102
|
-
Acceptance should cover valid LaTeX, parameter changes, dynamic ranges, non-numeric parameters and invalid ranges. Each plot has at most 16 curves; the whole document may request at most 20,000 sample points, and computation shares a budget of 2,000,000 steps, including hidden regions. Invalid samples should break the curve; empty data and local errors need explicit display. Pointer and keyboard readouts, narrow screens and legend interaction need separate browser checks. Corresponding protocol clauses: CP-STATE-12, CP-DIAG-04, CP-SEC-03.
|
|
103
|
-
|
|
104
|
-
## 5. Copyable proposal template
|
|
105
|
-
|
|
106
|
-
Copy the following into an issue, a PR description or a standalone design document. Replace every placeholder with an actual decision and explain why an item does not apply. Attribute declarations are review material, not a runtime-loadable schema.
|
|
107
|
-
|
|
108
|
-
```markdown
|
|
109
|
-
# Component proposal: <name>
|
|
110
|
-
|
|
111
|
-
## Purpose and boundaries
|
|
112
|
-
|
|
113
|
-
- Concrete document need to solve:
|
|
114
|
-
- Reader-triggered actions and observable results:
|
|
115
|
-
- Capability missing from existing components or Markdown combinations:
|
|
116
|
-
- Non-goals of this component:
|
|
117
|
-
|
|
118
|
-
## Version and name
|
|
119
|
-
|
|
120
|
-
| Item | Decision |
|
|
121
|
-
| --- | --- |
|
|
122
|
-
| Package version | Current value, target value and rationale |
|
|
123
|
-
| Syntax revision | Current value, target value and migration impact |
|
|
124
|
-
| Protocol revision | component-protocol-2, or describe the new revision |
|
|
125
|
-
| Name | Lowercase kebab-case; conflict check and maintainer decision |
|
|
126
|
-
| Shape | leaf / inline / container |
|
|
127
|
-
| Parent, direct children | Allowed scope, count, nesting and whitespace rules |
|
|
128
|
-
|
|
129
|
-
## Syntax
|
|
130
|
-
|
|
131
|
-
Provide a minimal runnable document and one form that must be rejected.
|
|
132
|
-
|
|
133
|
-
## Attributes
|
|
134
|
-
|
|
135
|
-
| Attribute | Type and unit | Static or dynamic | Required | Default | Constraints and failure diagnostics |
|
|
136
|
-
| --- | --- | --- | --- | --- | --- |
|
|
137
|
-
| To fill in | string/number/boolean/enum | Whether interpolation is allowed, how types are preserved | Yes/No | Specific value or none | Range, enum, length, code |
|
|
138
|
-
|
|
139
|
-
## State
|
|
140
|
-
|
|
141
|
-
- Whether there is a bind; value type and family; whether it is exclusive:
|
|
142
|
-
- How explicit and default initial values are produced:
|
|
143
|
-
- Conditions under which a same-name binding may be shared:
|
|
144
|
-
- Valid writes, invalid writes, atomicity and subscriptions:
|
|
145
|
-
- Input drafts and internal UI state:
|
|
146
|
-
- Scope of panel reset, shared values and internal state:
|
|
147
|
-
- Hiding, showing again, source changes, instance isolation:
|
|
148
|
-
- Timers, subscriptions, event listeners and disposal:
|
|
149
|
-
|
|
150
|
-
## Diagnostics and fallback
|
|
151
|
-
|
|
152
|
-
| Trigger | Phase | severity and code | Location | Expected result |
|
|
153
|
-
| --- | --- | --- | --- | --- |
|
|
154
|
-
| To fill in | compile/runtime/render | warning/error, specific code | Source range | Reject, keep the old state or show locally |
|
|
155
|
-
|
|
156
|
-
Describe the old implementation's behavior when displaying the unknown tag as source, and what changes once the name is recognized.
|
|
157
|
-
|
|
158
|
-
## Security, budgets and presentation
|
|
159
|
-
|
|
160
|
-
- How untrusted input is validated; responsibilities of trusted host code:
|
|
161
|
-
- Budgets for input length, collection size, computation count, recursion or sampling:
|
|
162
|
-
- Who sets budgets, at which phases they are checked, and the result when exceeded:
|
|
163
|
-
- Accessible name, role, state, keyboard and focus:
|
|
164
|
-
- 375px, touch targets, dark theme and style scoping:
|
|
165
|
-
- Style files and theme variables added or changed:
|
|
166
|
-
|
|
167
|
-
## Compatibility and migration
|
|
168
|
-
|
|
169
|
-
- Change classification and rationale:
|
|
170
|
-
- Old form, old result:
|
|
171
|
-
- New form, new result:
|
|
172
|
-
- Affected source, host API, diagnostics, budgets or rendering behavior:
|
|
173
|
-
- Migration method and post-upgrade verification:
|
|
174
|
-
|
|
175
|
-
## Files and acceptance
|
|
176
|
-
|
|
177
|
-
| Applicable CP-* clauses | Files to change | Cases or checks | Actual results and evidence |
|
|
178
|
-
| --- | --- | --- | --- |
|
|
179
|
-
| To fill in | Real paths; explain reuse when no change is needed | Normal, invalid, boundary, state or browser checks | Pass/fail/not run |
|
|
180
|
-
|
|
181
|
-
- Portable conformance data and component-specific tests:
|
|
182
|
-
- Commands actually run and their results:
|
|
183
|
-
- Browser, viewport, specific actions and observations:
|
|
184
|
-
- Outstanding evidence; rationale and alternative evidence for SHOULD deviations:
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
Proposals must satisfy applicable MUST clauses. SHOULD deviations record the reason, impact and alternative evidence. Existing components do not automatically become "certified" because the template exists.
|
|
188
|
-
|
|
189
|
-
## 6. Choosing checks by impact
|
|
190
|
-
|
|
191
|
-
Install existing dependencies in the root directory before running checks; see the [contributing guide](../../CONTRIBUTING.md) for the environment and full commands. Behavior changes must have tests that directly cover the behavior; the table below is used to determine the scope of checks.
|
|
192
|
-
|
|
193
|
-
| Change | Minimum useful checks |
|
|
194
|
-
| --- | --- |
|
|
195
|
-
| Protocol, guide or links only | `npm run test:docs`; verify the rules against the current syntax, security and compatibility documentation |
|
|
196
|
-
| Conformance data or runner | `npm run test:components`, `npm run typecheck` |
|
|
197
|
-
| Parsing, compilation, bindings or runtime | Targeted tests for the component, `npm run test:components`, `npm run build`; run related regressions or `npm test` for shared logic changes |
|
|
198
|
-
| React, styles or interaction | Corresponding renderer tests, `npm run build:demo`, and affected browser actions |
|
|
199
|
-
| Public entries, types or distribution files | After building, run `npm run test:package`, `npm run test:packed` |
|
|
200
|
-
| Documentation, syntax, examples or versions | `npm run test:docs`, compilation of the corresponding examples and a migration review |
|
|
201
|
-
| Full release gate | `npm run verify:release`; it covers the Node-side and browser checks, packed consumption and combined document behavior. Use it before release or when a change spans several of the rows above |
|
|
202
|
-
|
|
203
|
-
`npm run test:components` runs the protocol's representative `slider`, `tabs` and `plot` cases plus existing language conformance data. See the [conformance notes](../../examples/conformance/README.md) for file format, field meaning and execution order. New components keep adding their own cases; this command does not prove that all 48 tag names or all browser behavior are certified. Added `tests/**/*.test.ts` or `.tsx` files are also run by the existing `npm test` and CI.
|
|
204
|
-
|
|
205
|
-
Browser checks must record the specific environment and actions. Check real keyboard and focus, IME drafts, 375px layout, touch, themes, reset, hiding and showing again, timer pause and unmount cleanup as applicable to the component. Existing automated browser checks can provide evidence for corresponding behavior; items not yet covered, such as screen reader experience, require manual checks. Static SSR proves only server output, not real input, effect lifecycles or hydration.
|
|
206
|
-
|
|
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
|
-
|
|
209
|
-
|
|
210
|
-
See [local-draft-2 components and migration](../reference/local-components-v2-en.md) for new tags, colors and slot state. `0.5.2` is the preview release on the `next` channel.
|
|
1
|
+
# Component development guide
|
|
2
|
+
|
|
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](../reference/local-interaction-syntax-en.md).
|
|
4
|
+
|
|
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
|
+
|
|
7
|
+
## 1. What to submit
|
|
8
|
+
|
|
9
|
+
A complete component contribution includes a declaration, implementation, examples and acceptance evidence. Use the template in section 5 to describe the behavior first, then change code according to the implementation surfaces affected. Review needs to answer: how authors can write it, how readers operate it, how it behaves on errors, and what happens to existing documents after an upgrade.
|
|
10
|
+
|
|
11
|
+
The project currently extends components through repository code. There is no public runtime registrar, loadable component JSON or author import syntax; `LocalComponentSchema`, `LOCAL_COMPONENTS` and renderer-internal contexts are not a stable plugin SDK either. Conformance JSON contains source and expected results, not a component installation package.
|
|
12
|
+
|
|
13
|
+
Components continue to follow the simple local interaction scope. Inputs are named with `bind`, and outputs are read through expressions. Network services, author scripts, arbitrary HTML, event handlers, author CSS and persisted state are not part of the current author language. Images and links use the host-controlled URL policy; see the [security policy](../../SECURITY.md) for details.
|
|
14
|
+
|
|
15
|
+
## 2. From proposal to acceptance
|
|
16
|
+
|
|
17
|
+
1. Submit the declaration template in section 5, stating purpose, syntax, state, errors, budgets and version impact. When it overlaps existing components, explain what a combination of existing components or Markdown still lacks.
|
|
18
|
+
2. Mark the applicable `CP-*` clauses. A component without bindings, timing or computation may mark the corresponding items as "not applicable" and explain why.
|
|
19
|
+
3. Check the implementation locations in the table below. When reusing existing generic logic, explain why no new branch is needed; when a new branch is needed, check the compiler and runtime consumers together.
|
|
20
|
+
4. Add a minimal normal example, invalid input and boundary cases. For state, check initialization, rejected writes, sharing, hiding and reset; for computation, check budgets.
|
|
21
|
+
5. Run the affected checks from section 6. Keep the commands, results and browser observations, and state outstanding items clearly.
|
|
22
|
+
6. Update the syntax, compatibility notes, changelog and relevant examples. Attach the declaration and evidence in the PR so maintainers can verify version and migration impact.
|
|
23
|
+
|
|
24
|
+
| Implementation surface | Location | What to check |
|
|
25
|
+
| --- | --- | --- |
|
|
26
|
+
| Tag parsing | `src/local/parser.ts` | `VOID`, `PAIRED`, `INLINE` and the `KNOWN` set generated from them; shape, nesting, code isolation and unknown-region fallback |
|
|
27
|
+
| Component declaration | `src/local/schema.ts` | Name, `form`, `childRule`, parent, attribute types and defaults, `binding`, `initialRule` |
|
|
28
|
+
| Compilation | `src/local/compiler.ts` | Attributes and child content, expression types, binding family, shared constraints, initial values and budgets |
|
|
29
|
+
| State runtime | `src/local/runtime.ts` | Canonical control lookup, write types and constraints, atomic commits, array copies, reset and disposal |
|
|
30
|
+
| Controls and layout | `src/local/LocalDocumentView.tsx` | `COMPONENTS`, input drafts, accessible names, keyboard, visibility, reset tokens and effect cleanup |
|
|
31
|
+
| Visualization | `src/local/visuals.tsx`, `src/local/math.ts` | `VISUAL_COMPONENTS`, plot or table semantics, local errors, computation budgets, readouts and reset |
|
|
32
|
+
| Styles | `src/local/local.css`, `src/local/visuals.css`, `src/theme.css` | Theme variables, class prefixes, focus, narrow screens and styling effects outside the document |
|
|
33
|
+
| Budgets and types | `src/local/limits.ts`, `src/local/types.ts`, `src/local/render-types.ts` | Boundaries for new resources; core types do not depend on React; internal nodes do not become a persistence format |
|
|
34
|
+
| Evidence and documentation | `tests/`, [conformance data](../../examples/conformance/README.md), [syntax specification](../reference/local-interaction-syntax-en.md) | Concrete behavior cases, copyable examples, migration and check records |
|
|
35
|
+
|
|
36
|
+
A new declaration does not automatically synchronize the parser, runtime and renderer. Conversely, when existing generic validation is sufficient, there is no need to add branches just to complete the file checklist.
|
|
37
|
+
|
|
38
|
+
## 3. How to judge compatibility
|
|
39
|
+
|
|
40
|
+
Judge by the [compatibility notes](../compatibility/compatibility-en.md) and the CP-COMPAT clauses of the protocol. The project currently requires author-visible syntax changes to establish a new syntax revision and raise the package minor version; "the old valid form still works" does not mean a new tag can be added within the same syntax revision.
|
|
41
|
+
|
|
42
|
+
| Change | Handling |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| New tag, new author-visible attribute | Record it as a capability addition, establish a new syntax revision, update `LOCAL_SYNTAX_VERSION`, the package minor version, the syntax specification and conformance data |
|
|
45
|
+
| Rename, removal, changed default, binding type, child item or initial-value rule | Record as a breaking change and provide the old form, new form, affected scope and migration checks |
|
|
46
|
+
| Implementation fix, optimization or style adjustment that keeps existing semantics, accessibility and resource boundaries | Add regression evidence according to actual impact; classify public API or author semantics changes separately |
|
|
47
|
+
| Diagnostic code change | Update the corresponding conformance data and changelog; follow the 0.x diagnostic code compatibility convention and do not depend on message text |
|
|
48
|
+
| Change to a MUST clause, required declaration or machine format semantics of this protocol | Raise the protocol revision; judge separately whether syntax or API changes |
|
|
49
|
+
|
|
50
|
+
A new tag has one more migration impact: the old implementation displays the complete unknown region as inert source, while the new implementation may start executing inner content after recognizing the name. This must be recorded in the proposal with before/after cases. Whether a name joins the core component set is reviewed by maintainers; do not override the meaning of an existing name or quietly add an alias.
|
|
51
|
+
|
|
52
|
+
This protocol itself adds no author tags or attributes, so it keeps `local-draft-2` and the current package version.
|
|
53
|
+
|
|
54
|
+
## 4. Filling in a declaration with existing components
|
|
55
|
+
|
|
56
|
+
The three existing components below show the contracts for a control, a container and a computational visualization. They are executable examples, not design drafts for a new API.
|
|
57
|
+
|
|
58
|
+
### slider: a numeric control
|
|
59
|
+
|
|
60
|
+
```markdown
|
|
61
|
+
<slider bind="seats" label="People" initial="2" min="1" max="20">
|
|
62
|
+
|
|
63
|
+
Current cost: {{ seats * 100 }} USD.
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Declaration points: no body, number family, shareable binding; `min/max/step` are static constraints with defaults `0/100/1`; omitting `initial` takes `min`. Same-name numeric controls must have identical constraints, and there can be at most one explicit initial value.
|
|
67
|
+
|
|
68
|
+
Acceptance should prove that the initial value is 2, valid writes change the cost, out-of-range and off-step writes are rejected, a rejected write leaves the unchanged complete snapshot and revision, and shared controls read the same value. Without `bind`, check the independent internal state. Panel reset restores compile-time initial values; real dragging and keyboard stepping need browser evidence. Corresponding protocol clauses: CP-STATE-03, 04, 06, 08, 10.
|
|
69
|
+
|
|
70
|
+
### tabs: a stateful container
|
|
71
|
+
|
|
72
|
+
```markdown
|
|
73
|
+
<panel title="Plan">
|
|
74
|
+
<tabs bind="page" label="Plan pages" initial="basic">
|
|
75
|
+
<tab label="Basic" value="basic">
|
|
76
|
+
<slider bind="a" label="Basic quantity" initial="2" min="0" max="10">
|
|
77
|
+
</tab>
|
|
78
|
+
<tab label="Advanced" value="advanced">
|
|
79
|
+
<slider bind="b" label="Advanced quantity" initial="7" min="0" max="10">
|
|
80
|
+
</tab>
|
|
81
|
+
</tabs>
|
|
82
|
+
</panel>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Declaration points: `tabs` accepts only `tab` children, exposes a string value, and owns the binding exclusively. `tab.value` is unique; when omitted, `tab-1`, `tab-2` are generated in source order. Without `initial`, the first tab is selected. Without `bind`, selection stays inside the component.
|
|
86
|
+
|
|
87
|
+
Acceptance should prove that `b` on the inactive page still initializes to 7, switching preserves child content state, unknown page values are rejected, a second component cannot declare the same binding, and panel reset restores the page and child controls. Arrow keys, Home/End, focus, and the need for the reader to start a paused hidden timer again require corresponding browser checks. Corresponding protocol clauses: CP-STATE-11, CP-VIS and CP-LIFE.
|
|
88
|
+
|
|
89
|
+
### plot: budget-constrained computation
|
|
90
|
+
|
|
91
|
+
```markdown
|
|
92
|
+
<slider bind="a" label="Amplitude" initial="1" min="0" max="3" step="0.5">
|
|
93
|
+
<slider bind="high" label="Right bound" initial="3" min="1" max="10">
|
|
94
|
+
|
|
95
|
+
<plot label="Sine wave" min="-2" max="{{ high }}">
|
|
96
|
+
$$ y = a \sin x $$
|
|
97
|
+
</plot>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Declaration points: the body is one or more standalone formula blocks, each written `y = expression`; `min/max` may be dynamic and require `min < max`; `samples` is a static integer, default 200, range 2 to 2000. Formula parameters must be declared numeric bindings.
|
|
101
|
+
|
|
102
|
+
Acceptance should cover valid LaTeX, parameter changes, dynamic ranges, non-numeric parameters and invalid ranges. Each plot has at most 16 curves; the whole document may request at most 20,000 sample points, and computation shares a budget of 2,000,000 steps, including hidden regions. Invalid samples should break the curve; empty data and local errors need explicit display. Pointer and keyboard readouts, narrow screens and legend interaction need separate browser checks. Corresponding protocol clauses: CP-STATE-12, CP-DIAG-04, CP-SEC-03.
|
|
103
|
+
|
|
104
|
+
## 5. Copyable proposal template
|
|
105
|
+
|
|
106
|
+
Copy the following into an issue, a PR description or a standalone design document. Replace every placeholder with an actual decision and explain why an item does not apply. Attribute declarations are review material, not a runtime-loadable schema.
|
|
107
|
+
|
|
108
|
+
```markdown
|
|
109
|
+
# Component proposal: <name>
|
|
110
|
+
|
|
111
|
+
## Purpose and boundaries
|
|
112
|
+
|
|
113
|
+
- Concrete document need to solve:
|
|
114
|
+
- Reader-triggered actions and observable results:
|
|
115
|
+
- Capability missing from existing components or Markdown combinations:
|
|
116
|
+
- Non-goals of this component:
|
|
117
|
+
|
|
118
|
+
## Version and name
|
|
119
|
+
|
|
120
|
+
| Item | Decision |
|
|
121
|
+
| --- | --- |
|
|
122
|
+
| Package version | Current value, target value and rationale |
|
|
123
|
+
| Syntax revision | Current value, target value and migration impact |
|
|
124
|
+
| Protocol revision | component-protocol-2, or describe the new revision |
|
|
125
|
+
| Name | Lowercase kebab-case; conflict check and maintainer decision |
|
|
126
|
+
| Shape | leaf / inline / container |
|
|
127
|
+
| Parent, direct children | Allowed scope, count, nesting and whitespace rules |
|
|
128
|
+
|
|
129
|
+
## Syntax
|
|
130
|
+
|
|
131
|
+
Provide a minimal runnable document and one form that must be rejected.
|
|
132
|
+
|
|
133
|
+
## Attributes
|
|
134
|
+
|
|
135
|
+
| Attribute | Type and unit | Static or dynamic | Required | Default | Constraints and failure diagnostics |
|
|
136
|
+
| --- | --- | --- | --- | --- | --- |
|
|
137
|
+
| To fill in | string/number/boolean/enum | Whether interpolation is allowed, how types are preserved | Yes/No | Specific value or none | Range, enum, length, code |
|
|
138
|
+
|
|
139
|
+
## State
|
|
140
|
+
|
|
141
|
+
- Whether there is a bind; value type and family; whether it is exclusive:
|
|
142
|
+
- How explicit and default initial values are produced:
|
|
143
|
+
- Conditions under which a same-name binding may be shared:
|
|
144
|
+
- Valid writes, invalid writes, atomicity and subscriptions:
|
|
145
|
+
- Input drafts and internal UI state:
|
|
146
|
+
- Scope of panel reset, shared values and internal state:
|
|
147
|
+
- Hiding, showing again, source changes, instance isolation:
|
|
148
|
+
- Timers, subscriptions, event listeners and disposal:
|
|
149
|
+
|
|
150
|
+
## Diagnostics and fallback
|
|
151
|
+
|
|
152
|
+
| Trigger | Phase | severity and code | Location | Expected result |
|
|
153
|
+
| --- | --- | --- | --- | --- |
|
|
154
|
+
| To fill in | compile/runtime/render | warning/error, specific code | Source range | Reject, keep the old state or show locally |
|
|
155
|
+
|
|
156
|
+
Describe the old implementation's behavior when displaying the unknown tag as source, and what changes once the name is recognized.
|
|
157
|
+
|
|
158
|
+
## Security, budgets and presentation
|
|
159
|
+
|
|
160
|
+
- How untrusted input is validated; responsibilities of trusted host code:
|
|
161
|
+
- Budgets for input length, collection size, computation count, recursion or sampling:
|
|
162
|
+
- Who sets budgets, at which phases they are checked, and the result when exceeded:
|
|
163
|
+
- Accessible name, role, state, keyboard and focus:
|
|
164
|
+
- 375px, touch targets, dark theme and style scoping:
|
|
165
|
+
- Style files and theme variables added or changed:
|
|
166
|
+
|
|
167
|
+
## Compatibility and migration
|
|
168
|
+
|
|
169
|
+
- Change classification and rationale:
|
|
170
|
+
- Old form, old result:
|
|
171
|
+
- New form, new result:
|
|
172
|
+
- Affected source, host API, diagnostics, budgets or rendering behavior:
|
|
173
|
+
- Migration method and post-upgrade verification:
|
|
174
|
+
|
|
175
|
+
## Files and acceptance
|
|
176
|
+
|
|
177
|
+
| Applicable CP-* clauses | Files to change | Cases or checks | Actual results and evidence |
|
|
178
|
+
| --- | --- | --- | --- |
|
|
179
|
+
| To fill in | Real paths; explain reuse when no change is needed | Normal, invalid, boundary, state or browser checks | Pass/fail/not run |
|
|
180
|
+
|
|
181
|
+
- Portable conformance data and component-specific tests:
|
|
182
|
+
- Commands actually run and their results:
|
|
183
|
+
- Browser, viewport, specific actions and observations:
|
|
184
|
+
- Outstanding evidence; rationale and alternative evidence for SHOULD deviations:
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Proposals must satisfy applicable MUST clauses. SHOULD deviations record the reason, impact and alternative evidence. Existing components do not automatically become "certified" because the template exists.
|
|
188
|
+
|
|
189
|
+
## 6. Choosing checks by impact
|
|
190
|
+
|
|
191
|
+
Install existing dependencies in the root directory before running checks; see the [contributing guide](../../CONTRIBUTING.md) for the environment and full commands. Behavior changes must have tests that directly cover the behavior; the table below is used to determine the scope of checks.
|
|
192
|
+
|
|
193
|
+
| Change | Minimum useful checks |
|
|
194
|
+
| --- | --- |
|
|
195
|
+
| Protocol, guide or links only | `npm run test:docs`; verify the rules against the current syntax, security and compatibility documentation |
|
|
196
|
+
| Conformance data or runner | `npm run test:components`, `npm run typecheck` |
|
|
197
|
+
| Parsing, compilation, bindings or runtime | Targeted tests for the component, `npm run test:components`, `npm run build`; run related regressions or `npm test` for shared logic changes |
|
|
198
|
+
| React, styles or interaction | Corresponding renderer tests, `npm run build:demo`, and affected browser actions |
|
|
199
|
+
| Public entries, types or distribution files | After building, run `npm run test:package`, `npm run test:packed` |
|
|
200
|
+
| Documentation, syntax, examples or versions | `npm run test:docs`, compilation of the corresponding examples and a migration review |
|
|
201
|
+
| Full release gate | `npm run verify:release`; it covers the Node-side and browser checks, packed consumption and combined document behavior. Use it before release or when a change spans several of the rows above |
|
|
202
|
+
|
|
203
|
+
`npm run test:components` runs the protocol's representative `slider`, `tabs` and `plot` cases plus existing language conformance data. See the [conformance notes](../../examples/conformance/README.md) for file format, field meaning and execution order. New components keep adding their own cases; this command does not prove that all 48 tag names or all browser behavior are certified. Added `tests/**/*.test.ts` or `.tsx` files are also run by the existing `npm test` and CI.
|
|
204
|
+
|
|
205
|
+
Browser checks must record the specific environment and actions. Check real keyboard and focus, IME drafts, 375px layout, touch, themes, reset, hiding and showing again, timer pause and unmount cleanup as applicable to the component. Existing automated browser checks can provide evidence for corresponding behavior; items not yet covered, such as screen reader experience, require manual checks. Static SSR proves only server output, not real input, effect lifecycles or hydration.
|
|
206
|
+
|
|
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
|
+
|
|
209
|
+
|
|
210
|
+
See [local-draft-2 components and migration](../reference/local-components-v2-en.md) for new tags, colors and slot state. `0.5.2` is the preview release on the `next` channel.
|