cabbage-react 1.0.10 → 1.0.11

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;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,aAAa,MAAM;;sBAQjB,CAAC;CAuFnC,CAAC"}
1
+ {"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,aAAa,MAAM;;sBAMjB,CAAC;CAuFnC,CAAC"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react");console.log("Cabbage: loading cabbage.js");class u{static sendChannelUpdate(e,n=null,a=!1){if(a===!0||a===1)u.sendParameterUpdate(e,n);else{const s=e.value!==void 0?e.value:e.stringData||e.floatData;u.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 i={command:"midiMessage",obj:JSON.stringify(o)};s!==null?s.postMessage(i):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(i):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",i)}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 f=d=>{const[e,n]=m.useState();return m.useEffect(()=>{const a=s=>{const{id:o,widgetJson:i,command:t}=s.data;if(o===d&&i&&t==="widgetUpdate"){const r=JSON.parse(i);console.log(`[Cabbage-React] Received properties for channelId ${o}`,r),n(r)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:e}},w=d=>{const{properties:e}=f(d),[n,a]=m.useState(),[s,o]=m.useState();console.log("paramIdx-test-log",s);const i=t=>{a(t);const r={channel:d,paramIdx:s,value:t};u.sendParameterUpdate(r,null)};return m.useEffect(()=>{var c;const t=e==null?void 0:e.channels.find(b=>b.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 g=e==null?void 0:e.value;g!=null&&(console.log(`[Cabbage-React] Received initial value for channelId "${d}"`,g),a(g));const l=(c=t.range)==null?void 0:c.defaultValue;n===void 0&&l!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${t.id}"`,l),a(l))},[e]),m.useEffect(()=>{const t=r=>{const{command:g}=r.data;if(g==="parameterChange"){const{value:l,paramIdx:c}=r.data.data;if(console.log("paramIdx",s),console.log("value",l),console.log("incomingParameterIndex",c),console.log("event.data.data",r.data.data),c!==s||l===null)return;console.log(`[Cabbage-React] Received value change for parameterIndex ${c}`,l),a(l)}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[]),{value:n,setValue:i}};exports.Cabbage=u;exports.useCabbageProperties=f;exports.useCabbageState=w;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react");console.log("Cabbage: loading cabbage.js");class u{static sendChannelUpdate(e,n=null,a=!1){if(a===!0||a===1)u.sendParameterUpdate(e,n);else{const s=e.value!==void 0?e.value:e.stringData||e.floatData;u.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 i={command:"midiMessage",obj:JSON.stringify(o)};s!==null?s.postMessage(i):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(i):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",i)}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 f=d=>{const[e,n]=m.useState();return m.useEffect(()=>{const a=s=>{const{id:o,widgetJson:i,command:t}=s.data;if(o===d&&i&&t==="widgetUpdate"){const r=JSON.parse(i);console.log(`[Cabbage-React] Received properties for channelId ${o}`,r),n(r)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:e}},w=d=>{const{properties:e}=f(d),[n,a]=m.useState(),[s,o]=m.useState(),i=t=>{a(t);const r={channel:d,paramIdx:s,value:t};u.sendParameterUpdate(r,null)};return m.useEffect(()=>{var c;const t=e==null?void 0:e.channels.find(b=>b.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 g=e==null?void 0:e.value;g!=null&&(console.log(`[Cabbage-React] Received initial value for channelId "${d}"`,g),a(g));const l=(c=t.range)==null?void 0:c.defaultValue;n===void 0&&l!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${t.id}"`,l),a(l))},[e]),m.useEffect(()=>{const t=r=>{const{command:g}=r.data;if(g==="parameterChange"){const{value:l,paramIdx:c}=r.data.data;if(console.log("paramIdx",s),console.log("value",l),console.log("incomingParameterIndex",c),console.log("event.data.data",r.data.data),c!==s||l===null)return;console.log(`[Cabbage-React] Received value change for parameterIndex ${c}`,l),a(l)}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[s]),{value:n,setValue:i}};exports.Cabbage=u;exports.useCabbageProperties=f;exports.useCabbageState=w;
package/dist/index.mjs CHANGED
@@ -181,9 +181,7 @@ const b = (d) => {
181
181
  properties: e
182
182
  };
183
183
  }, I = (d) => {
184
- const { properties: e } = b(d), [n, a] = f(), [s, o] = f();
185
- console.log("paramIdx-test-log", s);
186
- const i = (t) => {
184
+ const { properties: e } = b(d), [n, a] = f(), [s, o] = f(), i = (t) => {
187
185
  a(t);
188
186
  const r = {
189
187
  channel: d,
@@ -228,7 +226,7 @@ const b = (d) => {
228
226
  return window.addEventListener("message", t), () => {
229
227
  window.removeEventListener("message", t);
230
228
  };
231
- }, []), {
229
+ }, [s]), {
232
230
  value: n,
233
231
  setValue: i
234
232
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",