@mind-elixir/open-desktop 0.0.2 → 0.0.4
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/dist/index.d.ts +2 -1
- package/dist/index.js +40 -28
- package/dist/index.umd.cjs +1 -1
- package/package.json +4 -4
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,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
const c = "https://desktop.mind-elixir.com/", E = "mind-elixir://open", T = "http://127.0.0.1:6595/create-mindmap", l = "http://127.0.0.1:6595/ping";
|
|
2
|
+
const w = (n) => {
|
|
3
|
+
const e = document.createElement("a");
|
|
4
|
+
e.href = n, e.style.display = "none", document.body.appendChild(e), e.click(), e.remove();
|
|
5
|
+
}, d = () => {
|
|
6
|
+
window.open(c, "_blank") || (window.location.href = c);
|
|
7
|
+
}, L = (n) => new Promise((e) => setTimeout(e, n)), U = async (n) => {
|
|
8
|
+
try {
|
|
9
|
+
return (await fetch(n)).ok;
|
|
10
|
+
} catch {
|
|
11
|
+
return !1;
|
|
12
|
+
}
|
|
13
|
+
}, _ = (n, e = 1e4) => new Promise((o, r) => {
|
|
14
|
+
const i = Date.now(), t = async () => {
|
|
11
15
|
try {
|
|
12
|
-
if ((await fetch(
|
|
16
|
+
if ((await fetch(n)).ok) {
|
|
13
17
|
o();
|
|
14
18
|
return;
|
|
15
19
|
}
|
|
16
20
|
} catch {
|
|
17
21
|
}
|
|
18
|
-
if (Date.now() -
|
|
19
|
-
|
|
22
|
+
if (Date.now() - i > e) {
|
|
23
|
+
r(new Error("服务启动超时"));
|
|
20
24
|
return;
|
|
21
25
|
}
|
|
22
|
-
setTimeout(
|
|
26
|
+
setTimeout(t, 100);
|
|
23
27
|
};
|
|
24
|
-
|
|
25
|
-
}),
|
|
28
|
+
t();
|
|
29
|
+
}), h = async (n, e, o = {}) => {
|
|
26
30
|
const {
|
|
27
|
-
appUrl:
|
|
28
|
-
serviceUrl:
|
|
29
|
-
pingUrl:
|
|
30
|
-
timeout: s = 8e3
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
appUrl: r = E,
|
|
32
|
+
serviceUrl: i = T,
|
|
33
|
+
pingUrl: t = l,
|
|
34
|
+
timeout: s = 8e3,
|
|
35
|
+
settleDelay: a = 1e3
|
|
36
|
+
} = o, p = await U(t);
|
|
37
|
+
if (w(r), !p) {
|
|
38
|
+
try {
|
|
39
|
+
await _(t, s);
|
|
40
|
+
} catch {
|
|
41
|
+
throw d(), new Error("未安装 Mind Elixir Desktop");
|
|
42
|
+
}
|
|
43
|
+
await L(a);
|
|
44
|
+
}
|
|
45
|
+
if (!(await fetch(i, {
|
|
33
46
|
method: "POST",
|
|
34
47
|
headers: {
|
|
35
48
|
"Content-Type": "application/json"
|
|
36
49
|
},
|
|
37
50
|
body: JSON.stringify({
|
|
38
|
-
mindmap: JSON.stringify(
|
|
39
|
-
source:
|
|
51
|
+
mindmap: JSON.stringify(n),
|
|
52
|
+
source: e || window.location.href
|
|
40
53
|
})
|
|
41
54
|
})).ok)
|
|
42
55
|
throw new Error("发送思维导图数据失败");
|
|
43
56
|
console.log("思维导图已成功发送到 Mind Elixir");
|
|
44
|
-
},
|
|
57
|
+
}, D = h;
|
|
45
58
|
export {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
a as openAppWithFallback
|
|
59
|
+
D as launchAndCreateMindmap,
|
|
60
|
+
h as launchMindElixir
|
|
49
61
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(t,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(t=typeof globalThis<"u"?globalThis:t||self,o(t.OpenDesktop={}))})(this,function(t){"use strict";const o="https://desktop.mind-elixir.com/",d="mind-elixir://open",E="http://127.0.0.1:6595/create-mindmap",l="http://127.0.0.1:6595/ping",T=n=>{const e=document.createElement("a");e.href=n,e.style.display="none",document.body.appendChild(e),e.click(),e.remove()},f=()=>{window.open(o,"_blank")||(window.location.href=o)},h=n=>new Promise(e=>setTimeout(e,n)),u=async n=>{try{return(await fetch(n)).ok}catch{return!1}},w=(n,e=1e4)=>new Promise((r,s)=>{const c=Date.now(),i=async()=>{try{if((await fetch(n)).ok){r();return}}catch{}if(Date.now()-c>e){s(new Error("服务启动超时"));return}setTimeout(i,100)};i()}),p=async(n,e,r={})=>{const{appUrl:s=d,serviceUrl:c=E,pingUrl:i=l,timeout:a=8e3,settleDelay:L=1e3}=r,U=await u(i);if(T(s),!U){try{await w(i,a)}catch{throw f(),new Error("未安装 Mind Elixir Desktop")}await h(L)}if(!(await fetch(c,{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")},m=p;t.launchAndCreateMindmap=m,t.launchMindElixir=p,Object.defineProperty(t,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.
|
|
4
|
+
"version": "0.0.4",
|
|
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.
|
|
27
|
+
"mind-elixir": "^5.10.0",
|
|
28
28
|
"@mind-elixir/typescript-config": "1.0.0"
|
|
29
29
|
},
|
|
30
30
|
"keywords": [
|