cabbage-react 1.0.53 → 1.0.54

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.
@@ -3,12 +3,15 @@
3
3
  * This hook listens to messages sent from the backend and updates the local state
4
4
  * whenever new data is received.
5
5
  * @param messageType - The value of the `type` property in the incoming message object to listen for.
6
- * @param onMessage - Callback fires immediately when receiving a new message (synchronous - bypasses state batching)
7
6
  * @param options - Optional configuration
7
+ * @param options.onMessage - Callback fires immediately when receiving a new message (synchronous - bypasses state batching)
8
8
  * @param options.skip - When true, the hook returns a NOP state and never registers listeners
9
+ * @param options.debug - When true, logs incoming messages for this hook to the console for debugging
9
10
  */
10
- export declare const useCabbageMessage: <T>(messageType: string, onMessage?: (message: T) => void, options?: {
11
+ export declare const useCabbageMessage: <T>(messageType: string, options?: {
12
+ onMessage?: (message: T) => void;
11
13
  skip?: boolean;
14
+ debug?: boolean;
12
15
  }) => {
13
16
  message: T | undefined;
14
17
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useCabbageMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageMessage.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAClC,aAAa,MAAM,EACnB,YAAY,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,EAChC,UAAU;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE;;CA4B5B,CAAC"}
1
+ {"version":3,"file":"useCabbageMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageMessage.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAClC,aAAa,MAAM,EACnB,UAAU;IACT,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;;CA6BD,CAAC"}
@@ -3,12 +3,15 @@
3
3
  * This hook listens for updates to parameter properties from the backend and updates the local state
4
4
  * whenever new data is received.
5
5
  * @param channelId
6
- * @param onPropertiesUpdate - Callback fires immediately when receiving an update to properties (synchronous - bypasses state batching)
7
6
  * @param options - Optional configuration
7
+ * @param options.onPropertiesUpdate - Callback fires immediately when receiving an update to properties (synchronous - bypasses state batching)
8
8
  * @param options.skip - When true, the hook returns a NOP state and never registers listeners
9
+ * @param options.debug - When true, logs incoming updates to properties for this hook to the console for debugging
9
10
  */
10
- export declare const useCabbageProperties: (channelId: string, onPropertiesUpdate?: (properties: Record<string, any>) => void, options?: {
11
+ export declare const useCabbageProperties: (channelId: string, options?: {
12
+ onPropertiesUpdate?: (properties: Record<string, any>) => void;
11
13
  skip?: boolean;
14
+ debug?: boolean;
12
15
  }) => {
13
16
  properties: Record<string, any> | undefined;
14
17
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,GAChC,WAAW,MAAM,EACjB,qBAAqB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,EAC9D,UAAU;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE;;CAiC5B,CAAC"}
1
+ {"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,GAChC,WAAW,MAAM,EACjB,UAAU;IACT,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;IAC/D,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;;CAkCD,CAAC"}
@@ -3,12 +3,15 @@
3
3
  * This hook listens for updates to a parameter value from the backend and
4
4
  * sends updates to the backend when the parameter value changes locally (e.g., through a UI slider).
5
5
  * @param channelId
6
- * @param onValueUpdate - Callback fires immediately when receiving a value update (synchronous - bypasses state batching)
7
6
  * @param options - Optional configuration
7
+ * @param options.onValueUpdate - Callback fires immediately when receiving a value update (synchronous - bypasses state batching)
8
8
  * @param options.skip - When true, the hook returns a NOP state and never registers listeners
9
+ * @param options.debug - When true, logs incoming value updates for this hook to the console for debugging
9
10
  */
10
- export declare const useCabbageState: <T>(channelId: string, onValueUpdate?: (value: T) => void, options?: {
11
+ export declare const useCabbageState: <T>(channelId: string, options?: {
12
+ onValueUpdate?: (value: T) => void;
11
13
  skip?: boolean;
14
+ debug?: boolean;
12
15
  }) => {
13
16
  value: T | undefined;
14
17
  setValue: (value: T, gesture?: "begin" | "value" | "end" | "complete") => void;
@@ -1 +1 @@
1
- {"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAChC,WAAW,MAAM,EACjB,gBAAgB,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAClC,UAAU;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE;;sBAYpB,CAAC,YACC,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU;CA8FhD,CAAC"}
1
+ {"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAChC,WAAW,MAAM,EACjB,UAAU;IACT,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACnC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;;sBAYO,CAAC,YACC,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU;CAqGhD,CAAC"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react");class M{static sendControlData({channel:e,value:a,gesture:n="complete"},o=null){const s={command:"controlData",channel:e,value:a,gesture:n};o!==null?o.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):window.parent!==window?window.parent.postMessage(s,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static isReadyToLoad(e=null,a={}){this.sendCustomCommand("isReadyToLoad",e)}static sendMidiMessageFromUI(e,a,n,o=null){var s={statusByte:e,dataByte1:a,dataByte2:n};const r={command:"midiMessage",obj:JSON.stringify(s)};o!==null?o.postMessage(r):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(r):window.parent!==window?window.parent.postMessage(r,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",r)}static MidiMessageFromHost(e,a,n){}static triggerFileOpenDialog(e,a,n={}){var o={channel:a,directory:n.directory||"",filters:n.filters||"*",openAtLastKnownLocation:n.openAtLastKnownLocation!==void 0?n.openAtLastKnownLocation:!0};const s={command:"fileOpen",obj:JSON.stringify(o)};e!==null?e.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):window.parent!==window?window.parent.postMessage(s,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static openUrl(e,a,n){var o={url:a,file:n};const s={command:"openUrl",obj:JSON.stringify(o)};e!==null?e.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):window.parent!==window?window.parent.postMessage(s,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static requestResize(e,a,n=null){const o={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(o):window.parent!==window?window.parent.postMessage(o,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",o)}static consumeKeypresses(e){typeof window.consumeKeypresses=="function"&&window.consumeKeypresses(e)}static sendChannelData(e,a,n=null){var o={channel:e};if(typeof a=="string")o.stringData=a;else if(typeof a=="number")o.floatData=a;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof a);return}const s={command:"channelData",obj:JSON.stringify(o)};n!==null?n.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):window.parent!==window?window.parent.postMessage(s,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}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):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static addMessageListener(e){const a=n=>{n.source!==window&&e(n.data)};return window.addEventListener("message",a),window.hostMessageCallback=e,()=>{window.removeEventListener("message",a),window.hostMessageCallback===e&&(window.hostMessageCallback=null)}}static sendCustomCommand(e,a=null,n={}){const o={command:e,text:JSON.stringify(n)};if(a!==null)a.postMessage(o);else if(typeof window.sendMessageFromUI=="function")try{const s=window.sendMessageFromUI(o)}catch(s){console.error("Cabbage: sendMessageFromUI threw error:",s),console.error("Cabbage: Error stack:",s.stack)}else window.parent!==window?window.parent.postMessage(o,"*"):(console.error("Cabbage: window.sendMessageFromUI is not available yet. Message:",o),console.error("Cabbage: typeof window.sendMessageFromUI:",typeof window.sendMessageFromUI),console.error("Cabbage: window.sendMessageFromUI value:",window.sendMessageFromUI))}}const C=(i,e,a)=>{if(!i||a?.skip)return{properties:void 0};const[n,o]=g.useState();return g.useEffect(()=>{const s=r=>{const{id:d,widgetJson:c,command:u}=r.data;if(d===i&&c&&u==="widgetUpdate"){const t=JSON.parse(c);console.log(`[Cabbage-React] Received properties for channelId: ${d}`,t),e&&e(t),o(t)}};return window.addEventListener("message",s),()=>window.removeEventListener("message",s)},[i,e]),{properties:n}},y=(i,e,a)=>{if(!i||a?.skip)return{value:void 0,setValue:()=>{}};const{properties:n}=C(i),[o,s]=g.useState(),[r,d]=g.useState(),c=(t,l="complete")=>{s(t),M.sendControlData({channel:i,value:t,gesture:l})},u=t=>{e&&e(t),s(t)};return g.useEffect(()=>{const t=n?.channels.find(m=>m.id===i);if(!t)return;const l=t.parameterIndex;if(r===void 0&&l!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId: ${t.id}`,l),d(l)),o!==void 0)return;const w=t.range?.value;w!=null&&(console.log(`[Cabbage-React] Received initial value for channelId: ${t.id}`,w),u(w))},[n]),g.useEffect(()=>{const t=l=>{const{command:w}=l.data;if(w==="parameterChange"){const{value:m,paramIdx:f}=l.data.data;if(f!==r||m===null)return;console.log(`[Cabbage-React] Received parameterChange for parameterIndex: ${f}`,m),u(m)}else if(w==="batchWidgetUpdate"){const f=l.data.widgets?.find(p=>p.id===i);if(!f)return;const b=JSON.parse(f.widgetJson).channels.find(p=>p.id===i)?.range?.value;console.log(`[Cabbage-React] Received batch widget update for channelId: ${f.id}`,b),u(b)}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[i,e,r]),{value:o,setValue:c}},v=(i,e,a)=>{if(!i||a?.skip)return{message:void 0};const[n,o]=g.useState();return g.useEffect(()=>{const s=r=>{const{data:d,type:c}=r;!d||c!=="message"||d.type===i&&(console.log(`[Cabbage-React] Received data for messageType: ${d.type}`,d),e&&e(d),o(d))};return window.addEventListener("message",s),()=>window.removeEventListener("message",s)},[i,e]),{message:n}};exports.Cabbage=M;exports.useCabbageMessage=v;exports.useCabbageProperties=C;exports.useCabbageState=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react");class b{static sendControlData({channel:e,value:s,gesture:a="complete"},t=null){const n={command:"controlData",channel:e,value:s,gesture:a};t!==null?t.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static isReadyToLoad(e=null,s={}){this.sendCustomCommand("isReadyToLoad",e)}static sendMidiMessageFromUI(e,s,a,t=null){var n={statusByte:e,dataByte1:s,dataByte2:a};const r={command:"midiMessage",obj:JSON.stringify(n)};t!==null?t.postMessage(r):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(r):window.parent!==window?window.parent.postMessage(r,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",r)}static MidiMessageFromHost(e,s,a){}static triggerFileOpenDialog(e,s,a={}){var t={channel:s,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.openAtLastKnownLocation:!0};const n={command:"fileOpen",obj:JSON.stringify(t)};e!==null?e.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static openUrl(e,s,a){var t={url:s,file:a};const n={command:"openUrl",obj:JSON.stringify(t)};e!==null?e.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static requestResize(e,s,a=null){const t={command:"requestResize",width:e,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(t):window.parent!==window?window.parent.postMessage(t,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",t)}static consumeKeypresses(e){typeof window.consumeKeypresses=="function"&&window.consumeKeypresses(e)}static sendChannelData(e,s,a=null){var t={channel:e};if(typeof s=="string")t.stringData=s;else if(typeof s=="number")t.floatData=s;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof s);return}const n={command:"channelData",obj:JSON.stringify(t)};a!==null?a.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static sendWidgetUpdate(e,s=null){const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};s!==null?s.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):window.parent!==window?window.parent.postMessage(a,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static addMessageListener(e){const s=a=>{a.source!==window&&e(a.data)};return window.addEventListener("message",s),window.hostMessageCallback=e,()=>{window.removeEventListener("message",s),window.hostMessageCallback===e&&(window.hostMessageCallback=null)}}static sendCustomCommand(e,s=null,a={}){const t={command:e,text:JSON.stringify(a)};if(s!==null)s.postMessage(t);else if(typeof window.sendMessageFromUI=="function")try{const n=window.sendMessageFromUI(t)}catch(n){console.error("Cabbage: sendMessageFromUI threw error:",n),console.error("Cabbage: Error stack:",n.stack)}else window.parent!==window?window.parent.postMessage(t,"*"):(console.error("Cabbage: window.sendMessageFromUI is not available yet. Message:",t),console.error("Cabbage: typeof window.sendMessageFromUI:",typeof window.sendMessageFromUI),console.error("Cabbage: window.sendMessageFromUI value:",window.sendMessageFromUI))}}const M=(i,e)=>{if(!i||e?.skip)return{properties:void 0};const[s,a]=g.useState();return g.useEffect(()=>{const t=n=>{const{id:r,widgetJson:w,command:f}=n.data;if(r===i&&w&&f==="widgetUpdate"){const o=JSON.parse(w);e?.debug&&console.log(`[Cabbage-React] Received properties for channelId: ${r}`,o),e?.onPropertiesUpdate&&e.onPropertiesUpdate(o),a(o)}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[i,e?.onPropertiesUpdate]),{properties:s}},C=(i,e)=>{if(!i||e?.skip)return{value:void 0,setValue:()=>{}};const{properties:s}=M(i),[a,t]=g.useState(),[n,r]=g.useState(),w=(o,d="complete")=>{t(o),b.sendControlData({channel:i,value:o,gesture:d})},f=o=>{e?.onValueUpdate&&e.onValueUpdate(o),t(o)};return g.useEffect(()=>{const o=s?.channels.find(c=>c.id===i);if(!o)return;const d=o.parameterIndex;if(n===void 0&&d!==void 0&&(e?.debug&&console.log(`[Cabbage-React] Received parameterIndex for channelId: ${o.id}`,d),r(d)),a!==void 0)return;const l=o.range?.value;l!=null&&(e?.debug&&console.log(`[Cabbage-React] Received initial value for channelId: ${o.id}`,l),f(l))},[s]),g.useEffect(()=>{const o=d=>{const{command:l}=d.data;if(l==="parameterChange"){const{value:c,paramIdx:u}=d.data.data;if(u!==n||c===null)return;e?.debug&&console.log(`[Cabbage-React] Received parameterChange for parameterIndex: ${u}`,c),f(c)}else if(l==="batchWidgetUpdate"){const u=d.data.widgets?.find(m=>m.id===i);if(!u)return;const p=JSON.parse(u.widgetJson).channels.find(m=>m.id===i)?.range?.value;e?.debug&&console.log(`[Cabbage-React] Received batch widget update for channelId: ${u.id}`,p),f(p)}};return window.addEventListener("message",o),()=>window.removeEventListener("message",o)},[i,e?.onValueUpdate,n]),{value:a,setValue:w}},U=(i,e)=>{if(!i||e?.skip)return{message:void 0};const[s,a]=g.useState();return g.useEffect(()=>{const t=n=>{const{data:r,type:w}=n;!r||w!=="message"||r.type===i&&(e?.debug&&console.log(`[Cabbage-React] Received data for messageType: ${r.type}`,r),e?.onMessage&&e.onMessage(r),a(r))};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[i,e?.onMessage]),{message:s}};exports.Cabbage=b;exports.useCabbageMessage=U;exports.useCabbageProperties=M;exports.useCabbageState=C;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { useState as p, useEffect as u } from "react";
2
- class C {
1
+ import { useState as f, useEffect as u } from "react";
2
+ class M {
3
3
  /**
4
4
  * Send a widget value change to the Cabbage backend.
5
5
  *
@@ -20,16 +20,16 @@ class C {
20
20
  * @param {string} [data.gesture="complete"] - The gesture type: "begin" (start of interaction), "value" (during interaction), "end" (end of continuous interaction), or "complete" (discrete action e.g. button click).
21
21
  * @param {Object|null} vscode - VS Code API object (null for plugin mode)
22
22
  */
23
- static sendControlData({ channel: e, value: a, gesture: n = "complete" }, o = null) {
24
- const s = {
23
+ static sendControlData({ channel: e, value: s, gesture: a = "complete" }, o = null) {
24
+ const n = {
25
25
  command: "controlData",
26
26
  channel: e,
27
- value: a,
28
- gesture: n
27
+ value: s,
28
+ gesture: a
29
29
  };
30
- o !== null ? o.postMessage(s) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(s) : window.parent !== window ? window.parent.postMessage(s, "*") : console.error(
30
+ o !== null ? o.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : window.parent !== window ? window.parent.postMessage(n, "*") : console.error(
31
31
  "Cabbage: window.sendMessageFromUI is not available. Message:",
32
- s
32
+ n
33
33
  );
34
34
  }
35
35
  /**
@@ -38,7 +38,7 @@ class C {
38
38
  * @param {Object|null} vscode - VS Code API object (null for plugin mode)
39
39
  * @param {Object} additionalData - Additional initialization data
40
40
  */
41
- static isReadyToLoad(e = null, a = {}) {
41
+ static isReadyToLoad(e = null, s = {}) {
42
42
  this.sendCustomCommand("isReadyToLoad", e);
43
43
  }
44
44
  /**
@@ -49,15 +49,15 @@ class C {
49
49
  * @param {number} dataByte2 - Second MIDI data byte
50
50
  * @param {Object|null} vscode - VS Code API object (null for plugin mode)
51
51
  */
52
- static sendMidiMessageFromUI(e, a, n, o = null) {
53
- var s = {
52
+ static sendMidiMessageFromUI(e, s, a, o = null) {
53
+ var n = {
54
54
  statusByte: e,
55
- dataByte1: a,
56
- dataByte2: n
55
+ dataByte1: s,
56
+ dataByte2: a
57
57
  };
58
58
  const r = {
59
59
  command: "midiMessage",
60
- obj: JSON.stringify(s)
60
+ obj: JSON.stringify(n)
61
61
  };
62
62
  o !== null ? o.postMessage(r) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(r) : window.parent !== window ? window.parent.postMessage(r, "*") : console.error(
63
63
  "Cabbage: window.sendMessageFromUI is not available. Message:",
@@ -71,7 +71,7 @@ class C {
71
71
  * @param {number} dataByte1 - First MIDI data byte
72
72
  * @param {number} dataByte2 - Second MIDI data byte
73
73
  */
74
- static MidiMessageFromHost(e, a, n) {
74
+ static MidiMessageFromHost(e, s, a) {
75
75
  }
76
76
  /**
77
77
  * Trigger a native file open dialog for file selection widgets.
@@ -83,20 +83,20 @@ class C {
83
83
  * @param {string} [options.filters="*"] - File filters (e.g., "*.wav;*.aiff")
84
84
  * @param {boolean} [options.openAtLastKnownLocation=true] - Whether to open at last known location
85
85
  */
86
- static triggerFileOpenDialog(e, a, n = {}) {
86
+ static triggerFileOpenDialog(e, s, a = {}) {
87
87
  var o = {
88
- channel: a,
89
- directory: n.directory || "",
90
- filters: n.filters || "*",
91
- openAtLastKnownLocation: n.openAtLastKnownLocation !== void 0 ? n.openAtLastKnownLocation : !0
88
+ channel: s,
89
+ directory: a.directory || "",
90
+ filters: a.filters || "*",
91
+ openAtLastKnownLocation: a.openAtLastKnownLocation !== void 0 ? a.openAtLastKnownLocation : !0
92
92
  };
93
- const s = {
93
+ const n = {
94
94
  command: "fileOpen",
95
95
  obj: JSON.stringify(o)
96
96
  };
97
- e !== null ? e.postMessage(s) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(s) : window.parent !== window ? window.parent.postMessage(s, "*") : console.error(
97
+ e !== null ? e.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : window.parent !== window ? window.parent.postMessage(n, "*") : console.error(
98
98
  "Cabbage: window.sendMessageFromUI is not available. Message:",
99
- s
99
+ n
100
100
  );
101
101
  }
102
102
  /**
@@ -106,18 +106,18 @@ class C {
106
106
  * @param {string} url - URL to open
107
107
  * @param {string} file - File path to open
108
108
  */
109
- static openUrl(e, a, n) {
109
+ static openUrl(e, s, a) {
110
110
  var o = {
111
- url: a,
112
- file: n
111
+ url: s,
112
+ file: a
113
113
  };
114
- const s = {
114
+ const n = {
115
115
  command: "openUrl",
116
116
  obj: JSON.stringify(o)
117
117
  };
118
- e !== null ? e.postMessage(s) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(s) : window.parent !== window ? window.parent.postMessage(s, "*") : console.error(
118
+ e !== null ? e.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : window.parent !== window ? window.parent.postMessage(n, "*") : console.error(
119
119
  "Cabbage: window.sendMessageFromUI is not available. Message:",
120
- s
120
+ n
121
121
  );
122
122
  }
123
123
  /**
@@ -132,13 +132,13 @@ class C {
132
132
  * The response will be sent via hostMessageCallback with:
133
133
  * {command: "resizeResponse", accepted: boolean, width: number, height: number}
134
134
  */
135
- static requestResize(e, a, n = null) {
135
+ static requestResize(e, s, a = null) {
136
136
  const o = {
137
137
  command: "requestResize",
138
138
  width: e,
139
- height: a
139
+ height: s
140
140
  };
141
- if (n !== null) {
141
+ if (a !== null) {
142
142
  console.warn(
143
143
  "Cabbage: requestResize is not supported in VS Code extension mode"
144
144
  );
@@ -178,28 +178,28 @@ class C {
178
178
  * @param {number|string} data - The data to send (number or string)
179
179
  * @param {Object|null} vscode - VS Code API object (null for plugin mode)
180
180
  */
181
- static sendChannelData(e, a, n = null) {
181
+ static sendChannelData(e, s, a = null) {
182
182
  var o = {
183
183
  channel: e
184
184
  };
185
- if (typeof a == "string")
186
- o.stringData = a;
187
- else if (typeof a == "number")
188
- o.floatData = a;
185
+ if (typeof s == "string")
186
+ o.stringData = s;
187
+ else if (typeof s == "number")
188
+ o.floatData = s;
189
189
  else {
190
190
  console.warn(
191
191
  "Cabbage: sendChannelData received unsupported data type:",
192
- typeof a
192
+ typeof s
193
193
  );
194
194
  return;
195
195
  }
196
- const s = {
196
+ const n = {
197
197
  command: "channelData",
198
198
  obj: JSON.stringify(o)
199
199
  };
200
- n !== null ? n.postMessage(s) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(s) : window.parent !== window ? window.parent.postMessage(s, "*") : console.error(
200
+ a !== null ? a.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : window.parent !== window ? window.parent.postMessage(n, "*") : console.error(
201
201
  "Cabbage: window.sendMessageFromUI is not available. Message:",
202
- s
202
+ n
203
203
  );
204
204
  }
205
205
  /**
@@ -209,14 +209,14 @@ class C {
209
209
  * @param {Object} widget - The widget configuration object to update
210
210
  * @param {Object|null} vscode - VS Code API object (null for plugin mode)
211
211
  */
212
- static sendWidgetUpdate(e, a = null) {
213
- const n = {
212
+ static sendWidgetUpdate(e, s = null) {
213
+ const a = {
214
214
  command: "widgetStateUpdate",
215
215
  obj: JSON.stringify(CabbageUtils.sanitizeForEditor(e))
216
216
  };
217
- a !== null ? a.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : window.parent !== window ? window.parent.postMessage(n, "*") : console.error(
217
+ s !== null ? s.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : console.error(
218
218
  "Cabbage: window.sendMessageFromUI is not available. Message:",
219
- n
219
+ a
220
220
  );
221
221
  }
222
222
  /**
@@ -255,25 +255,25 @@ class C {
255
255
  * onDestroy(() => remove?.());
256
256
  */
257
257
  static addMessageListener(e) {
258
- const a = (n) => {
259
- n.source !== window && e(n.data);
258
+ const s = (a) => {
259
+ a.source !== window && e(a.data);
260
260
  };
261
- return window.addEventListener("message", a), window.hostMessageCallback = e, () => {
262
- window.removeEventListener("message", a), window.hostMessageCallback === e && (window.hostMessageCallback = null);
261
+ return window.addEventListener("message", s), window.hostMessageCallback = e, () => {
262
+ window.removeEventListener("message", s), window.hostMessageCallback === e && (window.hostMessageCallback = null);
263
263
  };
264
264
  }
265
- static sendCustomCommand(e, a = null, n = {}) {
265
+ static sendCustomCommand(e, s = null, a = {}) {
266
266
  const o = {
267
267
  command: e,
268
- text: JSON.stringify(n)
268
+ text: JSON.stringify(a)
269
269
  };
270
- if (a !== null)
271
- a.postMessage(o);
270
+ if (s !== null)
271
+ s.postMessage(o);
272
272
  else if (typeof window.sendMessageFromUI == "function")
273
273
  try {
274
- const s = window.sendMessageFromUI(o);
275
- } catch (s) {
276
- console.error("Cabbage: sendMessageFromUI threw error:", s), console.error("Cabbage: Error stack:", s.stack);
274
+ const n = window.sendMessageFromUI(o);
275
+ } catch (n) {
276
+ console.error("Cabbage: sendMessageFromUI threw error:", n), console.error("Cabbage: Error stack:", n.stack);
277
277
  }
278
278
  else window.parent !== window ? window.parent.postMessage(o, "*") : (console.error(
279
279
  "Cabbage: window.sendMessageFromUI is not available yet. Message:",
@@ -287,91 +287,91 @@ class C {
287
287
  ));
288
288
  }
289
289
  }
290
- const y = (i, e, a) => {
291
- if (!i || a?.skip) return { properties: void 0 };
292
- const [n, o] = p();
290
+ const U = (i, e) => {
291
+ if (!i || e?.skip) return { properties: void 0 };
292
+ const [s, a] = f();
293
293
  return u(() => {
294
- const s = (r) => {
295
- const { id: d, widgetJson: g, command: f } = r.data;
296
- if (d === i && g && f === "widgetUpdate") {
294
+ const o = (n) => {
295
+ const { id: r, widgetJson: g, command: m } = n.data;
296
+ if (r === i && g && m === "widgetUpdate") {
297
297
  const t = JSON.parse(g);
298
- console.log(
299
- `[Cabbage-React] Received properties for channelId: ${d}`,
298
+ e?.debug && console.log(
299
+ `[Cabbage-React] Received properties for channelId: ${r}`,
300
300
  t
301
- ), e && e(t), o(t);
301
+ ), e?.onPropertiesUpdate && e.onPropertiesUpdate(t), a(t);
302
302
  }
303
303
  };
304
- return window.addEventListener("message", s), () => window.removeEventListener("message", s);
305
- }, [i, e]), { properties: n };
306
- }, F = (i, e, a) => {
307
- if (!i || a?.skip)
304
+ return window.addEventListener("message", o), () => window.removeEventListener("message", o);
305
+ }, [i, e?.onPropertiesUpdate]), { properties: s };
306
+ }, I = (i, e) => {
307
+ if (!i || e?.skip)
308
308
  return { value: void 0, setValue: () => {
309
309
  } };
310
- const { properties: n } = y(i), [o, s] = p(), [r, d] = p(), g = (t, l = "complete") => {
311
- s(t), C.sendControlData({
310
+ const { properties: s } = U(i), [a, o] = f(), [n, r] = f(), g = (t, d = "complete") => {
311
+ o(t), M.sendControlData({
312
312
  channel: i,
313
313
  value: t,
314
- gesture: l
314
+ gesture: d
315
315
  });
316
- }, f = (t) => {
317
- e && e(t), s(t);
316
+ }, m = (t) => {
317
+ e?.onValueUpdate && e.onValueUpdate(t), o(t);
318
318
  };
319
319
  return u(() => {
320
- const t = n?.channels.find(
321
- (c) => c.id === i
320
+ const t = s?.channels.find(
321
+ (w) => w.id === i
322
322
  );
323
323
  if (!t) return;
324
- const l = t.parameterIndex;
325
- if (r === void 0 && l !== void 0 && (console.log(
324
+ const d = t.parameterIndex;
325
+ if (n === void 0 && d !== void 0 && (e?.debug && console.log(
326
326
  `[Cabbage-React] Received parameterIndex for channelId: ${t.id}`,
327
- l
328
- ), d(l)), o !== void 0) return;
329
- const w = t.range?.value;
330
- w != null && (console.log(
327
+ d
328
+ ), r(d)), a !== void 0) return;
329
+ const l = t.range?.value;
330
+ l != null && (e?.debug && console.log(
331
331
  `[Cabbage-React] Received initial value for channelId: ${t.id}`,
332
- w
333
- ), f(w));
334
- }, [n]), u(() => {
335
- const t = (l) => {
336
- const { command: w } = l.data;
337
- if (w === "parameterChange") {
338
- const { value: c, paramIdx: m } = l.data.data;
339
- if (m !== r || c === null) return;
340
- console.log(
341
- `[Cabbage-React] Received parameterChange for parameterIndex: ${m}`,
342
- c
343
- ), f(c);
344
- } else if (w === "batchWidgetUpdate") {
345
- const m = l.data.widgets?.find((b) => b.id === i);
346
- if (!m) return;
347
- const M = JSON.parse(m.widgetJson).channels.find(
348
- (b) => b.id === i
332
+ l
333
+ ), m(l));
334
+ }, [s]), u(() => {
335
+ const t = (d) => {
336
+ const { command: l } = d.data;
337
+ if (l === "parameterChange") {
338
+ const { value: w, paramIdx: c } = d.data.data;
339
+ if (c !== n || w === null) return;
340
+ e?.debug && console.log(
341
+ `[Cabbage-React] Received parameterChange for parameterIndex: ${c}`,
342
+ w
343
+ ), m(w);
344
+ } else if (l === "batchWidgetUpdate") {
345
+ const c = d.data.widgets?.find((p) => p.id === i);
346
+ if (!c) return;
347
+ const b = JSON.parse(c.widgetJson).channels.find(
348
+ (p) => p.id === i
349
349
  )?.range?.value;
350
- console.log(
351
- `[Cabbage-React] Received batch widget update for channelId: ${m.id}`,
352
- M
353
- ), f(M);
350
+ e?.debug && console.log(
351
+ `[Cabbage-React] Received batch widget update for channelId: ${c.id}`,
352
+ b
353
+ ), m(b);
354
354
  }
355
355
  };
356
356
  return window.addEventListener("message", t), () => window.removeEventListener("message", t);
357
- }, [i, e, r]), { value: o, setValue: g };
358
- }, h = (i, e, a) => {
359
- if (!i || a?.skip) return { message: void 0 };
360
- const [n, o] = p();
357
+ }, [i, e?.onValueUpdate, n]), { value: a, setValue: g };
358
+ }, F = (i, e) => {
359
+ if (!i || e?.skip) return { message: void 0 };
360
+ const [s, a] = f();
361
361
  return u(() => {
362
- const s = (r) => {
363
- const { data: d, type: g } = r;
364
- !d || g !== "message" || d.type === i && (console.log(
365
- `[Cabbage-React] Received data for messageType: ${d.type}`,
366
- d
367
- ), e && e(d), o(d));
362
+ const o = (n) => {
363
+ const { data: r, type: g } = n;
364
+ !r || g !== "message" || r.type === i && (e?.debug && console.log(
365
+ `[Cabbage-React] Received data for messageType: ${r.type}`,
366
+ r
367
+ ), e?.onMessage && e.onMessage(r), a(r));
368
368
  };
369
- return window.addEventListener("message", s), () => window.removeEventListener("message", s);
370
- }, [i, e]), { message: n };
369
+ return window.addEventListener("message", o), () => window.removeEventListener("message", o);
370
+ }, [i, e?.onMessage]), { message: s };
371
371
  };
372
372
  export {
373
- C as Cabbage,
374
- h as useCabbageMessage,
375
- y as useCabbageProperties,
376
- F as useCabbageState
373
+ M as Cabbage,
374
+ F as useCabbageMessage,
375
+ U as useCabbageProperties,
376
+ I as useCabbageState
377
377
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.53",
3
+ "version": "1.0.54",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",