@moises.ai/extension 0.0.5 → 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.
Files changed (2) hide show
  1. package/dist/index.js +80 -67
  2. 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 l } from "@moises.ai/design-system";
3
- export * from "@moises.ai/design-system";
4
- class g {
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: t }] of this.pendingRequests.entries())
14
- t(new Error("Connection closed")), this.pendingRequests.delete(e);
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: t, source: n, origin: i } = e;
19
- if (n === this.target) {
20
- if (t.type === "response") {
21
- const { requestId: s, result: a, error: r } = t, c = this.pendingRequests.get(s);
22
- c && (r ? c.reject(new Error(r)) : c.resolve(a), this.pendingRequests.delete(s));
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 (t.type === "request") {
26
- const { method: s, params: a, requestId: r } = t, c = this.handlers.get(s);
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(n, r, null, `No handler for method: ${s}`);
29
+ this.sendResponse(t, i, null, `No handler for method: ${s}`);
29
30
  return;
30
31
  }
31
- Promise.resolve().then(() => c(a)).then((u) => this.sendResponse(n, r, u)).catch((u) => this.sendResponse(n, r, null, u.message));
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, t, n, i = null) {
36
+ sendResponse(e, n, t, o = null) {
36
37
  e.postMessage({
37
38
  type: "response",
38
- requestId: t,
39
- result: n,
40
- error: i
39
+ requestId: n,
40
+ result: t,
41
+ error: o
41
42
  }, "*");
42
43
  }
43
- on(e, t) {
44
- this.handlers.set(e, t);
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, t) {
50
- const n = async (i) => (this.off(e), t(i));
51
- this.on(e, n);
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, t) {
54
- const n = this.requestId++;
55
- return new Promise((i, s) => {
56
- this.pendingRequests.set(n, { resolve: i, reject: s }), this.target.postMessage({
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: t,
60
- requestId: n
60
+ params: n,
61
+ requestId: t
61
62
  }, "*");
62
63
  });
63
64
  }
64
65
  }
65
- class p {
66
+ class y {
66
67
  constructor(e) {
67
- this.rpc = new g(e), this.proxy = this.createProxy();
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, t) => t in e ? e[t] : new Proxy({}, {
72
- get: (n, i) => async (s) => {
73
- const a = `${t}.${i}`;
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 m(o) {
85
+ function q(r) {
85
86
  const e = {
86
- id: o.id,
87
- name: o.name,
88
- description: o.description,
89
- icon: o.icon,
90
- author: o.author,
91
- version: o.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: t, rpc: n } = new p({
95
+ }, { proxy: n, rpc: t } = new y({
95
96
  target: window.parent
96
97
  });
97
- t.link = async (s, a, r) => {
98
- const c = await t.register.link({ category: s, options: a });
99
- n.on(`${c.id}`, r);
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 i() {
102
- const s = t.register.extension(e);
102
+ async function o() {
103
+ const s = n.register.extension(e);
103
104
  return e.isLoaded = !0, s;
104
105
  }
105
- return { connect: i, plugin: e, api: t };
106
+ return { connect: o, plugin: e, api: n };
106
107
  }
107
- function w(o) {
108
- o.id;
109
- let e = null, t = !1;
110
- function n() {
111
- const [i, s] = f({
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: t,
125
+ isConnected: n,
114
126
  moises: e == null ? void 0 : e.api
115
127
  });
116
128
  h(() => {
117
- e || (e = m(o), s((r) => ({
118
- ...r,
129
+ e || (e = q(r), s((i) => ({
130
+ ...i,
119
131
  plugin: e,
120
132
  moises: e.api
121
133
  })));
122
- }, [o]), h(() => {
123
- e && !t && e.connect().then(() => {
124
- t = !0, s((r) => ({
125
- ...r,
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: r, width: c, height: u }) {
131
- const { moises: d } = i;
142
+ function a({ children: i, width: c, height: d }) {
143
+ const { moises: u } = o;
132
144
  return h(() => {
133
- d && d.ui.setPluginSize({ width: c, height: u });
134
- }, [c, u, d]), /* @__PURE__ */ React.createElement(l, { height: "100vh", style: { height: "100vh", backgroundColor: "var(--gray-1)" } }, /* @__PURE__ */ React.createElement(l, { p: "4" }, r));
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
- ...i,
149
+ ...o,
138
150
  ModalLayout: a
139
151
  };
140
152
  }
141
- return n;
153
+ return t;
142
154
  }
143
155
  export {
144
- w as initMoisesExtension
156
+ v as Theme,
157
+ P as initMoisesExtension
145
158
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moises.ai/extension",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "SDK for Moises AI extensions",
5
5
  "private": false,
6
6
  "type": "module",