@heikeson/md-engine 0.0.0-stage → 0.2.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,217 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ /** 子项参数 */
5
+ interface AccItemProps {
6
+ title?: string;
7
+ /** 锚点 id,供 `#id` 深链定位 */
8
+ id?: string;
9
+ /** `open` 默认展开;`close` 或省略则默认收起 */
10
+ type?: string;
11
+ /** 深链命中时由父级传入,优先级高于 type */
12
+ defaultOpen?: boolean;
13
+ children?: ReactNode;
14
+ }
15
+ /**
16
+ * 折叠面板子项
17
+ * @param props 标题、锚点、默认展开标记与内容
18
+ * @returns 可折叠条目
19
+ */
20
+ declare function AccItem({ title, id, type, defaultOpen, children }: AccItemProps): react.JSX.Element;
21
+
22
+ /**
23
+ * 折叠面板
24
+ * @param children 内层 `<AccItem>` 元素集合
25
+ */
26
+ declare function Accordion({ children }: {
27
+ children?: ReactNode;
28
+ }): react.JSX.Element;
29
+
30
+ declare function Callout({ type, title, icon, children, }: {
31
+ type?: string;
32
+ title?: string;
33
+ /** 自定义图标:字符串(emoji / 短文本,Markdown 属性可用)或 React 节点(TSX 直接使用时可用) */
34
+ icon?: ReactNode;
35
+ children?: ReactNode;
36
+ }): react.JSX.Element;
37
+
38
+ /**
39
+ * 卡片子项(`<Card title="…" href="…" icon="…">`)透传容器。
40
+ * 真实渲染由父组件 Cards 读取其 title / href / icon / children 后统一绘制。
41
+ * @param props 含 children 及指令透传的属性(title / href 等)
42
+ * @created 2026-09-03 22:17
43
+ * @updated 2026-09-03 22:17 随嵌套指令方案新增
44
+ */
45
+ declare function Card(props: {
46
+ children?: ReactNode;
47
+ [key: string]: unknown;
48
+ }): react.JSX.Element;
49
+
50
+ /**
51
+ * 卡片网格
52
+ * @param children 内层 `<Card>` 元素集合
53
+ */
54
+ declare function Cards({ children }: {
55
+ children?: ReactNode;
56
+ }): react.JSX.Element;
57
+
58
+ /** 文件参数 */
59
+ interface FileProps {
60
+ /** 文件名 */
61
+ name?: string;
62
+ /** 可选链接;协议不合规时降级为不可点击(审计 4.3) */
63
+ href?: string;
64
+ /** 图标覆盖:类别键(code/text/data/…)或扩展名;不写则按 name 自动匹配 */
65
+ icon?: string;
66
+ }
67
+ /**
68
+ * 文件行
69
+ * @param props 文件名、可选链接与图标覆盖值
70
+ * @returns 文件节点
71
+ */
72
+ declare function File({ name, href, icon }: FileProps): react.JSX.Element;
73
+
74
+ /**
75
+ * 文件树
76
+ * @param children 内层 `<Folder>` / `<File>` 元素
77
+ */
78
+ declare function Files({ children }: {
79
+ children?: ReactNode;
80
+ }): react.JSX.Element;
81
+
82
+ /** 目录参数 */
83
+ interface FolderProps {
84
+ /** 目录名 */
85
+ name?: string;
86
+ /** 默认展开(布尔属性,写 `defaultOpen` 即为真) */
87
+ defaultOpen?: boolean;
88
+ children?: ReactNode;
89
+ }
90
+ /**
91
+ * 可折叠目录
92
+ * @param props 目录名、默认展开与子项
93
+ * @returns 目录节点
94
+ */
95
+ declare function Folder({ name, defaultOpen, children }: FolderProps): react.JSX.Element;
96
+
97
+ /** 图片参数 */
98
+ interface ImageProps {
99
+ src?: string;
100
+ alt?: string;
101
+ align?: "left" | "center" | "right";
102
+ width?: string | number;
103
+ caption?: string;
104
+ /** 点击放大(布尔属性,写 `zoom` 即为真) */
105
+ zoom?: boolean;
106
+ children?: ReactNode;
107
+ }
108
+ /**
109
+ * 图片(含题注)
110
+ * @param props 图片来源、对齐、宽度、题注与缩放开关
111
+ * @returns 图片元素
112
+ */
113
+ declare function Image({ src, alt, align, width, caption, zoom, children, }: ImageProps): react.JSX.Element;
114
+
115
+ /**
116
+ * 步骤子项(`<Step title="…">`)透传容器。
117
+ * 真实渲染由父组件 Steps 读取其 title / children 后统一绘制,故此组件仅作占位。
118
+ * @param props 含 children 及指令透传的属性(title 等)
119
+ * @created 2026-09-03 22:17
120
+ * @updated 2026-09-03 22:17 随嵌套指令方案新增
121
+ */
122
+ declare function Step(props: {
123
+ children?: ReactNode;
124
+ [key: string]: unknown;
125
+ }): react.JSX.Element;
126
+
127
+ /**
128
+ * 步骤容器:聚合内层 `<Step title="…">` 为带序号竖线的步骤列表。
129
+ * 每个 step 的 title 取自指令属性,正文为其内部 Markdown 内容(可含任意块级元素)。
130
+ * @param children 内层 step 元素集合
131
+ * @created 2026-09-03 21:54
132
+ * @updated 2026-10-24 21:32 语法改为尖括号 `<Step>`,支持任意嵌套内容
133
+ */
134
+ declare function Steps({ children }: {
135
+ children?: ReactNode;
136
+ }): react.JSX.Element;
137
+
138
+ /**
139
+ * 选项卡子项(`<Tab value="…">`)透传容器。
140
+ * 真实渲染由父组件 Tabs 读取其 label / children 后统一绘制。
141
+ * @param props 含 children 及指令透传的属性(label 等)
142
+ * @created 2026-09-03 22:17
143
+ * @updated 2026-09-03 22:17 随嵌套指令方案新增
144
+ */
145
+ declare function Tab(props: {
146
+ children?: ReactNode;
147
+ [key: string]: unknown;
148
+ }): react.JSX.Element;
149
+
150
+ /**
151
+ * 选项卡
152
+ * @param children 内层 Tab 元素集合
153
+ */
154
+ declare function Tabs({ children }: {
155
+ children?: ReactNode;
156
+ }): react.JSX.Element | null;
157
+
158
+ /** 行参数 */
159
+ interface TypeItemProps {
160
+ /** 属性名 */
161
+ name?: string;
162
+ /** 类型表达式,如 `string` / `"a" | "b"` */
163
+ type?: string;
164
+ /** 默认值 */
165
+ default?: string;
166
+ /** 是否必填(布尔属性) */
167
+ required?: boolean;
168
+ /** 说明 */
169
+ children?: ReactNode;
170
+ }
171
+ /**
172
+ * 类型表行
173
+ * @param props 属性名、类型、默认值、必填标记与说明
174
+ * @returns 表格行
175
+ */
176
+ declare function TypeItem({ name, type, default: defaultValue, required, children }: TypeItemProps): react.JSX.Element;
177
+
178
+ /**
179
+ * 类型表
180
+ * @param children 内层 `<TypeItem>` 元素
181
+ * @returns 表格
182
+ */
183
+ declare function TypeTable({ children }: {
184
+ children?: ReactNode;
185
+ }): react.JSX.Element;
186
+
187
+ /**
188
+ * @file 内容组件集合与渲染映射
189
+ * @description 映射键与 mdast 节点名完全一致(首字母大写),由渲染层的 hast tagName 直接查表。
190
+ * 新增组件时:先在 registry 声明,再在此登记组件实现。
191
+ * @created 2026-10-24 20:10
192
+ * @updated 2026-10-24 21:58 文件树改为 Files / Folder / File
193
+ */
194
+
195
+ /**
196
+ * 组件名 → React 组件 的映射
197
+ * @description 键必须与 `<Name>` 中的名字一致(大小写敏感)
198
+ */
199
+ declare const mdxComponents: {
200
+ Callout: typeof Callout;
201
+ Tabs: typeof Tabs;
202
+ Tab: typeof Tab;
203
+ Steps: typeof Steps;
204
+ Step: typeof Step;
205
+ Cards: typeof Cards;
206
+ Card: typeof Card;
207
+ Accordion: typeof Accordion;
208
+ AccItem: typeof AccItem;
209
+ Files: typeof Files;
210
+ Folder: typeof Folder;
211
+ File: typeof File;
212
+ TypeTable: typeof TypeTable;
213
+ TypeItem: typeof TypeItem;
214
+ Image: typeof Image;
215
+ };
216
+
217
+ export { AccItem, Accordion, Callout, Card, Cards, File, Files, Folder, Image as MdImage, Step, Steps, Tab, Tabs, TypeItem, TypeTable, mdxComponents };
@@ -0,0 +1,3 @@
1
+ export { AccItem, Accordion, Callout, Card, Cards, File, Files, Folder, Image as MdImage, Step, Steps, Tab, Tabs, TypeItem, TypeTable, mdxComponents } from '../chunk-QDDS7MPU.js';
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,100 @@
1
+ import * as react from 'react';
2
+
3
+ /**
4
+ * @file Markdown 编辑器(文本即真源)
5
+ * @description 左源码(CodeMirror)右预览:编辑器只改 Markdown 文本,不做 HTML 中间态。
6
+ * 容器块通过「工具栏插入 + 文本编辑」维护,没有第二套文档模型。
7
+ * 声明顺序按「refs → 动作 → 编辑器实例 → 派生状态」组织,避免在声明前引用。
8
+ * @created 2026-10-24 21:12
9
+ * @updated 2026-10-24 21:10 补齐图片上传、修复 hook 依赖与声明顺序
10
+ */
11
+ /** 编辑器配置(只增不改) */
12
+ interface EditorConfig {
13
+ /** 图片上传(宿主注入),返回可访问 URL */
14
+ uploadImage?: (file: File) => Promise<string>;
15
+ placeholder?: string;
16
+ readOnly?: boolean;
17
+ }
18
+ /** 视图 */
19
+ type EditorView = "split" | "source" | "preview";
20
+ /** 编辑器参数 */
21
+ interface MarkdownEditorProps {
22
+ value: string;
23
+ onChange: (value: string) => void;
24
+ /** 初始视图;挂载后由工具栏切换按钮控制 */
25
+ view?: EditorView;
26
+ config?: EditorConfig;
27
+ /** 当前是否全屏(宿主控制,传入才显示按钮) */
28
+ fullscreen?: boolean;
29
+ /** 全屏切换回调 */
30
+ onToggleFullscreen?: () => void;
31
+ }
32
+ /**
33
+ * Markdown 编辑器
34
+ * @param props 文本、变更回调、视图与配置
35
+ * @returns 编辑器元素
36
+ */
37
+ declare function MarkdownEditor({ value, onChange, view, config, fullscreen, onToggleFullscreen, }: MarkdownEditorProps): react.JSX.Element;
38
+
39
+ /**
40
+ * @file 插入片段模板
41
+ * @description 组件名一律取自 `registry`,模板只描述"骨架"(标签 + 子项 + 空行),
42
+ * 禁止在别处硬编码 `<Callout` 之类的字符串。
43
+ * @created 2026-10-24 21:12
44
+ * @updated 2026-10-24 21:58 容器子项支持数组(Files 混用 Folder / File)
45
+ */
46
+ /**
47
+ * 生成容器的插入骨架
48
+ * @param name 组件名(须存在于 registry)
49
+ * @returns 可直接插入的 Markdown 片段;未知组件返回空串
50
+ */
51
+ declare function blockSnippet(name: string): string;
52
+ /** 工具栏里可一键插入的容器顺序 */
53
+ declare const INSERTABLE_BLOCKS: readonly ["Callout", "Tabs", "Steps", "Cards", "Accordion", "Files", "TypeTable", "Image"];
54
+
55
+ /**
56
+ * @file 编辑器文本动作(纯函数,无 DOM)
57
+ * @description 编辑器只改 Markdown 文本,不维护第二份文档模型。这里提供三个基础动作:
58
+ * 选区包裹、行首前缀切换、光标处插入。全部返回新文本与新选区,由调用方写回。
59
+ * @created 2026-10-24 21:12
60
+ * @updated 2026-10-24 21:12
61
+ */
62
+ /** 选区(全文 offset,end 不含) */
63
+ interface Selection {
64
+ start: number;
65
+ end: number;
66
+ }
67
+ /** 动作结果 */
68
+ interface EditResult {
69
+ value: string;
70
+ selection: Selection;
71
+ }
72
+ /**
73
+ * 在选区两侧包裹标记(粗体 / 斜体 / 行内码等)
74
+ * @param value 全文
75
+ * @param selection 当前选区
76
+ * @param before 前置标记
77
+ * @param after 后置标记
78
+ * @param placeholder 空选区时填充的占位文字
79
+ * @returns 新文本与新选区(选中原来那段内容)
80
+ */
81
+ declare function wrapSelection(value: string, selection: Selection, before: string, after: string, placeholder?: string): EditResult;
82
+ /**
83
+ * 切换行首前缀(标题 / 引用 / 列表)
84
+ * @description 选区内所有行都有该前缀则移除,否则统一加上(用于「再点一次取消」)
85
+ * @param value 全文
86
+ * @param selection 当前选区
87
+ * @param prefix 行首前缀,如 `## `、`- `、`> `
88
+ * @returns 新文本与新选区
89
+ */
90
+ declare function toggleLinePrefix(value: string, selection: Selection, prefix: string): EditResult;
91
+ /**
92
+ * 在光标处插入片段(字符级,用于行内内容)
93
+ * @param value 全文
94
+ * @param position 插入位置(通常为选区起点)
95
+ * @param snippet 片段文本
96
+ * @returns 新文本与光标位置(落在片段之后)
97
+ */
98
+ declare function insertAtCursor(value: string, position: number, snippet: string): EditResult;
99
+
100
+ export { type EditResult, type EditorConfig, type EditorView, INSERTABLE_BLOCKS, MarkdownEditor, type MarkdownEditorProps, type Selection, blockSnippet, insertAtCursor, toggleLinePrefix, wrapSelection };