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.
@@ -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;CAqGnC,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 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;
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 f } from "react";
1
+ import { useState as w, useEffect as b } from "react";
2
2
  console.log("Cabbage: loading cabbage.js");
3
- class I {
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 U = (i) => {
239
+ const I = (i) => {
240
240
  const [o, s] = w();
241
- return f(() => {
241
+ return b(() => {
242
242
  const a = (n) => {
243
- const { id: e, widgetJson: r, command: u } = n.data;
244
- if (e === i && r && u === "widgetUpdate") {
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 } = U(i), [a, n] = w(), [e, r] = w(), u = (t) => {
260
- n(t), I.sendControlData({
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 f(() => {
267
- var d, l;
266
+ return b(() => {
267
+ var m;
268
268
  const t = s == null ? void 0 : s.channels.find(
269
- (p) => p.id === i
269
+ (d) => d.id === i
270
270
  );
271
271
  if (!t) return;
272
- const g = t.parameterIndex;
273
- if (e === void 0 && g !== void 0 && (console.log(
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
- g
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(
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
- c
281
- ), n(c)) : m != null && console.log(
282
- `[Cabbage-React] Received default value for channelId: ${t.id}`,
283
- m
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: c } = g.data;
289
- if (c === "parameterChange") {
290
- const { value: d, paramIdx: l } = g.data.data;
291
- if (l !== e || d === null) return;
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: ${l}`,
290
+ `[Cabbage-React] Received parameterChange for parameterIndex: ${c}`,
294
291
  d
295
292
  ), n(d);
296
- } else if (c === "batchWidgetUpdate") {
297
- const d = g.data.widgets, l = d == null ? void 0 : d.find((M) => M.id === i);
298
- if (!l) return;
299
- const b = JSON.parse(l.widgetJson).channels.find(
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
- ), C = (m = b == null ? void 0 : b.range) == null ? void 0 : m.value;
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: ${l.id}`,
304
- C
305
- ), n(C);
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: u
310
+ setValue: f
314
311
  };
315
- }, h = (i) => {
312
+ }, y = (i) => {
316
313
  const [o, s] = w();
317
- return f(() => {
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
- I as Cabbage,
337
- h as useCabbageMessage,
338
- U as useCabbageProperties,
333
+ C as Cabbage,
334
+ y as useCabbageMessage,
335
+ I as useCabbageProperties,
339
336
  v as useCabbageState
340
337
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.42",
3
+ "version": "1.0.43",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",