@moises.ai/extension 0.0.4 → 0.0.7
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.js +80 -67
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
import { jsx as l } from "react/jsx-runtime";
|
1
2
|
import { useState as f, useEffect as h } from "react";
|
2
|
-
import { Box as
|
3
|
-
export * from "@
|
4
|
-
class
|
3
|
+
import { Theme as g, Box as p } from "@radix-ui/themes";
|
4
|
+
export * from "@radix-ui/themes";
|
5
|
+
class m {
|
5
6
|
constructor({ target: e }) {
|
6
7
|
this.target = e, this.handlers = /* @__PURE__ */ new Map(), this.pendingRequests = /* @__PURE__ */ new Map(), this.requestId = 0, this.connected = !1, this.boundHandler = this.handleMessage.bind(this), this.connect();
|
7
8
|
}
|
@@ -10,67 +11,67 @@ class g {
|
|
10
11
|
}
|
11
12
|
disconnect() {
|
12
13
|
window.removeEventListener("message", this.boundHandler);
|
13
|
-
for (const [e, { reject:
|
14
|
-
|
14
|
+
for (const [e, { reject: n }] of this.pendingRequests.entries())
|
15
|
+
n(new Error("Connection closed")), this.pendingRequests.delete(e);
|
15
16
|
this.connected = !1;
|
16
17
|
}
|
17
18
|
handleMessage(e) {
|
18
|
-
const { data:
|
19
|
-
if (
|
20
|
-
if (
|
21
|
-
const { requestId: s, result: a, error:
|
22
|
-
c && (
|
19
|
+
const { data: n, source: t, origin: o } = e;
|
20
|
+
if (t === this.target) {
|
21
|
+
if (n.type === "response") {
|
22
|
+
const { requestId: s, result: a, error: i } = n, c = this.pendingRequests.get(s);
|
23
|
+
c && (i ? c.reject(new Error(i)) : c.resolve(a), this.pendingRequests.delete(s));
|
23
24
|
return;
|
24
25
|
}
|
25
|
-
if (
|
26
|
-
const { method: s, params: a, requestId:
|
26
|
+
if (n.type === "request") {
|
27
|
+
const { method: s, params: a, requestId: i } = n, c = this.handlers.get(s);
|
27
28
|
if (!c) {
|
28
|
-
this.sendResponse(
|
29
|
+
this.sendResponse(t, i, null, `No handler for method: ${s}`);
|
29
30
|
return;
|
30
31
|
}
|
31
|
-
Promise.resolve().then(() => c(a)).then((
|
32
|
+
Promise.resolve().then(() => c(a)).then((d) => this.sendResponse(t, i, d)).catch((d) => this.sendResponse(t, i, null, d.message));
|
32
33
|
}
|
33
34
|
}
|
34
35
|
}
|
35
|
-
sendResponse(e,
|
36
|
+
sendResponse(e, n, t, o = null) {
|
36
37
|
e.postMessage({
|
37
38
|
type: "response",
|
38
|
-
requestId:
|
39
|
-
result:
|
40
|
-
error:
|
39
|
+
requestId: n,
|
40
|
+
result: t,
|
41
|
+
error: o
|
41
42
|
}, "*");
|
42
43
|
}
|
43
|
-
on(e,
|
44
|
-
this.handlers.set(e,
|
44
|
+
on(e, n) {
|
45
|
+
this.handlers.set(e, n);
|
45
46
|
}
|
46
47
|
off(e) {
|
47
48
|
this.handlers.delete(e);
|
48
49
|
}
|
49
|
-
once(e,
|
50
|
-
const
|
51
|
-
this.on(e,
|
50
|
+
once(e, n) {
|
51
|
+
const t = async (o) => (this.off(e), n(o));
|
52
|
+
this.on(e, t);
|
52
53
|
}
|
53
|
-
async call(e,
|
54
|
-
const
|
55
|
-
return new Promise((
|
56
|
-
this.pendingRequests.set(
|
54
|
+
async call(e, n) {
|
55
|
+
const t = this.requestId++;
|
56
|
+
return new Promise((o, s) => {
|
57
|
+
this.pendingRequests.set(t, { resolve: o, reject: s }), this.target.postMessage({
|
57
58
|
type: "request",
|
58
59
|
method: e,
|
59
|
-
params:
|
60
|
-
requestId:
|
60
|
+
params: n,
|
61
|
+
requestId: t
|
61
62
|
}, "*");
|
62
63
|
});
|
63
64
|
}
|
64
65
|
}
|
65
|
-
class
|
66
|
+
class y {
|
66
67
|
constructor(e) {
|
67
|
-
this.rpc = new
|
68
|
+
this.rpc = new m(e), this.proxy = this.createProxy();
|
68
69
|
}
|
69
70
|
createProxy() {
|
70
71
|
return new Proxy(this.rpc, {
|
71
|
-
get: (e,
|
72
|
-
get: (
|
73
|
-
const a = `${
|
72
|
+
get: (e, n) => n in e ? e[n] : new Proxy({}, {
|
73
|
+
get: (t, o) => async (s) => {
|
74
|
+
const a = `${n}.${o}`;
|
74
75
|
return e.call(a, s);
|
75
76
|
}
|
76
77
|
})
|
@@ -81,65 +82,77 @@ class p {
|
|
81
82
|
// return this.rpc.on(method, handler);
|
82
83
|
// }
|
83
84
|
}
|
84
|
-
function
|
85
|
+
function q(r) {
|
85
86
|
const e = {
|
86
|
-
id:
|
87
|
-
name:
|
88
|
-
description:
|
89
|
-
icon:
|
90
|
-
author:
|
91
|
-
version:
|
87
|
+
id: r.id,
|
88
|
+
name: r.name,
|
89
|
+
description: r.description,
|
90
|
+
icon: r.icon,
|
91
|
+
author: r.author,
|
92
|
+
version: r.version,
|
92
93
|
isLoaded: !1,
|
93
94
|
events: {}
|
94
|
-
}, { proxy:
|
95
|
+
}, { proxy: n, rpc: t } = new y({
|
95
96
|
target: window.parent
|
96
97
|
});
|
97
|
-
|
98
|
-
const c = await
|
99
|
-
|
98
|
+
n.link = async (s, a, i) => {
|
99
|
+
const c = await n.register.link({ category: s, options: a });
|
100
|
+
t.on(`${c.id}`, i);
|
100
101
|
};
|
101
|
-
async function
|
102
|
-
const s =
|
102
|
+
async function o() {
|
103
|
+
const s = n.register.extension(e);
|
103
104
|
return e.isLoaded = !0, s;
|
104
105
|
}
|
105
|
-
return { connect:
|
106
|
+
return { connect: o, plugin: e, api: n };
|
106
107
|
}
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
108
|
+
const v = ({ children: r, ...e }) => /* @__PURE__ */ l(
|
109
|
+
g,
|
110
|
+
{
|
111
|
+
accentColor: "cyan",
|
112
|
+
appearance: "dark",
|
113
|
+
radius: "small",
|
114
|
+
panelBackground: "solid",
|
115
|
+
...e,
|
116
|
+
children: r
|
117
|
+
}
|
118
|
+
);
|
119
|
+
function P(r) {
|
120
|
+
r.id;
|
121
|
+
let e = null, n = !1;
|
122
|
+
function t() {
|
123
|
+
const [o, s] = f({
|
112
124
|
plugin: e,
|
113
|
-
isConnected:
|
125
|
+
isConnected: n,
|
114
126
|
moises: e == null ? void 0 : e.api
|
115
127
|
});
|
116
128
|
h(() => {
|
117
|
-
e || (e =
|
118
|
-
...
|
129
|
+
e || (e = q(r), s((i) => ({
|
130
|
+
...i,
|
119
131
|
plugin: e,
|
120
132
|
moises: e.api
|
121
133
|
})));
|
122
|
-
}, [
|
123
|
-
e && !
|
124
|
-
|
125
|
-
...
|
134
|
+
}, [r]), h(() => {
|
135
|
+
e && !n && e.connect().then(() => {
|
136
|
+
n = !0, s((i) => ({
|
137
|
+
...i,
|
126
138
|
isConnected: !0
|
127
139
|
}));
|
128
140
|
});
|
129
141
|
}, []);
|
130
|
-
function a({ children:
|
131
|
-
const { moises:
|
142
|
+
function a({ children: i, width: c, height: d }) {
|
143
|
+
const { moises: u } = o;
|
132
144
|
return h(() => {
|
133
|
-
|
134
|
-
}, [c,
|
145
|
+
u && u.ui.setPluginSize({ width: c, height: d });
|
146
|
+
}, [c, d, u]), /* @__PURE__ */ l(p, { height: "100vh", style: { height: "100vh", backgroundColor: "var(--gray-1)" }, children: /* @__PURE__ */ l(p, { p: "4", children: i }) });
|
135
147
|
}
|
136
148
|
return {
|
137
|
-
...
|
149
|
+
...o,
|
138
150
|
ModalLayout: a
|
139
151
|
};
|
140
152
|
}
|
141
|
-
return
|
153
|
+
return t;
|
142
154
|
}
|
143
155
|
export {
|
144
|
-
|
156
|
+
v as Theme,
|
157
|
+
P as initMoisesExtension
|
145
158
|
};
|