reactive-md 0.5.0 → 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.
Files changed (48) hide show
  1. package/CHANGELOG-ch.md +16 -0
  2. package/CHANGELOG.md +16 -0
  3. package/README-ch.md +9 -7
  4. package/README-en.md +10 -7
  5. package/README.md +10 -7
  6. package/SECURITY-ch.md +4 -3
  7. package/SECURITY.md +4 -3
  8. package/THIRD_PARTY_NOTICES.md +45 -1
  9. package/dist-library/reactive-md-editor.css +1 -1
  10. package/dist-library/reactive-md-editor.js +739 -615
  11. package/dist-library/reactive-md-react.js +2081 -1904
  12. package/dist-library/reactive-md.js +440 -320
  13. package/dist-library/{runtime-DPuMxM_y.js → runtime-CXBdLQ3A.js} +8405 -2745
  14. package/dist-library/types/editor/editor-i18n.d.ts +7 -0
  15. package/dist-library/types/editor/editor-view-bar.d.ts +11 -0
  16. package/dist-library/types/editor/index.d.ts +1 -1
  17. package/dist-library/types/editor/types.d.ts +8 -1
  18. package/dist-library/types/local/LocalDocumentView.d.ts +10 -3
  19. package/dist-library/types/local/code-block.d.ts +3 -1
  20. package/dist-library/types/local/diagnostics.d.ts +25 -0
  21. package/dist-library/types/local/heading-anchors.d.ts +2 -0
  22. package/dist-library/types/local/html.d.ts +16 -0
  23. package/dist-library/types/local/image-view.d.ts +3 -1
  24. package/dist-library/types/local/index.d.ts +1 -1
  25. package/dist-library/types/local/options.d.ts +29 -0
  26. package/dist-library/types/local/types.d.ts +35 -1
  27. package/dist-library/types/local/worker.d.ts +18 -6
  28. package/dist-library/types/shareable.d.ts +9 -1
  29. package/dist-standalone/reactive-md-standalone.js +48 -48
  30. package/docs/compatibility-ch.md +4 -4
  31. package/docs/compatibility-en.md +4 -4
  32. package/docs/editor-ch.md +235 -216
  33. package/docs/editor-en.md +235 -216
  34. package/docs/html-compatibility-ch.md +98 -0
  35. package/docs/html-compatibility-en.md +98 -0
  36. package/docs/local-integration-ch.md +4 -1
  37. package/docs/local-integration-en.md +4 -1
  38. package/docs/local-interaction-syntax-ch.md +3 -1
  39. package/docs/local-interaction-syntax-en.md +1 -1
  40. package/docs/release-0.5.1-ch.md +39 -0
  41. package/docs/release-0.5.1-en.md +39 -0
  42. package/docs/releasing-ch.md +7 -7
  43. package/docs/releasing-en.md +8 -8
  44. package/docs/shareable-export-ch.md +2 -0
  45. package/docs/shareable-export-en.md +2 -0
  46. package/examples/local/README.md +2 -0
  47. package/examples/local/html-compat.reactive.md +24 -0
  48. package/package.json +3 -1
