@mind-elixir/open-desktop 0.0.3 → 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 +31 -119
- package/dist/index.d.ts +2 -1
- package/dist/index.js +60 -25
- package/dist/index.umd.cjs +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
# @mind-elixir/open-desktop
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## 功能特性
|
|
6
|
-
|
|
7
|
-
- 🚀 自动检测并启动 Mind Elixir Desktop 应用
|
|
8
|
-
- 📡 通过本地服务传输思维导图数据
|
|
9
|
-
- 🔄 智能回退机制:未安装应用时自动跳转到下载页面
|
|
10
|
-
- ⏱️ 可配置的超时和重试机制
|
|
11
|
-
- 📦 TypeScript 支持
|
|
3
|
+
在浏览器中启动 Mind Elixir 应用并传输思维导图数据的 JavaScript 库,支持桌面端、iOS 和 Android。
|
|
12
4
|
|
|
13
5
|
## 安装
|
|
14
6
|
|
|
@@ -16,133 +8,72 @@
|
|
|
16
8
|
npm install @mind-elixir/open-desktop
|
|
17
9
|
```
|
|
18
10
|
|
|
19
|
-
或者使用 yarn:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
yarn add @mind-elixir/open-desktop
|
|
23
|
-
```
|
|
24
|
-
|
|
25
11
|
## 使用方法
|
|
26
12
|
|
|
27
|
-
### 基本用法
|
|
28
|
-
|
|
29
13
|
```typescript
|
|
30
14
|
import { launchMindElixir } from '@mind-elixir/open-desktop'
|
|
31
15
|
import type { MindElixirData } from 'mind-elixir'
|
|
32
16
|
|
|
33
|
-
// 准备思维导图数据
|
|
34
17
|
const mindmapData: MindElixirData = {
|
|
35
18
|
nodeData: {
|
|
36
19
|
id: 'root',
|
|
37
20
|
topic: '中心主题',
|
|
38
|
-
children: [
|
|
39
|
-
{
|
|
40
|
-
id: 'node1',
|
|
41
|
-
topic: '分支1',
|
|
42
|
-
children: []
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
id: 'node2',
|
|
46
|
-
topic: '分支2',
|
|
47
|
-
children: []
|
|
48
|
-
}
|
|
49
|
-
]
|
|
21
|
+
children: [],
|
|
50
22
|
},
|
|
51
|
-
linkData: []
|
|
23
|
+
linkData: [],
|
|
52
24
|
}
|
|
53
25
|
|
|
54
|
-
// 启动 Mind Elixir 并传输数据
|
|
55
26
|
try {
|
|
56
27
|
await launchMindElixir(mindmapData)
|
|
57
|
-
console.log('思维导图已成功发送到 Mind Elixir Desktop')
|
|
58
28
|
} catch (error) {
|
|
59
29
|
console.error('启动失败:', error)
|
|
60
30
|
}
|
|
61
31
|
```
|
|
62
32
|
|
|
63
|
-
###
|
|
33
|
+
### 自定义配置
|
|
64
34
|
|
|
65
35
|
```typescript
|
|
66
|
-
import {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
}
|
|
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
|
+
})
|
|
88
45
|
```
|
|
89
46
|
|
|
90
|
-
##
|
|
91
|
-
|
|
92
|
-
### `launchMindElixir(mindmapData, source?, options?)`
|
|
93
|
-
|
|
94
|
-
启动 Mind Elixir Desktop 应用并传输思维导图数据。
|
|
47
|
+
## 移动端行为(iOS / Android)
|
|
95
48
|
|
|
96
|
-
|
|
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()` 导入逻辑。
|
|
97
50
|
|
|
98
|
-
|
|
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`
|
|
51
|
+
`launchMindElixir` 必须由点击等用户手势直接触发。移动端 Promise resolve 仅表示已完成 App 唤起,无法确认 App 内是否保存成功,也无法在 App 未安装时自动打开下载页。
|
|
105
52
|
|
|
106
|
-
|
|
53
|
+
脑图内容会包含在自定义协议 URL 中。此方式适合小中型脑图;包含大量图片或正文的超大型脑图可能受到系统 URL 长度限制,应改用一次性云端中转或系统文件分享。Android 的 Intent 数据还会经过共享的 Binder 事务缓冲区(约 1MB),更应保持 URL 精简。
|
|
107
54
|
|
|
108
|
-
|
|
55
|
+
## API
|
|
109
56
|
|
|
110
|
-
|
|
57
|
+
### `launchMindElixir(mindmapData, source?, options?)`
|
|
111
58
|
|
|
112
|
-
|
|
113
|
-
- `"服务启动超时"`: 应用启动超时
|
|
114
|
-
- `"发送思维导图数据失败"`: 数据传输失败
|
|
59
|
+
启动 Mind Elixir Desktop 应用并传输思维导图数据。`launchAndCreateMindmap` 为其别名。
|
|
115
60
|
|
|
116
|
-
|
|
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` |
|
|
117
70
|
|
|
118
|
-
|
|
119
|
-
2. **回退机制**: 如果应用未安装,自动重定向到 Mind Elixir Desktop 下载页面
|
|
120
|
-
3. **服务等待**: 等待本地服务 (端口 6595) 启动并可用
|
|
121
|
-
4. **数据传输**: 通过 HTTP POST 请求将思维导图数据发送到本地服务
|
|
71
|
+
返回 `Promise<void>`。桌面端未安装应用时,会自动打开下载页面,并抛出错误 `"未安装 Mind Elixir Desktop"`;其他失败场景分别抛出 `"服务启动超时"` 或 `"发送思维导图数据失败"`。移动端的完成语义见上方“移动端行为(iOS / Android)”。
|
|
122
72
|
|
|
123
73
|
## 系统要求
|
|
124
74
|
|
|
125
75
|
- 现代浏览器(支持 ES2017+)
|
|
126
|
-
- Mind Elixir
|
|
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
|
-
```
|
|
76
|
+
- Mind Elixir 桌面端,或支持 `create-mindmap` deep link 的 iOS / Android 应用([下载地址](https://desktop.mind-elixir.com/))
|
|
146
77
|
|
|
147
78
|
## 许可证
|
|
148
79
|
|
|
@@ -151,22 +82,3 @@ MIT License
|
|
|
151
82
|
## 相关链接
|
|
152
83
|
|
|
153
84
|
- [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,5 +1,4 @@
|
|
|
1
1
|
import { MindElixirData } from 'mind-elixir';
|
|
2
|
-
export declare function openAppWithFallback(url: string): Promise<unknown>;
|
|
3
2
|
/**
|
|
4
3
|
* 启动 Mind Elixir 并发送思维导图数据
|
|
5
4
|
* @param mindmapData 思维导图数据
|
|
@@ -11,10 +10,12 @@ export declare const launchMindElixir: (mindmapData: MindElixirData, source?: st
|
|
|
11
10
|
serviceUrl?: string;
|
|
12
11
|
pingUrl?: string;
|
|
13
12
|
timeout?: number;
|
|
13
|
+
settleDelay?: number;
|
|
14
14
|
}) => Promise<void>;
|
|
15
15
|
export declare const launchAndCreateMindmap: (mindmapData: MindElixirData, source?: string, options?: {
|
|
16
16
|
appUrl?: string;
|
|
17
17
|
serviceUrl?: string;
|
|
18
18
|
pingUrl?: string;
|
|
19
19
|
timeout?: number;
|
|
20
|
+
settleDelay?: number;
|
|
20
21
|
}) => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -1,49 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
const
|
|
10
|
-
|
|
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) => {
|
|
21
|
+
const e = document.createElement("a");
|
|
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) => {
|
|
26
|
+
try {
|
|
27
|
+
return (await fetch(t)).ok;
|
|
28
|
+
} catch {
|
|
29
|
+
return !1;
|
|
30
|
+
}
|
|
31
|
+
}, y = (t, e = 1e4) => new Promise((o, n) => {
|
|
32
|
+
const i = Date.now(), r = async () => {
|
|
11
33
|
try {
|
|
12
|
-
if ((await fetch(
|
|
34
|
+
if ((await fetch(t)).ok) {
|
|
13
35
|
o();
|
|
14
36
|
return;
|
|
15
37
|
}
|
|
16
38
|
} catch {
|
|
17
39
|
}
|
|
18
|
-
if (Date.now() -
|
|
19
|
-
|
|
40
|
+
if (Date.now() - i > e) {
|
|
41
|
+
n(new Error("服务启动超时"));
|
|
20
42
|
return;
|
|
21
43
|
}
|
|
22
44
|
setTimeout(r, 100);
|
|
23
45
|
};
|
|
24
46
|
r();
|
|
25
|
-
}),
|
|
47
|
+
}), _ = async (t, e, o = {}) => {
|
|
26
48
|
const {
|
|
27
|
-
appUrl:
|
|
28
|
-
serviceUrl:
|
|
29
|
-
pingUrl: r =
|
|
30
|
-
timeout: s = 8e3
|
|
49
|
+
appUrl: n = l,
|
|
50
|
+
serviceUrl: i = E,
|
|
51
|
+
pingUrl: r = h,
|
|
52
|
+
timeout: s = 8e3,
|
|
53
|
+
settleDelay: p = 1e3
|
|
31
54
|
} = o;
|
|
32
|
-
if (
|
|
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) {
|
|
61
|
+
try {
|
|
62
|
+
await y(r, s);
|
|
63
|
+
} catch {
|
|
64
|
+
throw u(), new Error("未安装 Mind Elixir Desktop");
|
|
65
|
+
}
|
|
66
|
+
await f(p);
|
|
67
|
+
}
|
|
68
|
+
if (!(await fetch(i, {
|
|
33
69
|
method: "POST",
|
|
34
70
|
headers: {
|
|
35
71
|
"Content-Type": "application/json"
|
|
36
72
|
},
|
|
37
73
|
body: JSON.stringify({
|
|
38
|
-
mindmap: JSON.stringify(
|
|
39
|
-
source:
|
|
74
|
+
mindmap: JSON.stringify(t),
|
|
75
|
+
source: e || window.location.href
|
|
40
76
|
})
|
|
41
77
|
})).ok)
|
|
42
78
|
throw new Error("发送思维导图数据失败");
|
|
43
79
|
console.log("思维导图已成功发送到 Mind Elixir");
|
|
44
|
-
},
|
|
80
|
+
}, D = _;
|
|
45
81
|
export {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
a as openAppWithFallback
|
|
82
|
+
D as launchAndCreateMindmap,
|
|
83
|
+
_ as launchMindElixir
|
|
49
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": {
|