cabbage-react 1.0.39 → 1.0.40

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/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:e,gesture:a="complete"},n=null){const s={command:"controlData",channel:o,value:e,gesture:a};n!==null?n.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static isReadyToLoad(o=null,e={}){this.sendCustomCommand("isReadyToLoad",o)}static sendMidiMessageFromUI(o,e,a,n=null){var s={statusByte:o,dataByte1:e,dataByte2:a};const r={command:"midiMessage",obj:JSON.stringify(s)};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,e,a){console.log("Cabbage: Got MIDI Message"+o+":"+e+":"+a)}static triggerFileOpenDialog(o,e,a={}){var n={channel:e,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.openAtLastKnownLocation:!0};const s={command:"fileOpen",obj:JSON.stringify(n)};o!==null?o.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static openUrl(o,e,a){var n={url:e,file:a};const s={command:"openUrl",obj:JSON.stringify(n)};o!==null?o.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static requestResize(o,e,a=null){const n={command:"requestResize",width:o,height:e};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,e,a=null){var n={channel:o};if(typeof e=="string")n.stringData=e;else if(typeof e=="number")n.floatData=e;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof e);return}const s={command:"channelData",obj:JSON.stringify(n)};console.log("Cabbage: sending channel data from UI",n),a!==null?a.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static sendWidgetUpdate(o,e=null){const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(o))};e!==null?e.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static sendCustomCommand(o,e=null,a={}){const n={command:o,text:JSON.stringify(a)};if(e!==null)e.postMessage(n);else if(typeof window.sendMessageFromUI=="function"){console.log("Cabbage: Calling window.sendMessageFromUI with:",n);try{const s=window.sendMessageFromUI(n);console.log("Cabbage: sendMessageFromUI returned:",s)}catch(s){console.error("Cabbage: sendMessageFromUI threw error:",s),console.error("Cabbage: Error stack:",s.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 p=i=>{const[o,e]=g.useState();return g.useEffect(()=>{const a=n=>{const{id:s,widgetJson:r,command:b}=n.data;if(s===i&&r&&b==="widgetUpdate"){const t=JSON.parse(r);console.log(`[Cabbage-React] Received properties for channelId ${s}`,t),e(t)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:o}},I=(i,o="complete")=>{const{properties:e}=p(i),[a,n]=g.useState(),[s,r]=g.useState(),b=t=>{n(t),C.sendControlData({channel:i,value:t,gesture:o})};return g.useEffect(()=>{var d;const t=e==null?void 0:e.channels.find(l=>l.id===i);if(!t)return;const c=t==null?void 0:t.parameterIndex;s===void 0&&c!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,c),r(c));const m=e==null?void 0:e.value;m!=null&&(console.log(`[Cabbage-React] Received initial value for channelId "${i}"`,m),n(m));const u=(d=t.range)==null?void 0:d.defaultValue;a===void 0&&u!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${t.id}"`,u),n(u))},[e]),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!==s||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),M=(u=f==null?void 0:f.range)==null?void 0:u.value;console.log(`[Cabbage-React] Received batch widget update for channelId "${l.id}"`,M),n(M)}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[s]),{value:a,setValue:b}},U=i=>{const[o,e]=g.useState();return g.useEffect(()=>{const a=n=>{const{data:s,type:r}=n;if(s&&r==="message"){if(s.id!==i)return;console.log(`[Cabbage-React] Received data for messageId ${s.id}`,s),e(s)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{data:o}};exports.Cabbage=C;exports.useCabbageMessage=U;exports.useCabbageProperties=p;exports.useCabbageState=I;
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:e,gesture:a="complete"},n=null){const s={command:"controlData",channel:o,value:e,gesture:a};n!==null?n.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static isReadyToLoad(o=null,e={}){this.sendCustomCommand("isReadyToLoad",o)}static sendMidiMessageFromUI(o,e,a,n=null){var s={statusByte:o,dataByte1:e,dataByte2:a};const r={command:"midiMessage",obj:JSON.stringify(s)};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,e,a){console.log("Cabbage: Got MIDI Message"+o+":"+e+":"+a)}static triggerFileOpenDialog(o,e,a={}){var n={channel:e,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.openAtLastKnownLocation:!0};const s={command:"fileOpen",obj:JSON.stringify(n)};o!==null?o.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static openUrl(o,e,a){var n={url:e,file:a};const s={command:"openUrl",obj:JSON.stringify(n)};o!==null?o.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static requestResize(o,e,a=null){const n={command:"requestResize",width:o,height:e};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,e,a=null){var n={channel:o};if(typeof e=="string")n.stringData=e;else if(typeof e=="number")n.floatData=e;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof e);return}const s={command:"channelData",obj:JSON.stringify(n)};console.log("Cabbage: sending channel data from UI",n),a!==null?a.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static sendWidgetUpdate(o,e=null){const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(o))};e!==null?e.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static sendCustomCommand(o,e=null,a={}){const n={command:o,text:JSON.stringify(a)};if(e!==null)e.postMessage(n);else if(typeof window.sendMessageFromUI=="function"){console.log("Cabbage: Calling window.sendMessageFromUI with:",n);try{const s=window.sendMessageFromUI(n);console.log("Cabbage: sendMessageFromUI returned:",s)}catch(s){console.error("Cabbage: sendMessageFromUI threw error:",s),console.error("Cabbage: Error stack:",s.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 p=i=>{const[o,e]=g.useState();return g.useEffect(()=>{const a=n=>{const{id:s,widgetJson:r,command:b}=n.data;if(s===i&&r&&b==="widgetUpdate"){const t=JSON.parse(r);console.log(`[Cabbage-React] Received properties for channelId: ${s}`,t),e(t)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:o}},I=(i,o="complete")=>{const{properties:e}=p(i),[a,n]=g.useState(),[s,r]=g.useState(),b=t=>{n(t),C.sendControlData({channel:i,value:t,gesture:o})};return g.useEffect(()=>{var d;const t=e==null?void 0:e.channels.find(l=>l.id===i);if(!t)return;const c=t==null?void 0:t.parameterIndex;s===void 0&&c!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId: ${t.id}`,c),r(c));const m=e==null?void 0:e.value;m!=null&&(console.log(`[Cabbage-React] Received initial value for channelId: ${i}`,m),n(m));const u=(d=t.range)==null?void 0:d.defaultValue;a===void 0&&u!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId: ${t.id}`,u),n(u))},[e]),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!==s||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),M=(u=f==null?void 0:f.range)==null?void 0:u.value;console.log(`[Cabbage-React] Received batch widget update for channelId: ${l.id}`,M),n(M)}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[s]),{value:a,setValue:b}},U=i=>{const[o,e]=g.useState();return g.useEffect(()=>{const a=n=>{const{data:s,type:r}=n;if(s&&r==="message"){if(s.id!==i)return;console.log(`[Cabbage-React] Received data for messageId: ${s.id}`,s),e(s)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{data:o}};exports.Cabbage=C;exports.useCabbageMessage=U;exports.useCabbageProperties=p;exports.useCabbageState=I;
package/dist/index.mjs CHANGED
@@ -244,7 +244,7 @@ const I = (i) => {
244
244
  if (s === i && r && b === "widgetUpdate") {
245
245
  const t = JSON.parse(r);
246
246
  console.log(
247
- `[Cabbage-React] Received properties for channelId ${s}`,
247
+ `[Cabbage-React] Received properties for channelId: ${s}`,
248
248
  t
249
249
  ), e(t);
250
250
  }
@@ -271,17 +271,17 @@ const I = (i) => {
271
271
  if (!t) return;
272
272
  const g = t == null ? void 0 : t.parameterIndex;
273
273
  s === void 0 && g !== void 0 && (console.log(
274
- `[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,
274
+ `[Cabbage-React] Received parameterIndex for channelId: ${t.id}`,
275
275
  g
276
276
  ), r(g));
277
277
  const c = e == null ? void 0 : e.value;
278
278
  c != null && (console.log(
279
- `[Cabbage-React] Received initial value for channelId "${i}"`,
279
+ `[Cabbage-React] Received initial value for channelId: ${i}`,
280
280
  c
281
281
  ), n(c));
282
282
  const m = (d = t.range) == null ? void 0 : d.defaultValue;
283
283
  a === void 0 && m !== void 0 && (console.log(
284
- `[Cabbage-React] Received default value for channelId "${t.id}"`,
284
+ `[Cabbage-React] Received default value for channelId: ${t.id}`,
285
285
  m
286
286
  ), n(m));
287
287
  }, [e]), f(() => {
@@ -292,7 +292,7 @@ const I = (i) => {
292
292
  const { value: d, paramIdx: l } = g.data.data;
293
293
  if (l !== s || d === null) return;
294
294
  console.log(
295
- `[Cabbage-React] Received parameterChange for parameterIndex "${l}"`,
295
+ `[Cabbage-React] Received parameterChange for parameterIndex: ${l}`,
296
296
  d
297
297
  ), n(d);
298
298
  } else if (c === "batchWidgetUpdate") {
@@ -302,7 +302,7 @@ const I = (i) => {
302
302
  (M) => M.id === i
303
303
  ), p = (m = u == null ? void 0 : u.range) == null ? void 0 : m.value;
304
304
  console.log(
305
- `[Cabbage-React] Received batch widget update for channelId "${l.id}"`,
305
+ `[Cabbage-React] Received batch widget update for channelId: ${l.id}`,
306
306
  p
307
307
  ), n(p);
308
308
  }
@@ -322,7 +322,7 @@ const I = (i) => {
322
322
  if (s && r === "message") {
323
323
  if (s.id !== i) return;
324
324
  console.log(
325
- `[Cabbage-React] Received data for messageId ${s.id}`,
325
+ `[Cabbage-React] Received data for messageId: ${s.id}`,
326
326
  s
327
327
  ), e(s);
328
328
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.39",
3
+ "version": "1.0.40",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",