cabbage-react 1.0.23 → 1.0.24
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 +35 -40
- 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,aAAa,MAAM,eAAe,OAAO;;sBAMvC,CAAC;;
|
|
1
|
+
{"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,aAAa,MAAM,eAAe,OAAO;;sBAMvC,CAAC;;CAoGnC,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 m=require("react");console.log("Cabbage: loading cabbage.js");class f{static sendChannelUpdate(e,a=null,n=!1){if(n===!0||n===1)f.sendParameterUpdate(e,a);else{const s=e.value!==void 0?e.value:e.stringData||e.floatData;f.sendChannelData(e.channel,s,a)}}static sendParameterUpdate(e,a=null){if(e.paramIdx===void 0||e.paramIdx===null){console.error("Cabbage.sendParameterUpdate: message missing paramIdx!",e);return}if(e.paramIdx<0){console.warn("Cabbage.sendParameterUpdate: paramIdx is -1, skipping (non-automatable widget)",e);return}const n={command:"parameterChange",paramIdx:e.paramIdx,channel:e.channel,value:e.value,channelType:e.channelType||"number"};a!==null?a.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static sendCustomCommand(e,a=null,n={}){const s={command:e,text:JSON.stringify(n)};if(a!==null)a.postMessage(s);else if(typeof window.sendMessageFromUI=="function"){console.log("Cabbage: Calling window.sendMessageFromUI with:",s);try{const o=window.sendMessageFromUI(s);console.log("Cabbage: sendMessageFromUI returned:",o)}catch(o){console.error("Cabbage: sendMessageFromUI threw error:",o),console.error("Cabbage: Error stack:",o.stack)}}else console.error("Cabbage: window.sendMessageFromUI is not available yet. Message:",s),console.error("Cabbage: typeof window.sendMessageFromUI:",typeof window.sendMessageFromUI),console.error("Cabbage: window.sendMessageFromUI value:",window.sendMessageFromUI)}static sendWidgetUpdate(e,a=null){const n={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};a!==null?a.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static sendMidiMessageFromUI(e,a,n,s=null){var o={statusByte:e,dataByte1:a,dataByte2:n};const l={command:"midiMessage",obj:JSON.stringify(o)};s!==null?s.postMessage(l):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(l):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",l)}static sendChannelData(e,a,n=null){var s={channel:e};if(typeof a=="string")s.stringData=a;else if(typeof a=="number")s.floatData=a;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof a);return}const o={command:"channelData",obj:JSON.stringify(s)};console.log("Cabbage: sending channel data from UI",s),n!==null?n.postMessage(o):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(o):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",o)}static MidiMessageFromHost(e,a,n){console.log("Cabbage: Got MIDI Message"+e+":"+a+":"+n)}static triggerFileOpenDialog(e,a,n={}){var s={channel:a,directory:n.directory||"",filters:n.filters||"*",openAtLastKnownLocation:n.openAtLastKnownLocation!==void 0?n.openAtLastKnownLocation:!0};const o={command:"fileOpen",obj:JSON.stringify(s)};e!==null?e.postMessage(o):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(o):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",o)}static openUrl(e,a,n){var s={url:a,file:n};const o={command:"openUrl",obj:JSON.stringify(s)};e!==null?e.postMessage(o):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(o):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",o)}static requestResize(e,a,n=null){const s={command:"requestResize",width:e,height:a};if(n!==null){console.warn("Cabbage: requestResize is not supported in VS Code extension mode");return}else typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}}const I=d=>{const[e,a]=m.useState();return m.useEffect(()=>{const n=s=>{const{id:o,widgetJson:l,command:b}=s.data;if(o===d&&l&&b==="widgetUpdate"){const t=JSON.parse(l);console.log(`[Cabbage-React] Received properties for channelId ${o}`,t),a(t)}};return window.addEventListener("message",n),()=>{window.removeEventListener("message",n)}},[]),{properties:e}},C=(d,e)=>{const{properties:a}=I(d),[n,s]=m.useState(),[o,l]=m.useState(),b=t=>{if(s(t),o===void 0){console.warn(`[Cabbage-React] parameterIndex not ready for "${d}"`);return}const r={paramIdx:o,channel:d,value:t,channelType:"number"};f.sendParameterUpdate(r,null)};return m.useEffect(()=>{var u;const t=a==null?void 0:a.channels.find(i=>i.id===d);if(!t)return;const r=t==null?void 0:t.parameterIndex;o===void 0&&r!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,r),l(r));const g=(u=t.range)==null?void 0:u.defaultValue;n===void 0&&g!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${t.id}"`,g),s(g))},[a]),m.useEffect(()=>{const t=r=>{var u;const{command:g}=r.data;if(g==="parameterChange"){if(e===!0)return;const{value:i,paramIdx:c}=r.data.data;if(c!==o||i===null)return;console.log(`[Cabbage-React] Received parameterChange for parameterIndex ${c}`,i),s(i)}else if(g==="batchWidgetUpdate"){const i=r.data.widgets,c=i==null?void 0:i.find(p=>p.id===d);if(!c)return;const w=JSON.parse(c.widgetJson).channels.find(p=>p.id===d),M=(u=w==null?void 0:w.range)==null?void 0:u.value;console.log(`[Cabbage-React] Received batch widget update for channelId ${c.id}`,M),s(M)}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[o,e]),{value:n,setValue:b,parameterIndex:o}};exports.Cabbage=f;exports.useCabbageProperties=I;exports.useCabbageState=C;
|
package/dist/index.mjs
CHANGED
|
@@ -236,12 +236,12 @@ class f {
|
|
|
236
236
|
);
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
|
-
const U = (
|
|
239
|
+
const U = (d) => {
|
|
240
240
|
const [e, a] = p();
|
|
241
241
|
return M(() => {
|
|
242
242
|
const n = (s) => {
|
|
243
|
-
const { id: o, widgetJson: l, command:
|
|
244
|
-
if (o ===
|
|
243
|
+
const { id: o, widgetJson: l, command: w } = s.data;
|
|
244
|
+
if (o === d && l && w === "widgetUpdate") {
|
|
245
245
|
const t = JSON.parse(l);
|
|
246
246
|
console.log(
|
|
247
247
|
`[Cabbage-React] Received properties for channelId ${o}`,
|
|
@@ -255,63 +255,58 @@ const U = (i) => {
|
|
|
255
255
|
}, []), {
|
|
256
256
|
properties: e
|
|
257
257
|
};
|
|
258
|
-
}, h = (
|
|
259
|
-
const { properties: a } = U(
|
|
258
|
+
}, h = (d, e) => {
|
|
259
|
+
const { properties: a } = U(d), [n, s] = p(), [o, l] = p(), w = (t) => {
|
|
260
260
|
if (s(t), o === void 0) {
|
|
261
261
|
console.warn(
|
|
262
|
-
`[Cabbage-React] parameterIndex not ready for "${
|
|
262
|
+
`[Cabbage-React] parameterIndex not ready for "${d}"`
|
|
263
263
|
);
|
|
264
264
|
return;
|
|
265
265
|
}
|
|
266
|
-
const
|
|
266
|
+
const r = {
|
|
267
267
|
paramIdx: o,
|
|
268
|
-
channel:
|
|
268
|
+
channel: d,
|
|
269
269
|
value: t,
|
|
270
270
|
channelType: "number"
|
|
271
271
|
};
|
|
272
|
-
f.sendParameterUpdate(
|
|
272
|
+
f.sendParameterUpdate(r, null);
|
|
273
273
|
};
|
|
274
274
|
return M(() => {
|
|
275
|
-
var
|
|
275
|
+
var m;
|
|
276
276
|
const t = a == null ? void 0 : a.channels.find(
|
|
277
|
-
(
|
|
277
|
+
(i) => i.id === d
|
|
278
278
|
);
|
|
279
279
|
if (!t) return;
|
|
280
|
-
const
|
|
281
|
-
o === void 0 &&
|
|
280
|
+
const r = t == null ? void 0 : t.parameterIndex;
|
|
281
|
+
o === void 0 && r !== void 0 && (console.log(
|
|
282
282
|
`[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,
|
|
283
|
-
|
|
284
|
-
), l(
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
`[Cabbage-React] Received initial value for channelId "${i}"`,
|
|
288
|
-
c
|
|
289
|
-
), s(c));
|
|
290
|
-
const m = (r = t.range) == null ? void 0 : r.defaultValue;
|
|
291
|
-
n === void 0 && m !== void 0 && (console.log(
|
|
283
|
+
r
|
|
284
|
+
), l(r));
|
|
285
|
+
const g = (m = t.range) == null ? void 0 : m.defaultValue;
|
|
286
|
+
n === void 0 && g !== void 0 && (console.log(
|
|
292
287
|
`[Cabbage-React] Received default value for channelId "${t.id}"`,
|
|
293
|
-
|
|
294
|
-
), s(
|
|
288
|
+
g
|
|
289
|
+
), s(g));
|
|
295
290
|
}, [a]), M(() => {
|
|
296
|
-
const t = (
|
|
291
|
+
const t = (r) => {
|
|
297
292
|
var m;
|
|
298
|
-
const { command:
|
|
299
|
-
if (
|
|
293
|
+
const { command: g } = r.data;
|
|
294
|
+
if (g === "parameterChange") {
|
|
300
295
|
if (e === !0) return;
|
|
301
|
-
const { value:
|
|
302
|
-
if (
|
|
296
|
+
const { value: i, paramIdx: c } = r.data.data;
|
|
297
|
+
if (c !== o || i === null) return;
|
|
303
298
|
console.log(
|
|
304
|
-
`[Cabbage-React] Received parameterChange for parameterIndex ${
|
|
305
|
-
|
|
306
|
-
), s(
|
|
307
|
-
} else if (
|
|
308
|
-
const
|
|
309
|
-
if (!
|
|
310
|
-
const
|
|
311
|
-
(b) => b.id ===
|
|
312
|
-
), I = (m =
|
|
299
|
+
`[Cabbage-React] Received parameterChange for parameterIndex ${c}`,
|
|
300
|
+
i
|
|
301
|
+
), s(i);
|
|
302
|
+
} else if (g === "batchWidgetUpdate") {
|
|
303
|
+
const i = r.data.widgets, c = i == null ? void 0 : i.find((b) => b.id === d);
|
|
304
|
+
if (!c) return;
|
|
305
|
+
const u = JSON.parse(c.widgetJson).channels.find(
|
|
306
|
+
(b) => b.id === d
|
|
307
|
+
), I = (m = u == null ? void 0 : u.range) == null ? void 0 : m.value;
|
|
313
308
|
console.log(
|
|
314
|
-
`[Cabbage-React] Received batch widget update for channelId ${
|
|
309
|
+
`[Cabbage-React] Received batch widget update for channelId ${c.id}`,
|
|
315
310
|
I
|
|
316
311
|
), s(I);
|
|
317
312
|
}
|
|
@@ -321,7 +316,7 @@ const U = (i) => {
|
|
|
321
316
|
};
|
|
322
317
|
}, [o, e]), {
|
|
323
318
|
value: n,
|
|
324
|
-
setValue:
|
|
319
|
+
setValue: w,
|
|
325
320
|
parameterIndex: o
|
|
326
321
|
};
|
|
327
322
|
};
|