reactive-md 0.4.1 → 0.5.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 +144 -113
- package/CHANGELOG.md +144 -113
- package/LICENSE +21 -21
- package/README-ch.md +154 -123
- package/README-en.md +179 -147
- package/README.md +179 -147
- package/SECURITY-ch.md +4 -3
- package/SECURITY.md +4 -3
- package/THIRD_PARTY_NOTICES.md +138 -1
- package/bin/reactive-md.mjs +1 -1
- package/dist-library/reactive-md-editor.css +2 -0
- package/dist-library/reactive-md-editor.js +3834 -0
- package/dist-library/reactive-md-react.js +9324 -1670
- package/dist-library/reactive-md.css +1 -1
- package/dist-library/reactive-md.js +426 -305
- package/dist-library/{runtime-D3QTVYaz.js → runtime-CXBdLQ3A.js} +8950 -2895
- package/dist-library/types/editor/ReactiveMarkdownEditor.d.ts +7 -0
- package/dist-library/types/editor/editor-commands.d.ts +50 -0
- package/dist-library/types/editor/editor-i18n.d.ts +109 -0
- package/dist-library/types/editor/editor-toolbar.d.ts +24 -0
- package/dist-library/types/editor/editor-view-bar.d.ts +11 -0
- package/dist-library/types/editor/extended-native-components.d.ts +58 -0
- package/dist-library/types/editor/index.d.ts +9 -0
- package/dist-library/types/editor/locale.d.ts +13 -0
- package/dist-library/types/editor/native-components.d.ts +47 -0
- package/dist-library/types/editor/source-authoring.d.ts +57 -0
- package/dist-library/types/editor/types.d.ts +51 -0
- package/dist-library/types/editor/use-gutter-metrics.d.ts +5 -0
- package/dist-library/types/editor/use-source-history.d.ts +16 -0
- package/dist-library/types/local/LocalDocumentView.d.ts +10 -3
- package/dist-library/types/local/code-block.d.ts +26 -0
- package/dist-library/types/local/diagnostics.d.ts +25 -0
- package/dist-library/types/local/footnotes.d.ts +51 -0
- package/dist-library/types/local/heading-anchors.d.ts +2 -0
- package/dist-library/types/local/html.d.ts +16 -0
- package/dist-library/types/local/image-view.d.ts +23 -0
- package/dist-library/types/local/index.d.ts +1 -1
- package/dist-library/types/local/options.d.ts +29 -0
- package/dist-library/types/local/types.d.ts +42 -1
- package/dist-library/types/local/worker.d.ts +18 -6
- package/dist-library/types/shareable.d.ts +9 -1
- package/dist-standalone/reactive-md-standalone.css +1 -1
- package/dist-standalone/reactive-md-standalone.js +49 -38
- package/docs/compatibility-ch.md +12 -8
- package/docs/compatibility-en.md +12 -8
- package/docs/component-protocol-ch.md +2 -2
- package/docs/component-protocol-en.md +2 -2
- package/docs/editor-ch.md +235 -0
- package/docs/editor-en.md +235 -0
- package/docs/html-compatibility-ch.md +98 -0
- package/docs/html-compatibility-en.md +98 -0
- package/docs/local-guide-ch.md +11 -5
- package/docs/local-guide-en.md +11 -5
- package/docs/local-integration-ch.md +4 -1
- package/docs/local-integration-en.md +4 -1
- package/docs/local-interaction-syntax-ch.md +9 -2
- package/docs/local-interaction-syntax-en.md +7 -2
- package/docs/release-0.4.1-ch.md +23 -23
- package/docs/release-0.4.1-en.md +23 -23
- package/docs/release-0.5.0-ch.md +41 -0
- package/docs/release-0.5.0-en.md +41 -0
- package/docs/release-0.5.1-ch.md +39 -0
- package/docs/release-0.5.1-en.md +39 -0
- package/docs/releasing-ch.md +108 -101
- package/docs/releasing-en.md +108 -101
- package/docs/shareable-export-ch.md +6 -2
- package/docs/shareable-export-en.md +6 -2
- package/examples/integration/core/package.json +7 -7
- package/examples/integration/react/index.html +12 -12
- package/examples/integration/react/main.jsx +21 -21
- package/examples/integration/react/package.json +9 -9
- package/examples/integration/react-editor.tsx +74 -0
- package/examples/local/README.md +2 -0
- package/examples/local/catalog.reactive.md +20 -20
- package/examples/local/checklist.reactive.md +32 -32
- package/examples/local/comparison.reactive.md +47 -47
- package/examples/local/components.reactive.md +44 -44
- package/examples/local/counter.reactive.md +7 -7
- package/examples/local/diagnostics.reactive.md +54 -54
- package/examples/local/diagram.reactive.md +44 -44
- package/examples/local/gallery.reactive.md +61 -61
- package/examples/local/html-compat.reactive.md +24 -0
- package/examples/local/parameters.reactive.md +36 -36
- package/examples/local/planning.reactive.md +24 -24
- package/examples/local/pricing.reactive.md +20 -20
- package/examples/local/zh/catalog.reactive.md +20 -20
- package/examples/local/zh/charts.reactive.md +73 -73
- package/examples/local/zh/checklist.reactive.md +32 -32
- package/examples/local/zh/comparison.reactive.md +47 -47
- package/examples/local/zh/components.reactive.md +44 -44
- package/examples/local/zh/counter.reactive.md +7 -7
- package/examples/local/zh/diagnostics.reactive.md +54 -54
- package/examples/local/zh/diagram.reactive.md +44 -44
- package/examples/local/zh/gallery.reactive.md +61 -61
- package/examples/local/zh/parameters.reactive.md +36 -36
- package/examples/local/zh/planning.reactive.md +24 -24
- package/examples/local/zh/pricing.reactive.md +20 -20
- package/package.json +135 -91
package/docs/compatibility-ch.md
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
# 版本与兼容性
|
|
2
2
|
|
|
3
|
-
Reactive MD 目前是 0.x 预览版。本页说明包版本、语法版本、可持久化的内容、诊断契约和当前平台范围。显式修订声明、迁移 API 与 `reactive-md migrate` 见[源码修订与迁移](source-versioning-ch.md),公开 API 与样式接入见[本地模式集成](local-integration-ch.md)
|
|
3
|
+
Reactive MD 目前是 0.x 预览版。本页说明包版本、语法版本、可持久化的内容、诊断契约和当前平台范围。显式修订声明、迁移 API 与 `reactive-md migrate` 见[源码修订与迁移](source-versioning-ch.md),公开 API 与样式接入见[本地模式集成](local-integration-ch.md),当前预览见[0.5.0 发布说明](release-0.5.0-ch.md),该 minor 系列见[0.4.0 发布与迁移](release-0.4.0-ch.md)。
|
|
4
4
|
|
|
5
5
|
## 版本对应
|
|
6
6
|
|
|
7
7
|
| 项目 | 当前值 | 说明 |
|
|
8
8
|
| --- | --- | --- |
|
|
9
|
-
| 包版本 | `0.
|
|
10
|
-
| 分发标签 | `latest` → `0.4.0`;`next` → `0.
|
|
9
|
+
| 包版本 | `0.5.1` | 0.x 预览版;0.5.1 面向 `next`,`latest` 仍为 `0.4.0` |
|
|
10
|
+
| 分发标签 | `latest` → `0.4.0`;`next` → `0.5.1`(预览目标) | 默认安装使用 `latest` |
|
|
11
11
|
| 语法版本 | `local-draft-2` | `LOCAL_SYNTAX_VERSION`;当前构建只接受这一修订 |
|
|
12
12
|
| 源码修订指令 | 可选 `<!-- reactive-md: local-draft-2 -->` | 文档前导区中的一行;无指令源码继续按当前修订解析 |
|
|
13
13
|
| 组块协议 | `component-protocol-1` | 贡献与验收契约,见[组块协议](component-protocol-ch.md);不是运行时版本选择参数 |
|
|
14
14
|
| 核心入口 | `reactive-md` | 编译、表达式与运行时,不加载 React |
|
|
15
15
|
| React 入口 | `reactive-md/react` | `LocalReactiveDocument`、`LocalDocumentView` |
|
|
16
|
-
|
|
|
16
|
+
| 编辑器入口 | `reactive-md/editor` | `ReactiveMarkdownEditor` 及其类型;需要 React 19 |
|
|
17
|
+
| 渲染器样式入口 | `reactive-md/styles.css` | 文档与组块样式,由宿主显式引入 |
|
|
18
|
+
| 编辑器样式入口 | `reactive-md/editor/styles.css` | 独立编辑器样式,作用域限定在编辑器根节点 |
|
|
17
19
|
|
|
18
20
|
一个包版本只对应一个语法修订。升级包之前,记录应用使用的 `LOCAL_SYNTAX_VERSION`。如果文档源码来自另一个语法修订,保留旧包版本渲染,或按下面的迁移说明改写。`compileLocal(source, options?)` 不提供语法版本参数;宿主可以通过 `options.limits.maxSyntaxNodes` 调整单次编译的语法节点预算,见[本地模式集成](local-integration-ch.md)。
|
|
19
21
|
|
|
@@ -46,6 +48,8 @@ Reactive MD 目前是 0.x 预览版。本页说明包版本、语法版本、可
|
|
|
46
48
|
|
|
47
49
|
## 破坏性变更与迁移
|
|
48
50
|
|
|
51
|
+
`0.5.0` 新增 `reactive-md/editor` 入口及其独立样式表;`0.5.1` 新增编辑器视图、主题配色和 HTML 兼容。`local-draft-2`、`component-protocol-1` 和 `reactive-md-theme-1` 保持不变。现有 `reactive-md`、`reactive-md/react` 和 `reactive-md/styles.css` 导入继续有效,为 0.4.x 编写的文档无需迁移。编辑器需要 React 19;历史与渲染边界见[编辑器指南](editor-ch.md)。
|
|
52
|
+
|
|
49
53
|
`0.4.0` 新增[条件、校验与本地集合](constraints-collections-ch.md):`LocalRuntime.validate()`、可序列化的 `LocalValidation` 规则、数字数组及生成表格。自行实现运行时适配器的宿主需补充 `validate()`,值类型穷举需加入 `number-array`;与 `sum`、`average`、`minOf`、`maxOf` 同名的旧绑定应重命名。
|
|
50
54
|
|
|
51
55
|
`0.4.0` 新增[命名计算与格式化函数](computations-formatting-ch.md)。`computed`/`const` 使用现有本地标签形式;新函数名成为保留字,使用本版本前需重命名冲突的输入绑定并同步修改引用。`document.bindings` 和 `initialState` 继续只包含可写控件,快照同时提供成功求值的计算结果。
|
|
@@ -77,7 +81,7 @@ Reactive MD 目前是 0.x 预览版。本页说明包版本、语法版本、可
|
|
|
77
81
|
- `line`、`column` 和 `range` 可以用于程序定位和编辑器跳转。
|
|
78
82
|
- `code` 是字符串标识,例如 `local.type`、`expression-type`、`latex-plot-range`。同一 0.x minor 系列内,现有诊断码的含义保持稳定;可以新增码,删除、改名或改变含义须在新 minor 版本中说明迁移。
|
|
79
83
|
- `message` 是默认英文显示文本,使用 `formatLocalDiagnostic(diagnostic, 'zh')` 可取得中文。文案可以改进;不要解析 message 或按完整文本做业务判断。语言切换保留机器字段。
|
|
80
|
-
- `severity` 为 `warning` 或 `error
|
|
84
|
+
- `severity` 为 `warning` 或 `error`。结构完整的未知标签保留源码并给出降级警告,编译仍可成功;脚注正常排版。编译错误会让 `result.ok` 为 `false` 并停用预览。运行时局部错误只影响对应内容。
|
|
81
85
|
|
|
82
86
|
完整规则和资源单位见[诊断与计数规则](diagnostics-counting-ch.md)。
|
|
83
87
|
|
|
@@ -87,17 +91,17 @@ Reactive MD 目前是 0.x 预览版。本页说明包版本、语法版本、可
|
|
|
87
91
|
| --- | --- |
|
|
88
92
|
| Node.js 22.12+ | 开发和 Node 端消费的最低版本;CI 目标为 22.12 与 24 |
|
|
89
93
|
| ESM | 唯一模块格式;不提供 CommonJS 入口 |
|
|
90
|
-
| React 19 | `reactive-md/react` 的要求;核心入口不依赖 React |
|
|
94
|
+
| React 19 | `reactive-md/react` 和 `reactive-md/editor` 的要求;核心入口不依赖 React |
|
|
91
95
|
| Microsoft Edge(Chromium 内核) | 本地浏览器验证使用 Edge |
|
|
92
96
|
| Playwright Chromium | Linux CI 浏览器目标 |
|
|
93
97
|
| Firefox、Safari/WebKit | 未验证,不作支持声明 |
|
|
94
98
|
| 可分享状态格式 | `reactive-md-state/v1`:公开参数、语法版本与源码摘要;见[可分享文档](shareable-export-ch.md) |
|
|
95
99
|
| 单文件 HTML 格式 | `reactive-md-html/v1`:交互或静态导出;仅交互模式内嵌独立运行时 |
|
|
96
|
-
| SSR | `react-dom/server` 静态渲染由 packed
|
|
100
|
+
| SSR | `react-dom/server` 静态渲染由 packed 检查覆盖。编辑器入口没有顶层 DOM 访问,可在服务端导入和渲染;编辑交互在客户端运行。单文件导出的静态首屏水合已在 Playwright Chromium/Edge 验证;通用 SSR 水合未验证,使用前需自行检查 |
|
|
97
101
|
|
|
98
102
|
Node 端消费指在 Node 中导入 `reactive-md`、调用 `compileLocal` 和 `createLocalRuntime`,不需要 DOM。React 渲染要求浏览器环境或宿主自行处理服务端输出。
|
|
99
103
|
|
|
100
104
|
语言范围见[语法规范](local-interaction-syntax-ch.md),安全边界与宿主责任见[安全策略](../SECURITY-ch.md)。
|
|
101
105
|
|
|
102
106
|
|
|
103
|
-
新增组块、颜色、槽位状态与迁移规则见[local-draft-2 扩展说明](local-components-v2-ch.md),升级清单见[0.4.0 发布与迁移](release-0.4.0-ch.md)
|
|
107
|
+
新增组块、颜色、槽位状态与迁移规则见[local-draft-2 扩展说明](local-components-v2-ch.md),升级清单见[0.4.0 发布与迁移](release-0.4.0-ch.md)。0.5.1 预览版面向 `next`,`latest` 仍为 `0.4.0`。
|
package/docs/compatibility-en.md
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
# Versions and compatibility
|
|
2
2
|
|
|
3
|
-
Reactive MD is currently a 0.x preview. This page covers package versions, syntax versions, what can be persisted, the diagnostics contract and the current platform scope. See [Source revisions and migration](source-versioning-en.md) for explicit revision declarations, the migration API and `reactive-md migrate`, [Local mode integration](local-integration-en.md) for the public API and style integration, and [0.4.0 release and migration](release-0.4.0-en.md) for
|
|
3
|
+
Reactive MD is currently a 0.x preview. This page covers package versions, syntax versions, what can be persisted, the diagnostics contract and the current platform scope. See [Source revisions and migration](source-versioning-en.md) for explicit revision declarations, the migration API and `reactive-md migrate`, [Local mode integration](local-integration-en.md) for the public API and style integration, [0.5.0 release notes](release-0.5.0-en.md) for the current preview, and [0.4.0 release and migration](release-0.4.0-en.md) for that minor series.
|
|
4
4
|
|
|
5
5
|
## Version mapping
|
|
6
6
|
|
|
7
7
|
| Item | Current value | Notes |
|
|
8
8
|
| --- | --- | --- |
|
|
9
|
-
| Package version | `0.
|
|
10
|
-
| Distribution tags | `latest` → `0.4.0`; `next` → `0.
|
|
9
|
+
| Package version | `0.5.1` | 0.x preview; 0.5.1 targets `next`, while `latest` remains `0.4.0` |
|
|
10
|
+
| Distribution tags | `latest` → `0.4.0`; `next` → `0.5.1` (preview target) | Default installs use `latest` |
|
|
11
11
|
| Syntax version | `local-draft-2` | `LOCAL_SYNTAX_VERSION`; the current build accepts only this revision |
|
|
12
12
|
| Source revision directive | Optional `<!-- reactive-md: local-draft-2 -->` | One line in the document prologue; unversioned source keeps current-revision behavior |
|
|
13
13
|
| Component protocol | `component-protocol-1` | Contribution and acceptance contract, see [Component protocol](component-protocol-en.md); not a runtime version selection parameter |
|
|
14
14
|
| Core entry | `reactive-md` | Compilation, expressions and runtime, without loading React |
|
|
15
15
|
| React entry | `reactive-md/react` | `LocalReactiveDocument`, `LocalDocumentView` |
|
|
16
|
-
|
|
|
16
|
+
| Editor entry | `reactive-md/editor` | `ReactiveMarkdownEditor` and its types; requires React 19 |
|
|
17
|
+
| Renderer style entry | `reactive-md/styles.css` | Document and component styles, explicitly imported by the host |
|
|
18
|
+
| Editor style entry | `reactive-md/editor/styles.css` | Independent editor styles, scoped to the editor root |
|
|
17
19
|
|
|
18
20
|
One package version corresponds to exactly one syntax revision. Before upgrading the package, record the `LOCAL_SYNTAX_VERSION` your application uses. If document sources come from another syntax revision, keep rendering them with the old package version or rewrite them according to the migration notes below. `compileLocal(source, options?)` has no syntax version parameter; hosts can adjust the syntax node budget for a single compilation through `options.limits.maxSyntaxNodes`, see [Local mode integration](local-integration-en.md).
|
|
19
21
|
|
|
@@ -46,6 +48,8 @@ Regression data in [the historical corpus](../examples/conformance/history/v0.3.
|
|
|
46
48
|
|
|
47
49
|
## Breaking changes and migration
|
|
48
50
|
|
|
51
|
+
`0.5.0` added the `reactive-md/editor` entry and its independent stylesheet. `0.5.1` adds editor views, theme palettes and HTML compatibility. They keep `local-draft-2`, `component-protocol-1` and `reactive-md-theme-1`. Existing `reactive-md`, `reactive-md/react` and `reactive-md/styles.css` imports keep working, and documents written for 0.4.x need no migration. The editor requires React 19; see the [editor guide](editor-en.md) for its history and rendering boundaries.
|
|
52
|
+
|
|
49
53
|
`0.4.0` adds [constraints and collections](constraints-collections-en.md): `LocalRuntime.validate()`, serializable `LocalValidation` rules, numeric arrays and generated tables. Hosts implementing a runtime adapter need the new `validate()` method; exhaustive value-kind checks need `number-array`. Rename bindings colliding with `sum`, `average`, `minOf` or `maxOf`.
|
|
50
54
|
|
|
51
55
|
`0.4.0` adds [named calculations and formatting functions](computations-formatting-en.md). `computed`/`const` use the existing local tag syntax. The new built-in function names become reserved; rename colliding input bindings and their references before using this release. `document.bindings` and `initialState` still contain writable controls; snapshots also expose successful calculated values.
|
|
@@ -77,7 +81,7 @@ Persist the original `.reactive.md` source. A `reactive-md-state/v1` file may pr
|
|
|
77
81
|
- `line`, `column` and `range` can be used for programmatic location and editor jumps.
|
|
78
82
|
- `code` is a string identifier, such as `local.type`, `expression-type` or `latex-plot-range`. Existing codes keep their meaning within one 0.x minor series. New codes may be added; removal, renaming or a change of meaning requires a new minor version and migration notes.
|
|
79
83
|
- `message` contains default English display text. Use `formatLocalDiagnostic(diagnostic, 'zh')` for Chinese. Wording may improve; do not parse messages or make business decisions based on their complete text. Language changes preserve machine fields.
|
|
80
|
-
- `severity` is `warning` or `error`. Structurally complete unknown tags
|
|
84
|
+
- `severity` is `warning` or `error`. Structurally complete unknown tags keep their source and produce fallback warnings, and compilation can still succeed; footnotes render normally. Compile errors make `result.ok` `false` and disable the preview. Runtime local errors affect only the corresponding content.
|
|
81
85
|
|
|
82
86
|
See [Diagnostics and counting rules](diagnostics-counting-en.md) for units and resource-budget scopes.
|
|
83
87
|
|
|
@@ -87,17 +91,17 @@ See [Diagnostics and counting rules](diagnostics-counting-en.md) for units and r
|
|
|
87
91
|
| --- | --- |
|
|
88
92
|
| Node.js 22.12+ | Minimum for development and Node-side consumption; CI targets both 22.12 and 24 |
|
|
89
93
|
| ESM | The only module format; no CommonJS entry |
|
|
90
|
-
| React 19 | Required by `reactive-md/react`; the core entry does not depend on React |
|
|
94
|
+
| React 19 | Required by `reactive-md/react` and `reactive-md/editor`; the core entry does not depend on React |
|
|
91
95
|
| Microsoft Edge (Chromium-based) | Local browser verification has used Edge |
|
|
92
96
|
| Playwright Chromium | Linux CI browser target |
|
|
93
97
|
| Firefox, Safari/WebKit | Unverified; no support claim |
|
|
94
98
|
| Shareable state format | `reactive-md-state/v1`: public parameter values with a syntax version and source digest; see [Shareable documents](shareable-export-en.md) |
|
|
95
99
|
| Single-file HTML format | `reactive-md-html/v1`: interactive or static export, with an inline standalone runtime only in interactive mode |
|
|
96
|
-
| SSR | `react-dom/server` static rendering is covered by the packed check. Static-first hydration of the single-file export is covered in Playwright Chromium/Edge; general SSR hydration is unverified and should be checked before use |
|
|
100
|
+
| SSR | `react-dom/server` static rendering is covered by the packed check. The editor entry has no top-level DOM access and can be imported and rendered on the server; editing interactions run on the client. Static-first hydration of the single-file export is covered in Playwright Chromium/Edge; general SSR hydration is unverified and should be checked before use |
|
|
97
101
|
|
|
98
102
|
Node-side consumption means importing `reactive-md` in Node and calling `compileLocal` and `createLocalRuntime` without a DOM. React rendering requires a browser environment, or the host must handle server output itself.
|
|
99
103
|
|
|
100
104
|
See the [syntax specification](local-interaction-syntax-en.md) for the language scope, and the [security policy](../SECURITY.md) for the security boundary and host responsibilities.
|
|
101
105
|
|
|
102
106
|
|
|
103
|
-
See [local-draft-2 components and migration](local-components-v2-en.md) for new tags, colors and slot state, and [0.4.0 release and migration](release-0.4.0-en.md) for the upgrade checklist.
|
|
107
|
+
See [local-draft-2 components and migration](local-components-v2-en.md) for new tags, colors and slot state, and [0.4.0 release and migration](release-0.4.0-en.md) for the upgrade checklist. The 0.5.1 preview targets `next`; `latest` remains `0.4.0`.
|
|
@@ -333,11 +333,11 @@ range-slider 和 coordinate 的每个数值槽位也独占拥有绑定;范围
|
|
|
333
333
|
- 成功:`ok: true`,带有文档和诊断;诊断可以包含警告。
|
|
334
334
|
- 失败:`ok: false`,只有诊断;交互预览停用。
|
|
335
335
|
|
|
336
|
-
|
|
336
|
+
结构完整但未知的标签产生警告;组件结构不完整、标签错配、已知组块的未知属性或类型错误、绑定错误、表达式错误和预算超限产生错误。错误阻止编译成功,警告不阻止。正常脚注不产生不支持警告。
|
|
337
337
|
|
|
338
338
|
### CP-DIAG-03 降级隔离(现有)
|
|
339
339
|
|
|
340
|
-
结构完整的未知标签按原始源码显示,给出 `local.component.unknown`
|
|
340
|
+
结构完整的未知标签按原始源码显示,给出 `local.component.unknown` 警告。降级区域内的控件、插值和公式不执行,不初始化绑定,也不产生网络动作。脚注支持 Markdown 排版、编号和返回链接;脚注正文中的控件与插值仍按文字显示,不初始化绑定。其他正文和交互继续工作。
|
|
341
341
|
|
|
342
342
|
无法可靠恢复的未知标签和标签结构错误仍然阻止编译,不能通过降级绕过校验。
|
|
343
343
|
|
|
@@ -333,11 +333,11 @@ Compilation has exactly two outcomes:
|
|
|
333
333
|
- Success: `ok: true`, with the document and diagnostics; diagnostics may contain warnings.
|
|
334
334
|
- Failure: `ok: false`, with diagnostics only; the interactive preview is disabled.
|
|
335
335
|
|
|
336
|
-
Structurally complete but unknown tags
|
|
336
|
+
Structurally complete but unknown tags produce warnings; incomplete component structures, mismatched tags, unknown attributes or type errors on known components, binding errors, expression errors and budget overruns produce errors. Errors block successful compilation; warnings do not. Normal footnotes produce no unsupported-syntax warning.
|
|
337
337
|
|
|
338
338
|
### CP-DIAG-03 Fallback isolation (existing)
|
|
339
339
|
|
|
340
|
-
Structurally complete unknown tags are displayed as original source with a `local.component.unknown` warning. Controls, interpolations and formulas inside the fallback region are not executed, do not initialize bindings and cause no network actions.
|
|
340
|
+
Structurally complete unknown tags are displayed as original source with a `local.component.unknown` warning. Controls, interpolations and formulas inside the fallback region are not executed, do not initialize bindings and cause no network actions. Footnotes support Markdown layout, numbering and return links; controls and interpolations inside definitions remain text and create no bindings. Other prose and interactions keep working.
|
|
341
341
|
|
|
342
342
|
Unknown tags that cannot be reliably recovered and tag structure errors still block compilation; fallback cannot be used to bypass validation.
|
|
343
343
|
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# React 源码编辑器
|
|
2
|
+
|
|
3
|
+
`reactive-md/editor` 是用于 Reactive MD 源码的受控 React 19 编辑器,由 Playground 编辑器抽出。它提供源码高亮、格式与插入工具栏、补全、绑定导航、重命名与格式化、撤销重做、行号及滚动同步。编辑器内置字数底栏及编辑、并排、预览三种视图。宿主保存源码,并提供预览内容、持久化和导出。
|
|
4
|
+
|
|
5
|
+
编辑器有独立样式表 `reactive-md/editor/styles.css`,与 `reactive-md/styles.css` 分开。只编辑源码的页面不会加载文档渲染样式。
|
|
6
|
+
|
|
7
|
+
编辑器属于 `0.5.0` 预览版,目标渠道为 `next`;`latest` 仍为 `0.4.0`。现有 `reactive-md`、`reactive-md/react` 和 `reactive-md/styles.css` 导入保持不变。
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install reactive-md@next
|
|
13
|
+
npm install react@19 react-dom@19
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
需要固定预览版时使用 `npm install reactive-md@0.5.0`。包只提供 ESM,工具和服务端渲染需要 Node.js 22.12 或更新版本。
|
|
17
|
+
|
|
18
|
+
## 最小受控编辑器
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { useState } from 'react';
|
|
22
|
+
import { ReactiveMarkdownEditor } from 'reactive-md/editor';
|
|
23
|
+
import 'reactive-md/editor/styles.css';
|
|
24
|
+
|
|
25
|
+
const initialSource = `# 费用估算
|
|
26
|
+
|
|
27
|
+
<slider bind="people" label="人数" initial="2" min="1" max="20">
|
|
28
|
+
|
|
29
|
+
每月费用:**{{ people * 100 }} 元**。`;
|
|
30
|
+
|
|
31
|
+
export function SourceEditor() {
|
|
32
|
+
const [source, setSource] = useState(initialSource);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<ReactiveMarkdownEditor
|
|
36
|
+
value={source}
|
|
37
|
+
onChange={setSource}
|
|
38
|
+
ariaLabel="文档源码"
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`value` 和 `onChange` 为必需属性。组件渲染一个 textarea,并维护自己的撤销历史;源码文本保存在宿主状态中。内置文案默认为英文。
|
|
45
|
+
|
|
46
|
+
## 入口
|
|
47
|
+
|
|
48
|
+
| 入口 | 内容 | 依赖 |
|
|
49
|
+
| --- | --- | --- |
|
|
50
|
+
| `reactive-md/editor` | `ReactiveMarkdownEditor` 及其类型 | React 19 |
|
|
51
|
+
| `reactive-md/editor/styles.css` | 编辑器样式,作用域限定在编辑器根节点 | 由宿主显式引入 |
|
|
52
|
+
|
|
53
|
+
样式表在应用或渲染编辑器的组件模块中引入一次即可。支持 CSS 导入的构建工具或框架可以把它放在编辑器模块旁边。
|
|
54
|
+
|
|
55
|
+
## ref 句柄
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import { useRef, useState } from 'react';
|
|
59
|
+
import {
|
|
60
|
+
ReactiveMarkdownEditor,
|
|
61
|
+
type ReactiveMarkdownEditorHandle,
|
|
62
|
+
} from 'reactive-md/editor';
|
|
63
|
+
|
|
64
|
+
export function SourceEditor() {
|
|
65
|
+
const [source, setSource] = useState('');
|
|
66
|
+
const editor = useRef<ReactiveMarkdownEditorHandle>(null);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<button type="button" onClick={() => editor.current?.focus()}>聚焦</button>
|
|
71
|
+
<button type="button" onClick={() => editor.current?.undo()}>撤销</button>
|
|
72
|
+
<button type="button" onClick={() => editor.current?.selectRange({ start: 0, end: 5 })}>
|
|
73
|
+
选中标题
|
|
74
|
+
</button>
|
|
75
|
+
<ReactiveMarkdownEditor ref={editor} value={source} onChange={setSource} />
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
| 方法 | 行为 |
|
|
82
|
+
| --- | --- |
|
|
83
|
+
| `focus(selection?)` | 聚焦 textarea,可同时应用选区。 |
|
|
84
|
+
| `selectRange(range)` | 选中一段源码。区间与编译诊断一样使用 UTF-16 半开区间偏移。 |
|
|
85
|
+
| `getSelection()` | 返回当前选区。 |
|
|
86
|
+
| `getTextarea()` | 返回底层 textarea;挂载前为 `null`。 |
|
|
87
|
+
| `undo()` / `redo()` | 在该实例的历史中前后移动,并通过 `onChange` 发出结果值。到达历史两端或 `readOnly`、`disabled` 时不执行操作。 |
|
|
88
|
+
|
|
89
|
+
入口同时导出 `ReactiveMarkdownEditorProps`、`ReactiveMarkdownEditorHandle`、`EditorLocale`、`EditorTheme` 和 `EditorSelection` 类型。
|
|
90
|
+
|
|
91
|
+
## 属性
|
|
92
|
+
|
|
93
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
94
|
+
| --- | --- | --- | --- |
|
|
95
|
+
| `value` | `string` | 必需 | 受控源码文本。 |
|
|
96
|
+
| `onChange` | `(value: string) => void` | 必需 | 接收输入、工具栏命令及撤销重做后的新源码。 |
|
|
97
|
+
| `locale` | `'en' \| 'zh'` | `'en'` | 该实例的内置文案语言,不改变源码内容。 |
|
|
98
|
+
| `theme` | `'light' \| 'dark' \| 'auto'` | `'auto'` | 在编辑器根节点设置 `data-editor-theme`。`auto` 跟随系统偏好。 |
|
|
99
|
+
| `preview` | `ReactNode` | 无 | 在编辑器内部渲染的预览内容。提供后启用底栏三种视图切换。 |
|
|
100
|
+
| `viewMode` | `EditorViewMode` | 无 | 受控视图:`'edit'`、`'split'` 或 `'preview'`。 |
|
|
101
|
+
| `defaultViewMode` | `EditorViewMode` | `'edit'` | 非受控视图的初始模式。 |
|
|
102
|
+
| `onViewModeChange` | `(mode: EditorViewMode) => void` | 无 | 用户点击底栏视图按钮时调用。 |
|
|
103
|
+
| `id` | `string` | 自动生成 | textarea 的 id。实例用它关联内部标签和行号栏。 |
|
|
104
|
+
| `className` | `string` | 无 | 加到 `.reactive-md-editor` 根节点。 |
|
|
105
|
+
| `style` | `CSSProperties` | 无 | 根节点的内联样式。 |
|
|
106
|
+
| `height` | `number \| string` | `560` | 数字按像素计算,字符串可使用任意 CSS 长度。 |
|
|
107
|
+
| `minHeight` | `number \| string` | `280` | 最小高度,单位规则与 `height` 相同。 |
|
|
108
|
+
| `placeholder` | `string` | 无 | 源码为空时的占位提示。 |
|
|
109
|
+
| `ariaLabel` | `string` | 本地化标签 | textarea 的可访问名称。 |
|
|
110
|
+
| `readOnly` | `boolean` | `false` | 文本仍可选中和复制,但不能修改。 |
|
|
111
|
+
| `disabled` | `boolean` | `false` | 阻止聚焦和编辑。 |
|
|
112
|
+
| `documentKey` | `string \| number` | 无 | 切换到独立源码文档时修改该值。变化会重置撤销历史与选区。 |
|
|
113
|
+
| `diagnostics` | `readonly Diagnostic[]` | 无 | 在行号栏标记诊断所在行,不阻止输入,也不代替宿主校验。 |
|
|
114
|
+
| `document` | `LocalDocument \| null` | `null` | 已编译文档,用于作者工具显示绑定值类型。编辑器不会编译它。 |
|
|
115
|
+
| `toolbar` | `boolean` | `true` | 显示格式与插入工具栏,包括导出操作。 |
|
|
116
|
+
| `authoring` | `boolean` | `true` | 启用补全、绑定导航、重命名和格式化工具。 |
|
|
117
|
+
| `onExport` | `() => void` | 无 | 工具栏导出操作调用该回调,用于打开宿主导出对话框或自行写文件。 |
|
|
118
|
+
| `textareaRef` | `RefObject<HTMLTextAreaElement \| null>` | 无 | 接收底层 textarea,供宿主的高级用法读取。 |
|
|
119
|
+
|
|
120
|
+
## 编辑器内置视图
|
|
121
|
+
|
|
122
|
+
底栏位于编辑器边框内,紧贴编辑区域下缘,显示 Unicode 字符数和视图按钮。提供 `preview` 后,编辑器管理编辑、并排和预览布局。容器宽度不超过 600px 时,仅显示编辑和预览选项;并排模式暂时显示为编辑模式,恢复宽屏后回到并排。
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
<ReactiveMarkdownEditor
|
|
126
|
+
value={source}
|
|
127
|
+
onChange={setSource}
|
|
128
|
+
preview={<LocalDocumentView document={compiledDocument} />}
|
|
129
|
+
defaultViewMode="split"
|
|
130
|
+
/>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
切换视图会保留源码选区、撤销历史及预览组件的状态。需要从外部控制视图时,同时传入 `viewMode` 和 `onViewModeChange`。只编辑源码时可省略 `preview`,底栏保留字符数及键盘提示。在源码中按 Esc,再按 Tab 可聚焦工具栏。
|
|
134
|
+
|
|
135
|
+
## 受控值与历史
|
|
136
|
+
|
|
137
|
+
每次编辑都会以新源码调用 `onChange`,包括输入、工具栏格式化、插入模板、重命名、格式化及撤销重做。把该值回传给 `value`。编辑器把自己发出的修改视为当前会话的一部分,常规受控值回传会保留撤销步骤。
|
|
138
|
+
|
|
139
|
+
外部修改 `value` 会更新显示的文本。宿主用另一份独立文档替换文本时,在同一次渲染中修改 `documentKey`。键变化会清空撤销重做、重置选区并采用新值。
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
const [documentKey, setDocumentKey] = useState('estimate');
|
|
143
|
+
const [source, setSource] = useState(loadSource('estimate'));
|
|
144
|
+
|
|
145
|
+
function openDocument(key: string, text: string) {
|
|
146
|
+
setDocumentKey(key);
|
|
147
|
+
setSource(text);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
<ReactiveMarkdownEditor
|
|
151
|
+
value={source}
|
|
152
|
+
onChange={setSource}
|
|
153
|
+
documentKey={documentKey}
|
|
154
|
+
/>
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
撤销历史属于当前挂载实例,不保存、不跨实例共享,也不从整个 `value` 属性推导。切换文档时修改 `documentKey`,不要在每次输入时重新挂载组件。
|
|
158
|
+
|
|
159
|
+
## 语言与主题
|
|
160
|
+
|
|
161
|
+
每个实例使用自己的语言和主题。编辑器不修改文档的 `data-theme` 属性,不写入浏览器存储,也不读取 Playground 的语言设置。
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
<ReactiveMarkdownEditor
|
|
165
|
+
value={source}
|
|
166
|
+
onChange={setSource}
|
|
167
|
+
locale="zh"
|
|
168
|
+
theme="dark"
|
|
169
|
+
/>
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`theme="auto"` 跟随系统颜色偏好,并响应偏好变化。同一页面的两个编辑器可以使用不同设置。主题通过 `.reactive-md-editor` 根节点上的本地 `data-editor-theme` 属性设置。
|
|
173
|
+
|
|
174
|
+
## 只读与禁用
|
|
175
|
+
|
|
176
|
+
`readOnly` 保留源码显示、聚焦和选择,输入、工具栏、补全、重命名、格式化以及 ref 的 `undo`、`redo` 都不能改变值。
|
|
177
|
+
|
|
178
|
+
`disabled` 同时阻止聚焦和指针交互。两种模式均会禁用工具栏导出操作,不会自行改变值或历史。宿主不允许编辑源码时使用它们,例如展示只读预览期间。
|
|
179
|
+
|
|
180
|
+
宿主从外部替换 `value` 或改变 `documentKey` 时,编辑器重置历史、选区和滚动位置;回传 `onChange` 收到的值会保留这些状态。未提供 `onExport` 时隐藏导出按钮。
|
|
181
|
+
|
|
182
|
+
## 诊断与已编译文档
|
|
183
|
+
|
|
184
|
+
可选的作者工具会在本地分析源码并检查语法。预览文档的编译由宿主管理;需要行标记或绑定值类型时,可把该结果传入:
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
import { compileLocal } from 'reactive-md';
|
|
188
|
+
|
|
189
|
+
const result = compileLocal(source);
|
|
190
|
+
|
|
191
|
+
<ReactiveMarkdownEditor
|
|
192
|
+
value={source}
|
|
193
|
+
onChange={setSource}
|
|
194
|
+
diagnostics={result.diagnostics}
|
|
195
|
+
document={result.ok ? result.document : null}
|
|
196
|
+
/>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
`diagnostics` 在行号栏标记报告所在行。未完成的源码仍可继续输入,编译错误不会锁住 textarea。`document` 为作者检查面板提供绑定值类型。两个属性都可省略;只编辑 Markdown 时无需传入。
|
|
200
|
+
|
|
201
|
+
## 尺寸与布局
|
|
202
|
+
|
|
203
|
+
编辑器填满容器宽度。`height` 默认 `560px`,`minHeight` 默认 `280px`;数字按像素处理,字符串可以使用 `vh`、`rem` 等 CSS 长度。行号栏随行数变化,软换行时行号和高亮仍与滚动位置同步。
|
|
204
|
+
|
|
205
|
+
在宿主布局中使用 `className` 或 `style` 控制外边距和位置。内部元素类名属于实现细节。
|
|
206
|
+
|
|
207
|
+
## 工具栏与作者工具
|
|
208
|
+
|
|
209
|
+
`toolbar={false}` 移除格式与插入工具栏,包括导出操作。`authoring={false}` 保留 textarea 和工具栏,但停用语法高亮、补全、绑定导航、重命名和格式化。两者默认启用。
|
|
210
|
+
|
|
211
|
+
工具栏处理 Markdown 格式,插入列表、表格、链接、图片和内置组块模板,并提供撤销重做。格式化命令基于当前选区,通过 `onChange` 返回新源码。
|
|
212
|
+
|
|
213
|
+
## 宿主职责
|
|
214
|
+
|
|
215
|
+
编辑器负责编辑源码,其余由宿主处理:
|
|
216
|
+
|
|
217
|
+
- 预览:编译 `value`,用 `reactive-md/react` 或自己的运行时渲染。
|
|
218
|
+
- 持久化:保存源码。编辑器不自动保存、不写入本地存储,也不把源码发送到任何地方。
|
|
219
|
+
- 导出:通过 `onExport` 把工具栏操作接到 HTML 导出、下载对话框或文件服务。编辑器不生成可分享的 HTML 文件。
|
|
220
|
+
|
|
221
|
+
编译调度和防抖同样属于宿主。见[本地模式集成](local-integration-ch.md)与[可分享文档与静态导出](shareable-export-ch.md)。包含编辑器、预览和文档切换的完整示例见 [react-editor.tsx](../examples/integration/react-editor.tsx)。
|
|
222
|
+
|
|
223
|
+
## 服务端渲染
|
|
224
|
+
|
|
225
|
+
编辑器入口没有顶层 `window` 或 `document` 访问。用 `react-dom/server` 导入并渲染初始 textarea 是安全的。聚焦、选区、补全、布局测量和工具栏菜单在浏览器挂载后运行,交互检查和浏览器测试需要客户端环境。
|
|
226
|
+
|
|
227
|
+
## 样式与作用域
|
|
228
|
+
|
|
229
|
+
`reactive-md/editor/styles.css` 包含编辑器自己的 token 和规则,所有选择器限定在 `.reactive-md-editor` 及其后代,不会改写宿主的按钮、输入框或页面正文。主题由上面的实例属性提供。
|
|
230
|
+
|
|
231
|
+
同一页面还渲染文档预览时,再引入 `reactive-md/styles.css`。两份样式表彼此独立,加载顺序不限。
|
|
232
|
+
|
|
233
|
+
## 兼容性
|
|
234
|
+
|
|
235
|
+
`0.5.0` 新增编辑器入口,`local-draft-2`、`component-protocol-1` 和 `reactive-md-theme-1` 保持不变。只渲染文档的项目升级时无需修改导入或源码。编辑器是新增入口,没有旧 API 需要迁移。见[0.5.0 发布说明](release-0.5.0-ch.md)与[版本与兼容性](compatibility-ch.md)。
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# React source editor
|
|
2
|
+
|
|
3
|
+
`reactive-md/editor` is a controlled React 19 editor for Reactive MD source. It comes from the Playground editor and provides source highlighting, a formatting and insertion toolbar, completion, binding navigation, rename and format commands, undo and redo, line numbers and scroll synchronization. Its built-in status bar provides a character count and Edit, Split and Preview views. The host keeps the source text and supplies preview content, persistence and export.
|
|
4
|
+
|
|
5
|
+
The editor has its own stylesheet at `reactive-md/editor/styles.css`. It is separate from `reactive-md/styles.css`, so a page that only edits source does not load document rendering styles.
|
|
6
|
+
|
|
7
|
+
The editor is part of the `0.5.0` preview, which targets the `next` channel. `latest` remains `0.4.0`. Existing `reactive-md`, `reactive-md/react` and `reactive-md/styles.css` imports are unchanged.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install reactive-md@next
|
|
13
|
+
npm install react@19 react-dom@19
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Pin the preview with `npm install reactive-md@0.5.0`. The package ships ESM only and needs Node.js 22.12 or newer for tooling and server rendering.
|
|
17
|
+
|
|
18
|
+
## Minimal controlled editor
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { useState } from 'react';
|
|
22
|
+
import { ReactiveMarkdownEditor } from 'reactive-md/editor';
|
|
23
|
+
import 'reactive-md/editor/styles.css';
|
|
24
|
+
|
|
25
|
+
const initialSource = `# Cost estimate
|
|
26
|
+
|
|
27
|
+
<slider bind="people" label="People" initial="2" min="1" max="20">
|
|
28
|
+
|
|
29
|
+
Monthly cost: **{{ people * 100 }} USD**.`;
|
|
30
|
+
|
|
31
|
+
export function SourceEditor() {
|
|
32
|
+
const [source, setSource] = useState(initialSource);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<ReactiveMarkdownEditor
|
|
36
|
+
value={source}
|
|
37
|
+
onChange={setSource}
|
|
38
|
+
ariaLabel="Document source"
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`value` and `onChange` are required. The component renders a textarea and keeps its own undo history. The source text stays in your state. Built-in labels default to English.
|
|
45
|
+
|
|
46
|
+
## Entries
|
|
47
|
+
|
|
48
|
+
| Entry | Contents | Dependency |
|
|
49
|
+
| --- | --- | --- |
|
|
50
|
+
| `reactive-md/editor` | `ReactiveMarkdownEditor` and its types | React 19 |
|
|
51
|
+
| `reactive-md/editor/styles.css` | Editor styles, scoped to the editor root | Imported explicitly by the host |
|
|
52
|
+
|
|
53
|
+
Import the stylesheet once in the application or in the component module that renders the editor. A bundler or framework that handles CSS imports can place it with the editor module.
|
|
54
|
+
|
|
55
|
+
## Ref handle
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import { useRef, useState } from 'react';
|
|
59
|
+
import {
|
|
60
|
+
ReactiveMarkdownEditor,
|
|
61
|
+
type ReactiveMarkdownEditorHandle,
|
|
62
|
+
} from 'reactive-md/editor';
|
|
63
|
+
|
|
64
|
+
export function SourceEditor() {
|
|
65
|
+
const [source, setSource] = useState('');
|
|
66
|
+
const editor = useRef<ReactiveMarkdownEditorHandle>(null);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<button type="button" onClick={() => editor.current?.focus()}>Focus</button>
|
|
71
|
+
<button type="button" onClick={() => editor.current?.undo()}>Undo</button>
|
|
72
|
+
<button type="button" onClick={() => editor.current?.selectRange({ start: 0, end: 5 })}>
|
|
73
|
+
Select heading
|
|
74
|
+
</button>
|
|
75
|
+
<ReactiveMarkdownEditor ref={editor} value={source} onChange={setSource} />
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
| Method | Behavior |
|
|
82
|
+
| --- | --- |
|
|
83
|
+
| `focus(selection?)` | Focuses the textarea. Applies the optional selection. |
|
|
84
|
+
| `selectRange(range)` | Selects a source range. Ranges use the same UTF-16 half-open offsets as compile diagnostics. |
|
|
85
|
+
| `getSelection()` | Returns the current selection. |
|
|
86
|
+
| `getTextarea()` | Returns the underlying textarea, or `null` before mount. |
|
|
87
|
+
| `undo()` / `redo()` | Moves through this instance's history and emits the resulting value through `onChange`. Both are no-ops at the ends of the history and while `readOnly` or `disabled` is set. |
|
|
88
|
+
|
|
89
|
+
The entry also exports `ReactiveMarkdownEditorProps`, `ReactiveMarkdownEditorHandle`, `EditorLocale`, `EditorTheme` and `EditorSelection` types.
|
|
90
|
+
|
|
91
|
+
## Props
|
|
92
|
+
|
|
93
|
+
| Prop | Type | Default | Notes |
|
|
94
|
+
| --- | --- | --- | --- |
|
|
95
|
+
| `value` | `string` | required | Controlled source text. |
|
|
96
|
+
| `onChange` | `(value: string) => void` | required | Receives the next source for typing, toolbar commands and undo or redo. |
|
|
97
|
+
| `locale` | `'en' \| 'zh'` | `'en'` | Built-in labels for this instance. Source text is unchanged. |
|
|
98
|
+
| `theme` | `'light' \| 'dark' \| 'auto'` | `'auto'` | Sets `data-editor-theme` on the editor root. `auto` follows the system preference. |
|
|
99
|
+
| `preview` | `ReactNode` | none | Preview content rendered inside the editor. Enables the three view buttons. |
|
|
100
|
+
| `viewMode` | `EditorViewMode` | none | Controlled view: `'edit'`, `'split'` or `'preview'`. |
|
|
101
|
+
| `defaultViewMode` | `EditorViewMode` | `'edit'` | Initial mode for an uncontrolled instance. |
|
|
102
|
+
| `onViewModeChange` | `(mode: EditorViewMode) => void` | none | Called when a view button is clicked. |
|
|
103
|
+
| `id` | `string` | generated | Textarea id. The instance uses it for its internal labels and gutter. |
|
|
104
|
+
| `className` | `string` | none | Added to the `.reactive-md-editor` root. |
|
|
105
|
+
| `style` | `CSSProperties` | none | Inline styles for the root. |
|
|
106
|
+
| `height` | `number \| string` | `560` | A number is pixels. A string accepts any CSS length. |
|
|
107
|
+
| `minHeight` | `number \| string` | `280` | Minimum editor height, in the same units as `height`. |
|
|
108
|
+
| `placeholder` | `string` | none | Placeholder for an empty source. |
|
|
109
|
+
| `ariaLabel` | `string` | localized label | Accessible name for the textarea. |
|
|
110
|
+
| `readOnly` | `boolean` | `false` | Keeps text selectable and copyable while blocking changes. |
|
|
111
|
+
| `disabled` | `boolean` | `false` | Blocks focus and editing. |
|
|
112
|
+
| `documentKey` | `string \| number` | none | Change it when the editor switches to an independent source document. The change resets undo history and selection. |
|
|
113
|
+
| `diagnostics` | `readonly Diagnostic[]` | none | Marks diagnostic lines in the gutter. It does not block typing or replace host validation. |
|
|
114
|
+
| `document` | `LocalDocument \| null` | `null` | Compiled document used to show binding value types in the authoring tools. The editor does not compile it. |
|
|
115
|
+
| `toolbar` | `boolean` | `true` | Shows the formatting and insertion toolbar, including its export action. |
|
|
116
|
+
| `authoring` | `boolean` | `true` | Enables completion, binding navigation, rename and format tools. |
|
|
117
|
+
| `onExport` | `() => void` | none | Called by the toolbar export action. Use it to open your export dialog or write the file yourself. |
|
|
118
|
+
| `textareaRef` | `RefObject<HTMLTextAreaElement \| null>` | none | Receives the underlying textarea for advanced host code. |
|
|
119
|
+
|
|
120
|
+
## Built-in editor views
|
|
121
|
+
|
|
122
|
+
The status bar sits inside the editor frame, directly below its editing area. It shows the Unicode character count and view buttons. Pass `preview` to enable Edit, Split and Preview. Containers up to 600px wide offer only Edit and Preview. Split temporarily displays Edit at that width and returns to Split when the container widens.
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
<ReactiveMarkdownEditor
|
|
126
|
+
value={source}
|
|
127
|
+
onChange={setSource}
|
|
128
|
+
preview={<LocalDocumentView document={compiledDocument} />}
|
|
129
|
+
defaultViewMode="split"
|
|
130
|
+
/>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Switching views preserves the source selection, undo history and preview component state. Pass both `viewMode` and `onViewModeChange` to control the mode from the host. Source-only instances retain the count and keyboard hint. Press Esc, then Tab in the source to focus the toolbar.
|
|
134
|
+
|
|
135
|
+
## Controlled value and history
|
|
136
|
+
|
|
137
|
+
Every edit calls `onChange` with the next source: typing, toolbar formatting, insertion templates, rename, format and undo or redo. Pass that value back into `value`. The editor treats the edits it emits as part of the current session, so a normal controlled round trip keeps undo steps.
|
|
138
|
+
|
|
139
|
+
An external change to `value` updates the displayed text. When the host replaces the text with an independent document, update `documentKey` in the same render. A key change clears undo and redo, resets the selection and adopts the new value.
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
const [documentKey, setDocumentKey] = useState('estimate');
|
|
143
|
+
const [source, setSource] = useState(loadSource('estimate'));
|
|
144
|
+
|
|
145
|
+
function openDocument(key: string, text: string) {
|
|
146
|
+
setDocumentKey(key);
|
|
147
|
+
setSource(text);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
<ReactiveMarkdownEditor
|
|
151
|
+
value={source}
|
|
152
|
+
onChange={setSource}
|
|
153
|
+
documentKey={documentKey}
|
|
154
|
+
/>
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Undo history belongs to the mounted instance. It is not saved, not shared between instances and not derived from the whole `value` prop. Use `documentKey` for document switches rather than remounting on every keystroke.
|
|
158
|
+
|
|
159
|
+
## Locale and theme
|
|
160
|
+
|
|
161
|
+
Each instance applies its own locale and theme. The editor does not change the document `data-theme` attribute, does not write browser storage and does not read the Playground language setting.
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
<ReactiveMarkdownEditor
|
|
165
|
+
value={source}
|
|
166
|
+
onChange={setSource}
|
|
167
|
+
locale="zh"
|
|
168
|
+
theme="dark"
|
|
169
|
+
/>
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`theme="auto"` follows the system color preference, including preference changes. Two editors on one page can use different values. The theme is set through the local `data-editor-theme` attribute on the `.reactive-md-editor` root.
|
|
173
|
+
|
|
174
|
+
## Read-only and disabled
|
|
175
|
+
|
|
176
|
+
`readOnly` keeps the source visible, focusable and selectable. Typing, the toolbar, completion, rename, format and the ref `undo` and `redo` methods cannot change the value.
|
|
177
|
+
|
|
178
|
+
`disabled` also blocks focus and pointer interaction. Both modes disable the toolbar export action. Neither mode changes the value or the history on its own. Use them when a host is not allowed to edit source, for example while a read-only preview is shown.
|
|
179
|
+
|
|
180
|
+
Replacing `value` externally or changing `documentKey` resets history, selection and the editor's scroll position. Echoing a value received through `onChange` preserves them. The export button is hidden until `onExport` is provided.
|
|
181
|
+
|
|
182
|
+
## Diagnostics and compiled document
|
|
183
|
+
|
|
184
|
+
The optional authoring tools analyze source locally, including syntax checks. The host manages compilation for its preview and can pass that result when it wants line markers or binding value types:
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
import { compileLocal } from 'reactive-md';
|
|
188
|
+
|
|
189
|
+
const result = compileLocal(source);
|
|
190
|
+
|
|
191
|
+
<ReactiveMarkdownEditor
|
|
192
|
+
value={source}
|
|
193
|
+
onChange={setSource}
|
|
194
|
+
diagnostics={result.diagnostics}
|
|
195
|
+
document={result.ok ? result.document : null}
|
|
196
|
+
/>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
`diagnostics` marks the reported lines in the gutter. Incomplete source remains editable, and a compile error does not lock the textarea. `document` supplies binding value types for the authoring inspection panel. Both props are optional; pass neither when the editor is used only to edit Markdown.
|
|
200
|
+
|
|
201
|
+
## Sizing and layout
|
|
202
|
+
|
|
203
|
+
The editor fills the width of its container. `height` defaults to `560px` and `minHeight` to `280px`; numbers are pixels and strings can use `vh`, `rem` or other CSS lengths. The gutter follows line count, and soft-wrapped lines keep their line number and highlighting aligned during scrolling.
|
|
204
|
+
|
|
205
|
+
Use `className` or `style` for margins and placement in a host layout. Internal element class names are implementation details.
|
|
206
|
+
|
|
207
|
+
## Toolbar and authoring tools
|
|
208
|
+
|
|
209
|
+
`toolbar={false}` removes the formatting and insertion toolbar, including its export action. `authoring={false}` keeps the textarea and toolbar but disables syntax highlighting, completion, binding navigation, rename and format. Both default to enabled.
|
|
210
|
+
|
|
211
|
+
The toolbar formats Markdown, inserts lists, tables, links, images and the built-in component templates, and exposes undo and redo. Formatting commands use the current selection and return the next source through `onChange`.
|
|
212
|
+
|
|
213
|
+
## Host responsibilities
|
|
214
|
+
|
|
215
|
+
The editor edits source. The host handles the rest:
|
|
216
|
+
|
|
217
|
+
- Preview: compile `value` and render it with `reactive-md/react` or your own runtime.
|
|
218
|
+
- Persistence: store the source. The editor does not auto-save, write local storage or send the source anywhere.
|
|
219
|
+
- Export: pass `onExport` to connect the toolbar action to your HTML export, download dialog or file service. The editor does not build a shareable HTML file.
|
|
220
|
+
|
|
221
|
+
Compilation scheduling and debouncing also stay in the host. See [Local mode integration](local-integration-en.md) and [Shareable documents and static export](shareable-export-en.md). A complete editor, preview and document-switching example is in [react-editor.tsx](../examples/integration/react-editor.tsx).
|
|
222
|
+
|
|
223
|
+
## Server rendering
|
|
224
|
+
|
|
225
|
+
The editor entry has no top-level `window` or `document` access. Importing it and rendering the initial textarea with `react-dom/server` is safe. Focus, selection, completion, layout measurement and toolbar menus run after the component mounts in a browser, so interactive checks and browser tests need a client.
|
|
226
|
+
|
|
227
|
+
## Styles and scope
|
|
228
|
+
|
|
229
|
+
`reactive-md/editor/styles.css` contains the editor's own tokens and rules. All selectors are scoped to `.reactive-md-editor` or its descendants, so the stylesheet does not restyle host buttons, inputs or the page body. The theme comes from the instance attribute described above.
|
|
230
|
+
|
|
231
|
+
If the same page also renders a document preview, import `reactive-md/styles.css` as well. The two stylesheets are independent and can be loaded in either order.
|
|
232
|
+
|
|
233
|
+
## Compatibility
|
|
234
|
+
|
|
235
|
+
`0.5.0` adds the editor entry and keeps `local-draft-2`, `component-protocol-1` and `reactive-md-theme-1`. Projects that only render documents can upgrade without changing imports or source. The editor is new, so it has no older API to migrate from. See the [0.5.0 release notes](release-0.5.0-en.md) and [Versions and compatibility](compatibility-en.md).
|