cabbage-react 1.0.41 → 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 +32 -37
- 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,4 +1,4 @@
|
|
|
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
3
|
class C {
|
|
4
4
|
/**
|
|
@@ -238,10 +238,10 @@ class C {
|
|
|
238
238
|
}
|
|
239
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,48 @@ const I = (i) => {
|
|
|
256
256
|
properties: o
|
|
257
257
|
};
|
|
258
258
|
}, v = (i, o = "complete") => {
|
|
259
|
-
const { properties: s } = I(i), [a, n] = w(), [e, r] = w(),
|
|
259
|
+
const { properties: s } = I(i), [a, n] = w(), [e, r] = w(), f = (t) => {
|
|
260
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
|
-
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
|
-
`[Cabbage-React] Received default value for channelId: ${t.id}`,
|
|
285
|
-
m
|
|
286
|
-
), n(m));
|
|
287
|
-
}, [s]), f(() => {
|
|
288
|
-
const t = (g) => {
|
|
280
|
+
g
|
|
281
|
+
), n(g));
|
|
282
|
+
}, [s]), b(() => {
|
|
283
|
+
const t = (l) => {
|
|
289
284
|
var m;
|
|
290
|
-
const { command:
|
|
291
|
-
if (
|
|
292
|
-
const { value: d, paramIdx:
|
|
293
|
-
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;
|
|
294
289
|
console.log(
|
|
295
|
-
`[Cabbage-React] Received parameterChange for parameterIndex: ${
|
|
290
|
+
`[Cabbage-React] Received parameterChange for parameterIndex: ${c}`,
|
|
296
291
|
d
|
|
297
292
|
), n(d);
|
|
298
|
-
} else if (
|
|
299
|
-
const d =
|
|
300
|
-
if (!
|
|
301
|
-
const u = JSON.parse(
|
|
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(
|
|
302
297
|
(M) => M.id === i
|
|
303
298
|
), p = (m = u == null ? void 0 : u.range) == null ? void 0 : m.value;
|
|
304
299
|
console.log(
|
|
305
|
-
`[Cabbage-React] Received batch widget update for channelId: ${
|
|
300
|
+
`[Cabbage-React] Received batch widget update for channelId: ${c.id}`,
|
|
306
301
|
p
|
|
307
302
|
), n(p);
|
|
308
303
|
}
|
|
@@ -312,11 +307,11 @@ const I = (i) => {
|
|
|
312
307
|
};
|
|
313
308
|
}, [e]), {
|
|
314
309
|
value: a,
|
|
315
|
-
setValue:
|
|
310
|
+
setValue: f
|
|
316
311
|
};
|
|
317
|
-
},
|
|
312
|
+
}, y = (i) => {
|
|
318
313
|
const [o, s] = w();
|
|
319
|
-
return
|
|
314
|
+
return b(() => {
|
|
320
315
|
const a = (n) => {
|
|
321
316
|
const { data: e, type: r } = n;
|
|
322
317
|
if (e && r === "message") {
|
|
@@ -336,7 +331,7 @@ const I = (i) => {
|
|
|
336
331
|
};
|
|
337
332
|
export {
|
|
338
333
|
C as Cabbage,
|
|
339
|
-
|
|
334
|
+
y as useCabbageMessage,
|
|
340
335
|
I as useCabbageProperties,
|
|
341
336
|
v as useCabbageState
|
|
342
337
|
};
|