cabbage-react 1.0.13 → 1.0.14

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 u=require("react");console.log("Cabbage: loading cabbage.js");class f{static sendChannelUpdate(e,n=null,a=!1){if(a===!0||a===1)f.sendParameterUpdate(e,n);else{const s=e.value!==void 0?e.value:e.stringData||e.floatData;f.sendChannelData(e.channel,s,n)}}static sendParameterUpdate(e,n=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 a={command:"parameterChange",paramIdx:e.paramIdx,channel:e.channel,value:e.value,channelType:e.channelType||"number"};n!==null?n.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static sendCustomCommand(e,n=null,a={}){const s={command:e,text:JSON.stringify(a)};if(n!==null)n.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,n=null){const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};n!==null?n.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static sendMidiMessageFromUI(e,n,a,s=null){var o={statusByte:e,dataByte1:n,dataByte2:a};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,n,a=null){var s={channel:e};if(typeof n=="string")s.stringData=n;else if(typeof n=="number")s.floatData=n;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof n);return}const o={command:"channelData",obj:JSON.stringify(s)};console.log("Cabbage: sending channel data from UI",s),a!==null?a.postMessage(o):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(o):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",o)}static MidiMessageFromHost(e,n,a){console.log("Cabbage: Got MIDI Message"+e+":"+n+":"+a)}static triggerFileOpenDialog(e,n,a={}){var s={channel:n,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.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,n,a){var s={url:n,file:a};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)}}const M=d=>{const[e,n]=u.useState();return u.useEffect(()=>{const a=s=>{const{id:o,widgetJson:l,command:t}=s.data;if(o===d&&l&&t==="widgetUpdate"){const r=JSON.parse(l);console.log(`[Cabbage-React] Received properties for channelId ${o}`,r),n(r)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:e}},I=d=>{const{properties:e}=M(d),[n,a]=u.useState(),[s,o]=u.useState(),l=t=>{a(t);const r={channel:d,paramIdx:s,value:t};f.sendParameterUpdate(r,null)};return u.useEffect(()=>{var i;const t=e==null?void 0:e.channels.find(g=>g.id===d);if(!t)return;const r=t==null?void 0:t.parameterIndex;s===void 0&&r!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,r),o(r));const c=e==null?void 0:e.value;c!=null&&(console.log(`[Cabbage-React] Received initial value for channelId "${d}"`,c),a(c));const m=(i=t.range)==null?void 0:i.defaultValue;n===void 0&&m!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${t.id}"`,m),a(m))},[e]),u.useEffect(()=>{const t=r=>{var m;const{command:c}=r.data;if(c==="parameterChange"){const{value:i,paramIdx:g}=r.data.data;if(g!==s||i===null)return;console.log(`[Cabbage-React] Received value change for parameterIndex ${g}`,i),a(i)}else if(c==="batchWidgetUpdate"){const i=r.data.widgets,g=i==null?void 0:i.find(w=>w.id===d);if(!g)return;const b=JSON.parse(g.widgetJson).channels.find(w=>w.id===d),p=(m=b==null?void 0:b.range)==null?void 0:m.value;console.log(`[Cabbage-React] Received batch widget update for channelId ${g.id}`,p),a(p)}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[s]),{value:n,setValue:l}};exports.Cabbage=f;exports.useCabbageProperties=M;exports.useCabbageState=I;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react");console.log("Cabbage: loading cabbage.js");class f{static sendChannelUpdate(e,n=null,a=!1){if(a===!0||a===1)f.sendParameterUpdate(e,n);else{const s=e.value!==void 0?e.value:e.stringData||e.floatData;f.sendChannelData(e.channel,s,n)}}static sendParameterUpdate(e,n=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 a={command:"parameterChange",paramIdx:e.paramIdx,channel:e.channel,value:e.value,channelType:e.channelType||"number"};n!==null?n.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static sendCustomCommand(e,n=null,a={}){const s={command:e,text:JSON.stringify(a)};if(n!==null)n.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,n=null){const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};n!==null?n.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static sendMidiMessageFromUI(e,n,a,s=null){var o={statusByte:e,dataByte1:n,dataByte2:a};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,n,a=null){var s={channel:e};if(typeof n=="string")s.stringData=n;else if(typeof n=="number")s.floatData=n;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof n);return}const o={command:"channelData",obj:JSON.stringify(s)};console.log("Cabbage: sending channel data from UI",s),a!==null?a.postMessage(o):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(o):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",o)}static MidiMessageFromHost(e,n,a){console.log("Cabbage: Got MIDI Message"+e+":"+n+":"+a)}static triggerFileOpenDialog(e,n,a={}){var s={channel:n,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.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,n,a){var s={url:n,file:a};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)}}const M=d=>{const[e,n]=u.useState();return u.useEffect(()=>{const a=s=>{const{id:o,widgetJson:l,command:t}=s.data;if(o===d&&l&&t==="widgetUpdate"){const r=JSON.parse(l);console.log(`[Cabbage-React] Received properties for channelId ${o}`,r),n(r)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:e}},I=d=>{const{properties:e}=M(d),[n,a]=u.useState(),[s,o]=u.useState(),l=t=>{a(t);const r={channel:d,paramIdx:s,value:t};f.sendParameterUpdate(r,null)};return u.useEffect(()=>{var i;const t=e==null?void 0:e.channels.find(g=>g.id===d);if(!t)return;const r=t==null?void 0:t.parameterIndex;s===void 0&&r!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,r),o(r));const c=e==null?void 0:e.value;c!=null&&(console.log(`[Cabbage-React] Received initial value for channelId "${d}"`,c),a(c));const m=(i=t.range)==null?void 0:i.defaultValue;n===void 0&&m!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${t.id}"`,m),a(m))},[e]),u.useEffect(()=>{const t=r=>{var m;const{command:c}=r.data;if(c==="parameterChange"){const{value:i,paramIdx:g}=r.data.data;if(g!==s||i===null)return;console.log(`[Cabbage-React] Received parameterChange for parameterIndex ${g}`,i),a(i)}else if(c==="batchWidgetUpdate"){const i=r.data.widgets,g=i==null?void 0:i.find(w=>w.id===d);if(!g)return;const b=JSON.parse(g.widgetJson).channels.find(w=>w.id===d),p=(m=b==null?void 0:b.range)==null?void 0:m.value;console.log(`[Cabbage-React] Received batch widget update for channelId ${g.id}`,p),a(p)}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[s]),{value:n,setValue:l}};exports.Cabbage=f;exports.useCabbageProperties=M;exports.useCabbageState=I;
package/dist/index.mjs CHANGED
@@ -219,7 +219,7 @@ const I = (d) => {
219
219
  const { value: i, paramIdx: g } = r.data.data;
220
220
  if (g !== s || i === null) return;
221
221
  console.log(
222
- `[Cabbage-React] Received value change for parameterIndex ${g}`,
222
+ `[Cabbage-React] Received parameterChange for parameterIndex ${g}`,
223
223
  i
224
224
  ), a(i);
225
225
  } else if (c === "batchWidgetUpdate") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",