@mind-elixir/open-desktop 0.0.2 → 0.0.3

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 CHANGED
@@ -1,172 +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
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.js CHANGED
@@ -1,28 +1,28 @@
1
- function a(t) {
2
- return new Promise((n, o) => {
1
+ function a(n) {
2
+ return new Promise((t, o) => {
3
3
  const i = Date.now(), e = document.createElement("iframe");
4
- e.style.display = "none", e.src = t, document.body.appendChild(e), setTimeout(() => {
5
- Date.now() - i < 1500 ? (window.open("https://desktop.mind-elixir.com/", "_blank"), o("未安装 Mind Elixir Desktop")) : n(!0);
4
+ e.style.display = "none", e.src = n, document.body.appendChild(e), setTimeout(() => {
5
+ Date.now() - i < 1500 ? (window.open("https://desktop.mind-elixir.com/", "_blank"), o("未安装 Mind Elixir Desktop")) : t(!0);
6
6
  }, 2e3);
7
7
  });
8
8
  }
9
- const c = (t, n = 1e4) => new Promise((o, i) => {
9
+ const c = (n, t = 1e4) => new Promise((o, i) => {
10
10
  const e = Date.now(), r = async () => {
11
11
  try {
12
- if ((await fetch(t)).ok) {
12
+ if ((await fetch(n)).ok) {
13
13
  o();
14
14
  return;
15
15
  }
16
16
  } catch {
17
17
  }
18
- if (Date.now() - e > n) {
18
+ if (Date.now() - e > t) {
19
19
  i(new Error("服务启动超时"));
20
20
  return;
21
21
  }
22
22
  setTimeout(r, 100);
23
23
  };
24
24
  r();
25
- }), p = async (t, n, o = {}) => {
25
+ }), p = async (n, t, o = {}) => {
26
26
  const {
27
27
  appUrl: i = "mind-elixir://open",
28
28
  serviceUrl: e = "http://127.0.0.1:6595/create-mindmap",
@@ -35,8 +35,8 @@ const c = (t, n = 1e4) => new Promise((o, i) => {
35
35
  "Content-Type": "application/json"
36
36
  },
37
37
  body: JSON.stringify({
38
- mindmap: JSON.stringify(t),
39
- source: n || window.location.href.split("?")[0]
38
+ mindmap: JSON.stringify(n),
39
+ source: t || window.location.href
40
40
  })
41
41
  })).ok)
42
42
  throw new Error("发送思维导图数据失败");
@@ -1 +1 @@
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"})});
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})})).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"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mind-elixir/open-desktop",
3
3
  "private": false,
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "type": "module",
6
6
  "description": "Import XMind files to MindElixir format",
7
7
  "main": "./dist/index.js",
@@ -11,9 +11,9 @@
11
11
  },
12
12
  "exports": {
13
13
  ".": {
14
+ "types": "./dist/index.d.ts",
14
15
  "import": "./dist/index.js",
15
- "require": "./dist/index.umd.cjs",
16
- "types": "./dist/index.d.ts"
16
+ "require": "./dist/index.umd.cjs"
17
17
  }
18
18
  },
19
19
  "files": [
@@ -24,7 +24,7 @@
24
24
  "typescript": "~5.8.3",
25
25
  "vite": "^6.3.5",
26
26
  "vite-plugin-dts": "^4.5.4",
27
- "mind-elixir": "^5.0.0",
27
+ "mind-elixir": "^5.10.0",
28
28
  "@mind-elixir/typescript-config": "1.0.0"
29
29
  },
30
30
  "keywords": [