@xiangfa/mindmap 0.3.0 → 0.5.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.
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright [2026] [U14App Team]
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md CHANGED
@@ -2,26 +2,29 @@
2
2
 
3
3
  # Open MindMap
4
4
 
5
+ [![npm version](https://img.shields.io/npm/v/@xiangfa/mindmap)](https://www.npmjs.com/package/@xiangfa/mindmap)
6
+ [![npm downloads](https://img.shields.io/npm/dm/@xiangfa/mindmap)](https://www.npmjs.com/package/@xiangfa/mindmap)
7
+ [![license](https://img.shields.io/npm/l/@xiangfa/mindmap)](./LICENSE)
8
+ [![react](https://img.shields.io/badge/react-%E2%89%A518-blue)](https://react.dev)
9
+
5
10
  A beautiful, interactive mind map component for React.
6
11
 
7
12
  **Natively supports AI stream output** with Markdown list syntax and **iOS-style UI**.
8
13
 
9
14
  Zero dependencies. SVG-based. Keyboard-first. Dark mode ready.
10
15
 
11
- [![npm version](https://img.shields.io/npm/v/@xiangfa/mindmap.svg?style=flat-square)](https://www.npmjs.com/package/@xiangfa/mindmap)
12
- [![npm downloads](https://img.shields.io/npm/dm/@xiangfa/mindmap.svg?style=flat-square)](https://www.npmjs.com/package/@xiangfa/mindmap)
13
- [![bundle size](https://img.shields.io/bundlephobia/minzip/@xiangfa/mindmap?style=flat-square)](https://bundlephobia.com/package/@xiangfa/mindmap)
14
- [![license](https://img.shields.io/github/license/u14app/mindmap?style=flat-square)](https://github.com/u14app/mindmap/blob/main/LICENSE)
15
-
16
16
  English | [中文](README.zh-CN.md)
17
17
 
18
18
  </div>
19
19
 
20
20
  ---
21
21
 
22
+ ![Open MindMap](/public/screenshot.png)
23
+
22
24
  ## Features
23
25
 
24
26
  - **AI stream ready** — natively supports AI streaming output; feed a markdown list in, get a real-time mind map out
27
+ - **Built-in AI generation** — connect any OpenAI-compatible API to generate mind maps from natural language; supports text, image, and PDF attachments
25
28
  - **Pure SVG rendering** — no canvas, no external layout engines, razor-sharp at any zoom level
26
29
  - **iOS-style UI** — frosted glass controls, rounded corners, smooth animations, clean and polished design
27
30
  - **Plugin system** — 7 built-in plugins for extended syntax (dotted lines, folding, multi-line, tags, cross-links, LaTeX, frontmatter); fully extensible
@@ -137,6 +140,38 @@ In readonly mode, users can still pan, zoom, and select nodes, but cannot create
137
140
  <MindMap data={data} theme="light" /> {/* always light */}
138
141
  ```
139
142
 
143
+ ### Custom Styling
144
+
145
+ Override CSS custom properties on the container to customize colors, fonts, and more:
146
+
147
+ ```css
148
+ /* Override theme variables */
149
+ .mindmap-container {
150
+ --mindmap-root-bg: #1a73e8;
151
+ --mindmap-canvas-bg: #f0f4f8;
152
+ --mindmap-node-text: #1a1a2e;
153
+ }
154
+ ```
155
+
156
+ Target specific elements with semantic CSS classes:
157
+
158
+ ```css
159
+ /* Style all edges */
160
+ .mindmap-edge { stroke-width: 3; }
161
+
162
+ /* Style root node background */
163
+ .mindmap-node-root .mindmap-node-bg { fill: #6c5ce7; }
164
+ ```
165
+
166
+ Customize individual branch colors via `data-branch-index`:
167
+
168
+ ```css
169
+ .mindmap-edge[data-branch-index="0"] { stroke: #e74c3c; }
170
+ .mindmap-edge[data-branch-index="1"] { stroke: #2ecc71; }
171
+ ```
172
+
173
+ > See [Custom Styling Guide](docs/Custom%20Styling.md) for the full list of 30+ CSS variables, class selectors, and examples.
174
+
140
175
  ### Layout Direction
141
176
 
142
177
  ```tsx
@@ -237,6 +272,48 @@ function App() {
237
272
  }
238
273
  ```
239
274
 
275
+ ### AI Generation
276
+
277
+ Add a built-in AI input bar to generate mind maps from natural language. Connects to any OpenAI-compatible API with streaming support:
278
+
279
+ ```tsx
280
+ <MindMap
281
+ ai={{
282
+ apiUrl: "https://api.openai.com/v1/chat/completions",
283
+ apiKey: "sk-...",
284
+ model: "gpt-5",
285
+ }}
286
+ />
287
+ ```
288
+
289
+ Enable file attachments (text, image, PDF):
290
+
291
+ ```tsx
292
+ <MindMap
293
+ ai={{
294
+ apiUrl: "https://api.openai.com/v1/chat/completions",
295
+ apiKey: "sk-...",
296
+ model: "gpt-5",
297
+ attachments: ["text", "image", "pdf"],
298
+ }}
299
+ />
300
+ ```
301
+
302
+ Customize the system prompt:
303
+
304
+ ```tsx
305
+ <MindMap
306
+ ai={{
307
+ apiUrl: "https://api.openai.com/v1/chat/completions",
308
+ apiKey: "sk-...",
309
+ model: "gpt-5",
310
+ systemPrompt: "Generate a mind map about the given topic...",
311
+ }}
312
+ />
313
+ ```
314
+
315
+ > **Security Note:** The API key is sent from the browser. For production, use a proxy endpoint to keep your key server-side.
316
+
240
317
  ### Listening for Changes
241
318
 
242
319
  ```tsx
@@ -405,6 +482,7 @@ Render mathematical formulas (requires [KaTeX](https://katex.org/)):
405
482
  | `messages` | `Partial<MindMapMessages>` | - | Override any UI text string |
406
483
  | `readonly` | `boolean` | `false` | Display-only mode (no editing, no creating) |
407
484
  | `toolbar` | `boolean \| ToolbarConfig` | `true` | Show/hide zoom controls |
485
+ | `ai` | `MindMapAIConfig` | - | AI generation configuration (API endpoint, key, model, attachments) |
408
486
  | `plugins` | `MindMapPlugin[]` | `allPlugins` | Plugins to enable for extended syntax |
409
487
  | `onDataChange` | `(data: MindMapData[]) => void` | - | Called when the tree is modified by user interaction |
410
488
 
@@ -416,6 +494,28 @@ interface ToolbarConfig {
416
494
  }
417
495
  ```
418
496
 
497
+ ### MindMapAIConfig
498
+
499
+ ```ts
500
+ type AIAttachmentType = "text" | "image" | "pdf";
501
+
502
+ interface MindMapAIConfig {
503
+ apiUrl: string; // OpenAI-compatible API endpoint
504
+ apiKey: string; // API key (Bearer token)
505
+ model: string; // Model name (e.g., "gpt-5")
506
+ systemPrompt?: string; // Custom system prompt (has a built-in default)
507
+ attachments?: AIAttachmentType[]; // Allowed attachment types (default: [])
508
+ }
509
+ ```
510
+
511
+ | Field | Type | Required | Description |
512
+ | -------------- | -------------------- | -------- | ---------------------------------------------------------------------------------------- |
513
+ | `apiUrl` | `string` | Yes | OpenAI-compatible chat completions endpoint |
514
+ | `apiKey` | `string` | Yes | API key sent as `Bearer` token |
515
+ | `model` | `string` | Yes | Model identifier (e.g., `gpt-5`, `deepseek-chat`) |
516
+ | `systemPrompt` | `string` | No | Override the built-in mind map generation prompt |
517
+ | `attachments` | `AIAttachmentType[]` | No | Enable file uploads: `"text"` (text/\*), `"image"` (image/\*), `"pdf"` (application/pdf) |
518
+
419
519
  ### Ref Methods
420
520
 
421
521
  | Method | Returns | Description |
@@ -531,4 +631,4 @@ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md)
531
631
 
532
632
  ## License
533
633
 
534
- [MIT](LICENSE)
634
+ [Apache-2.0](LICENSE)
package/README.zh-CN.md CHANGED
@@ -2,26 +2,29 @@
2
2
 
3
3
  # Open MindMap
4
4
 
5
+ [![npm version](https://img.shields.io/npm/v/@xiangfa/mindmap)](https://www.npmjs.com/package/@xiangfa/mindmap)
6
+ [![npm downloads](https://img.shields.io/npm/dm/@xiangfa/mindmap)](https://www.npmjs.com/package/@xiangfa/mindmap)
7
+ [![license](https://img.shields.io/npm/l/@xiangfa/mindmap)](./LICENSE)
8
+ [![react](https://img.shields.io/badge/react-%E2%89%A518-blue)](https://react.dev)
9
+
5
10
  一个精美的 React 交互式思维导图组件。
6
11
 
7
12
  **原生支持 AI 流式输出**,使用 Markdown 列表语法,搭配 **iOS 风格 UI**。
8
13
 
9
14
  零依赖。基于 SVG。键盘优先。支持暗色模式。
10
15
 
11
- [![npm version](https://img.shields.io/npm/v/@xiangfa/mindmap.svg?style=flat-square)](https://www.npmjs.com/package/@xiangfa/mindmap)
12
- [![npm downloads](https://img.shields.io/npm/dm/@xiangfa/mindmap.svg?style=flat-square)](https://www.npmjs.com/package/@xiangfa/mindmap)
13
- [![bundle size](https://img.shields.io/bundlephobia/minzip/@xiangfa/mindmap?style=flat-square)](https://bundlephobia.com/package/@xiangfa/mindmap)
14
- [![license](https://img.shields.io/github/license/u14app/mindmap?style=flat-square)](https://github.com/u14app/mindmap/blob/main/LICENSE)
15
-
16
16
  [English](README.md) | 中文
17
17
 
18
18
  </div>
19
19
 
20
20
  ---
21
21
 
22
+ ![Open MindMap](/public/screenshot.png)
23
+
22
24
  ## 特性
23
25
 
24
26
  - **AI 流式输出** — 原生支持 AI 流式输出;输入 Markdown 列表,实时生成思维导图
27
+ - **内置 AI 生成** — 连接任意 OpenAI 兼容 API,通过自然语言生成思维导图;支持文本、图片和 PDF 附件上传
25
28
  - **纯 SVG 渲染** — 无 Canvas、无外部布局引擎,任意缩放级别下都清晰锐利
26
29
  - **iOS 风格 UI** — 毛玻璃控件、圆角设计、流畅动画,简洁精致
27
30
  - **插件系统** — 7 个内置插件扩展语法(虚线、折叠、多行、标签、跨链接、LaTeX、frontmatter);完全可扩展
@@ -137,6 +140,38 @@ const markdown = `
137
140
  <MindMap data={data} theme="light" /> {/* 始终亮色 */}
138
141
  ```
139
142
 
143
+ ### 自定义样式
144
+
145
+ 通过覆盖容器上的 CSS 自定义属性来定制颜色、字体等:
146
+
147
+ ```css
148
+ /* 覆盖主题变量 */
149
+ .mindmap-container {
150
+ --mindmap-root-bg: #1a73e8;
151
+ --mindmap-canvas-bg: #f0f4f8;
152
+ --mindmap-node-text: #1a1a2e;
153
+ }
154
+ ```
155
+
156
+ 通过语义化 CSS 类选择器定制特定元素:
157
+
158
+ ```css
159
+ /* 定制所有连线 */
160
+ .mindmap-edge { stroke-width: 3; }
161
+
162
+ /* 定制根节点背景 */
163
+ .mindmap-node-root .mindmap-node-bg { fill: #6c5ce7; }
164
+ ```
165
+
166
+ 通过 `data-branch-index` 定制各分支颜色:
167
+
168
+ ```css
169
+ .mindmap-edge[data-branch-index="0"] { stroke: #e74c3c; }
170
+ .mindmap-edge[data-branch-index="1"] { stroke: #2ecc71; }
171
+ ```
172
+
173
+ > 完整的 30+ CSS 变量、class 选择器和示例请参阅 [自定义样式指南](docs/Custom%20Styling.md)。
174
+
140
175
  ### 布局方向
141
176
 
142
177
  ```tsx
@@ -237,6 +272,48 @@ function App() {
237
272
  }
238
273
  ```
239
274
 
275
+ ### AI 生成
276
+
277
+ 添加内置 AI 输入栏,通过自然语言生成思维导图。支持连接任意 OpenAI 兼容 API 并流式输出:
278
+
279
+ ```tsx
280
+ <MindMap
281
+ ai={{
282
+ apiUrl: "https://api.openai.com/v1/chat/completions",
283
+ apiKey: "sk-...",
284
+ model: "gpt-5",
285
+ }}
286
+ />
287
+ ```
288
+
289
+ 启用附件上传(文本、图片、PDF):
290
+
291
+ ```tsx
292
+ <MindMap
293
+ ai={{
294
+ apiUrl: "https://api.openai.com/v1/chat/completions",
295
+ apiKey: "sk-...",
296
+ model: "gpt-5",
297
+ attachments: ["text", "image", "pdf"],
298
+ }}
299
+ />
300
+ ```
301
+
302
+ 自定义系统提示词:
303
+
304
+ ```tsx
305
+ <MindMap
306
+ ai={{
307
+ apiUrl: "https://api.openai.com/v1/chat/completions",
308
+ apiKey: "sk-...",
309
+ model: "gpt-5",
310
+ systemPrompt: "根据给定的主题生成思维导图...",
311
+ }}
312
+ />
313
+ ```
314
+
315
+ > **安全提示:** API 密钥会从浏览器发送。生产环境中建议使用代理端点来保护密钥安全。
316
+
240
317
  ### 监听变更
241
318
 
242
319
  ```tsx
@@ -405,6 +482,7 @@ theme: dark
405
482
  | `messages` | `Partial<MindMapMessages>` | - | 覆盖任意 UI 文本字符串 |
406
483
  | `readonly` | `boolean` | `false` | 仅显示模式(不可编辑、不可创建) |
407
484
  | `toolbar` | `boolean \| ToolbarConfig` | `true` | 显示/隐藏缩放控件 |
485
+ | `ai` | `MindMapAIConfig` | - | AI 生成配置(API 地址、密钥、模型、附件类型) |
408
486
  | `plugins` | `MindMapPlugin[]` | `allPlugins` | 启用的扩展语法插件 |
409
487
  | `onDataChange` | `(data: MindMapData[]) => void` | - | 用户交互修改树时调用 |
410
488
 
@@ -416,6 +494,28 @@ interface ToolbarConfig {
416
494
  }
417
495
  ```
418
496
 
497
+ ### MindMapAIConfig
498
+
499
+ ```ts
500
+ type AIAttachmentType = "text" | "image" | "pdf";
501
+
502
+ interface MindMapAIConfig {
503
+ apiUrl: string; // OpenAI 兼容 API 端点
504
+ apiKey: string; // API 密钥(Bearer token)
505
+ model: string; // 模型名称(如 "gpt-5")
506
+ systemPrompt?: string; // 自定义系统提示词(内置默认值)
507
+ attachments?: AIAttachmentType[]; // 允许的附件类型(默认:[])
508
+ }
509
+ ```
510
+
511
+ | 字段 | 类型 | 必填 | 说明 |
512
+ | -------------- | -------------------- | ---- | ------------------------------------------------------------------------------------ |
513
+ | `apiUrl` | `string` | 是 | OpenAI 兼容的 chat completions 端点 |
514
+ | `apiKey` | `string` | 是 | API 密钥,作为 `Bearer` token 发送 |
515
+ | `model` | `string` | 是 | 模型标识符(如 `gpt-5`、`deepseek-chat`) |
516
+ | `systemPrompt` | `string` | 否 | 覆盖内置的思维导图生成提示词 |
517
+ | `attachments` | `AIAttachmentType[]` | 否 | 启用文件上传:`"text"`(text/\*)、`"image"`(image/\*)、`"pdf"`(application/pdf) |
518
+
419
519
  ### Ref 方法
420
520
 
421
521
  | 方法 | 返回值 | 说明 |
@@ -531,4 +631,4 @@ pnpm lint # 运行代码检查
531
631
 
532
632
  ## 许可证
533
633
 
534
- [MIT](LICENSE)
634
+ [Apache-2.0](LICENSE)
@@ -0,0 +1,13 @@
1
+ import type { MindMapAIConfig } from "../types";
2
+ import type { ThemeColors } from "../utils/theme";
3
+ import type { MindMapMessages } from "../utils/i18n";
4
+ export interface MindMapAIInputProps {
5
+ config: MindMapAIConfig;
6
+ theme: ThemeColors;
7
+ messages: MindMapMessages;
8
+ currentMarkdown?: string;
9
+ onMarkdownStream: (markdown: string) => void;
10
+ onComplete: () => void;
11
+ onError: (error: string) => void;
12
+ }
13
+ export declare function MindMapAIInput({ config, theme, messages, currentMarkdown, onMarkdownStream, onComplete, onError, }: MindMapAIInputProps): import("react/jsx-runtime").JSX.Element;
@@ -17,4 +17,4 @@ export interface MindMapContextMenuProps {
17
17
  onDirectionChange: (dir: LayoutDirection) => void;
18
18
  onClose: () => void;
19
19
  }
20
- export declare function MindMapContextMenu({ position, theme, messages, readonly: readonlyProp, onNewRootNode, onExportSVG, onExportPNG, onExportMarkdown, onDirectionChange, onClose, }: MindMapContextMenuProps): import("react/jsx-runtime").JSX.Element;
20
+ export declare function MindMapContextMenu({ position, messages, readonly: readonlyProp, onNewRootNode, onExportSVG, onExportPNG, onExportMarkdown, onDirectionChange, onClose, }: MindMapContextMenuProps): import("react/jsx-runtime").JSX.Element;
@@ -13,4 +13,4 @@ export interface MindMapControlsProps {
13
13
  onModeToggle: () => void;
14
14
  onFullscreenToggle: () => void;
15
15
  }
16
- export declare function MindMapControls({ zoom, theme, messages, showZoom, mode, isFullscreen, onZoomIn, onZoomOut, onAutoFit, onModeToggle, onFullscreenToggle, }: MindMapControlsProps): import("react/jsx-runtime").JSX.Element;
16
+ export declare function MindMapControls({ zoom, messages, showZoom, mode, isFullscreen, onZoomIn, onZoomOut, onAutoFit, onModeToggle, onFullscreenToggle, }: MindMapControlsProps): import("react/jsx-runtime").JSX.Element;
@@ -5,4 +5,8 @@ interface IconProps {
5
5
  export declare function IconPlus({ size, className }: IconProps): import("react/jsx-runtime").JSX.Element;
6
6
  export declare function IconMinus({ size, className }: IconProps): import("react/jsx-runtime").JSX.Element;
7
7
  export declare function IconClose({ size, className }: IconProps): import("react/jsx-runtime").JSX.Element;
8
+ export declare function IconLightning({ size, className }: IconProps): import("react/jsx-runtime").JSX.Element;
9
+ export declare function IconPaperclip({ size, className }: IconProps): import("react/jsx-runtime").JSX.Element;
10
+ export declare function IconStop({ size, className }: IconProps): import("react/jsx-runtime").JSX.Element;
11
+ export declare function IconLoaderCircle({ size, className }: IconProps): import("react/jsx-runtime").JSX.Element;
8
12
  export {};