cabbage-react 1.0.41 → 1.0.42
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 +21 -23
- 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;CAqGnC,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react");console.log("Cabbage: loading cabbage.js");class
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react");console.log("Cabbage: loading cabbage.js");class C{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 I=i=>{const[o,s]=g.useState();return g.useEffect(()=>{const a=n=>{const{id:e,widgetJson:r,command:b}=n.data;if(e===i&&r&&b==="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}},U=(i,o="complete")=>{const{properties:s}=I(i),[a,n]=g.useState(),[e,r]=g.useState(),b=t=>{n(t),C.sendControlData({channel:i,value:t,gesture:o})};return g.useEffect(()=>{var d,l;const t=s==null?void 0:s.channels.find(M=>M.id===i);if(!t)return;const c=t.parameterIndex;if(e===void 0&&c!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId: ${t.id}`,c),r(c)),a!==void 0)return;const m=(d=t.range)==null?void 0:d.value,u=(l=t.range)==null?void 0:l.defaultValue;m!=null?(console.log(`[Cabbage-React] Received initial value for channelId: ${t.id}`,m),n(m)):u!=null&&console.log(`[Cabbage-React] Received default value for channelId: ${t.id}`,u),n(u)},[s]),g.useEffect(()=>{const t=c=>{var u;const{command:m}=c.data;if(m==="parameterChange"){const{value:d,paramIdx:l}=c.data.data;if(l!==e||d===null)return;console.log(`[Cabbage-React] Received parameterChange for parameterIndex: ${l}`,d),n(d)}else if(m==="batchWidgetUpdate"){const d=c.data.widgets,l=d==null?void 0:d.find(w=>w.id===i);if(!l)return;const f=JSON.parse(l.widgetJson).channels.find(w=>w.id===i),p=(u=f==null?void 0:f.range)==null?void 0:u.value;console.log(`[Cabbage-React] Received batch widget update for channelId: ${l.id}`,p),n(p)}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[e]),{value:a,setValue:b}},F=i=>{const[o,s]=g.useState();return g.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=C;exports.useCabbageMessage=F;exports.useCabbageProperties=I;exports.useCabbageState=U;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState as w, useEffect as f } from "react";
|
|
2
2
|
console.log("Cabbage: loading cabbage.js");
|
|
3
|
-
class
|
|
3
|
+
class I {
|
|
4
4
|
/**
|
|
5
5
|
* Send a widget value change to the Cabbage backend.
|
|
6
6
|
*
|
|
@@ -236,12 +236,12 @@ class C {
|
|
|
236
236
|
);
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
|
-
const
|
|
239
|
+
const U = (i) => {
|
|
240
240
|
const [o, s] = w();
|
|
241
241
|
return f(() => {
|
|
242
242
|
const a = (n) => {
|
|
243
|
-
const { id: e, widgetJson: r, command:
|
|
244
|
-
if (e === i && r &&
|
|
243
|
+
const { id: e, widgetJson: r, command: u } = n.data;
|
|
244
|
+
if (e === i && r && u === "widgetUpdate") {
|
|
245
245
|
const t = JSON.parse(r);
|
|
246
246
|
console.log(
|
|
247
247
|
`[Cabbage-React] Received properties for channelId: ${e}`,
|
|
@@ -256,34 +256,32 @@ const I = (i) => {
|
|
|
256
256
|
properties: o
|
|
257
257
|
};
|
|
258
258
|
}, v = (i, o = "complete") => {
|
|
259
|
-
const { properties: s } =
|
|
260
|
-
n(t),
|
|
259
|
+
const { properties: s } = U(i), [a, n] = w(), [e, r] = w(), u = (t) => {
|
|
260
|
+
n(t), I.sendControlData({
|
|
261
261
|
channel: i,
|
|
262
262
|
value: t,
|
|
263
263
|
gesture: o
|
|
264
264
|
});
|
|
265
265
|
};
|
|
266
266
|
return f(() => {
|
|
267
|
-
var d;
|
|
267
|
+
var d, l;
|
|
268
268
|
const t = s == null ? void 0 : s.channels.find(
|
|
269
|
-
(
|
|
269
|
+
(p) => p.id === i
|
|
270
270
|
);
|
|
271
271
|
if (!t) return;
|
|
272
272
|
const g = t.parameterIndex;
|
|
273
|
-
e === void 0 && g !== void 0 && (console.log(
|
|
273
|
+
if (e === void 0 && g !== void 0 && (console.log(
|
|
274
274
|
`[Cabbage-React] Received parameterIndex for channelId: ${t.id}`,
|
|
275
275
|
g
|
|
276
|
-
), r(g));
|
|
277
|
-
const c = t.range.value;
|
|
278
|
-
c != null
|
|
276
|
+
), r(g)), a !== void 0) return;
|
|
277
|
+
const c = (d = t.range) == null ? void 0 : d.value, m = (l = t.range) == null ? void 0 : l.defaultValue;
|
|
278
|
+
c != null ? (console.log(
|
|
279
279
|
`[Cabbage-React] Received initial value for channelId: ${t.id}`,
|
|
280
280
|
c
|
|
281
|
-
), n(c))
|
|
282
|
-
const m = (d = t.range) == null ? void 0 : d.defaultValue;
|
|
283
|
-
a === void 0 && m !== void 0 && (console.log(
|
|
281
|
+
), n(c)) : m != null && console.log(
|
|
284
282
|
`[Cabbage-React] Received default value for channelId: ${t.id}`,
|
|
285
283
|
m
|
|
286
|
-
), n(m)
|
|
284
|
+
), n(m);
|
|
287
285
|
}, [s]), f(() => {
|
|
288
286
|
const t = (g) => {
|
|
289
287
|
var m;
|
|
@@ -298,13 +296,13 @@ const I = (i) => {
|
|
|
298
296
|
} else if (c === "batchWidgetUpdate") {
|
|
299
297
|
const d = g.data.widgets, l = d == null ? void 0 : d.find((M) => M.id === i);
|
|
300
298
|
if (!l) return;
|
|
301
|
-
const
|
|
299
|
+
const b = JSON.parse(l.widgetJson).channels.find(
|
|
302
300
|
(M) => M.id === i
|
|
303
|
-
),
|
|
301
|
+
), C = (m = b == null ? void 0 : b.range) == null ? void 0 : m.value;
|
|
304
302
|
console.log(
|
|
305
303
|
`[Cabbage-React] Received batch widget update for channelId: ${l.id}`,
|
|
306
|
-
|
|
307
|
-
), n(
|
|
304
|
+
C
|
|
305
|
+
), n(C);
|
|
308
306
|
}
|
|
309
307
|
};
|
|
310
308
|
return window.addEventListener("message", t), () => {
|
|
@@ -312,7 +310,7 @@ const I = (i) => {
|
|
|
312
310
|
};
|
|
313
311
|
}, [e]), {
|
|
314
312
|
value: a,
|
|
315
|
-
setValue:
|
|
313
|
+
setValue: u
|
|
316
314
|
};
|
|
317
315
|
}, h = (i) => {
|
|
318
316
|
const [o, s] = w();
|
|
@@ -335,8 +333,8 @@ const I = (i) => {
|
|
|
335
333
|
};
|
|
336
334
|
};
|
|
337
335
|
export {
|
|
338
|
-
|
|
336
|
+
I as Cabbage,
|
|
339
337
|
h as useCabbageMessage,
|
|
340
|
-
|
|
338
|
+
U as useCabbageProperties,
|
|
341
339
|
v as useCabbageState
|
|
342
340
|
};
|