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.
Files changed (98) hide show
  1. package/CHANGELOG-ch.md +144 -113
  2. package/CHANGELOG.md +144 -113
  3. package/LICENSE +21 -21
  4. package/README-ch.md +154 -123
  5. package/README-en.md +179 -147
  6. package/README.md +179 -147
  7. package/SECURITY-ch.md +4 -3
  8. package/SECURITY.md +4 -3
  9. package/THIRD_PARTY_NOTICES.md +138 -1
  10. package/bin/reactive-md.mjs +1 -1
  11. package/dist-library/reactive-md-editor.css +2 -0
  12. package/dist-library/reactive-md-editor.js +3834 -0
  13. package/dist-library/reactive-md-react.js +9324 -1670
  14. package/dist-library/reactive-md.css +1 -1
  15. package/dist-library/reactive-md.js +426 -305
  16. package/dist-library/{runtime-D3QTVYaz.js → runtime-CXBdLQ3A.js} +8950 -2895
  17. package/dist-library/types/editor/ReactiveMarkdownEditor.d.ts +7 -0
  18. package/dist-library/types/editor/editor-commands.d.ts +50 -0
  19. package/dist-library/types/editor/editor-i18n.d.ts +109 -0
  20. package/dist-library/types/editor/editor-toolbar.d.ts +24 -0
  21. package/dist-library/types/editor/editor-view-bar.d.ts +11 -0
  22. package/dist-library/types/editor/extended-native-components.d.ts +58 -0
  23. package/dist-library/types/editor/index.d.ts +9 -0
  24. package/dist-library/types/editor/locale.d.ts +13 -0
  25. package/dist-library/types/editor/native-components.d.ts +47 -0
  26. package/dist-library/types/editor/source-authoring.d.ts +57 -0
  27. package/dist-library/types/editor/types.d.ts +51 -0
  28. package/dist-library/types/editor/use-gutter-metrics.d.ts +5 -0
  29. package/dist-library/types/editor/use-source-history.d.ts +16 -0
  30. package/dist-library/types/local/LocalDocumentView.d.ts +10 -3
  31. package/dist-library/types/local/code-block.d.ts +26 -0
  32. package/dist-library/types/local/diagnostics.d.ts +25 -0
  33. package/dist-library/types/local/footnotes.d.ts +51 -0
  34. package/dist-library/types/local/heading-anchors.d.ts +2 -0
  35. package/dist-library/types/local/html.d.ts +16 -0
  36. package/dist-library/types/local/image-view.d.ts +23 -0
  37. package/dist-library/types/local/index.d.ts +1 -1
  38. package/dist-library/types/local/options.d.ts +29 -0
  39. package/dist-library/types/local/types.d.ts +42 -1
  40. package/dist-library/types/local/worker.d.ts +18 -6
  41. package/dist-library/types/shareable.d.ts +9 -1
  42. package/dist-standalone/reactive-md-standalone.css +1 -1
  43. package/dist-standalone/reactive-md-standalone.js +49 -38
  44. package/docs/compatibility-ch.md +12 -8
  45. package/docs/compatibility-en.md +12 -8
  46. package/docs/component-protocol-ch.md +2 -2
  47. package/docs/component-protocol-en.md +2 -2
  48. package/docs/editor-ch.md +235 -0
  49. package/docs/editor-en.md +235 -0
  50. package/docs/html-compatibility-ch.md +98 -0
  51. package/docs/html-compatibility-en.md +98 -0
  52. package/docs/local-guide-ch.md +11 -5
  53. package/docs/local-guide-en.md +11 -5
  54. package/docs/local-integration-ch.md +4 -1
  55. package/docs/local-integration-en.md +4 -1
  56. package/docs/local-interaction-syntax-ch.md +9 -2
  57. package/docs/local-interaction-syntax-en.md +7 -2
  58. package/docs/release-0.4.1-ch.md +23 -23
  59. package/docs/release-0.4.1-en.md +23 -23
  60. package/docs/release-0.5.0-ch.md +41 -0
  61. package/docs/release-0.5.0-en.md +41 -0
  62. package/docs/release-0.5.1-ch.md +39 -0
  63. package/docs/release-0.5.1-en.md +39 -0
  64. package/docs/releasing-ch.md +108 -101
  65. package/docs/releasing-en.md +108 -101
  66. package/docs/shareable-export-ch.md +6 -2
  67. package/docs/shareable-export-en.md +6 -2
  68. package/examples/integration/core/package.json +7 -7
  69. package/examples/integration/react/index.html +12 -12
  70. package/examples/integration/react/main.jsx +21 -21
  71. package/examples/integration/react/package.json +9 -9
  72. package/examples/integration/react-editor.tsx +74 -0
  73. package/examples/local/README.md +2 -0
  74. package/examples/local/catalog.reactive.md +20 -20
  75. package/examples/local/checklist.reactive.md +32 -32
  76. package/examples/local/comparison.reactive.md +47 -47
  77. package/examples/local/components.reactive.md +44 -44
  78. package/examples/local/counter.reactive.md +7 -7
  79. package/examples/local/diagnostics.reactive.md +54 -54
  80. package/examples/local/diagram.reactive.md +44 -44
  81. package/examples/local/gallery.reactive.md +61 -61
  82. package/examples/local/html-compat.reactive.md +24 -0
  83. package/examples/local/parameters.reactive.md +36 -36
  84. package/examples/local/planning.reactive.md +24 -24
  85. package/examples/local/pricing.reactive.md +20 -20
  86. package/examples/local/zh/catalog.reactive.md +20 -20
  87. package/examples/local/zh/charts.reactive.md +73 -73
  88. package/examples/local/zh/checklist.reactive.md +32 -32
  89. package/examples/local/zh/comparison.reactive.md +47 -47
  90. package/examples/local/zh/components.reactive.md +44 -44
  91. package/examples/local/zh/counter.reactive.md +7 -7
  92. package/examples/local/zh/diagnostics.reactive.md +54 -54
  93. package/examples/local/zh/diagram.reactive.md +44 -44
  94. package/examples/local/zh/gallery.reactive.md +61 -61
  95. package/examples/local/zh/parameters.reactive.md +36 -36
  96. package/examples/local/zh/planning.reactive.md +24 -24
  97. package/examples/local/zh/pricing.reactive.md +20 -20
  98. package/package.json +135 -91
