cabbage-react 1.0.42 → 1.0.43
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/hooks/useCabbageState.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +40 -43
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,aACrB,MAAM,YACR,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU;;sBAOb,CAAC;
|
|
1
|
+
{"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,aACrB,MAAM,YACR,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU;;sBAOb,CAAC;CA6FnC,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react");console.log("Cabbage: loading cabbage.js");class p{static sendControlData({channel:o,value:s,gesture:a="complete"},n=null){const e={command:"controlData",channel:o,value:s,gesture:a};n!==null?n.postMessage(e):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(e):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",e)}static isReadyToLoad(o=null,s={}){this.sendCustomCommand("isReadyToLoad",o)}static sendMidiMessageFromUI(o,s,a,n=null){var e={statusByte:o,dataByte1:s,dataByte2:a};const r={command:"midiMessage",obj:JSON.stringify(e)};n!==null?n.postMessage(r):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(r):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",r)}static MidiMessageFromHost(o,s,a){console.log("Cabbage: Got MIDI Message"+o+":"+s+":"+a)}static triggerFileOpenDialog(o,s,a={}){var n={channel:s,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.openAtLastKnownLocation:!0};const e={command:"fileOpen",obj:JSON.stringify(n)};o!==null?o.postMessage(e):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(e):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",e)}static openUrl(o,s,a){var n={url:s,file:a};const e={command:"openUrl",obj:JSON.stringify(n)};o!==null?o.postMessage(e):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(e):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",e)}static requestResize(o,s,a=null){const n={command:"requestResize",width:o,height:s};if(a!==null){console.warn("Cabbage: requestResize is not supported in VS Code extension mode");return}else typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static sendChannelData(o,s,a=null){var n={channel:o};if(typeof s=="string")n.stringData=s;else if(typeof s=="number")n.floatData=s;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof s);return}const e={command:"channelData",obj:JSON.stringify(n)};console.log("Cabbage: sending channel data from UI",n),a!==null?a.postMessage(e):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(e):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",e)}static sendWidgetUpdate(o,s=null){const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(o))};s!==null?s.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static sendCustomCommand(o,s=null,a={}){const n={command:o,text:JSON.stringify(a)};if(s!==null)s.postMessage(n);else if(typeof window.sendMessageFromUI=="function"){console.log("Cabbage: Calling window.sendMessageFromUI with:",n);try{const e=window.sendMessageFromUI(n);console.log("Cabbage: sendMessageFromUI returned:",e)}catch(e){console.error("Cabbage: sendMessageFromUI threw error:",e),console.error("Cabbage: Error stack:",e.stack)}}else console.error("Cabbage: window.sendMessageFromUI is not available yet. Message:",n),console.error("Cabbage: typeof window.sendMessageFromUI:",typeof window.sendMessageFromUI),console.error("Cabbage: window.sendMessageFromUI value:",window.sendMessageFromUI)}}const C=i=>{const[o,s]=l.useState();return l.useEffect(()=>{const a=n=>{const{id:e,widgetJson:r,command:u}=n.data;if(e===i&&r&&u==="widgetUpdate"){const t=JSON.parse(r);console.log(`[Cabbage-React] Received properties for channelId: ${e}`,t),s(t)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:o}},I=(i,o="complete")=>{const{properties:s}=C(i),[a,n]=l.useState(),[e,r]=l.useState(),u=t=>{n(t),p.sendControlData({channel:i,value:t,gesture:o})};return l.useEffect(()=>{var b;const t=s==null?void 0:s.channels.find(d=>d.id===i);if(!t)return;const g=t.parameterIndex;if(e===void 0&&g!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId: ${t.id}`,g),r(g)),a!==void 0)return;const c=(b=t.range)==null?void 0:b.value;c!=null&&(console.log(`[Cabbage-React] Received initial value for channelId: ${t.id}`,c),n(c))},[s]),l.useEffect(()=>{const t=g=>{var b;const{command:c}=g.data;if(c==="parameterChange"){const{value:d,paramIdx:m}=g.data.data;if(m!==e||d===null)return;console.log(`[Cabbage-React] Received parameterChange for parameterIndex: ${m}`,d),n(d)}else if(c==="batchWidgetUpdate"){const d=g.data.widgets,m=d==null?void 0:d.find(f=>f.id===i);if(!m)return;const w=JSON.parse(m.widgetJson).channels.find(f=>f.id===i),M=(b=w==null?void 0:w.range)==null?void 0:b.value;console.log(`[Cabbage-React] Received batch widget update for channelId: ${m.id}`,M),n(M)}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[e]),{value:a,setValue:u}},U=i=>{const[o,s]=l.useState();return l.useEffect(()=>{const a=n=>{const{data:e,type:r}=n;if(e&&r==="message"){if(e.id!==i)return;console.log(`[Cabbage-React] Received data for messageId: ${e.id}`,e),s(e)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{data:o}};exports.Cabbage=p;exports.useCabbageMessage=U;exports.useCabbageProperties=C;exports.useCabbageState=I;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useState as w, useEffect as
|
|
1
|
+
import { useState as w, useEffect as b } from "react";
|
|
2
2
|
console.log("Cabbage: loading cabbage.js");
|
|
3
|
-
class
|
|
3
|
+
class C {
|
|
4
4
|
/**
|
|
5
5
|
* Send a widget value change to the Cabbage backend.
|
|
6
6
|
*
|
|
@@ -236,12 +236,12 @@ class I {
|
|
|
236
236
|
);
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
|
-
const
|
|
239
|
+
const I = (i) => {
|
|
240
240
|
const [o, s] = w();
|
|
241
|
-
return
|
|
241
|
+
return b(() => {
|
|
242
242
|
const a = (n) => {
|
|
243
|
-
const { id: e, widgetJson: r, command:
|
|
244
|
-
if (e === i && r &&
|
|
243
|
+
const { id: e, widgetJson: r, command: f } = n.data;
|
|
244
|
+
if (e === i && r && f === "widgetUpdate") {
|
|
245
245
|
const t = JSON.parse(r);
|
|
246
246
|
console.log(
|
|
247
247
|
`[Cabbage-React] Received properties for channelId: ${e}`,
|
|
@@ -256,53 +256,50 @@ const U = (i) => {
|
|
|
256
256
|
properties: o
|
|
257
257
|
};
|
|
258
258
|
}, v = (i, o = "complete") => {
|
|
259
|
-
const { properties: s } =
|
|
260
|
-
n(t),
|
|
259
|
+
const { properties: s } = I(i), [a, n] = w(), [e, r] = w(), f = (t) => {
|
|
260
|
+
n(t), C.sendControlData({
|
|
261
261
|
channel: i,
|
|
262
262
|
value: t,
|
|
263
263
|
gesture: o
|
|
264
264
|
});
|
|
265
265
|
};
|
|
266
|
-
return
|
|
267
|
-
var
|
|
266
|
+
return b(() => {
|
|
267
|
+
var m;
|
|
268
268
|
const t = s == null ? void 0 : s.channels.find(
|
|
269
|
-
(
|
|
269
|
+
(d) => d.id === i
|
|
270
270
|
);
|
|
271
271
|
if (!t) return;
|
|
272
|
-
const
|
|
273
|
-
if (e === void 0 &&
|
|
272
|
+
const l = t.parameterIndex;
|
|
273
|
+
if (e === void 0 && l !== void 0 && (console.log(
|
|
274
274
|
`[Cabbage-React] Received parameterIndex for channelId: ${t.id}`,
|
|
275
|
-
|
|
276
|
-
), r(
|
|
277
|
-
const
|
|
278
|
-
|
|
275
|
+
l
|
|
276
|
+
), r(l)), a !== void 0) return;
|
|
277
|
+
const g = (m = t.range) == null ? void 0 : m.value;
|
|
278
|
+
g != null && (console.log(
|
|
279
279
|
`[Cabbage-React] Received initial value for channelId: ${t.id}`,
|
|
280
|
-
|
|
281
|
-
), n(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
), n(m);
|
|
285
|
-
}, [s]), f(() => {
|
|
286
|
-
const t = (g) => {
|
|
280
|
+
g
|
|
281
|
+
), n(g));
|
|
282
|
+
}, [s]), b(() => {
|
|
283
|
+
const t = (l) => {
|
|
287
284
|
var m;
|
|
288
|
-
const { command:
|
|
289
|
-
if (
|
|
290
|
-
const { value: d, paramIdx:
|
|
291
|
-
if (
|
|
285
|
+
const { command: g } = l.data;
|
|
286
|
+
if (g === "parameterChange") {
|
|
287
|
+
const { value: d, paramIdx: c } = l.data.data;
|
|
288
|
+
if (c !== e || d === null) return;
|
|
292
289
|
console.log(
|
|
293
|
-
`[Cabbage-React] Received parameterChange for parameterIndex: ${
|
|
290
|
+
`[Cabbage-React] Received parameterChange for parameterIndex: ${c}`,
|
|
294
291
|
d
|
|
295
292
|
), n(d);
|
|
296
|
-
} else if (
|
|
297
|
-
const d =
|
|
298
|
-
if (!
|
|
299
|
-
const
|
|
293
|
+
} else if (g === "batchWidgetUpdate") {
|
|
294
|
+
const d = l.data.widgets, c = d == null ? void 0 : d.find((M) => M.id === i);
|
|
295
|
+
if (!c) return;
|
|
296
|
+
const u = JSON.parse(c.widgetJson).channels.find(
|
|
300
297
|
(M) => M.id === i
|
|
301
|
-
),
|
|
298
|
+
), p = (m = u == null ? void 0 : u.range) == null ? void 0 : m.value;
|
|
302
299
|
console.log(
|
|
303
|
-
`[Cabbage-React] Received batch widget update for channelId: ${
|
|
304
|
-
|
|
305
|
-
), n(
|
|
300
|
+
`[Cabbage-React] Received batch widget update for channelId: ${c.id}`,
|
|
301
|
+
p
|
|
302
|
+
), n(p);
|
|
306
303
|
}
|
|
307
304
|
};
|
|
308
305
|
return window.addEventListener("message", t), () => {
|
|
@@ -310,11 +307,11 @@ const U = (i) => {
|
|
|
310
307
|
};
|
|
311
308
|
}, [e]), {
|
|
312
309
|
value: a,
|
|
313
|
-
setValue:
|
|
310
|
+
setValue: f
|
|
314
311
|
};
|
|
315
|
-
},
|
|
312
|
+
}, y = (i) => {
|
|
316
313
|
const [o, s] = w();
|
|
317
|
-
return
|
|
314
|
+
return b(() => {
|
|
318
315
|
const a = (n) => {
|
|
319
316
|
const { data: e, type: r } = n;
|
|
320
317
|
if (e && r === "message") {
|
|
@@ -333,8 +330,8 @@ const U = (i) => {
|
|
|
333
330
|
};
|
|
334
331
|
};
|
|
335
332
|
export {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
333
|
+
C as Cabbage,
|
|
334
|
+
y as useCabbageMessage,
|
|
335
|
+
I as useCabbageProperties,
|
|
339
336
|
v as useCabbageState
|
|
340
337
|
};
|