@moises.ai/extension 0.0.18 → 0.0.20
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 +277 -63
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import { jsx as
|
2
|
-
import { useState as q, useEffect as
|
1
|
+
import { jsx as f } from "react/jsx-runtime";
|
2
|
+
import { useState as q, useEffect as h } from "react";
|
3
3
|
import { Box as p } from "@moises.ai/design-system";
|
4
4
|
export * from "@moises.ai/design-system";
|
5
|
-
class
|
5
|
+
class y {
|
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
|
}
|
@@ -16,28 +16,28 @@ class m {
|
|
16
16
|
this.connected = !1;
|
17
17
|
}
|
18
18
|
handleMessage(e) {
|
19
|
-
const { data: n, source:
|
20
|
-
if (
|
19
|
+
const { data: n, source: o, origin: i } = e;
|
20
|
+
if (o === this.target) {
|
21
21
|
if (n.type === "response") {
|
22
|
-
const { requestId: r, result:
|
23
|
-
c && (t ? c.reject(new Error(t)) : c.resolve(
|
22
|
+
const { requestId: r, result: l, error: t } = n, c = this.pendingRequests.get(r);
|
23
|
+
c && (t ? c.reject(new Error(t)) : c.resolve(l), this.pendingRequests.delete(r));
|
24
24
|
return;
|
25
25
|
}
|
26
26
|
if (n.type === "request") {
|
27
|
-
const { method: r, params:
|
27
|
+
const { method: r, params: l, requestId: t } = n, c = this.handlers.get(r);
|
28
28
|
if (!c) {
|
29
|
-
this.sendResponse(
|
29
|
+
this.sendResponse(o, t, null, `No handler for method: ${r}`);
|
30
30
|
return;
|
31
31
|
}
|
32
|
-
Promise.resolve().then(() => c(
|
32
|
+
Promise.resolve().then(() => c(l)).then((a) => this.sendResponse(o, t, a)).catch((a) => this.sendResponse(o, t, null, a.message));
|
33
33
|
}
|
34
34
|
}
|
35
35
|
}
|
36
|
-
sendResponse(e, n,
|
36
|
+
sendResponse(e, n, o, i = null) {
|
37
37
|
e.postMessage({
|
38
38
|
type: "response",
|
39
39
|
requestId: n,
|
40
|
-
result:
|
40
|
+
result: o,
|
41
41
|
error: i
|
42
42
|
}, "*");
|
43
43
|
}
|
@@ -48,31 +48,31 @@ class m {
|
|
48
48
|
this.handlers.delete(e);
|
49
49
|
}
|
50
50
|
once(e, n) {
|
51
|
-
const
|
52
|
-
this.on(e,
|
51
|
+
const o = async (i) => (this.off(e), n(i));
|
52
|
+
this.on(e, o);
|
53
53
|
}
|
54
54
|
async call(e, n) {
|
55
|
-
const
|
55
|
+
const o = this.requestId++;
|
56
56
|
return new Promise((i, r) => {
|
57
|
-
this.pendingRequests.set(
|
57
|
+
this.pendingRequests.set(o, { resolve: i, reject: r }), this.target.postMessage({
|
58
58
|
type: "request",
|
59
59
|
method: e,
|
60
60
|
params: n,
|
61
|
-
requestId:
|
61
|
+
requestId: o
|
62
62
|
}, "*");
|
63
63
|
});
|
64
64
|
}
|
65
65
|
}
|
66
|
-
class
|
66
|
+
class P {
|
67
67
|
constructor(e) {
|
68
|
-
this.rpc = new
|
68
|
+
this.rpc = new y(e), this.proxy = this.createProxy();
|
69
69
|
}
|
70
70
|
createProxy() {
|
71
71
|
return new Proxy(this.rpc, {
|
72
72
|
get: (e, n) => n in e ? e[n] : new Proxy({}, {
|
73
|
-
get: (
|
74
|
-
const
|
75
|
-
return e.call(
|
73
|
+
get: (o, i) => async (r) => {
|
74
|
+
const l = `${n}.${i}`;
|
75
|
+
return e.call(l, r);
|
76
76
|
}
|
77
77
|
})
|
78
78
|
});
|
@@ -82,45 +82,259 @@ class v {
|
|
82
82
|
// return this.rpc.on(method, handler);
|
83
83
|
// }
|
84
84
|
}
|
85
|
-
|
85
|
+
const v = {
|
86
|
+
/**
|
87
|
+
* Exports the audio from the current session
|
88
|
+
* @async
|
89
|
+
* @function export
|
90
|
+
* @memberof session
|
91
|
+
* @returns {Promise<AudioData>} Promise that resolves with the exported audio data
|
92
|
+
* @example const audioData = await session.export()
|
93
|
+
*/
|
94
|
+
export: async function() {
|
95
|
+
return console.log("session.export");
|
96
|
+
},
|
97
|
+
/**
|
98
|
+
* Gets the list of tracks from the session
|
99
|
+
* @async
|
100
|
+
* @function tracks
|
101
|
+
* @memberof session
|
102
|
+
* @returns {Promise<Array>} Promise that resolves with an array of tracks
|
103
|
+
* @example
|
104
|
+
* const tracks = await session.tracks()
|
105
|
+
* console.log(tracks.length) // number of tracks
|
106
|
+
*/
|
107
|
+
tracks: async function() {
|
108
|
+
return console.log("session.tracks");
|
109
|
+
},
|
110
|
+
/**
|
111
|
+
* Starts session playback
|
112
|
+
* @function play
|
113
|
+
* @memberof session
|
114
|
+
* @returns {void} Does not return a value
|
115
|
+
* @example session.play()
|
116
|
+
*/
|
117
|
+
play: function() {
|
118
|
+
return console.log("session.play");
|
119
|
+
},
|
120
|
+
/**
|
121
|
+
* Pauses session playback
|
122
|
+
* @function pause
|
123
|
+
* @memberof session
|
124
|
+
* @returns {void} Does not return a value
|
125
|
+
* @example session.pause()
|
126
|
+
*/
|
127
|
+
pause: function() {
|
128
|
+
return console.log("session.pause");
|
129
|
+
},
|
130
|
+
/**
|
131
|
+
* Toggles between play and pause
|
132
|
+
* @function togglePlayback
|
133
|
+
* @memberof session
|
134
|
+
* @returns {void} Does not return a value
|
135
|
+
* @example session.togglePlayback()
|
136
|
+
*/
|
137
|
+
togglePlayback: function() {
|
138
|
+
return console.log("session.togglePlayback");
|
139
|
+
},
|
140
|
+
/**
|
141
|
+
* Clears the current selection in the session
|
142
|
+
* @function clearSelection
|
143
|
+
* @memberof session
|
144
|
+
* @returns {void} Does not return a value
|
145
|
+
* @example session.clearSelection()
|
146
|
+
*/
|
147
|
+
clearSelection: function() {
|
148
|
+
return console.log("session.clearSelection");
|
149
|
+
},
|
150
|
+
/**
|
151
|
+
* Sets a selection in the session
|
152
|
+
* @function setSelection
|
153
|
+
* @memberof session
|
154
|
+
* @param {Object} params - Selection parameters
|
155
|
+
* @param {string} params.trackId - ID of the track to be selected
|
156
|
+
* @param {number} params.start - Start position of the selection
|
157
|
+
* @param {number} params.end - End position of the selection
|
158
|
+
* @returns {void} Does not return a value
|
159
|
+
* @example
|
160
|
+
* // Selects an interval in a specific track
|
161
|
+
* session.setSelection({
|
162
|
+
* trackId: "track-123",
|
163
|
+
* start: 0,
|
164
|
+
* end: 30
|
165
|
+
* })
|
166
|
+
*
|
167
|
+
* // Selects an interval without specifying a track
|
168
|
+
* session.setSelection({ start: 10, end: 20 })
|
169
|
+
*/
|
170
|
+
setSelection: function(s) {
|
171
|
+
return console.log("session.setSelection", s);
|
172
|
+
}
|
173
|
+
}, R = {
|
174
|
+
/**
|
175
|
+
* Sets the extension size in the interface
|
176
|
+
* @function setPluginSize
|
177
|
+
* @memberof ui
|
178
|
+
* @param {Object} params - Size parameters
|
179
|
+
* @param {number} params.width - Width in pixels
|
180
|
+
* @param {number} params.height - Height in pixels
|
181
|
+
* @returns {void} Does not return a value
|
182
|
+
* @example ui.setPluginSize({ width: 800, height: 600 })
|
183
|
+
*/
|
184
|
+
setPluginSize: function(s) {
|
185
|
+
return console.log("ui.setPluginSize", s);
|
186
|
+
},
|
187
|
+
/**
|
188
|
+
* Displays a progress bar or loading indicator
|
189
|
+
* @async
|
190
|
+
* @function progress
|
191
|
+
* @memberof ui
|
192
|
+
* @param {Object} options - Progress configuration options
|
193
|
+
* @param {string} options.message - Progress message
|
194
|
+
* @param {number} options.value - Progress value (0-100)
|
195
|
+
* @returns {Promise<void>} Promise that resolves when the operation is complete
|
196
|
+
* @example await ui.progress({ message: "Loading...", value: 50 })
|
197
|
+
*/
|
198
|
+
progress: async function(s) {
|
199
|
+
return console.log("ui.progress", s);
|
200
|
+
},
|
201
|
+
/**
|
202
|
+
* Displays an alert to the user
|
203
|
+
* @async
|
204
|
+
* @function alert
|
205
|
+
* @memberof ui
|
206
|
+
* @param {Object} options - Alert configuration options
|
207
|
+
* @param {string} options.title - Alert title
|
208
|
+
* @param {string} options.message - Alert message
|
209
|
+
* @returns {Promise<void>} Promise that resolves when the alert is closed
|
210
|
+
* @example await ui.alert({ title: "Notice", message: "Operation completed!" })
|
211
|
+
*/
|
212
|
+
alert: async function(s) {
|
213
|
+
return console.log("ui.alert", s);
|
214
|
+
},
|
215
|
+
/**
|
216
|
+
* Displays a confirmation dialog
|
217
|
+
* @async
|
218
|
+
* @function confirm
|
219
|
+
* @memberof ui
|
220
|
+
* @param {Object} options - Confirmation configuration options
|
221
|
+
* @param {string} options.title - Confirmation title
|
222
|
+
* @param {string} options.message - Confirmation message
|
223
|
+
* @returns {Promise<boolean>} Promise that resolves with true if confirmed, false if cancelled
|
224
|
+
* @example
|
225
|
+
* const confirmed = await ui.confirm({
|
226
|
+
* title: "Confirm",
|
227
|
+
* message: "Do you want to continue?"
|
228
|
+
* })
|
229
|
+
*/
|
230
|
+
confirm: async function(s) {
|
231
|
+
return console.log("ui.confirm", s);
|
232
|
+
},
|
233
|
+
/**
|
234
|
+
* Displays a text input dialog
|
235
|
+
* @async
|
236
|
+
* @function prompt
|
237
|
+
* @memberof ui
|
238
|
+
* @param {Object} options - Prompt configuration options
|
239
|
+
* @param {string} options.title - Prompt title
|
240
|
+
* @param {string} options.message - Prompt message
|
241
|
+
* @param {string} options.defaultValue - Default input value
|
242
|
+
* @returns {Promise<string>} Promise that resolves with the entered text
|
243
|
+
* @example
|
244
|
+
* const userInput = await ui.prompt({
|
245
|
+
* title: "Name",
|
246
|
+
* message: "Enter your name:"
|
247
|
+
* })
|
248
|
+
*/
|
249
|
+
prompt: async function(s) {
|
250
|
+
return console.log("ui.prompt", s);
|
251
|
+
},
|
252
|
+
/**
|
253
|
+
* Creates a panel in the interface
|
254
|
+
* @async
|
255
|
+
* @function panel
|
256
|
+
* @memberof ui
|
257
|
+
* @param {Object} options - Panel configuration options
|
258
|
+
* @param {string} options.title - Panel title
|
259
|
+
* @param {string} options.content - Panel content
|
260
|
+
* @returns {Promise<Object>} Promise that resolves with the created panel object
|
261
|
+
* @returns {string} returns.id - Unique panel ID
|
262
|
+
* @example
|
263
|
+
* const panel = await ui.panel({ title: "My Panel" })
|
264
|
+
* console.log(panel.id) // "panel-1"
|
265
|
+
*/
|
266
|
+
panel: async function(s) {
|
267
|
+
return console.log("ui.panel", s);
|
268
|
+
},
|
269
|
+
/**
|
270
|
+
* Closes the extension
|
271
|
+
* @async
|
272
|
+
* @function close
|
273
|
+
* @memberof ui
|
274
|
+
* @returns {Promise<void>} Promise that resolves when the extension is closed
|
275
|
+
* @example await ui.close()
|
276
|
+
*/
|
277
|
+
close: async function() {
|
278
|
+
return console.log("ui.close");
|
279
|
+
},
|
280
|
+
/**
|
281
|
+
* Opens the extension
|
282
|
+
* @async
|
283
|
+
* @function open
|
284
|
+
* @memberof ui
|
285
|
+
* @param {Object} [params]={} - Open parameters
|
286
|
+
* @param {string} params.mountPoint="sidePanel" - Location where the extension will be mounted
|
287
|
+
* @returns {Promise<void>} Promise that resolves when the extension is opened
|
288
|
+
* @example
|
289
|
+
* // Opens in side panel (default)
|
290
|
+
* await ui.open()
|
291
|
+
*
|
292
|
+
* // Opens in a specific location
|
293
|
+
* await ui.open({ mountPoint: "mainPanel" })
|
294
|
+
*/
|
295
|
+
open: async function(s = {}) {
|
296
|
+
return console.log("ui.open", s);
|
297
|
+
}
|
298
|
+
};
|
299
|
+
function b(s) {
|
86
300
|
const e = {
|
87
|
-
id:
|
88
|
-
name:
|
89
|
-
description:
|
90
|
-
icon:
|
91
|
-
author:
|
92
|
-
version:
|
301
|
+
id: s.id,
|
302
|
+
name: s.name,
|
303
|
+
description: s.description,
|
304
|
+
icon: s.icon,
|
305
|
+
author: s.author,
|
306
|
+
version: s.version,
|
93
307
|
isLoaded: !1,
|
94
308
|
events: {}
|
95
|
-
}, { proxy: n, rpc:
|
309
|
+
}, { proxy: n, rpc: o } = new P({
|
96
310
|
target: window.parent
|
97
311
|
});
|
98
|
-
n.link = async (r,
|
99
|
-
const c = await n.register.link({ category: r, options:
|
100
|
-
|
101
|
-
};
|
312
|
+
n.link = async (r, l, t) => {
|
313
|
+
const c = await n.register.link({ category: r, options: l });
|
314
|
+
o.on(`${c.id}`, t);
|
315
|
+
}, n.ui = R, n.session = v;
|
102
316
|
async function i() {
|
103
317
|
const r = n.register.extension(e);
|
104
318
|
return e.isLoaded = !0, r;
|
105
319
|
}
|
106
320
|
return { connect: i, plugin: e, api: n };
|
107
321
|
}
|
108
|
-
function E(
|
109
|
-
|
322
|
+
function E(s) {
|
323
|
+
s.id;
|
110
324
|
let e = null, n = !1;
|
111
|
-
function
|
325
|
+
function o() {
|
112
326
|
const [i, r] = q({
|
113
327
|
plugin: e,
|
114
328
|
isConnected: n,
|
115
329
|
moises: e == null ? void 0 : e.api
|
116
330
|
});
|
117
|
-
|
118
|
-
e || (e =
|
331
|
+
h(() => {
|
332
|
+
e || (e = b(s), r((t) => ({
|
119
333
|
...t,
|
120
334
|
plugin: e,
|
121
335
|
moises: e.api
|
122
336
|
})));
|
123
|
-
}, [
|
337
|
+
}, [s]), h(() => {
|
124
338
|
e && !n && e.connect().then(() => {
|
125
339
|
n = !0, r((t) => ({
|
126
340
|
...t,
|
@@ -128,46 +342,46 @@ function E(o) {
|
|
128
342
|
}));
|
129
343
|
});
|
130
344
|
}, []);
|
131
|
-
function
|
345
|
+
function l({ children: t, width: c, height: a }) {
|
132
346
|
const { moises: u } = i;
|
133
|
-
return
|
134
|
-
u && u.ui.setPluginSize({ width: c, height:
|
135
|
-
}, [c,
|
347
|
+
return h(() => {
|
348
|
+
u && u.ui.setPluginSize({ width: c, height: a });
|
349
|
+
}, [c, a, u]), /* @__PURE__ */ f(p, { height: "100vh", style: { height: "100vh", backgroundColor: "var(--gray-1)" }, children: /* @__PURE__ */ f(p, { p: "4", children: t }) });
|
136
350
|
}
|
137
351
|
return {
|
138
352
|
...i,
|
139
|
-
ModalLayout:
|
353
|
+
ModalLayout: l
|
140
354
|
};
|
141
355
|
}
|
142
|
-
return
|
356
|
+
return o;
|
143
357
|
}
|
144
|
-
function $({ id:
|
145
|
-
const
|
146
|
-
id:
|
358
|
+
function $({ id: s, url: e, exposedAPI: n, iframeRef: o, onRegisterMetadata: i, onRegisterLink: r }) {
|
359
|
+
const l = {
|
360
|
+
id: s,
|
147
361
|
url: e
|
148
362
|
};
|
149
|
-
|
150
|
-
const t = new
|
151
|
-
target:
|
363
|
+
o.current && (o.current.src = e);
|
364
|
+
const t = new y({
|
365
|
+
target: o.current.contentWindow
|
152
366
|
});
|
153
367
|
t.on("register.extension", async (u) => {
|
154
368
|
i(u);
|
155
|
-
}), t.on("register.link", async ({ category: u, options:
|
156
|
-
const
|
157
|
-
return r({ id:
|
369
|
+
}), t.on("register.link", async ({ category: u, options: d }) => {
|
370
|
+
const g = `link:${u}:${d.label}`;
|
371
|
+
return r({ id: g, category: u, options: d }), { id: g };
|
158
372
|
});
|
159
|
-
for (const [u,
|
160
|
-
for (const [
|
161
|
-
const w = `${u}.${
|
162
|
-
t.on(w, async (x) => await
|
373
|
+
for (const [u, d] of Object.entries(n))
|
374
|
+
for (const [g, m] of Object.entries(d)) {
|
375
|
+
const w = `${u}.${g}`;
|
376
|
+
t.on(w, async (x) => await m(x));
|
163
377
|
}
|
164
|
-
function c(u,
|
165
|
-
return t.call(u,
|
378
|
+
function c(u, d) {
|
379
|
+
return t.call(u, d);
|
166
380
|
}
|
167
|
-
function
|
381
|
+
function a() {
|
168
382
|
t.disconnect();
|
169
383
|
}
|
170
|
-
return { plugin:
|
384
|
+
return { plugin: l, rpc: t, call: c, disconnect: a };
|
171
385
|
}
|
172
386
|
export {
|
173
387
|
$ as MoisesExtensionHost,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@moises.ai/extension",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.20",
|
4
4
|
"description": "SDK for Moises AI extensions",
|
5
5
|
"private": false,
|
6
6
|
"type": "module",
|
@@ -31,7 +31,7 @@
|
|
31
31
|
"dev": "vite build --watch"
|
32
32
|
},
|
33
33
|
"dependencies": {
|
34
|
-
"@moises.ai/design-system": "2.0.
|
34
|
+
"@moises.ai/design-system": "2.0.15"
|
35
35
|
},
|
36
36
|
"peerDependencies": {
|
37
37
|
"react": "*",
|