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