package/docs/editor-en.md CHANGED
@@ -1,216 +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. The host keeps the source text and owns preview, 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
- | `id` | `string` | generated | Textarea id. The instance uses it for its internal labels and gutter. |
100
- | `className` | `string` | none | Added to the `.reactive-md-editor` root. |
101
- | `style` | `CSSProperties` | none | Inline styles for the root. |
102
- | `height` | `number \| string` | `560` | A number is pixels. A string accepts any CSS length. |
103
- | `minHeight` | `number \| string` | `280` | Minimum editor height, in the same units as `height`. |
104
- | `placeholder` | `string` | none | Placeholder for an empty source. |
105
- | `ariaLabel` | `string` | localized label | Accessible name for the textarea. |
106
- | `readOnly` | `boolean` | `false` | Keeps text selectable and copyable while blocking changes. |
107
- | `disabled` | `boolean` | `false` | Blocks focus and editing. |
108
- | `documentKey` | `string \| number` | none | Change it when the editor switches to an independent source document. The change resets undo history and selection. |
109
- | `diagnostics` | `readonly Diagnostic[]` | none | Marks diagnostic lines in the gutter. It does not block typing or replace host validation. |
110
- | `document` | `LocalDocument \| null` | `null` | Compiled document used to show binding value types in the authoring tools. The editor does not compile it. |
111
- | `toolbar` | `boolean` | `true` | Shows the formatting and insertion toolbar, including its export action. |
112
- | `authoring` | `boolean` | `true` | Enables completion, binding navigation, rename and format tools. |
113
- | `onExport` | `() => void` | none | Called by the toolbar export action. Use it to open your export dialog or write the file yourself. |
114
- | `textareaRef` | `RefObject<HTMLTextAreaElement \| null>` | none | Receives the underlying textarea for advanced host code. |
115
-
116
- ## Controlled value and history
117
-
118
- 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.
119
-
120
- 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.
121
-
122
- ```tsx
123
- const [documentKey, setDocumentKey] = useState('estimate');
124
- const [source, setSource] = useState(loadSource('estimate'));
125
-
126
- function openDocument(key: string, text: string) {
127
- setDocumentKey(key);
128
- setSource(text);
129
- }
130
-
131
- <ReactiveMarkdownEditor
132
- value={source}
133
- onChange={setSource}
134
- documentKey={documentKey}
135
- />
136
- ```
137
-
138
- 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.
139
-
140
- ## Locale and theme
141
-
142
- 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.
143
-
144
- ```tsx
145
- <ReactiveMarkdownEditor
146
- value={source}
147
- onChange={setSource}
148
- locale="zh"
149
- theme="dark"
150
- />
151
- ```
152
-
153
- `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.
154
-
155
- ## Read-only and disabled
156
-
157
- `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.
158
-
159
- `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.
160
-
161
- 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.
162
-
163
- ## Diagnostics and compiled document
164
-
165
- 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:
166
-
167
- ```tsx
168
- import { compileLocal } from 'reactive-md';
169
-
170
- const result = compileLocal(source);
171
-
172
- <ReactiveMarkdownEditor
173
- value={source}
174
- onChange={setSource}
175
- diagnostics={result.diagnostics}
176
- document={result.ok ? result.document : null}
177
- />
178
- ```
179
-
180
- `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.
181
-
182
- ## Sizing and layout
183
-
184
- 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.
185
-
186
- Use `className` or `style` for margins and placement in a host layout. Internal element class names are implementation details.
187
-
188
- ## Toolbar and authoring tools
189
-
190
- `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.
191
-
192
- 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`.
193
-
194
- ## Host responsibilities
195
-
196
- The editor edits source. The host handles the rest:
197
-
198
- - Preview: compile `value` and render it with `reactive-md/react` or your own runtime.
199
- - Persistence: store the source. The editor does not auto-save, write local storage or send the source anywhere.
200
- - 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.
201
-
202
- 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).
203
-
204
- ## Server rendering
205
-
206
- 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.
207
-
208
- ## Styles and scope
209
-
210
- `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.
211
-
212
- 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.
213
-
214
- ## Compatibility
215
-
216
- `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).
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).
@@ -0,0 +1,98 @@
1
+ # HTML 部分兼容与暂时性分流政策
2
+
3
+ 此功能面向下个发行版。默认文档继续使用 Markdown、ReactiveMD 控件和表达式,并支持下表中的 P0 HTML。CSS、JavaScript 和扩展 HTML 由宿主分别开启,默认全部关闭。
4
+
5
+ ## 暂时性分流政策
6
+
7
+ 为了避开作者 CSS、JavaScript、扩展 HTML 与 ReactiveMD 之间的混合解析和渲染冲突,本版采用整篇分流:
8
+
9
+ | 编译选项 | 文档行为 |
10
+ | --- | --- |
11
+ | 三个开关全部关闭或省略 | 使用 ReactiveMD 解析器和现有 React 渲染器,支持 P0 HTML |
12
+ | 任意一个开关为 `true` | 整篇源码按原生 HTML 处理,在隔离的 iframe 中渲染 |
13
+
14
+ 原生 HTML 路径中的 `# 标题`、`**强调**`、LaTeX 和 `{{ 表达式 }}` 保持普通文本;`<input>`、`<table>` 等按 HTML 语义处理,ReactiveMD 组件不建立绑定。关闭全部开关会重新编译回默认模式。此政策是本版的过渡方案,后续版本再评估混合兼容。
15
+
16
+ 开关是宿主能力设置,源码、参数状态文件和文档标签不能自行开启它们。Demo 始终显示当前模式,刷新页面后回到三个开关全部关闭的状态。
17
+
18
+ ## 开关与 API
19
+
20
+ ```ts
21
+ import { compileLocal } from 'reactive-md';
22
+
23
+ // Markdown、ReactiveMD 与 P0 HTML。
24
+ const reactive = compileLocal(source);
25
+
26
+ // 整篇按原生 HTML 处理;只允许作者 CSS。
27
+ const html = compileLocal(source, {
28
+ enableCss: true,
29
+ enableJavaScript: false,
30
+ enableExtendedHtml: false,
31
+ });
32
+ ```
33
+
34
+ | 选项 | 默认值 | 作用 |
35
+ | --- | --- | --- |
36
+ | `enableCss` | `false` | 允许作者 CSS |
37
+ | `enableJavaScript` | `false` | 允许作者脚本和事件处理代码 |
38
+ | `enableExtendedHtml` | `false` | 允许 P1 标签、嵌入、表单、SVG/MathML 和整页 HTML 功能 |
39
+
40
+ 选项必须是布尔值。开启一个开关不会顺带开启其他两个。带样式的扩展元素需要同时允许扩展 HTML 和 CSS;扩展元素中的脚本需要同时允许扩展 HTML 和 JavaScript。内置组件使用的样式、交互代码、图表 SVG 和公式 MathML 不受作者能力开关影响。
41
+
42
+ 现有源码长度和 `limits.maxSyntaxNodes` 预算继续生效。HTML 路径按解析遍历的节点计数,嵌套 `srcdoc` 共用累计预算。
43
+
44
+ React 快捷组件通过 `compileOptions` 接收同样的设置:
45
+
46
+ ```tsx
47
+ <LocalReactiveDocument
48
+ source={source}
49
+ compileOptions={{ enableCss: true }}
50
+ />
51
+ ```
52
+
53
+ 底层宿主把 `compileLocal` 生成的文档交给 `LocalDocumentView`。原生 HTML 文档的 `document.html` 记录三个归一化开关;参数和绑定集合为空。该字段属于运行时元数据,保存文档时保留原始源码和宿主设置。
54
+
55
+ ## 默认支持的 P0 HTML
56
+
57
+ | 用途 | 标签 |
58
+ | --- | --- |
59
+ | 行内文字 | `b`、`strong`、`i`、`em`、`s`、`del`、`u`、`mark`、`sup`、`sub` |
60
+ | 换行与分隔 | `br`、`hr` |
61
+ | 段落与标题 | `p`、`h1` 至 `h6` |
62
+ | 容器 | `div`、`span` |
63
+ | 折叠内容 | `details`、`summary` |
64
+ | 引用 | `blockquote` |
65
+ | 代码 | `code`、`pre`、`pre` 内的 `code` |
66
+ | 列表 | `ul`、`ol`、`li`,含 `ol[start]` |
67
+ | 链接与图片 | `a`、`img`,沿用默认路径的 URL 策略 |
68
+ | 其他写法 | HTML 注释、命名及数字字符引用、HTML 大小写和空元素写法 |
69
+
70
+ 容器中的正文继续解析 Markdown、公式、插值和 ReactiveMD 控件;`code`、`pre` 中的内容按字面显示。`details` 复用现有折叠组件的主题和交互,支持富文本标题、嵌套和 `open`,静态模式展开正文。HTML 布尔属性按存在与否判断,因此 `open="false"` 仍表示展开;现有 ReactiveMD 组件的布尔值规则保持不变。
71
+
72
+ 可运行示例见 [HTML 与 ReactiveMD](../examples/local/html-compat.reactive.md)。
73
+
74
+ 通用属性按允许列表接收,支持文档标识、标题、语言、方向和可访问性属性。默认模式中的作者 `style`、事件处理属性及不支持的标签保持惰性源码或产生定位诊断。图片仍需宿主明确允许后才加载。代码与不支持区域不执行脚本。
75
+
76
+ ## 扩展 HTML
77
+
78
+ `enableExtendedHtml` 管理以下作者语法:
79
+
80
+ - 表格及结构:`table`、`caption`、`thead`、`tbody`、`tfoot`、`tr`、`th`、`td`。
81
+ - 定义列表:`dl`、`dt`、`dd`。
82
+ - 补充文字语义:`small`、`kbd`、`samp`、`var`、`abbr`、`q`、`cite`、`ins`。
83
+ - 图文和结构:`figure`、`figcaption`、`article`、`section`、`aside`、`header`、`footer`、`ruby`、`rt`、`rp`、`wbr`。
84
+ - 原生表单、`iframe`、`object`、`embed`、`dialog`、任意 SVG/MathML 和整页 HTML 功能。
85
+
86
+ 在默认模式中,已有的 ReactiveMD `<table>`、`<section>`、`<input>`、`<select>` 等组件继续采用当前语义。在原生 HTML 模式中,同名元素采用浏览器语义。
87
+
88
+ ## 隔离与导出
89
+
90
+ 作者 HTML 放在不带 `allow-same-origin` 的沙箱 iframe 中。源码中的整页结构、样式和脚本作用于该隔离文档。资源加载、表单提交和导航仍受 CSP 与沙箱限制;启用扩展 HTML 不代表获得全部网络能力。
91
+
92
+ 本版支持内联 CSS 和 JavaScript,自动外部资源请求仍受限:外部脚本、样式表、图片、媒体及嵌入资源不会因开启开关而自动加载。扩展 HTML 允许隔离文档中的 HTTP(S) 表单提交和 `<base>` 地址解析,保留顶层导航与宿主访问限制。iframe 可用 `srcdoc` 提供内联内容;`object`、`embed` 的外部资源仍受 CSP 限制。
93
+
94
+ 启用任意 JavaScript 后,脚本可以动态创建元素和样式,另两个开关主要约束作者源码。宿主隔离仍有效,但这些开关不承诺逐项阻止脚本的运行时 DOM 操作。
95
+
96
+ 交互导出保留本次编译选项和文档路径。原生 HTML 的静态导出保留浏览器内建的折叠和表单行为,并禁用作者 JavaScript。这类文档没有可保存的 ReactiveMD 参数。旧导出载荷省略编译选项时采用三个开关全部关闭的默认行为。
97
+
98
+ 相关规则见[集成说明](local-integration-ch.md)、[可分享导出](shareable-export-ch.md)和[安全约定](../SECURITY-ch.md)。