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,212 @@
|
|
|
1
|
+
{
|
|
2
|
+
"syntaxVersion": "local-draft-2",
|
|
3
|
+
"cases": [
|
|
4
|
+
{
|
|
5
|
+
"name": "shared numeric binding has one initial value and updates prose",
|
|
6
|
+
"source": "<number bind=\"n\" label=\"Count\" initial=\"2\" min=\"0\" max=\"10\">\n<slider bind=\"n\" label=\"Shared count\" min=\"0\" max=\"10\">\n\nTotal: {{ n * 2 }}",
|
|
7
|
+
"ok": true,
|
|
8
|
+
"initial": {
|
|
9
|
+
"n": 2
|
|
10
|
+
},
|
|
11
|
+
"actions": [
|
|
12
|
+
{
|
|
13
|
+
"bind": "n",
|
|
14
|
+
"value": 5
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"text": "Total: {{ n * 2 }}",
|
|
18
|
+
"expectedText": "Total: 10"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "hidden controls initialize their bindings",
|
|
22
|
+
"source": "<toggle bind=\"show\" label=\"Show\">\n<if when=\"{{ show }}\">\n<number bind=\"n\" label=\"Hidden count\" initial=\"4\">\n</if>\n\n{{ n * 2 }}",
|
|
23
|
+
"ok": true,
|
|
24
|
+
"initial": {
|
|
25
|
+
"show": false,
|
|
26
|
+
"n": 4
|
|
27
|
+
},
|
|
28
|
+
"text": "{{ n * 2 }}",
|
|
29
|
+
"expectedText": "8"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "invalid state writes keep the last valid value",
|
|
33
|
+
"source": "<number bind=\"n\" label=\"Count\" initial=\"4\" min=\"0\" max=\"10\">",
|
|
34
|
+
"ok": true,
|
|
35
|
+
"initial": {
|
|
36
|
+
"n": 4
|
|
37
|
+
},
|
|
38
|
+
"actions": [
|
|
39
|
+
{
|
|
40
|
+
"bind": "n",
|
|
41
|
+
"value": 11,
|
|
42
|
+
"codes": [
|
|
43
|
+
"local.runtime.value"
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"text": "{{ n }}",
|
|
48
|
+
"expectedText": "4"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "code fences keep controls and interpolation literal",
|
|
52
|
+
"source": "```markdown\n<counter bind=\"n\" label=\"Literal\">\n{{ missing }}\n```",
|
|
53
|
+
"ok": true,
|
|
54
|
+
"bindingNames": []
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "unknown components preserve source with a warning",
|
|
58
|
+
"source": "<slidr label=\"Typo\">\n</slidr>",
|
|
59
|
+
"ok": true,
|
|
60
|
+
"bindingNames": [],
|
|
61
|
+
"codes": [
|
|
62
|
+
"local.component.unknown"
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"name": "unbound expression names produce a compiler diagnostic",
|
|
67
|
+
"source": "Total: {{ missing * 2 }}",
|
|
68
|
+
"ok": false,
|
|
69
|
+
"codes": [
|
|
70
|
+
"local.binding.unknown"
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"name": "multi-select-values",
|
|
75
|
+
"source": "<multi-select bind=\"subjects\" label=\"Subjects\" max-selected=\"2\">\n<option value=\"math\">Math</option>\n<option value=\"physics\">Physics</option>\n</multi-select>",
|
|
76
|
+
"ok": true,
|
|
77
|
+
"codes": [],
|
|
78
|
+
"initial": {
|
|
79
|
+
"subjects": []
|
|
80
|
+
},
|
|
81
|
+
"bindingNames": [
|
|
82
|
+
"subjects"
|
|
83
|
+
],
|
|
84
|
+
"actions": [
|
|
85
|
+
{
|
|
86
|
+
"bind": "subjects",
|
|
87
|
+
"value": [
|
|
88
|
+
"physics",
|
|
89
|
+
"math"
|
|
90
|
+
],
|
|
91
|
+
"codes": []
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
"text": "{{ len(subjects) }}",
|
|
95
|
+
"expectedText": "2"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"name": "range-slots",
|
|
99
|
+
"source": "<range-slider label=\"Interval\" bind-start=\"low\" bind-end=\"high\" initial-start=\"20\" initial-end=\"80\">",
|
|
100
|
+
"ok": true,
|
|
101
|
+
"codes": [],
|
|
102
|
+
"initial": {
|
|
103
|
+
"low": 20,
|
|
104
|
+
"high": 80
|
|
105
|
+
},
|
|
106
|
+
"bindingNames": [
|
|
107
|
+
"low",
|
|
108
|
+
"high"
|
|
109
|
+
],
|
|
110
|
+
"text": "{{ high - low }}",
|
|
111
|
+
"expectedText": "60"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"name": "coordinate-slots",
|
|
115
|
+
"source": "<coordinate label=\"Point\" bind-x=\"px\" bind-y=\"py\" initial-x=\"1\" initial-y=\"2\">",
|
|
116
|
+
"ok": true,
|
|
117
|
+
"codes": [],
|
|
118
|
+
"initial": {
|
|
119
|
+
"px": 1,
|
|
120
|
+
"py": 2
|
|
121
|
+
},
|
|
122
|
+
"bindingNames": [
|
|
123
|
+
"px",
|
|
124
|
+
"py"
|
|
125
|
+
],
|
|
126
|
+
"text": "{{ px + py }}",
|
|
127
|
+
"expectedText": "3"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"name": "steps-initialization",
|
|
131
|
+
"source": "<steps label=\"Path\" bind=\"lesson\">\n<step label=\"Read\">\nRead first.\n</step>\n<step label=\"Try\">\nTry next.\n</step>\n</steps>",
|
|
132
|
+
"ok": true,
|
|
133
|
+
"codes": [],
|
|
134
|
+
"initial": {
|
|
135
|
+
"lesson": "step-1"
|
|
136
|
+
},
|
|
137
|
+
"bindingNames": [
|
|
138
|
+
"lesson"
|
|
139
|
+
],
|
|
140
|
+
"actions": [
|
|
141
|
+
{
|
|
142
|
+
"bind": "lesson",
|
|
143
|
+
"value": "step-2",
|
|
144
|
+
"codes": []
|
|
145
|
+
}
|
|
146
|
+
],
|
|
147
|
+
"text": "{{ lesson }}",
|
|
148
|
+
"expectedText": "step-2"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"name": "jump-colored-prose",
|
|
152
|
+
"source": "<jump to=\"result\">Results</jump>\n\n<section color=\"#123\">\n\n<text color=\"red\">Important</text>\n\n</section>\n\n<anchor id=\"result\">\n\nDone.",
|
|
153
|
+
"ok": true,
|
|
154
|
+
"codes": []
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"name": "quiz-choice",
|
|
158
|
+
"source": "<quiz label=\"Two plus three\" answer=\"b\">\n<option value=\"a\">4</option>\n<option value=\"b\">5</option>\n</quiz>",
|
|
159
|
+
"ok": true,
|
|
160
|
+
"codes": []
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"name": "selection-key",
|
|
164
|
+
"source": "<table bind=\"project\" key=\"Project\" initial=\"Visual\">\n| Project | Cost |\n| --- | ---: |\n| Content | 120 |\n| Visual | 230 |\n</table>",
|
|
165
|
+
"ok": true,
|
|
166
|
+
"codes": [],
|
|
167
|
+
"initial": {
|
|
168
|
+
"project": "Visual"
|
|
169
|
+
},
|
|
170
|
+
"bindingNames": [
|
|
171
|
+
"project"
|
|
172
|
+
],
|
|
173
|
+
"actions": [
|
|
174
|
+
{
|
|
175
|
+
"bind": "project",
|
|
176
|
+
"value": "Content",
|
|
177
|
+
"codes": []
|
|
178
|
+
}
|
|
179
|
+
],
|
|
180
|
+
"text": "{{ project }}",
|
|
181
|
+
"expectedText": "Content"
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"name": "computed-values-recalculate-from-controls-and-arrays",
|
|
185
|
+
"source": "<computed name=\"costs\" value=\"{{ [seats * 80, materials ? seats * 20 : 0] }}\">\n<computed name=\"total\" value=\"{{ sum(costs) }}\">\n\n<number bind=\"seats\" label=\"Seats\" initial=\"4\" min=\"1\" max=\"20\">\n<toggle bind=\"materials\" label=\"Materials\">\n\nTotal: {{ total }}.",
|
|
186
|
+
"ok": true,
|
|
187
|
+
"codes": [],
|
|
188
|
+
"initial": {
|
|
189
|
+
"seats": 4,
|
|
190
|
+
"materials": false
|
|
191
|
+
},
|
|
192
|
+
"bindingNames": [
|
|
193
|
+
"materials",
|
|
194
|
+
"seats"
|
|
195
|
+
],
|
|
196
|
+
"actions": [
|
|
197
|
+
{
|
|
198
|
+
"bind": "materials",
|
|
199
|
+
"value": true,
|
|
200
|
+
"codes": []
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"bind": "seats",
|
|
204
|
+
"value": 6,
|
|
205
|
+
"codes": []
|
|
206
|
+
}
|
|
207
|
+
],
|
|
208
|
+
"text": "Total: {{ total }}.",
|
|
209
|
+
"expectedText": "Total: 600."
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
}
|
|
@@ -1,29 +1,45 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
# Standalone integration examples
|
|
2
|
+
|
|
3
|
+
These directories use the package's public entry points and can be copied outside the repository. The commands below start from the current directory.
|
|
4
|
+
|
|
5
|
+
These examples target `0.4.0`, the preview release on the `next` channel. First run `npm pack` in the repository, then copy the desired example directory outside the repository. In each command below, replace `/path/to/reactive-md-0.4.0.tgz` with the tarball's absolute path. The install uses the built package; React and Vite are installed from the example's own dependencies where needed.
|
|
6
|
+
|
|
7
|
+
## Node core
|
|
8
|
+
|
|
9
|
+
Requires Node.js 22.12 or newer. The core example needs no React and makes no network requests.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
cd core
|
|
13
|
+
npm install /path/to/reactive-md-0.4.0.tgz --ignore-scripts --no-audit --no-fund
|
|
14
|
+
npm start
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
It should print `People: 2, cost: 200` first, then `People: 5, cost: 500`. The source is in [core/index.mjs](core/index.mjs).
|
|
18
|
+
|
|
19
|
+
The core and worker examples use host APIs added in the `0.4.0` preview.
|
|
20
|
+
|
|
21
|
+
## React page
|
|
22
|
+
|
|
23
|
+
Requires Node.js 22.12 or newer. The first install fetches React 19 and Vite.
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
cd react
|
|
27
|
+
npm install /path/to/reactive-md-0.4.0.tgz
|
|
28
|
+
npm run dev
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Open the local URL printed by the terminal, adjust the headcount and watch the cost change. The example entry is [react/main.jsx](react/main.jsx), and the library styles are imported through `reactive-md/styles.css`.
|
|
32
|
+
|
|
33
|
+
## Worker compilation
|
|
34
|
+
|
|
35
|
+
[worker](worker) is a copyable browser page that keeps compilation off the main thread. It debounces edits, compiles in a module Worker, and falls back to the main thread when a Worker cannot start or crashes.
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
cd worker
|
|
39
|
+
npm install /path/to/reactive-md-0.4.0.tgz
|
|
40
|
+
npm run dev
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The UI and scheduler wiring live in [worker/main.js](worker/main.js); the Worker entry is [worker/worker.js](worker/worker.js).
|
|
44
|
+
|
|
45
|
+
From the source repository root, `npm run verify:release` runs the complete gate, including standalone offline installation from the packed tarball, strict type checking, combined-feature checks, React rendering and HTML export. Use `npm run test:packed` for the focused package check after building. See the [integration guide](../../docs/local-integration-en.md) for the API and host policies.
|
|
@@ -1,19 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
print();
|
|
19
|
-
|
|
1
|
+
import {
|
|
2
|
+
compileLocal,
|
|
3
|
+
createLocalRuntime,
|
|
4
|
+
exportLocalState,
|
|
5
|
+
importLocalState,
|
|
6
|
+
LOCAL_SYNTAX_VERSION,
|
|
7
|
+
} from 'reactive-md';
|
|
8
|
+
|
|
9
|
+
const source = `<number bind="people" label="People" initial="2" min="1" max="20">
|
|
10
|
+
|
|
11
|
+
People: {{ people }}, cost: {{ people * 100 }}`;
|
|
12
|
+
const result = compileLocal(source);
|
|
13
|
+
if (!result.ok) throw new Error(JSON.stringify(result.diagnostics));
|
|
14
|
+
|
|
15
|
+
console.log(`Syntax: ${LOCAL_SYNTAX_VERSION}`);
|
|
16
|
+
const runtime = createLocalRuntime(result.document);
|
|
17
|
+
try {
|
|
18
|
+
const print = () => console.log(runtime.text('People: {{ people }}, cost: {{ people * 100 }}'));
|
|
19
|
+
print();
|
|
20
|
+
console.log(`People parameter: ${runtime.getParameter('people')}`);
|
|
21
|
+
|
|
22
|
+
const diagnostics = runtime.setParameters({ people: 5 });
|
|
23
|
+
if (diagnostics.length) throw new Error(JSON.stringify(diagnostics));
|
|
24
|
+
print();
|
|
25
|
+
|
|
26
|
+
const file = exportLocalState(runtime, { name: 'reactive-md-core-example', version: '1' });
|
|
27
|
+
runtime.setParameter('people', 1);
|
|
28
|
+
const imported = importLocalState(runtime, JSON.stringify(file));
|
|
29
|
+
if (imported.length) throw new Error(JSON.stringify(imported));
|
|
30
|
+
print();
|
|
31
|
+
console.log(`State: ${file.format}, document ${file.sourceDigest}`);
|
|
32
|
+
} finally { runtime.dispose(); }
|
|
@@ -3,14 +3,14 @@ import { createRoot } from 'react-dom/client';
|
|
|
3
3
|
import { LocalReactiveDocument } from 'reactive-md/react';
|
|
4
4
|
import 'reactive-md/styles.css';
|
|
5
5
|
|
|
6
|
-
const source = `#
|
|
6
|
+
const source = `# Cost estimate
|
|
7
7
|
|
|
8
|
-
<panel title="
|
|
9
|
-
<slider bind="people" label="
|
|
10
|
-
<toggle bind="annual" label="
|
|
8
|
+
<panel title="Adjust the plan">
|
|
9
|
+
<slider bind="people" label="People" initial="2" min="1" max="20">
|
|
10
|
+
<toggle bind="annual" label="Annual billing">
|
|
11
11
|
</panel>
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Monthly cost: **{{ people * (annual ? 80 : 100) }} USD**.`;
|
|
14
14
|
|
|
15
15
|
createRoot(document.getElementById('root')).render(
|
|
16
16
|
<React.StrictMode>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Reactive MD worker compilation</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<main>
|
|
10
|
+
<h1>Worker compilation</h1>
|
|
11
|
+
<p>Edit the source; compilation is debounced and runs in a module Worker, falling back to the main thread if needed.</p>
|
|
12
|
+
<textarea id="source" rows="12" cols="80" spellcheck="false"></textarea>
|
|
13
|
+
<p id="status">Starting...</p>
|
|
14
|
+
<pre id="diagnostics"></pre>
|
|
15
|
+
<pre id="preview"></pre>
|
|
16
|
+
</main>
|
|
17
|
+
<script type="module" src="/main.js"></script>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { LocalCompileScheduler } from 'reactive-md';
|
|
2
|
+
|
|
3
|
+
const editor = document.getElementById('source');
|
|
4
|
+
const status = document.getElementById('status');
|
|
5
|
+
const diagnostics = document.getElementById('diagnostics');
|
|
6
|
+
const preview = document.getElementById('preview');
|
|
7
|
+
|
|
8
|
+
const initialSource = `# Compile in a Worker
|
|
9
|
+
|
|
10
|
+
Edits are compiled off the main thread after a short debounce. Keep typing and the status below updates.
|
|
11
|
+
|
|
12
|
+
<slider bind="people" label="People" min="1" max="20">`;
|
|
13
|
+
|
|
14
|
+
editor.value = initialSource;
|
|
15
|
+
|
|
16
|
+
function createWorker() {
|
|
17
|
+
return new Worker(new URL('./worker.js', import.meta.url), { type: 'module' });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function formatDiagnostics(list) {
|
|
21
|
+
return list.length
|
|
22
|
+
? list.map((diagnostic) => `${diagnostic.line}:${diagnostic.column} ${diagnostic.code}: ${diagnostic.message}`).join('\n')
|
|
23
|
+
: 'No diagnostics.';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function showResult(outcome) {
|
|
27
|
+
const { result, duration, mode } = outcome;
|
|
28
|
+
status.textContent = `Compiled in ${duration} ms (${mode})`;
|
|
29
|
+
diagnostics.textContent = formatDiagnostics(result.diagnostics);
|
|
30
|
+
if (!result.ok) {
|
|
31
|
+
preview.textContent = 'No document';
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const heading = result.document.nodes.find((node) => node.type === 'heading');
|
|
35
|
+
const title = heading
|
|
36
|
+
? (heading.children ?? []).map((child) => child.value ?? '').join('') || 'Untitled'
|
|
37
|
+
: 'Untitled';
|
|
38
|
+
const bindings = Object.keys(result.document.bindings);
|
|
39
|
+
preview.textContent = [
|
|
40
|
+
`Title: ${title}`,
|
|
41
|
+
`Nodes: ${result.document.nodes.length}`,
|
|
42
|
+
`Bindings: ${bindings.length ? bindings.join(', ') : 'none'}`,
|
|
43
|
+
].join('\n');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const scheduler = new LocalCompileScheduler({
|
|
47
|
+
createWorker,
|
|
48
|
+
onResult: showResult,
|
|
49
|
+
onPendingChange: (pending) => {
|
|
50
|
+
if (pending) status.textContent = 'Compiling...';
|
|
51
|
+
},
|
|
52
|
+
onModeChange: (mode, detail) => {
|
|
53
|
+
status.textContent = mode === 'worker'
|
|
54
|
+
? 'Compiling in a Worker...'
|
|
55
|
+
: `Compiling on the main thread${detail ? ` (${detail})` : ''}`;
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
editor.addEventListener('input', () => scheduler.schedule(editor.value));
|
|
60
|
+
window.addEventListener('beforeunload', () => scheduler.dispose());
|
|
61
|
+
scheduler.schedule(editor.value);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "reactive-md-worker-example",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"engines": { "node": ">=22.12.0" },
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite --host 127.0.0.1",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"preview": "vite preview --host 127.0.0.1"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": { "reactive-md": "^0.4.0" },
|
|
12
|
+
"devDependencies": { "vite": "^8.3.5" }
|
|
13
|
+
}
|
package/examples/local/README.md
CHANGED
|
@@ -1,66 +1,72 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
| [
|
|
20
|
-
| [
|
|
21
|
-
| [
|
|
22
|
-
| [
|
|
23
|
-
| [
|
|
24
|
-
| [
|
|
25
|
-
| [
|
|
26
|
-
| [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
|
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
1
|
+
# Local interaction syntax demo
|
|
2
|
+
|
|
3
|
+
These are standalone authoring examples for `local-draft-2`, described in the [local interaction syntax specification](../../docs/local-interaction-syntax-en.md). The Playground starts with a [quick calculator](pricing.reactive.md), followed by six focused [feature tours](showcase/README.md). Components are distributed across these six scenarios; diagnostics has an auxiliary menu. Hosts can compile and render every document through the [local mode API](../../docs/local-integration-en.md).
|
|
4
|
+
|
|
5
|
+
The original eleven working examples and one intentionally broken diagnostics document remain in this directory, with Chinese versions in [zh/](zh/). The six feature tours live in [showcase/](showcase/README.md), with Chinese sources in [showcase/zh/](showcase/zh/). Each file runs independently. Controls, expressions and visualizations use local state.
|
|
6
|
+
|
|
7
|
+
## Start with the short examples
|
|
8
|
+
|
|
9
|
+
The [workshop recipe](recipes/workshop.reactive.md) ([中文](recipes/workshop-zh.reactive.md)) combines cross-field validation, conditional tones, numeric aggregates and generated table rows. See the [constraints and collections reference](../../docs/constraints-collections-en.md) for rules and budgets.
|
|
10
|
+
|
|
11
|
+
The [invoice recipe](recipes/invoice.reactive.md) ([中文](recipes/invoice-zh.reactive.md)) demonstrates shared calculations, constants, formatting and UTC date differences. The [calculation reference](../../docs/computations-formatting-en.md) explains its rules.
|
|
12
|
+
|
|
13
|
+
Start with the [plan calculator](pricing.reactive.md), then choose a [feature tour](showcase/README.md). For the smallest possible state example, read the original [counter](counter.reactive.md). If you are new to the syntax, read the [new user guide](../../docs/local-guide-en.md).
|
|
14
|
+
|
|
15
|
+
## Original standalone catalog
|
|
16
|
+
|
|
17
|
+
| File | Contents |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| [counter.reactive.md](counter.reactive.md) | One-line counter with built-in plus, minus and reset |
|
|
20
|
+
| [pricing.reactive.md](pricing.reactive.md) | Plan calculator with parameters linked inside a panel |
|
|
21
|
+
| [comparison.reactive.md](comparison.reactive.md) | Side-by-side comparison, a switch declared in place, tabs that manage their own selection |
|
|
22
|
+
| [parameters.reactive.md](parameters.reactive.md) | Live parameter panel with text, date and choice inputs |
|
|
23
|
+
| [checklist.reactive.md](checklist.reactive.md) | Fixed checkable list and an enhanced table |
|
|
24
|
+
| [charts.reactive.md](charts.reactive.md) | Charts built from tables, with a compound-interest formula in LaTeX |
|
|
25
|
+
| [diagram.reactive.md](diagram.reactive.md) | Auto-laid-out interactive diagram and curves |
|
|
26
|
+
| [catalog.reactive.md](catalog.reactive.md) | Local catalog search, sorting and paging |
|
|
27
|
+
| [planning.reactive.md](planning.reactive.md) | Timeline, timer and bill-splitting calculation |
|
|
28
|
+
| [components.reactive.md](components.reactive.md) | Content cards, disclosures, tabs and hint components |
|
|
29
|
+
| [gallery.reactive.md](gallery.reactive.md) | Common inputs, standalone components and code shown as-is |
|
|
30
|
+
| [diagnostics.reactive.md](diagnostics.reactive.md) | Intentionally broken diagnostics example |
|
|
31
|
+
|
|
32
|
+
The Playground example index is maintained in the repository's demo application.
|
|
33
|
+
|
|
34
|
+
## Expected behavior of the working examples
|
|
35
|
+
|
|
36
|
+
The table below lists the initial values and interaction checkpoints for each document. Numbers follow the formulas in the prose.
|
|
37
|
+
|
|
38
|
+
| Example | Initial display | Interaction checks |
|
|
39
|
+
| --- | --- | --- |
|
|
40
|
+
| comparison | Basic 100 USD, Pro 200 USD | Annual billing changes them to 80/160; switching tabs needs no declared variable; reset returns to monthly billing |
|
|
41
|
+
| parameters | Date 2026-10-22, personal use, name empty | Entering a name updates the card; selecting team use updates the description; checking the switch shows the preparation checklist; panel reset restores fields and switches |
|
|
42
|
+
| checklist | 1/3 items, progress about 33.33% | Selecting all shows the completion notice; reset restores only the first item; the table sorts by price, searches and pages |
|
|
43
|
+
| charts | 4 budget comparisons; savings parameters 10000, 500, 5%, 20 years; plan bars 40/70 | With the rate at 0 the end-of-curve readout is 130000; the default compound readout is about 232643.24; with 5 people the bars are 100/175 |
|
|
44
|
+
| diagram | Input node selected, a=1, f=1 | Clicking the compute node updates the details and prose; at a=0 the curve flattens and a notice appears; both fixed curves are shown together |
|
|
45
|
+
| catalog | 8 catalog rows, 4 rows per page | Searching for "visual" returns chart/plot/diagram; no match shows the empty state; reset clears the query, sorting and page |
|
|
46
|
+
| planning | 45-minute timeline, countdown paused at 60 seconds, 88 USD per person | timer start/pause/reset; with the extra charge at 0 each person pays 80 USD; the reference task starting at 15 overlaps the main section |
|
|
47
|
+
| components | Concise explanation, first disclosure open | Selecting detailed switches the prose; the tooltip is keyboard-focusable; other disclosures open independently |
|
|
48
|
+
| pricing | 2 people, 100 USD each, 200 USD total | Annual billing gives 160 USD; annual billing for 5 people is 400 USD and shows the team notice; reset returns to 200 USD |
|
|
49
|
+
| counter | 0 | Three increments show 3; three decrements return to 0 and disable minus; reset returns to 0 |
|
|
50
|
+
| gallery | Alex, quantity 3, Pro, monthly billing, cost 240 USD | Annual billing gives 192 USD; hiding and showing the express section keeps its checks; the standalone counter and timer need no bind; `example` in the code block creates no variable |
|
|
51
|
+
|
|
52
|
+
In parameters, the conditional checklist sits outside the panel: its existing checks survive hiding and are outside that panel's reset scope. The standalone counter and timer in gallery also sit outside the input panel, so resetting the input panel does not affect them.
|
|
53
|
+
|
|
54
|
+
## Expected results of the diagnostics example
|
|
55
|
+
|
|
56
|
+
[diagnostics.reactive.md](diagnostics.reactive.md) intentionally contains the following 9 error classes. The editor should collect recoverable, independent diagnostics, and the document as a whole must not activate interactions.
|
|
57
|
+
|
|
58
|
+
1. `seat` is not declared; the message can suggest the existing parameter `seats`.
|
|
59
|
+
2. `seats` has a duplicate explicit initial; both sources are reported.
|
|
60
|
+
3. `ratio` has initial value 12, above the maximum 10.
|
|
61
|
+
4. if.when receives `seats`, a number, where a boolean is required.
|
|
62
|
+
5. `slidr` is an unknown component; the message can suggest `slider`.
|
|
63
|
+
6. `on-click` is not part of counter or the local interaction event syntax.
|
|
64
|
+
7. The edge target `missing` does not exist.
|
|
65
|
+
8. The integral can be displayed but is not a computable structure in the first plot version.
|
|
66
|
+
9. The chart's cost column contains `20 USD`, text where a plain number is required.
|
|
67
|
+
|
|
68
|
+
## Check entry points
|
|
69
|
+
|
|
70
|
+
`npm test` checks parsing, bindings, expressions, LaTeX, the runtime and examples; `npm run test:demo` checks the Playground index; `npm run verify:release` runs the complete Node-side and browser gate, including real-tarball consumption and HTML export. See the [contributing guide](../../CONTRIBUTING.md) for individual commands.
|
|
71
|
+
|
|
72
|
+
The [six scenarios](showcase/README.md) include all 48 tag names: intervals, coordinates and numeric questions in Functions; input choices in Forms; linked selection in Data; jumps and prose colors in Layout; guided steps and choice questions in Flow; todos and timing in Checklists. The standalone gallery and interaction-tour sources remain available as authoring examples.
|