@@ -0,0 +1,7 @@
1
+ import type { ReactiveMarkdownEditorHandle, ReactiveMarkdownEditorProps } from './types.js';
2
+ /**
3
+ * Controlled Markdown source editor with the demo's toolbar and authoring
4
+ * tools. The textarea is the only editing surface; every transformation is
5
+ * reported through `onChange`, and undo history stays inside this instance.
6
+ */
7
+ export declare const ReactiveMarkdownEditor: import("react").ForwardRefExoticComponent<ReactiveMarkdownEditorProps & import("react").RefAttributes<ReactiveMarkdownEditorHandle>>;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Pure text transformations behind the Markdown source toolbar.
3
+ *
4
+ * Every command receives the current source value and selection, clamps the
5
+ * selection, and returns a new value plus the selection that should be
6
+ * restored on the textarea. Nothing in this module touches the DOM.
7
+ *
8
+ * Commands that insert human-readable text accept an optional locale and
9
+ * default to English, so direct callers keep their original output.
10
+ */
11
+ import type { EditorEdit, EditorLocale, EditorSelection } from './types.js';
12
+ export type { EditorEdit, EditorSelection } from './types.js';
13
+ export interface InsertTemplateOptions {
14
+ block?: boolean;
15
+ }
16
+ export declare function formatBold(value: string, selection: EditorSelection, locale?: EditorLocale): EditorEdit;
17
+ export declare function formatItalic(value: string, selection: EditorSelection, locale?: EditorLocale): EditorEdit;
18
+ export declare function formatStrike(value: string, selection: EditorSelection, locale?: EditorLocale): EditorEdit;
19
+ export declare function formatInlineCode(value: string, rawSelection: EditorSelection, locale?: EditorLocale): EditorEdit;
20
+ export declare function formatHeading(value: string, rawSelection: EditorSelection, level: 0 | 1 | 2 | 3 | 4 | 5 | 6): EditorEdit;
21
+ export declare function formatBulletList(value: string, selection: EditorSelection): EditorEdit;
22
+ export declare function formatOrderedList(value: string, selection: EditorSelection): EditorEdit;
23
+ export declare function formatTaskList(value: string, selection: EditorSelection): EditorEdit;
24
+ export declare function formatQuote(value: string, selection: EditorSelection): EditorEdit;
25
+ export declare function indentSelection(value: string, rawSelection: EditorSelection): EditorEdit;
26
+ export declare function outdentSelection(value: string, rawSelection: EditorSelection): EditorEdit;
27
+ export declare function insertLink(value: string, rawSelection: EditorSelection, locale?: EditorLocale): EditorEdit;
28
+ export declare function insertImage(value: string, rawSelection: EditorSelection, locale?: EditorLocale): EditorEdit;
29
+ export declare function insertCodeBlock(value: string, rawSelection: EditorSelection, locale?: EditorLocale): EditorEdit;
30
+ export declare function insertTable(value: string, rawSelection: EditorSelection, locale?: EditorLocale): EditorEdit;
31
+ export declare function insertDivider(value: string, rawSelection: EditorSelection): EditorEdit;
32
+ export declare function insertText(value: string, rawSelection: EditorSelection, text: string): EditorEdit;
33
+ export declare function insertTemplate(value: string, rawSelection: EditorSelection, template: string, options?: InsertTemplateOptions): EditorEdit;
34
+ export type EditorListType = 'bullet' | 'ordered' | 'task';
35
+ export interface EditorFormatState {
36
+ headingLevel: 0 | 1 | 2 | 3 | 4 | 5 | 6;
37
+ bold: boolean;
38
+ italic: boolean;
39
+ strike: boolean;
40
+ inlineCode: boolean;
41
+ list: EditorListType | null;
42
+ quote: boolean;
43
+ }
44
+ /**
45
+ * Reads the formatting that applies at the selection without changing the
46
+ * document. Line-level state comes from the line holding `selection.start`;
47
+ * inline state comes from markers around or enclosing the selection (or
48
+ * around the caret when the selection is collapsed).
49
+ */
50
+ export declare function readFormatState(value: string, rawSelection: EditorSelection): EditorFormatState;
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Typed copy for the source editor: toolbar chrome, command placeholders and
3
+ * native-component picker text.
4
+ *
5
+ * English strings are the canonical defaults. Chinese strings use the wording
6
+ * shipped in the demo. English native-component labels, descriptions and
7
+ * templates live in `native-components.ts`; this module carries the Chinese
8
+ * overrides plus the group names for both languages.
9
+ */
10
+ import type { EditorLocale } from './types.js';
11
+ export interface EditorCommandCopy {
12
+ boldPlaceholder: string;
13
+ italicPlaceholder: string;
14
+ strikePlaceholder: string;
15
+ inlineCodePlaceholder: string;
16
+ linkText: string;
17
+ imageAlt: string;
18
+ codeBlockPlaceholder: string;
19
+ tableHeaders: readonly [string, string, string];
20
+ tableRows: readonly [
21
+ readonly [string, string, string],
22
+ readonly [string, string, string]
23
+ ];
24
+ }
25
+ export interface EditorToolbarCopy {
26
+ toolbarLabel: string;
27
+ headingLabels: readonly [string, string, string, string, string, string, string];
28
+ headingLevelLabel(heading: string): string;
29
+ headingMenuLabel: string;
30
+ bold: string;
31
+ italic: string;
32
+ listLabel: string;
33
+ listLabelWithType(list: string): string;
34
+ listMenuLabel: string;
35
+ listLabels: {
36
+ bullet: string;
37
+ ordered: string;
38
+ task: string;
39
+ };
40
+ decreaseIndent: string;
41
+ increaseIndent: string;
42
+ insertLink: string;
43
+ insert: string;
44
+ insertMenuLabel: string;
45
+ insertItems: {
46
+ image: string;
47
+ table: string;
48
+ divider: string;
49
+ codeBlock: string;
50
+ inlineCode: string;
51
+ strikethrough: string;
52
+ quote: string;
53
+ };
54
+ emoji: string;
55
+ insertEmojiMenuLabel: string;
56
+ insertEmojiLabel(emoji: string): string;
57
+ componentsTriggerLabel: string;
58
+ componentsLabel: string;
59
+ componentsCompactLabel: string;
60
+ nativeMenuLabel: string;
61
+ nativeTitle: string;
62
+ closeNativeLabel: string;
63
+ searchPlaceholder: string;
64
+ searchLabel: string;
65
+ nativeListLabel: string;
66
+ noMatchingComponents: string;
67
+ inlineBadge: string;
68
+ historyLabel: string;
69
+ undo: string;
70
+ redo: string;
71
+ download: string;
72
+ more: string;
73
+ moreMenuLabel: string;
74
+ linkMenuItem: string;
75
+ }
76
+ export interface NativeComponentGroupCopy {
77
+ input: string;
78
+ action: string;
79
+ layout: string;
80
+ data: string;
81
+ hint: string;
82
+ }
83
+ export interface NativeComponentCopy {
84
+ label: string;
85
+ description: string;
86
+ keywords: readonly string[];
87
+ template: string;
88
+ }
89
+ export interface NativeComponentCatalogCopy {
90
+ groups: NativeComponentGroupCopy;
91
+ /** Per-component Chinese overrides keyed by the stable component id. */
92
+ components: Readonly<Record<string, NativeComponentCopy>>;
93
+ }
94
+ export interface EditorChromeCopy {
95
+ /** Accessible name for the textarea when the host passes no ariaLabel. */
96
+ sourceLabel: string;
97
+ region: string;
98
+ previewRegion: string;
99
+ viewLabel: string;
100
+ count(value: string): string;
101
+ keyboardHint: string;
102
+ edit: string;
103
+ split: string;
104
+ preview: string;
105
+ }
106
+ export declare const EDITOR_CHROME_COPY: Record<EditorLocale, EditorChromeCopy>;
107
+ export declare const EDITOR_COMMAND_COPY: Record<EditorLocale, EditorCommandCopy>;
108
+ export declare const EDITOR_TOOLBAR_COPY: Record<EditorLocale, EditorToolbarCopy>;
109
+ export declare const NATIVE_COMPONENT_CATALOG_COPY: Record<EditorLocale, NativeComponentCatalogCopy>;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Editor toolbar for the Reactive MD editor.
3
+ *
4
+ * The toolbar only reads the textarea and hands pure `EditorEdit` results back
5
+ * to the editor. The editor owns history, focus restoration and the controlled
6
+ * value. Format state is derived from the current selection so the toolbar
7
+ * reflects the block and inline formatting under the caret.
8
+ */
9
+ import { type ReactElement, type RefObject } from 'react';
10
+ import { type EditorEdit } from './editor-commands.js';
11
+ export interface EditorToolbarProps {
12
+ editorRef: RefObject<HTMLTextAreaElement | null>;
13
+ onEdit(edit: EditorEdit): void;
14
+ onUndo(): void;
15
+ onRedo(): void;
16
+ canUndo: boolean;
17
+ canRedo: boolean;
18
+ onExport?(): void;
19
+ /** Render the download action only when the host supplies a handler. */
20
+ showExport?: boolean;
21
+ /** Read-only and disabled editors leave every action without effect. */
22
+ disabled?: boolean;
23
+ }
24
+ export declare function EditorToolbar({ editorRef, onEdit, onUndo, onRedo, canUndo, canRedo, onExport, showExport, disabled, }: EditorToolbarProps): ReactElement;
@@ -0,0 +1,11 @@
1
+ import type { EditorViewMode } from './types.js';
2
+ export declare function EditorViewBar({ source, mode, onModeChange, sourceId, previewId, hasPreview, allowSplit, toolbar }: {
3
+ source: string;
4
+ mode: EditorViewMode;
5
+ onModeChange(mode: EditorViewMode): void;
6
+ sourceId: string;
7
+ previewId: string;
8
+ hasPreview: boolean;
9
+ allowSplit: boolean;
10
+ toolbar: boolean;
11
+ }): import("react").JSX.Element;
@@ -0,0 +1,58 @@
1
+ import type { NativeComponentDefinition } from './native-components.js';
2
+ export declare const EXTENDED_NATIVE_COMPONENTS: readonly NativeComponentDefinition[];
3
+ export declare const EXTENDED_NATIVE_COMPONENT_COPY_ZH: {
4
+ jump: {
5
+ label: string;
6
+ description: string;
7
+ keywords: string[];
8
+ template: string;
9
+ };
10
+ anchor: {
11
+ label: string;
12
+ description: string;
13
+ keywords: string[];
14
+ template: string;
15
+ };
16
+ text: {
17
+ label: string;
18
+ description: string;
19
+ keywords: string[];
20
+ template: string;
21
+ };
22
+ section: {
23
+ label: string;
24
+ description: string;
25
+ keywords: string[];
26
+ template: string;
27
+ };
28
+ 'multi-select': {
29
+ label: string;
30
+ description: string;
31
+ keywords: string[];
32
+ template: string;
33
+ };
34
+ 'range-slider': {
35
+ label: string;
36
+ description: string;
37
+ keywords: string[];
38
+ template: string;
39
+ };
40
+ coordinate: {
41
+ label: string;
42
+ description: string;
43
+ keywords: string[];
44
+ template: string;
45
+ };
46
+ quiz: {
47
+ label: string;
48
+ description: string;
49
+ keywords: string[];
50
+ template: string;
51
+ };
52
+ steps: {
53
+ label: string;
54
+ description: string;
55
+ keywords: string[];
56
+ template: string;
57
+ };
58
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Public entry for the Reactive MD source editor.
3
+ *
4
+ * This module carries no CSS import, so consumers that only need the component
5
+ * can tree-shake or server-render it. Import `reactive-md/editor/styles.css`
6
+ * for the stylesheet, or use `./library` for the CSS-included bundle.
7
+ */
8
+ export { ReactiveMarkdownEditor } from './ReactiveMarkdownEditor.js';
9
+ export type { EditorEdit, EditorLocale, EditorSelection, EditorTheme, EditorViewMode, ReactiveMarkdownEditorHandle, ReactiveMarkdownEditorProps, } from './types.js';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Private locale context for the editor package.
3
+ *
4
+ * The editor keeps its own language state so it can be mounted anywhere
5
+ * without touching the host document or borrowing the demo's provider.
6
+ */
7
+ import { type ReactNode } from 'react';
8
+ import type { EditorLocale } from './types.js';
9
+ export declare function EditorLocaleProvider({ locale, children, }: {
10
+ locale: EditorLocale;
11
+ children: ReactNode;
12
+ }): import("react").JSX.Element;
13
+ export declare function useEditorLocale(): EditorLocale;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Catalog of `local-draft-2` native components offered by the editor toolbar.
3
+ *
4
+ * Templates stay close to the documented authoring syntax:
5
+ * - `{{bind:base}}` is resolved by `renderNativeSnippet` to a fresh bind name.
6
+ * - `{{selection}}`, `{{selection:fallback}}`, `{{caret}}` and `{{select:value}}`
7
+ * are left for the toolbar's `insertTemplate` handler.
8
+ * - Leaf components never receive a closing tag; container bodies use blank
9
+ * lines so inserted Markdown keeps a natural block layout.
10
+ */
11
+ import type { EditorLocale } from './types.js';
12
+ export type NativeComponentGroupId = 'input' | 'action' | 'layout' | 'data' | 'hint';
13
+ export interface NativeComponentGroup {
14
+ id: NativeComponentGroupId;
15
+ label: string;
16
+ }
17
+ export interface NativeComponentDefinition {
18
+ id: string;
19
+ label: string;
20
+ description: string;
21
+ group: NativeComponentGroupId;
22
+ keywords: string[];
23
+ inline?: boolean;
24
+ template: string;
25
+ }
26
+ export declare const NATIVE_COMPONENT_GROUPS: readonly NativeComponentGroup[];
27
+ export declare const NATIVE_COMPONENTS: readonly NativeComponentDefinition[];
28
+ export declare const NATIVE_COMPONENT_GROUPS_ZH: readonly NativeComponentGroup[];
29
+ export declare const NATIVE_COMPONENTS_ZH: readonly NativeComponentDefinition[];
30
+ export interface NativeComponentCatalog {
31
+ groups: readonly NativeComponentGroup[];
32
+ components: readonly NativeComponentDefinition[];
33
+ }
34
+ /**
35
+ * Catalog for the active UI language. Labels, descriptions and templates are
36
+ * localized; keywords keep both English and Chinese terms so either query
37
+ * works in either language.
38
+ */
39
+ export declare function getNativeComponentCatalog(locale?: EditorLocale): NativeComponentCatalog;
40
+ /**
41
+ * Render one toolbar template for insertion into `source`.
42
+ *
43
+ * Only `{{bind:base}}` is resolved here. Selection, caret and selectable tokens
44
+ * stay intact for the toolbar's `insertTemplate` step. `selectedText` is kept
45
+ * for future use; it never replaces the tokens here.
46
+ */
47
+ export declare function renderNativeSnippet(component: NativeComponentDefinition, source: string, selectedText?: string): string;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Authoring aids layered on the plain source textarea.
3
+ *
4
+ * The textarea stays the single editable surface: the highlight layer is a
5
+ * pointer-transparent copy of the source with token colours, and every action
6
+ * hands an `EditorEdit` back to the editor so history, selection restoration
7
+ * and controlled updates keep working unchanged.
8
+ */
9
+ import { type RefObject } from 'react';
10
+ import type { Diagnostic, LocalDocument, SourceRange } from 'reactive-md';
11
+ import type { EditorEdit } from './types.js';
12
+ export interface AuthorToken {
13
+ kind: string;
14
+ range: SourceRange;
15
+ }
16
+ export interface AuthorBinding {
17
+ name: string;
18
+ declarations: SourceRange[];
19
+ references: SourceRange[];
20
+ }
21
+ export interface AuthorCompletion {
22
+ label: string;
23
+ insertText: string;
24
+ range: SourceRange;
25
+ kind: 'tag' | 'attribute' | 'binding' | 'value';
26
+ detail?: string;
27
+ }
28
+ export interface AuthorAnalysis {
29
+ tokens: AuthorToken[];
30
+ bindings: AuthorBinding[];
31
+ diagnostics: Diagnostic[];
32
+ }
33
+ /**
34
+ * Analyses the exact source; caret movement never retriggers this work.
35
+ * `enabled` lets the editor skip the analysis when authoring tools are off.
36
+ */
37
+ export declare function useAuthorAnalysis(source: string, enabled?: boolean): AuthorAnalysis;
38
+ export interface AuthorHighlightProps {
39
+ source: string;
40
+ tokens: AuthorToken[];
41
+ /** Content width of the textarea, i.e. its client width without scrollbars. */
42
+ width: number;
43
+ editorRef: RefObject<HTMLTextAreaElement | null>;
44
+ }
45
+ export declare const AuthorHighlight: import("react").MemoExoticComponent<({ source, tokens, width, editorRef, }: AuthorHighlightProps) => import("react").JSX.Element>;
46
+ export interface AuthoringPanelProps {
47
+ source: string;
48
+ analysis: AuthorAnalysis;
49
+ /** Latest successful document, used for binding value types. */
50
+ bindingDocument: LocalDocument | null;
51
+ editorRef: RefObject<HTMLTextAreaElement | null>;
52
+ onEdit(edit: EditorEdit): void;
53
+ onLocate(range: SourceRange): void;
54
+ /** Read-only and disabled editors block every authoring action. */
55
+ disabled?: boolean;
56
+ }
57
+ export declare function AuthoringPanel({ source, analysis, bindingDocument, editorRef, onEdit, onLocate, disabled, }: AuthoringPanelProps): import("react").JSX.Element;
@@ -0,0 +1,51 @@
1
+ import type { CSSProperties, ReactNode, RefObject } from 'react';
2
+ import type { Diagnostic, LocalDocument, SourceRange } from '../local/types.js';
3
+ export type EditorLocale = 'en' | 'zh';
4
+ export type EditorTheme = 'light' | 'dark' | 'auto';
5
+ export type EditorViewMode = 'edit' | 'split' | 'preview';
6
+ export interface EditorSelection {
7
+ start: number;
8
+ end: number;
9
+ }
10
+ export interface EditorEdit {
11
+ value: string;
12
+ selection: EditorSelection;
13
+ }
14
+ export interface ReactiveMarkdownEditorProps {
15
+ value: string;
16
+ onChange(value: string): void;
17
+ locale?: EditorLocale;
18
+ theme?: EditorTheme;
19
+ /** Preview content rendered inside the editor frame. Enables view switching. */
20
+ preview?: ReactNode;
21
+ /** Controlled view mode; omit to let the editor manage its own mode. */
22
+ viewMode?: EditorViewMode;
23
+ defaultViewMode?: EditorViewMode;
24
+ onViewModeChange?(mode: EditorViewMode): void;
25
+ id?: string;
26
+ className?: string;
27
+ style?: CSSProperties;
28
+ height?: number | string;
29
+ minHeight?: number | string;
30
+ placeholder?: string;
31
+ ariaLabel?: string;
32
+ readOnly?: boolean;
33
+ disabled?: boolean;
34
+ /** Reset history, selection and scroll when switching source documents. */
35
+ documentKey?: string | number;
36
+ diagnostics?: readonly Diagnostic[];
37
+ /** Optional compiled document for the binding inspector's value types. */
38
+ document?: LocalDocument | null;
39
+ toolbar?: boolean;
40
+ authoring?: boolean;
41
+ onExport?(): void;
42
+ textareaRef?: RefObject<HTMLTextAreaElement | null>;
43
+ }
44
+ export interface ReactiveMarkdownEditorHandle {
45
+ focus(selection?: EditorSelection): void;
46
+ selectRange(range: SourceRange): void;
47
+ getSelection(): EditorSelection;
48
+ getTextarea(): HTMLTextAreaElement | null;
49
+ undo(): void;
50
+ redo(): void;
51
+ }
@@ -0,0 +1,5 @@
1
+ import { type RefObject } from 'react';
2
+ export declare function useGutterMetrics(lines: string[], mirrorRef: RefObject<HTMLDivElement | null>, editorRef: RefObject<HTMLTextAreaElement | null>): {
3
+ width: number;
4
+ heights: number[];
5
+ };
@@ -0,0 +1,16 @@
1
+ import type { EditorSelection } from './types.js';
2
+ export interface HistoryEntry {
3
+ value: string;
4
+ selection: EditorSelection;
5
+ }
6
+ export interface SourceHistoryStore {
7
+ readonly canUndo: boolean;
8
+ readonly canRedo: boolean;
9
+ record(value: string, selection: EditorSelection, mode?: 'merge' | 'separate'): void;
10
+ undo(): HistoryEntry | null;
11
+ redo(): HistoryEntry | null;
12
+ reset(value: string, selection?: EditorSelection): void;
13
+ }
14
+ export type SourceHistory = SourceHistoryStore;
15
+ export declare function createSourceHistory(initialValue: string, initialSelection?: EditorSelection, now?: () => number): SourceHistoryStore;
16
+ export declare function useSourceHistory(initialValue: string, initialSelection?: EditorSelection): SourceHistory;
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode } from 'react';
2
- import type { Diagnostic, LocalDocument, LocalNode, LocalRuntime } from './types.js';
2
+ import type { Diagnostic, LocalCompileOptions, LocalDocument, LocalNode, LocalRuntime } from './types.js';
3
3
  import type { LocalRenderMode } from './render-types.js';
