@mind-elixir/open-desktop 0.0.1 → 0.0.2
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/README.md +172 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +5 -3
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# @mind-elixir/open-desktop
|
|
2
|
+
|
|
3
|
+
一个用于在浏览器中启动 Mind Elixir Desktop 应用并传输思维导图数据的 JavaScript 库。
|
|
4
|
+
|
|
5
|
+
## 功能特性
|
|
6
|
+
|
|
7
|
+
- 🚀 自动检测并启动 Mind Elixir Desktop 应用
|
|
8
|
+
- 📡 通过本地服务传输思维导图数据
|
|
9
|
+
- 🔄 智能回退机制:未安装应用时自动跳转到下载页面
|
|
10
|
+
- ⏱️ 可配置的超时和重试机制
|
|
11
|
+
- 📦 TypeScript 支持
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @mind-elixir/open-desktop
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
或者使用 yarn:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn add @mind-elixir/open-desktop
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 使用方法
|
|
26
|
+
|
|
27
|
+
### 基本用法
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { launchMindElixir } from '@mind-elixir/open-desktop'
|
|
31
|
+
import type { MindElixirData } from 'mind-elixir'
|
|
32
|
+
|
|
33
|
+
// 准备思维导图数据
|
|
34
|
+
const mindmapData: MindElixirData = {
|
|
35
|
+
nodeData: {
|
|
36
|
+
id: 'root',
|
|
37
|
+
topic: '中心主题',
|
|
38
|
+
children: [
|
|
39
|
+
{
|
|
40
|
+
id: 'node1',
|
|
41
|
+
topic: '分支1',
|
|
42
|
+
children: []
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: 'node2',
|
|
46
|
+
topic: '分支2',
|
|
47
|
+
children: []
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
linkData: []
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 启动 Mind Elixir 并传输数据
|
|
55
|
+
try {
|
|
56
|
+
await launchMindElixir(mindmapData)
|
|
57
|
+
console.log('思维导图已成功发送到 Mind Elixir Desktop')
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error('启动失败:', error)
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 高级配置
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { launchMindElixir } from '@mind-elixir/open-desktop'
|
|
67
|
+
|
|
68
|
+
const mindmapData = { /* 你的思维导图数据 */ }
|
|
69
|
+
const source = 'https://your-website.com' // 可选:数据来源URL
|
|
70
|
+
|
|
71
|
+
const options = {
|
|
72
|
+
appUrl: 'mind-elixir://open', // 应用协议URL
|
|
73
|
+
serviceUrl: 'http://127.0.0.1:6595/create-mindmap', // 服务端点
|
|
74
|
+
pingUrl: 'http://127.0.0.1:6595/ping', // 健康检查端点
|
|
75
|
+
timeout: 10000 // 超时时间(毫秒)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
await launchMindElixir(mindmapData, source, options)
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (error.message === '未安装 Mind Elixir Desktop') {
|
|
82
|
+
// 用户将被自动重定向到下载页面
|
|
83
|
+
console.log('请安装 Mind Elixir Desktop 应用')
|
|
84
|
+
} else {
|
|
85
|
+
console.error('其他错误:', error)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## API 文档
|
|
91
|
+
|
|
92
|
+
### `launchMindElixir(mindmapData, source?, options?)`
|
|
93
|
+
|
|
94
|
+
启动 Mind Elixir Desktop 应用并传输思维导图数据。
|
|
95
|
+
|
|
96
|
+
#### 参数
|
|
97
|
+
|
|
98
|
+
- **mindmapData** (`MindElixirData`): 思维导图数据对象
|
|
99
|
+
- **source** (`string`, 可选): 数据来源URL,默认为当前页面URL
|
|
100
|
+
- **options** (`object`, 可选): 配置选项
|
|
101
|
+
- **appUrl** (`string`): 应用协议URL,默认 `'mind-elixir://open'`
|
|
102
|
+
- **serviceUrl** (`string`): 服务端点URL,默认 `'http://127.0.0.1:6595/create-mindmap'`
|
|
103
|
+
- **pingUrl** (`string`): 健康检查端点URL,默认 `'http://127.0.0.1:6595/ping'`
|
|
104
|
+
- **timeout** (`number`): 服务启动超时时间(毫秒),默认 `8000`
|
|
105
|
+
|
|
106
|
+
#### 返回值
|
|
107
|
+
|
|
108
|
+
返回一个 `Promise<void>`,成功时解析,失败时抛出错误。
|
|
109
|
+
|
|
110
|
+
#### 错误处理
|
|
111
|
+
|
|
112
|
+
- `"未安装 Mind Elixir Desktop"`: 检测到用户未安装应用,会自动打开下载页面
|
|
113
|
+
- `"服务启动超时"`: 应用启动超时
|
|
114
|
+
- `"发送思维导图数据失败"`: 数据传输失败
|
|
115
|
+
|
|
116
|
+
## 工作原理
|
|
117
|
+
|
|
118
|
+
1. **应用检测**: 使用自定义协议 `mind-elixir://` 尝试启动桌面应用
|
|
119
|
+
2. **回退机制**: 如果应用未安装,自动重定向到 Mind Elixir Desktop 下载页面
|
|
120
|
+
3. **服务等待**: 等待本地服务 (端口 6595) 启动并可用
|
|
121
|
+
4. **数据传输**: 通过 HTTP POST 请求将思维导图数据发送到本地服务
|
|
122
|
+
|
|
123
|
+
## 系统要求
|
|
124
|
+
|
|
125
|
+
- 现代浏览器(支持 ES2017+)
|
|
126
|
+
- Mind Elixir Desktop 应用(用于完整功能)
|
|
127
|
+
|
|
128
|
+
## 开发
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# 安装依赖
|
|
132
|
+
npm install
|
|
133
|
+
|
|
134
|
+
# 开发模式(监听文件变化)
|
|
135
|
+
npm run dev
|
|
136
|
+
|
|
137
|
+
# 构建
|
|
138
|
+
npm run build
|
|
139
|
+
|
|
140
|
+
# 类型检查
|
|
141
|
+
npm run check-types
|
|
142
|
+
|
|
143
|
+
# 清理构建文件
|
|
144
|
+
npm run clean
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## 许可证
|
|
148
|
+
|
|
149
|
+
MIT License
|
|
150
|
+
|
|
151
|
+
## 相关链接
|
|
152
|
+
|
|
153
|
+
- [Mind Elixir](https://github.com/ssshooter/mind-elixir-core) - 核心思维导图库
|
|
154
|
+
- [Mind Elixir Desktop](https://desktop.mind-elixir.com/) - 桌面应用下载
|
|
155
|
+
|
|
156
|
+
## 贡献
|
|
157
|
+
|
|
158
|
+
欢迎提交 Issue 和 Pull Request!
|
|
159
|
+
|
|
160
|
+
## 更新日志
|
|
161
|
+
|
|
162
|
+
### 0.0.1
|
|
163
|
+
|
|
164
|
+
- 初始版本
|
|
165
|
+
- 支持启动 Mind Elixir Desktop 应用
|
|
166
|
+
- 支持传输思维导图数据
|
|
167
|
+
- 智能回退机制
|
|
168
|
+
|
|
169
|
+
### 0.0.2
|
|
170
|
+
|
|
171
|
+
- 导出 openAppWithFallback 方法,可以直接打开地址(无其他操作)
|
|
172
|
+
- launchMindElixir 重命名为 launchAndCreateMindmap
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MindElixirData } from 'mind-elixir';
|
|
2
|
+
export declare function openAppWithFallback(url: string): Promise<unknown>;
|
|
2
3
|
/**
|
|
3
4
|
* 启动 Mind Elixir 并发送思维导图数据
|
|
4
5
|
* @param mindmapData 思维导图数据
|
|
@@ -11,3 +12,9 @@ export declare const launchMindElixir: (mindmapData: MindElixirData, source?: st
|
|
|
11
12
|
pingUrl?: string;
|
|
12
13
|
timeout?: number;
|
|
13
14
|
}) => Promise<void>;
|
|
15
|
+
export declare const launchAndCreateMindmap: (mindmapData: MindElixirData, source?: string, options?: {
|
|
16
|
+
appUrl?: string;
|
|
17
|
+
serviceUrl?: string;
|
|
18
|
+
pingUrl?: string;
|
|
19
|
+
timeout?: number;
|
|
20
|
+
}) => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ const c = (t, n = 1e4) => new Promise((o, i) => {
|
|
|
22
22
|
setTimeout(r, 100);
|
|
23
23
|
};
|
|
24
24
|
r();
|
|
25
|
-
}),
|
|
25
|
+
}), p = async (t, n, o = {}) => {
|
|
26
26
|
const {
|
|
27
27
|
appUrl: i = "mind-elixir://open",
|
|
28
28
|
serviceUrl: e = "http://127.0.0.1:6595/create-mindmap",
|
|
@@ -41,7 +41,9 @@ const c = (t, n = 1e4) => new Promise((o, i) => {
|
|
|
41
41
|
})).ok)
|
|
42
42
|
throw new Error("发送思维导图数据失败");
|
|
43
43
|
console.log("思维导图已成功发送到 Mind Elixir");
|
|
44
|
-
};
|
|
44
|
+
}, d = p;
|
|
45
45
|
export {
|
|
46
|
-
|
|
46
|
+
d as launchAndCreateMindmap,
|
|
47
|
+
p as launchMindElixir,
|
|
48
|
+
a as openAppWithFallback
|
|
47
49
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e.OpenDesktop={}))})(this,function(e){"use strict";function t(i){return new Promise((o,r)=>{const s=Date.now(),n=document.createElement("iframe");n.style.display="none",n.src=i,document.body.appendChild(n),setTimeout(()=>{Date.now()-s<1500?(window.open("https://desktop.mind-elixir.com/","_blank"),r("未安装 Mind Elixir Desktop")):o(!0)},2e3)})}const d=(i,o=1e4)=>new Promise((r,s)=>{const n=Date.now(),a=async()=>{try{if((await fetch(i)).ok){r();return}}catch{}if(Date.now()-n>o){s(new Error("服务启动超时"));return}setTimeout(a,100)};a()}),p=async(i,o,r={})=>{const{appUrl:s="mind-elixir://open",serviceUrl:n="http://127.0.0.1:6595/create-mindmap",pingUrl:a="http://127.0.0.1:6595/ping",timeout:c=8e3}=r;if(await t(s),await d(a,c),!(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mindmap:JSON.stringify(i),source:o||window.location.href.split("?")[0]})})).ok)throw new Error("发送思维导图数据失败");console.log("思维导图已成功发送到 Mind Elixir")},l=p;e.launchAndCreateMindmap=l,e.launchMindElixir=p,e.openAppWithFallback=t,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|