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