4
4
  import { type LocalColorScheme, type LocalThemeDefinition } from './theme.js';
5
5
  import { type LocalLocale, type Localize } from './i18n.js';
@@ -59,6 +59,12 @@ export interface LocalReactiveDocumentProps {
59
59
  staticFirst?: boolean;
60
60
  /** Trusted image URL mapping forwarded to `LocalDocumentView`. */
61
61
  imageResolver?: LocalImageResolver;
62
+ /**
63
+ * Host-owned compile options. HTML capability flags select the temporary
64
+ * whole-document native branch; the component recompiles when a flag or the
65
+ * node budget changes, but not when an equal object is recreated.
66
+ */
67
+ compileOptions?: LocalCompileOptions;
62
68
  }
63
69
  interface LocalComponentProps {
64
70
  node: LocalNode;
@@ -77,6 +83,7 @@ export declare function textProblem(value: string, options: {
77
83
  email?: boolean;
78
84
  }, t?: Localize): string | null;
79
85
  export declare const COMPONENTS: Record<string, (props: LocalComponentProps) => ReactNode>;
80
- export declare function LocalDocumentView({ document, runtime, onDiagnostics, urlPolicy, locale, themes, colorScheme, mode, staticFirst, imageResolver, }: LocalDocumentViewProps): import("react").JSX.Element;
81
- export declare function LocalReactiveDocument({ source, onDiagnostics, urlPolicy, locale, themes, colorScheme, mode, staticFirst, imageResolver, }: LocalReactiveDocumentProps): import("react").JSX.Element;
86
+ /** Keep the two render paths in separate components so mode changes obey hook ordering. */
87
+ export declare function LocalDocumentView(props: LocalDocumentViewProps): import("react").JSX.Element;
88
+ export declare function LocalReactiveDocument({ source, onDiagnostics, urlPolicy, locale, themes, colorScheme, mode, staticFirst, imageResolver, compileOptions, }: LocalReactiveDocumentProps): import("react").JSX.Element;
82
89
  export {};
@@ -0,0 +1,26 @@
1
+ import { type ReactElement, type ReactNode } from 'react';
2
+ /**
3
+ * Fenced code blocks with optional syntax highlighting and a copy button.
4
+ *
5
+ * Highlighting is renderer-only and never trusts source as HTML: lowlight
6
+ * produces a hast tree whose text and span nodes are mapped back to React text
7
+ * and span elements. Unknown languages, oversized sources, mismatched text and
8
+ * highlighting failures all fall back to the exact source value.
9
+ */
10
+ /** Sources longer than this render as plain text; highlighting cost grows with input. */
11
+ export declare const MAX_HIGHLIGHT_CHARS = 20000;
12
+ export interface CodeHighlight {
13
+ /** Highlighted children, or `null` when the source should render verbatim. */
14
+ nodes: ReactNode[] | null;
15
+ highlighted: boolean;
16
+ }
17
+ /** Highlight a source string without automatic language detection. */
18
+ export declare function highlightCode(value: string, language?: string): CodeHighlight;
19
+ export interface CodeBlockViewProps {
20
+ value: string;
21
+ language?: string;
22
+ mode: 'interactive' | 'static';
23
+ /** Renderer-validated P0 HTML attributes, never raw source attributes. */
24
+ htmlProps?: Record<string, string>;
25
+ }
26
+ export declare function CodeBlockView({ value, language, mode, htmlProps }: CodeBlockViewProps): ReactElement;
@@ -226,6 +226,26 @@ export declare const LOCAL_DIAGNOSTIC_MESSAGES: {
226
226
  readonly en: 'Raw HTML is not part of the local interaction syntax.';
227
227
  readonly zh: '原始 HTML 不属于本地交互语法。';
228
228
  };
229
+ readonly 'html.extended': {
230
+ readonly en: 'HTML element <{name}> requires enableExtendedHtml in this mode; it is shown as source.';
231
+ readonly zh: '此模式下 HTML 元素 <{name}> 需要启用 enableExtendedHtml;已按源码显示。';
232
+ };
233
+ readonly 'html.attribute': {
234
+ readonly en: 'HTML attribute {name} on <{tag}> is not supported; the element is shown as source.';
235
+ readonly zh: '<{tag}> 上的 HTML 属性 {name} 不受支持;该元素已按源码显示。';
236
+ };
237
+ readonly 'html.unsafeUrl': {
238
+ readonly en: 'Unsafe URL in attribute {name} was removed.';
239
+ readonly zh: '属性 {name} 中的不安全 URL 已移除。';
240
+ };
241
+ readonly 'html.capability': {
242
+ readonly en: 'Author {feature} was disabled by the compile options.';
243
+ readonly zh: '编译选项已禁用作者提供的{feature}。';
244
+ };
245
+ readonly 'options.htmlFlag': {
246
+ readonly en: 'Compile option {name} must be a boolean.';
247
+ readonly zh: '编译选项 {name} 必须是布尔值。';
248
+ };
229
249
  readonly 'component.unknownSuggestion': {
230
250
  readonly en: 'Unknown component <{name}>. Did you mean <{suggestion}>?';
231
251
  readonly zh: '未知组件 <{name}>。是否想使用 <{suggestion}>?';
@@ -1241,6 +1261,11 @@ declare const LOCAL_DIAGNOSTIC_TEMPLATE_ALIASES: {
1241
1261
  readonly 'local.math.whitespace': 'math.whitespace';
1242
1262
  readonly 'local.footnote.unsupported': 'footnote.unsupported';
1243
1263
  readonly 'local.html': 'html.raw';
1264
+ readonly 'local.html.extended': 'html.extended';
1265
+ readonly 'local.html.attribute': 'html.attribute';
1266
+ readonly 'local.html.unsafe-url': 'html.unsafeUrl';
1267
+ readonly 'local.html.capability': 'html.capability';
1268
+ readonly 'local.options.invalid.html-flag': 'options.htmlFlag';
1244
1269
  readonly 'local.component.unknown.suggestion': 'component.unknownSuggestion';
1245
1270
  readonly 'local.component.unknown': 'component.unknownPlain';
1246
1271
  readonly 'local.attribute.format': 'attribute.lowercase';
@@ -0,0 +1,51 @@
1
+ import type { LocalDocument, LocalNode } from './types.js';
2
+ /** One rendered reference occurrence and the endnote it points at. */
3
+ export interface LocalFootnoteReferenceSite {
4
+ node: LocalNode;
5
+ /** Unique, instance-scoped DOM id for this occurrence. */
6
+ id: string;
7
+ }
8
+ /** One referenced definition, numbered by first reference order. */
9
+ export interface LocalFootnoteEntry {
10
+ identifier: string;
11
+ /** 1-based number shared by every reference to this identifier. */
12
+ number: number;
13
+ definition: LocalNode;
14
+ /** Instance-scoped DOM id of the endnote list item. */
15
+ id: string;
16
+ references: LocalFootnoteReferenceSite[];
17
+ }
18
+ /** What a single `footnoteReference` node renders as. */
19
+ export interface LocalFootnoteSite {
20
+ /** Unique DOM id of the reference link; empty for an undefined reference. */
21
+ id: string;
22
+ /** The matching entry, or `null` when no definition exists. */
23
+ entry: LocalFootnoteEntry | null;
24
+ /** Original label, shown as `[^label]` for undefined references. */
25
+ label: string;
26
+ }
27
+ export interface LocalFootnoteIndex {
28
+ /** Referenced definitions in first-reference order. */
29
+ entries: LocalFootnoteEntry[];
30
+ siteFor(node: LocalNode): LocalFootnoteSite | undefined;
31
+ }
32
+ /**
33
+ * The parser already normalizes identifiers, but a hand-built tree may carry
34
+ * raw labels. Whitespace runs collapse and case is folded so references and
35
+ * definitions still meet; the renderer never uses this value in HTML.
36
+ */
37
+ export declare function normalizeFootnoteIdentifier(value: string): string;
38
+ /** Normalized, non-empty identifier used to pair references and definitions. */
39
+ export declare function footnoteIdentifier(node: LocalNode): string;
40
+ /** Original label shown to readers; never used to build a DOM id. */
41
+ export declare function footnoteLabelText(node: LocalNode): string;
42
+ /**
43
+ * Collect definitions and references for one document instance.
44
+ *
45
+ * Numbering follows the order references become visible: body references in
46
+ * source order first, then references exposed inside already-numbered endnote
47
+ * bodies. References inside a definition that is never displayed therefore do
48
+ * not create an endnote or a dangling backlink. Duplicate definitions keep the
49
+ * first one; unresolved references render as `[^label]` and are not numbered.
50
+ */
51
+ export declare function collectLocalFootnotes(document: LocalDocument, instanceId: string): LocalFootnoteIndex;
@@ -11,7 +11,9 @@ import type { LocalDocument, LocalNode } from './types.js';
11
11
  export declare function createHeadingAnchors(document: LocalDocument, namespace: string, includeExplicitAnchors?: boolean): {
12
12
  ids: Map<LocalNode, string>;
13
13
  anchorIds: Map<LocalNode, string>;
14
+ htmlIds: Map<LocalNode, string>;
14
15
  /** Namespaced DOM id for a static jump/anchor target slug, if it exists. */
15
16
  targetId(to: string): string | undefined;
17
+ referenceId(to: string): string;
16
18
  resolve(href: string): string;
17
19
  };
@@ -0,0 +1,16 @@
1
+ import type { Diagnostic, LocalHtmlPolicy } from './types.js';
2
+ export interface LocalHtmlSanitizeResult {
3
+ markup: string;
4
+ diagnostics: Diagnostic[];
5
+ }
6
+ /** The sandbox always keeps author documents separate from their host. */
7
+ export declare function localHtmlSandbox(policy: LocalHtmlPolicy): string;
8
+ /** Resources stay offline; extended HTML permits explicit HTTP(S) form submissions. */
9
+ export declare function localHtmlContentSecurityPolicy(policy: LocalHtmlPolicy): string;
10
+ /**
11
+ * Parse, sanitize and serialize a whole native HTML document. The result is a
12
+ * complete document string suitable for a sandboxed `srcdoc` iframe.
13
+ */
14
+ export declare function sanitizeLocalHtmlDocument(source: string, policy: LocalHtmlPolicy, maxSyntaxNodes: number): LocalHtmlSanitizeResult;
15
+ export declare const LOCAL_HTML_P0_ELEMENTS: Set<string>;
16
+ export declare const LOCAL_HTML_VOID_ELEMENTS: Set<string>;