@zhenryx/react-editor 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,96 @@
1
+ 'use client';
2
+ type RichTextEditorFeature = 'undo' | 'redo' | 'format' | 'bold' | 'italic' | 'strike' | 'list' | 'orderedList' | 'quote' | 'hr' | 'code' | 'table' | 'image' | 'link' | 'toc' | 'history' | 'color' | 'background' | 'underline' | 'align' | 'video' | 'formula' | 'template' | 'wide' | 'todo' | 'codeRun' | 'save' | 'sidebar' | 'outline' | 'syntax' | 'importMd' | 'exportMd' | 'more' | 'other';
3
+ type RichTextEditorFeatures = Partial<Record<RichTextEditorFeature, boolean>>;
4
+ interface RichTextEditorProps {
5
+ /** 当前文章内容(Markdown) */
6
+ markdown: string;
7
+ /** 内容变化时回传 Markdown */
8
+ onChange: (markdown: string) => void;
9
+ /** 图片上传:返回可访问的图片 URL */
10
+ onUploadImage: (file: File) => Promise<string>;
11
+ /** 提供「切换到 Markdown 编辑器」等外部动作;不传则不显示该按钮 */
12
+ onSwitchToMarkdown?: () => void;
13
+ /** 切换按钮文字,默认「使用 Markdown 编辑器」 */
14
+ switchLabel?: string;
15
+ /** Markdown → HTML 渲染器;不传时退化为纯文本段落,建议传入 */
16
+ renderMarkdown?: (markdown: string) => string;
17
+ /** 正文为空时的提示 */
18
+ placeholder?: string;
19
+ className?: string;
20
+ /** 按按钮控制功能开关;不传 = 全部开启 */
21
+ features?: RichTextEditorFeatures;
22
+ }
23
+ declare function RichTextEditor({ markdown, onChange, onUploadImage, onSwitchToMarkdown, switchLabel, renderMarkdown, placeholder, className, features }: RichTextEditorProps): import("react").JSX.Element;
24
+ type MarkdownEditorView = 'markdown' | 'split' | 'preview';
25
+ interface MarkdownEditorProps {
26
+ /** 当前内容(Markdown) */
27
+ markdown: string;
28
+ /** 内容变化时回传 Markdown */
29
+ onChange: (markdown: string) => void;
30
+ /** 上传图片并返回可访问 URL */
31
+ onUploadImage: (file: File) => Promise<string>;
32
+ /** Markdown → HTML 渲染器;不传时退化为纯文本段落 */
33
+ renderMarkdown?: (markdown: string) => string;
34
+ /** 提供「切换到普通编辑器」入口;不传则不显示按钮 */
35
+ onSwitchToRichEditor?: () => void;
36
+ /** 切换按钮文字,默认「使用普通编辑器」 */
37
+ switchLabel?: string;
38
+ /** 保存草稿回调(工具栏保存图标) */
39
+ onSave?: () => void;
40
+ /** 导出文件名(不含扩展名),默认 article */
41
+ fileBaseName?: string;
42
+ /** 按按钮控制功能开关 */
43
+ features?: RichTextEditorFeatures;
44
+ /** 初始视图:Markdown / 比对 / 预览,默认比对 */
45
+ initialView?: MarkdownEditorView;
46
+ /** 正文为空时的占位 */
47
+ placeholder?: string;
48
+ className?: string;
49
+ }
50
+ declare function MarkdownEditor({ markdown, onChange, onUploadImage, renderMarkdown, onSwitchToRichEditor, switchLabel, onSave, fileBaseName, features, initialView, placeholder, className }: MarkdownEditorProps): import("react").JSX.Element;
51
+ type MarkdownRichEditorMode = 'rich' | 'markdown';
52
+ interface MarkdownRichEditorProps extends Omit<RichTextEditorProps, 'onSwitchToMarkdown' | 'className' | 'switchLabel'> {
53
+ /** 受控模式;不传时使用 defaultMode 内部维护 */
54
+ mode?: MarkdownRichEditorMode;
55
+ /** 非受控初始模式,默认 rich */
56
+ defaultMode?: MarkdownRichEditorMode;
57
+ /** 模式变化回调 */
58
+ onModeChange?: (mode: MarkdownRichEditorMode) => void;
59
+ /** Markdown 编辑器初始视图,默认 split */
60
+ markdownView?: MarkdownEditorView;
61
+ /** Markdown 编辑器的切换按钮文字,默认「使用普通编辑器」 */
62
+ markdownSwitchLabel?: string;
63
+ /** Markdown 工具栏保存回调 */
64
+ onSave?: () => void;
65
+ /** Markdown 导出文件名(不含扩展名) */
66
+ fileBaseName?: string;
67
+ /** 富文本模式切换按钮文字,默认「使用 Markdown 编辑器」 */
68
+ richSwitchLabel?: string;
69
+ /** 普通编辑器专用渲染器;不传则复用 renderMarkdown */
70
+ renderRichMarkdown?: (markdown: string) => string;
71
+ /** 共用功能开关 */
72
+ features?: RichTextEditorFeatures;
73
+ className?: string;
74
+ markdownClassName?: string;
75
+ richClassName?: string;
76
+ }
77
+ /** 普通编辑器 + Markdown 编辑器,一个组件内切换 */
78
+ declare function MarkdownRichEditor({ mode, defaultMode, onModeChange, markdownView, markdownSwitchLabel, renderRichMarkdown, onSave, fileBaseName, richSwitchLabel, className, markdownClassName, richClassName, ...props }: MarkdownRichEditorProps): import("react").JSX.Element;
79
+ declare function defaultRenderMarkdown(markdown: string): string;
80
+ /**
81
+ * contentEditable HTML → Markdown(2026-11-16)
82
+ *
83
+ * 普通编辑器只做 Markdown 能表达的能力(标题 / 加粗 / 斜体 / 删除线 / 列表 /
84
+ * 引用 / 代码块 / 链接 / 图片 / 表格 / 分割线),因此转换是可逆的:
85
+ * 普通编辑器读入时用 renderMarkdown(),保存时用本文件转回 Markdown。
86
+ */
87
+ /** contentEditable 的 innerHTML → Markdown */
88
+ declare function htmlToMarkdown(html: string): string;
89
+ declare function safeRichHref(raw: string): string;
90
+ /**
91
+ * 为 Markdown 渲染出的 HTML 代码块增加「源码 / 预览 / 复制 / 全屏 / 刷新」。
92
+ * 只处理 language-html / language-htm,普通代码块完全不动。
93
+ */
94
+ declare function enhanceHtmlCodeBlocks(container: HTMLElement): void;
95
+ export { MarkdownEditor, type MarkdownEditorProps, type MarkdownEditorView, MarkdownRichEditor, type MarkdownRichEditorMode, type MarkdownRichEditorProps, RichTextEditor, type RichTextEditorFeature, type RichTextEditorFeatures, type RichTextEditorProps, defaultRenderMarkdown, enhanceHtmlCodeBlocks, htmlToMarkdown, safeRichHref };
96
+ //# sourceMappingURL=index.d.mts.map