@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 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
- function a(t) {
2
- return new Promise((n, o) => {
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);
6
- }, 2e3);
7
- });
8
- }
9
- const c = (t, n = 1e4) => new Promise((o, i) => {
10
- const e = Date.now(), r = async () => {
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(t)).ok) {
16
+ if ((await fetch(n)).ok) {
13
17
  o();
14
18
  return;
15
19
  }
16
20
  } catch {
17
21
  }
18
- if (Date.now() - e > n) {
19
- i(new Error("服务启动超时"));
22
+ if (Date.now() - i > e) {
23
+ r(new Error("服务启动超时"));
20
24
  return;
21
25
  }
22
- setTimeout(r, 100);
26
+ setTimeout(t, 100);
23
27
  };
24
- r();
25
- }), p = async (t, n, o = {}) => {
28
+ t();
29
+ }), h = async (n, e, o = {}) => {
26
30
  const {
27
- appUrl: i = "mind-elixir://open",
28
- serviceUrl: e = "http://127.0.0.1:6595/create-mindmap",
29
- pingUrl: r = "http://127.0.0.1:6595/ping",
30
- timeout: s = 8e3
31
- } = o;
32
- if (await a(i), await c(r, s), !(await fetch(e, {
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(t),
39
- source: n || window.location.href.split("?")[0]
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
- }, d = p;
57
+ }, D = h;
45
58
  export {
46
- d as launchAndCreateMindmap,
47
- p as launchMindElixir,
48
- a as openAppWithFallback
59
+ D as launchAndCreateMindmap,
60
+ h as launchMindElixir
49
61
  };
@@ -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(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.2",
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.0.0",
27
+ "mind-elixir": "^5.10.0",
28
28
  "@mind-elixir/typescript-config": "1.0.0"
29
29
  },
30
30
  "keywords": [