@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/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { jsx as h } from "react/jsx-runtime";
2
- import { useState as f, useEffect as l } from "react";
3
- import { Box as p, Theme as g } from "@radix-ui/themes";
4
- export * from "@radix-ui/themes";
5
- class m {
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: n }] of this.pendingRequests.entries())
15
- n(new Error("Connection closed")), this.pendingRequests.delete(e);
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: 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));
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 (n.type === "request") {
27
- const { method: s, params: a, requestId: i } = n, c = this.handlers.get(s);
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(t, i, null, `No handler for method: ${s}`);
29
+ this.sendResponse(n, r, null, `No handler for method: ${s}`);
30
30
  return;
31
31
  }
32
- Promise.resolve().then(() => c(a)).then((d) => this.sendResponse(t, i, d)).catch((d) => this.sendResponse(t, i, null, d.message));
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, n, t, o = null) {
36
+ sendResponse(e, t, n, i = null) {
37
37
  e.postMessage({
38
38
  type: "response",
39
- requestId: n,
40
- result: t,
41
- error: o
39
+ requestId: t,
40
+ result: n,
41
+ error: i
42
42
  }, "*");
43
43
  }
44
- on(e, n) {
45
- this.handlers.set(e, n);
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, n) {
51
- const t = async (o) => (this.off(e), n(o));
52
- this.on(e, t);
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, n) {
55
- const t = this.requestId++;
56
- return new Promise((o, s) => {
57
- this.pendingRequests.set(t, { resolve: o, reject: s }), this.target.postMessage({
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: n,
61
- requestId: t
60
+ params: t,
61
+ requestId: n
62
62
  }, "*");
63
63
  });
64
64
  }
65
65
  }
66
- class y {
66
+ class m {
67
67
  constructor(e) {
68
- this.rpc = new m(e), this.proxy = this.createProxy();
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, n) => n in e ? e[n] : new Proxy({}, {
73
- get: (t, o) => async (s) => {
74
- const a = `${n}.${o}`;
75
- return e.call(a, s);
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 q(r) {
85
+ function y(o) {
86
86
  const e = {
87
- id: r.id,
88
- name: r.name,
89
- description: r.description,
90
- icon: r.icon,
91
- author: r.author,
92
- version: r.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: n, rpc: t } = new y({
95
+ }, { proxy: t, rpc: n } = new m({
96
96
  target: window.parent
97
97
  });
98
- n.link = async (s, a, i) => {
99
- const c = await n.register.link({ category: s, options: a });
100
- t.on(`${c.id}`, i);
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 o() {
103
- const s = n.register.extension(e);
102
+ async function i() {
103
+ const s = t.register.extension(e);
104
104
  return e.isLoaded = !0, s;
105
105
  }
106
- return { connect: o, plugin: e, api: n };
106
+ return { connect: i, plugin: e, api: t };
107
107
  }
108
- function v(r) {
109
- r.id;
110
- let e = null, n = !1;
111
- function t() {
112
- const [o, s] = f({
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: n,
114
+ isConnected: t,
115
115
  moises: e == null ? void 0 : e.api
116
116
  });
117
- l(() => {
118
- e || (e = q(r), s((i) => ({
119
- ...i,
117
+ h(() => {
118
+ e || (e = y(o), s((r) => ({
119
+ ...r,
120
120
  plugin: e,
121
121
  moises: e.api
122
122
  })));
123
- }, [r]), l(() => {
124
- e && !n && e.connect().then(() => {
125
- n = !0, s((i) => ({
126
- ...i,
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 a({ children: i, width: c, height: d }) {
132
- const { moises: u } = o;
133
- return l(() => {
134
- u && u.ui.setPluginSize({ width: c, height: d });
135
- }, [c, d, u]), /* @__PURE__ */ h(p, { height: "100vh", style: { height: "100vh", backgroundColor: "var(--gray-1)" }, children: /* @__PURE__ */ h(p, { p: "4", children: i }) });
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
- ...o,
139
- ModalLayout: a
138
+ ...i,
139
+ ModalLayout: d
140
140
  };
141
141
  }
142
- return t;
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
- P as Theme,
157
- v as initMoisesExtension
145
+ R as initMoisesExtension
158
146
  };