@mind-elixir/open-desktop 0.0.4 → 0.0.5
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 +84 -172
- package/dist/index.js +49 -26
- package/dist/index.umd.cjs +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,172 +1,84 @@
|
|
|
1
|
-
# @mind-elixir/open-desktop
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
|
1
|
+
# @mind-elixir/open-desktop
|
|
2
|
+
|
|
3
|
+
在浏览器中启动 Mind Elixir 应用并传输思维导图数据的 JavaScript 库,支持桌面端、iOS 和 Android。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mind-elixir/open-desktop
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 使用方法
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { launchMindElixir } from '@mind-elixir/open-desktop'
|
|
15
|
+
import type { MindElixirData } from 'mind-elixir'
|
|
16
|
+
|
|
17
|
+
const mindmapData: MindElixirData = {
|
|
18
|
+
nodeData: {
|
|
19
|
+
id: 'root',
|
|
20
|
+
topic: '中心主题',
|
|
21
|
+
children: [],
|
|
22
|
+
},
|
|
23
|
+
linkData: [],
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
await launchMindElixir(mindmapData)
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error('启动失败:', error)
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 自定义配置
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { launchAndCreateMindmap } from '@mind-elixir/open-desktop'
|
|
37
|
+
|
|
38
|
+
await launchAndCreateMindmap(mindmapData, source, {
|
|
39
|
+
appUrl: 'mind-elixir://open',
|
|
40
|
+
serviceUrl: 'http://127.0.0.1:6595/create-mindmap',
|
|
41
|
+
pingUrl: 'http://127.0.0.1:6595/ping',
|
|
42
|
+
timeout: 8000, // 应用启动超时(毫秒)
|
|
43
|
+
settleDelay: 1000, // 服务就绪后等待前端加载完成(毫秒)
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 移动端行为(iOS / Android)
|
|
48
|
+
|
|
49
|
+
移动端不使用 `127.0.0.1` 服务。库会把脑图 JSON 编码为 URL-safe Base64,通过 `mind-elixir://create-mindmap` 自定义协议交给 App,因此需要配合支持该协议的 Mind Elixir iOS / Android 版本使用。Android 端由 Manifest 中已注册的 `mind-elixir` scheme 接收,复用 App 的 `getCurrent()` / `onOpenUrl()` 导入逻辑。
|
|
50
|
+
|
|
51
|
+
`launchMindElixir` 必须由点击等用户手势直接触发。移动端 Promise resolve 仅表示已完成 App 唤起,无法确认 App 内是否保存成功,也无法在 App 未安装时自动打开下载页。
|
|
52
|
+
|
|
53
|
+
脑图内容会包含在自定义协议 URL 中。此方式适合小中型脑图;包含大量图片或正文的超大型脑图可能受到系统 URL 长度限制,应改用一次性云端中转或系统文件分享。Android 的 Intent 数据还会经过共享的 Binder 事务缓冲区(约 1MB),更应保持 URL 精简。
|
|
54
|
+
|
|
55
|
+
## API
|
|
56
|
+
|
|
57
|
+
### `launchMindElixir(mindmapData, source?, options?)`
|
|
58
|
+
|
|
59
|
+
启动 Mind Elixir Desktop 应用并传输思维导图数据。`launchAndCreateMindmap` 为其别名。
|
|
60
|
+
|
|
61
|
+
| 参数 | 类型 | 说明 |
|
|
62
|
+
| --- | --- | --- |
|
|
63
|
+
| `mindmapData` | `MindElixirData` | 思维导图数据 |
|
|
64
|
+
| `source` | `string` | 数据来源 URL,默认当前页面 URL |
|
|
65
|
+
| `options.appUrl` | `string` | 应用协议 URL |
|
|
66
|
+
| `options.serviceUrl` | `string` | 服务端点 URL |
|
|
67
|
+
| `options.pingUrl` | `string` | 健康检查端点 URL |
|
|
68
|
+
| `options.timeout` | `number` | 应用启动超时,默认 `8000` |
|
|
69
|
+
| `options.settleDelay` | `number` | 服务就绪后等待时间,默认 `1000` |
|
|
70
|
+
|
|
71
|
+
返回 `Promise<void>`。桌面端未安装应用时,会自动打开下载页面,并抛出错误 `"未安装 Mind Elixir Desktop"`;其他失败场景分别抛出 `"服务启动超时"` 或 `"发送思维导图数据失败"`。移动端的完成语义见上方“移动端行为(iOS / Android)”。
|
|
72
|
+
|
|
73
|
+
## 系统要求
|
|
74
|
+
|
|
75
|
+
- 现代浏览器(支持 ES2017+)
|
|
76
|
+
- Mind Elixir 桌面端,或支持 `create-mindmap` deep link 的 iOS / Android 应用([下载地址](https://desktop.mind-elixir.com/))
|
|
77
|
+
|
|
78
|
+
## 许可证
|
|
79
|
+
|
|
80
|
+
MIT License
|
|
81
|
+
|
|
82
|
+
## 相关链接
|
|
83
|
+
|
|
84
|
+
- [Mind Elixir](https://github.com/ssshooter/mind-elixir-core) - 核心思维导图库
|
package/dist/index.js
CHANGED
|
@@ -1,46 +1,69 @@
|
|
|
1
|
-
const
|
|
2
|
-
const w = (
|
|
1
|
+
const a = "https://desktop.mind-elixir.com/", l = "mind-elixir://open", E = "http://127.0.0.1:6595/create-mindmap", h = "http://127.0.0.1:6595/ping";
|
|
2
|
+
const w = () => /iPad|iPhone|iPod|Android/i.test(navigator.userAgent) || // iPadOS 默认使用桌面版 UA,通过触摸点数量区分 Mac。
|
|
3
|
+
navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1, m = () => typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`, T = (t) => {
|
|
4
|
+
const e = new TextEncoder().encode(t);
|
|
5
|
+
let o = "";
|
|
6
|
+
for (const n of e) o += String.fromCharCode(n);
|
|
7
|
+
return btoa(o).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
8
|
+
}, U = (t, e, o) => {
|
|
9
|
+
const n = new URL(t);
|
|
10
|
+
return n.host = "create-mindmap", n.pathname = "", n.search = "", n.hash = "", n.searchParams.set(
|
|
11
|
+
"data",
|
|
12
|
+
T(
|
|
13
|
+
JSON.stringify({
|
|
14
|
+
mindmap: JSON.stringify(e),
|
|
15
|
+
source: o,
|
|
16
|
+
requestId: m()
|
|
17
|
+
})
|
|
18
|
+
)
|
|
19
|
+
), n.toString();
|
|
20
|
+
}, c = (t) => {
|
|
3
21
|
const e = document.createElement("a");
|
|
4
|
-
e.href =
|
|
5
|
-
},
|
|
6
|
-
window.open(
|
|
7
|
-
},
|
|
22
|
+
e.href = t, e.style.display = "none", document.body.appendChild(e), e.click(), e.remove();
|
|
23
|
+
}, u = () => {
|
|
24
|
+
window.open(a, "_blank") || (window.location.href = a);
|
|
25
|
+
}, f = (t) => new Promise((e) => setTimeout(e, t)), L = async (t) => {
|
|
8
26
|
try {
|
|
9
|
-
return (await fetch(
|
|
27
|
+
return (await fetch(t)).ok;
|
|
10
28
|
} catch {
|
|
11
29
|
return !1;
|
|
12
30
|
}
|
|
13
|
-
},
|
|
14
|
-
const i = Date.now(),
|
|
31
|
+
}, y = (t, e = 1e4) => new Promise((o, n) => {
|
|
32
|
+
const i = Date.now(), r = async () => {
|
|
15
33
|
try {
|
|
16
|
-
if ((await fetch(
|
|
34
|
+
if ((await fetch(t)).ok) {
|
|
17
35
|
o();
|
|
18
36
|
return;
|
|
19
37
|
}
|
|
20
38
|
} catch {
|
|
21
39
|
}
|
|
22
40
|
if (Date.now() - i > e) {
|
|
23
|
-
|
|
41
|
+
n(new Error("服务启动超时"));
|
|
24
42
|
return;
|
|
25
43
|
}
|
|
26
|
-
setTimeout(
|
|
44
|
+
setTimeout(r, 100);
|
|
27
45
|
};
|
|
28
|
-
|
|
29
|
-
}),
|
|
46
|
+
r();
|
|
47
|
+
}), _ = async (t, e, o = {}) => {
|
|
30
48
|
const {
|
|
31
|
-
appUrl:
|
|
32
|
-
serviceUrl: i =
|
|
33
|
-
pingUrl:
|
|
49
|
+
appUrl: n = l,
|
|
50
|
+
serviceUrl: i = E,
|
|
51
|
+
pingUrl: r = h,
|
|
34
52
|
timeout: s = 8e3,
|
|
35
|
-
settleDelay:
|
|
36
|
-
} = o
|
|
37
|
-
if (w(
|
|
53
|
+
settleDelay: p = 1e3
|
|
54
|
+
} = o;
|
|
55
|
+
if (w()) {
|
|
56
|
+
c(U(n, t, e || window.location.href));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const d = await L(r);
|
|
60
|
+
if (c(n), !d) {
|
|
38
61
|
try {
|
|
39
|
-
await
|
|
62
|
+
await y(r, s);
|
|
40
63
|
} catch {
|
|
41
|
-
throw
|
|
64
|
+
throw u(), new Error("未安装 Mind Elixir Desktop");
|
|
42
65
|
}
|
|
43
|
-
await
|
|
66
|
+
await f(p);
|
|
44
67
|
}
|
|
45
68
|
if (!(await fetch(i, {
|
|
46
69
|
method: "POST",
|
|
@@ -48,14 +71,14 @@ const w = (n) => {
|
|
|
48
71
|
"Content-Type": "application/json"
|
|
49
72
|
},
|
|
50
73
|
body: JSON.stringify({
|
|
51
|
-
mindmap: JSON.stringify(
|
|
74
|
+
mindmap: JSON.stringify(t),
|
|
52
75
|
source: e || window.location.href
|
|
53
76
|
})
|
|
54
77
|
})).ok)
|
|
55
78
|
throw new Error("发送思维导图数据失败");
|
|
56
79
|
console.log("思维导图已成功发送到 Mind Elixir");
|
|
57
|
-
}, D =
|
|
80
|
+
}, D = _;
|
|
58
81
|
export {
|
|
59
82
|
D as launchAndCreateMindmap,
|
|
60
|
-
|
|
83
|
+
_ as launchMindElixir
|
|
61
84
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(r,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(r=typeof globalThis<"u"?globalThis:r||self,i(r.OpenDesktop={}))})(this,function(r){"use strict";const i="https://desktop.mind-elixir.com/",l="mind-elixir://open",f="http://127.0.0.1:6595/create-mindmap",h="http://127.0.0.1:6595/ping",u=()=>/iPad|iPhone|iPod|Android/i.test(navigator.userAgent)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1,E=()=>typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2)}`,m=n=>{const e=new TextEncoder().encode(n);let o="";for(const t of e)o+=String.fromCharCode(t);return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},T=(n,e,o)=>{const t=new URL(n);return t.host="create-mindmap",t.pathname="",t.search="",t.hash="",t.searchParams.set("data",m(JSON.stringify({mindmap:JSON.stringify(e),source:o,requestId:E()}))),t.toString()},d=n=>{const e=document.createElement("a");e.href=n,e.style.display="none",document.body.appendChild(e),e.click(),e.remove()},w=()=>{window.open(i,"_blank")||(window.location.href=i)},U=n=>new Promise(e=>setTimeout(e,n)),y=async n=>{try{return(await fetch(n)).ok}catch{return!1}},L=(n,e=1e4)=>new Promise((o,t)=>{const a=Date.now(),s=async()=>{try{if((await fetch(n)).ok){o();return}}catch{}if(Date.now()-a>e){t(new Error("服务启动超时"));return}setTimeout(s,100)};s()}),p=async(n,e,o={})=>{const{appUrl:t=l,serviceUrl:a=f,pingUrl:s=h,timeout:c=8e3,settleDelay:_=1e3}=o;if(u()){d(T(t,n,e||window.location.href));return}const g=await y(s);if(d(t),!g){try{await L(s,c)}catch{throw w(),new Error("未安装 Mind Elixir Desktop")}await U(_)}if(!(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mindmap:JSON.stringify(n),source:e||window.location.href})})).ok)throw new Error("发送思维导图数据失败");console.log("思维导图已成功发送到 Mind Elixir")},A=p;r.launchAndCreateMindmap=A,r.launchMindElixir=p,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mind-elixir/open-desktop",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "Launch Mind Elixir and import mind map data from a browser",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"publishConfig": {
|