cabbage-react 1.0.49 → 1.0.51

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,7 +3,7 @@
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 (synchronous - bypasses state batching)
6
+ * @param onMessage - Callback fires immediately when receiving a new message (synchronous - bypasses state batching)
7
7
  */
8
8
  export declare const useCabbageMessage: <T>(messageType: string, onMessage?: (message: T) => void) => {
9
9
  message: T | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"useCabbageMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageMessage.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,eACrB,MAAM,cACP,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI;;CA0BhC,CAAC"}
1
+ {"version":3,"file":"useCabbageMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageMessage.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAClC,aAAa,MAAM,EACnB,YAAY,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI;;CAyBhC,CAAC"}
@@ -3,8 +3,10 @@
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)
6
7
  */
7
- export declare const useCabbageProperties: (channelId: string) => {
8
+ export declare const useCabbageProperties: (channelId: string, onPropertiesUpdate?: (properties: Record<string, any>) => void) => {
8
9
  properties: Record<string, any> | undefined;
10
+ onPropertiesUpdate: ((properties: Record<string, any>) => void) | undefined;
9
11
  };
10
12
  //# sourceMappingURL=useCabbageProperties.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,cAAe,MAAM;;CA8BrD,CAAC"}
1
+ {"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAChC,WAAW,MAAM,EACjB,qBAAqB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI;;sCAA5B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI;CAiC9D,CAAC"}
@@ -4,8 +4,9 @@
4
4
  * sends updates to the backend when the parameter value changes locally (e.g., through a UI slider).
5
5
  * @param channelId
6
6
  * @param gesture - The gesture type: "begin" (start of interaction), "value" (during interaction), "end" (end of continuous interaction), or "complete" (discrete action e.g. button click).
7
+ * @param onValueUpdate - Callback fires immediately when receiving a value update (synchronous - bypasses state batching)
7
8
  */
8
- export declare const useCabbageState: <T>(channelId: string, gesture?: "begin" | "value" | "end" | "complete") => {
9
+ export declare const useCabbageState: <T>(channelId: string, gesture?: "begin" | "value" | "end" | "complete", onValueUpdate?: (value: T) => void) => {
9
10
  value: T | undefined;
10
11
  setValue: (value: T) => void;
11
12
  };
@@ -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;CA2FnC,CAAC"}
1
+ {"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAChC,WAAW,MAAM,EACjB,UAAS,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,UAAuB,EAC5D,gBAAgB,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI;;sBAOA,CAAC;CAgGnC,CAAC"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react");class M{static sendControlData({channel:s,value:e,gesture:a="complete"},o=null){const n={command:"controlData",channel:s,value:e,gesture:a};o!==null?o.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(s=null,e={}){this.sendCustomCommand("isReadyToLoad",s)}static sendMidiMessageFromUI(s,e,a,o=null){var n={statusByte:s,dataByte1:e,dataByte2:a};const t={command:"midiMessage",obj:JSON.stringify(n)};o!==null?o.postMessage(t):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 MidiMessageFromHost(s,e,a){}static triggerFileOpenDialog(s,e,a={}){var o={channel:e,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.openAtLastKnownLocation:!0};const n={command:"fileOpen",obj:JSON.stringify(o)};s!==null?s.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(s,e,a){var o={url:e,file:a};const n={command:"openUrl",obj:JSON.stringify(o)};s!==null?s.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(s,e,a=null){const o={command:"requestResize",width:s,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(o):window.parent!==window?window.parent.postMessage(o,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",o)}static consumeKeypresses(s){typeof window.consumeKeypresses=="function"&&window.consumeKeypresses(s)}static sendChannelData(s,e,a=null){var o={channel:s};if(typeof e=="string")o.stringData=e;else if(typeof e=="number")o.floatData=e;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof e);return}const n={command:"channelData",obj:JSON.stringify(o)};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(s,e=null){const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(s))};e!==null?e.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(s){const e=a=>{a.source!==window&&s(a.data)};return window.addEventListener("message",e),window.hostMessageCallback=s,()=>{window.removeEventListener("message",e),window.hostMessageCallback===s&&(window.hostMessageCallback=null)}}static sendCustomCommand(s,e=null,a={}){const o={command:s,text:JSON.stringify(a)};if(e!==null)e.postMessage(o);else if(typeof window.sendMessageFromUI=="function")try{const n=window.sendMessageFromUI(o)}catch(n){console.error("Cabbage: sendMessageFromUI threw error:",n),console.error("Cabbage: Error stack:",n.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=r=>{const[s,e]=l.useState();return l.useEffect(()=>{const a=o=>{const{id:n,widgetJson:t,command:m}=o.data;if(n===r&&t&&m==="widgetUpdate"){const i=JSON.parse(t);console.log(`[Cabbage-React] Received properties for channelId: ${n}`,i),e(i)}};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[]),{properties:s}},y=(r,s="complete")=>{const{properties:e}=C(r),[a,o]=l.useState(),[n,t]=l.useState(),m=i=>{o(i),M.sendControlData({channel:r,value:i,gesture:s})};return l.useEffect(()=>{var f;const i=e==null?void 0:e.channels.find(d=>d.id===r);if(!i)return;const g=i.parameterIndex;if(n===void 0&&g!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId: ${i.id}`,g),t(g)),a!==void 0)return;const w=(f=i.range)==null?void 0:f.value;w!=null&&(console.log(`[Cabbage-React] Received initial value for channelId: ${i.id}`,w),o(w))},[e]),l.useEffect(()=>{const i=g=>{var f;const{command:w}=g.data;if(w==="parameterChange"){const{value:d,paramIdx:c}=g.data.data;if(c!==n||d===null)return;console.log(`[Cabbage-React] Received parameterChange for parameterIndex: ${c}`,d),o(d)}else if(w==="batchWidgetUpdate"){const d=g.data.widgets,c=d==null?void 0:d.find(p=>p.id===r);if(!c)return;const u=JSON.parse(c.widgetJson).channels.find(p=>p.id===r),b=(f=u==null?void 0:u.range)==null?void 0:f.value;console.log(`[Cabbage-React] Received batch widget update for channelId: ${c.id}`,b),o(b)}};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[n]),{value:a,setValue:m}},I=(r,s)=>{const[e,a]=l.useState();return l.useEffect(()=>{const o=n=>{const{data:t,type:m}=n;!t||m!=="message"||t.type===r&&(console.log(`[Cabbage-React] Received data for messageType: ${t.type}`,t),s&&s(t),a(t))};return window.addEventListener("message",o),()=>window.removeEventListener("message",o)},[r,s]),{message:e}};exports.Cabbage=M;exports.useCabbageMessage=I;exports.useCabbageProperties=C;exports.useCabbageState=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react");class M{static sendControlData({channel:e,value:s,gesture:n="complete"},o=null){const a={command:"controlData",channel:e,value:s,gesture:n};o!==null?o.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 isReadyToLoad(e=null,s={}){this.sendCustomCommand("isReadyToLoad",e)}static sendMidiMessageFromUI(e,s,n,o=null){var a={statusByte:e,dataByte1:s,dataByte2:n};const t={command:"midiMessage",obj:JSON.stringify(a)};o!==null?o.postMessage(t):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 MidiMessageFromHost(e,s,n){}static triggerFileOpenDialog(e,s,n={}){var o={channel:s,directory:n.directory||"",filters:n.filters||"*",openAtLastKnownLocation:n.openAtLastKnownLocation!==void 0?n.openAtLastKnownLocation:!0};const a={command:"fileOpen",obj:JSON.stringify(o)};e!==null?e.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 openUrl(e,s,n){var o={url:s,file:n};const a={command:"openUrl",obj:JSON.stringify(o)};e!==null?e.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 requestResize(e,s,n=null){const o={command:"requestResize",width:e,height:s};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,s,n=null){var o={channel:e};if(typeof s=="string")o.stringData=s;else if(typeof s=="number")o.floatData=s;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof s);return}const a={command:"channelData",obj:JSON.stringify(o)};n!==null?n.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 sendWidgetUpdate(e,s=null){const n={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};s!==null?s.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 s=n=>{n.source!==window&&e(n.data)};return window.addEventListener("message",s),window.hostMessageCallback=e,()=>{window.removeEventListener("message",s),window.hostMessageCallback===e&&(window.hostMessageCallback=null)}}static sendCustomCommand(e,s=null,n={}){const o={command:e,text:JSON.stringify(n)};if(s!==null)s.postMessage(o);else if(typeof window.sendMessageFromUI=="function")try{const a=window.sendMessageFromUI(o)}catch(a){console.error("Cabbage: sendMessageFromUI threw error:",a),console.error("Cabbage: Error stack:",a.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=(r,e)=>{const[s,n]=d.useState();return d.useEffect(()=>{const o=a=>{const{id:t,widgetJson:c,command:u}=a.data;if(t===r&&c&&u==="widgetUpdate"){const l=JSON.parse(c);console.log(`[Cabbage-React] Received properties for channelId: ${t}`,l),e&&e(l),n(l)}};return window.addEventListener("message",o),()=>window.removeEventListener("message",o)},[r,e]),{properties:s,onPropertiesUpdate:e}},y=(r,e="complete",s)=>{const{properties:n}=C(r),[o,a]=d.useState(),[t,c]=d.useState(),u=i=>{a(i),M.sendControlData({channel:r,value:i,gesture:e})},l=i=>{s&&s(i),a(i)};return d.useEffect(()=>{const i=n?.channels.find(m=>m.id===r);if(!i)return;const g=i.parameterIndex;if(t===void 0&&g!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId: ${i.id}`,g),c(g)),o!==void 0)return;const w=i.range?.value;w!=null&&(console.log(`[Cabbage-React] Received initial value for channelId: ${i.id}`,w),l(w))},[n]),d.useEffect(()=>{const i=g=>{const{command:w}=g.data;if(w==="parameterChange"){const{value:m,paramIdx:f}=g.data.data;if(f!==t||m===null)return;console.log(`[Cabbage-React] Received parameterChange for parameterIndex: ${f}`,m),l(m)}else if(w==="batchWidgetUpdate"){const f=g.data.widgets?.find(p=>p.id===r);if(!f)return;const b=JSON.parse(f.widgetJson).channels.find(p=>p.id===r)?.range?.value;console.log(`[Cabbage-React] Received batch widget update for channelId: ${f.id}`,b),l(b)}};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[r,s,t]),{value:o,setValue:u}},I=(r,e)=>{const[s,n]=d.useState();return d.useEffect(()=>{const o=a=>{const{data:t,type:c}=a;!t||c!=="message"||t.type===r&&(console.log(`[Cabbage-React] Received data for messageType: ${t.type}`,t),e&&e(t),n(t))};return window.addEventListener("message",o),()=>window.removeEventListener("message",o)},[r,e]),{message:s}};exports.Cabbage=M;exports.useCabbageMessage=I;exports.useCabbageProperties=C;exports.useCabbageState=y;
package/dist/index.mjs CHANGED
@@ -20,11 +20,11 @@ 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: s, value: e, gesture: n = "complete" }, o = null) {
23
+ static sendControlData({ channel: e, value: s, gesture: n = "complete" }, o = null) {
24
24
  const a = {
25
25
  command: "controlData",
26
- channel: s,
27
- value: e,
26
+ channel: e,
27
+ value: s,
28
28
  gesture: n
29
29
  };
30
30
  o !== null ? o.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : console.error(
@@ -38,8 +38,8 @@ 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(s = null, e = {}) {
42
- this.sendCustomCommand("isReadyToLoad", s);
41
+ static isReadyToLoad(e = null, s = {}) {
42
+ this.sendCustomCommand("isReadyToLoad", e);
43
43
  }
44
44
  /**
45
45
  * Send a MIDI message from the UI to the Cabbage backend.
@@ -49,10 +49,10 @@ 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(s, e, n, o = null) {
52
+ static sendMidiMessageFromUI(e, s, n, o = null) {
53
53
  var a = {
54
- statusByte: s,
55
- dataByte1: e,
54
+ statusByte: e,
55
+ dataByte1: s,
56
56
  dataByte2: n
57
57
  };
58
58
  const t = {
@@ -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(s, e, n) {
74
+ static MidiMessageFromHost(e, s, n) {
75
75
  }
76
76
  /**
77
77
  * Trigger a native file open dialog for file selection widgets.
@@ -83,9 +83,9 @@ 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(s, e, n = {}) {
86
+ static triggerFileOpenDialog(e, s, n = {}) {
87
87
  var o = {
88
- channel: e,
88
+ channel: s,
89
89
  directory: n.directory || "",
90
90
  filters: n.filters || "*",
91
91
  openAtLastKnownLocation: n.openAtLastKnownLocation !== void 0 ? n.openAtLastKnownLocation : !0
@@ -94,7 +94,7 @@ class C {
94
94
  command: "fileOpen",
95
95
  obj: JSON.stringify(o)
96
96
  };
97
- s !== null ? s.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : console.error(
97
+ e !== null ? e.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : console.error(
98
98
  "Cabbage: window.sendMessageFromUI is not available. Message:",
99
99
  a
100
100
  );
@@ -106,16 +106,16 @@ class C {
106
106
  * @param {string} url - URL to open
107
107
  * @param {string} file - File path to open
108
108
  */
109
- static openUrl(s, e, n) {
109
+ static openUrl(e, s, n) {
110
110
  var o = {
111
- url: e,
111
+ url: s,
112
112
  file: n
113
113
  };
114
114
  const a = {
115
115
  command: "openUrl",
116
116
  obj: JSON.stringify(o)
117
117
  };
118
- s !== null ? s.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : console.error(
118
+ e !== null ? e.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : console.error(
119
119
  "Cabbage: window.sendMessageFromUI is not available. Message:",
120
120
  a
121
121
  );
@@ -132,11 +132,11 @@ 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(s, e, n = null) {
135
+ static requestResize(e, s, n = null) {
136
136
  const o = {
137
137
  command: "requestResize",
138
- width: s,
139
- height: e
138
+ width: e,
139
+ height: s
140
140
  };
141
141
  if (n !== null) {
142
142
  console.warn(
@@ -168,8 +168,8 @@ class C {
168
168
  * myCustomEditor.addEventListener('focus', () => Cabbage.consumeKeypresses(true));
169
169
  * myCustomEditor.addEventListener('blur', () => Cabbage.consumeKeypresses(false));
170
170
  */
171
- static consumeKeypresses(s) {
172
- typeof window.consumeKeypresses == "function" && window.consumeKeypresses(s);
171
+ static consumeKeypresses(e) {
172
+ typeof window.consumeKeypresses == "function" && window.consumeKeypresses(e);
173
173
  }
174
174
  /**
175
175
  * Send channel data directly to Csound without DAW automation involvement.
@@ -178,18 +178,18 @@ 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(s, e, n = null) {
181
+ static sendChannelData(e, s, n = null) {
182
182
  var o = {
183
- channel: s
183
+ channel: e
184
184
  };
185
- if (typeof e == "string")
186
- o.stringData = e;
187
- else if (typeof e == "number")
188
- o.floatData = e;
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 e
192
+ typeof s
193
193
  );
194
194
  return;
195
195
  }
@@ -209,12 +209,12 @@ 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(s, e = null) {
212
+ static sendWidgetUpdate(e, s = null) {
213
213
  const n = {
214
214
  command: "widgetStateUpdate",
215
- obj: JSON.stringify(CabbageUtils.sanitizeForEditor(s))
215
+ obj: JSON.stringify(CabbageUtils.sanitizeForEditor(e))
216
216
  };
217
- e !== null ? e.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : window.parent !== window ? window.parent.postMessage(n, "*") : console.error(
217
+ s !== null ? s.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : window.parent !== window ? window.parent.postMessage(n, "*") : console.error(
218
218
  "Cabbage: window.sendMessageFromUI is not available. Message:",
219
219
  n
220
220
  );
@@ -254,21 +254,21 @@ class C {
254
254
  * onMount(() => { remove = Cabbage.addMessageListener((msg) => { ... }); });
255
255
  * onDestroy(() => remove?.());
256
256
  */
257
- static addMessageListener(s) {
258
- const e = (n) => {
259
- n.source !== window && s(n.data);
257
+ static addMessageListener(e) {
258
+ const s = (n) => {
259
+ n.source !== window && e(n.data);
260
260
  };
261
- return window.addEventListener("message", e), window.hostMessageCallback = s, () => {
262
- window.removeEventListener("message", e), window.hostMessageCallback === s && (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(s, e = null, n = {}) {
265
+ static sendCustomCommand(e, s = null, n = {}) {
266
266
  const o = {
267
- command: s,
267
+ command: e,
268
268
  text: JSON.stringify(n)
269
269
  };
270
- if (e !== null)
271
- e.postMessage(o);
270
+ if (s !== null)
271
+ s.postMessage(o);
272
272
  else if (typeof window.sendMessageFromUI == "function")
273
273
  try {
274
274
  const a = window.sendMessageFromUI(o);
@@ -287,91 +287,92 @@ class C {
287
287
  ));
288
288
  }
289
289
  }
290
- const y = (r) => {
291
- const [s, e] = f();
290
+ const y = (r, e) => {
291
+ const [s, n] = f();
292
292
  return p(() => {
293
- const n = (o) => {
294
- const { id: a, widgetJson: t, command: c } = o.data;
295
- if (a === r && t && c === "widgetUpdate") {
296
- const i = JSON.parse(t);
293
+ const o = (a) => {
294
+ const { id: t, widgetJson: g, command: u } = a.data;
295
+ if (t === r && g && u === "widgetUpdate") {
296
+ const d = JSON.parse(g);
297
297
  console.log(
298
- `[Cabbage-React] Received properties for channelId: ${a}`,
299
- i
300
- ), e(i);
298
+ `[Cabbage-React] Received properties for channelId: ${t}`,
299
+ d
300
+ ), e && e(d), n(d);
301
301
  }
302
302
  };
303
- return window.addEventListener("message", n), () => window.removeEventListener("message", n);
304
- }, []), {
305
- properties: s
303
+ return window.addEventListener("message", o), () => window.removeEventListener("message", o);
304
+ }, [r, e]), {
305
+ properties: s,
306
+ onPropertiesUpdate: e
306
307
  };
307
- }, F = (r, s = "complete") => {
308
- const { properties: e } = y(r), [n, o] = f(), [a, t] = f(), c = (i) => {
309
- o(i), C.sendControlData({
308
+ }, h = (r, e = "complete", s) => {
309
+ const { properties: n } = y(r), [o, a] = f(), [t, g] = f(), u = (i) => {
310
+ a(i), C.sendControlData({
310
311
  channel: r,
311
312
  value: i,
312
- gesture: s
313
+ gesture: e
313
314
  });
315
+ }, d = (i) => {
316
+ s && s(i), a(i);
314
317
  };
315
318
  return p(() => {
316
- var m;
317
- const i = e == null ? void 0 : e.channels.find(
318
- (d) => d.id === r
319
+ const i = n?.channels.find(
320
+ (c) => c.id === r
319
321
  );
320
322
  if (!i) return;
321
323
  const l = i.parameterIndex;
322
- if (a === void 0 && l !== void 0 && (console.log(
324
+ if (t === void 0 && l !== void 0 && (console.log(
323
325
  `[Cabbage-React] Received parameterIndex for channelId: ${i.id}`,
324
326
  l
325
- ), t(l)), n !== void 0) return;
326
- const w = (m = i.range) == null ? void 0 : m.value;
327
+ ), g(l)), o !== void 0) return;
328
+ const w = i.range?.value;
327
329
  w != null && (console.log(
328
330
  `[Cabbage-React] Received initial value for channelId: ${i.id}`,
329
331
  w
330
- ), o(w));
331
- }, [e]), p(() => {
332
+ ), d(w));
333
+ }, [n]), p(() => {
332
334
  const i = (l) => {
333
- var m;
334
335
  const { command: w } = l.data;
335
336
  if (w === "parameterChange") {
336
- const { value: d, paramIdx: g } = l.data.data;
337
- if (g !== a || d === null) return;
337
+ const { value: c, paramIdx: m } = l.data.data;
338
+ if (m !== t || c === null) return;
338
339
  console.log(
339
- `[Cabbage-React] Received parameterChange for parameterIndex: ${g}`,
340
- d
341
- ), o(d);
340
+ `[Cabbage-React] Received parameterChange for parameterIndex: ${m}`,
341
+ c
342
+ ), d(c);
342
343
  } else if (w === "batchWidgetUpdate") {
343
- const d = l.data.widgets, g = d == null ? void 0 : d.find((b) => b.id === r);
344
- if (!g) return;
345
- const u = JSON.parse(g.widgetJson).channels.find(
344
+ const m = l.data.widgets?.find((b) => b.id === r);
345
+ if (!m) return;
346
+ const M = JSON.parse(m.widgetJson).channels.find(
346
347
  (b) => b.id === r
347
- ), M = (m = u == null ? void 0 : u.range) == null ? void 0 : m.value;
348
+ )?.range?.value;
348
349
  console.log(
349
- `[Cabbage-React] Received batch widget update for channelId: ${g.id}`,
350
+ `[Cabbage-React] Received batch widget update for channelId: ${m.id}`,
350
351
  M
351
- ), o(M);
352
+ ), d(M);
352
353
  }
353
354
  };
354
355
  return window.addEventListener("message", i), () => window.removeEventListener("message", i);
355
- }, [a]), {
356
- value: n,
357
- setValue: c
356
+ }, [r, s, t]), {
357
+ value: o,
358
+ setValue: u
358
359
  };
359
- }, v = (r, s) => {
360
- const [e, n] = f();
360
+ }, v = (r, e) => {
361
+ const [s, n] = f();
361
362
  return p(() => {
362
363
  const o = (a) => {
363
- const { data: t, type: c } = a;
364
- !t || c !== "message" || t.type === r && (console.log(
364
+ const { data: t, type: g } = a;
365
+ !t || g !== "message" || t.type === r && (console.log(
365
366
  `[Cabbage-React] Received data for messageType: ${t.type}`,
366
367
  t
367
- ), s && s(t), n(t));
368
+ ), e && e(t), n(t));
368
369
  };
369
370
  return window.addEventListener("message", o), () => window.removeEventListener("message", o);
370
- }, [r, s]), { message: e };
371
+ }, [r, e]), { message: s };
371
372
  };
372
373
  export {
373
374
  C as Cabbage,
374
375
  v as useCabbageMessage,
375
376
  y as useCabbageProperties,
376
- F as useCabbageState
377
+ h as useCabbageState
377
378
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.49",
3
+ "version": "1.0.51",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",
@@ -26,21 +26,21 @@
26
26
  "build": "vite build"
27
27
  },
28
28
  "dependencies": {
29
- "react": "^19.1.0",
30
- "vite-plugin-dts": "^4.5.3"
29
+ "react": "^19.2.4",
30
+ "vite-plugin-dts": "^4.5.4"
31
31
  },
32
32
  "devDependencies": {
33
- "@eslint/js": "^9.21.0",
34
- "@types/node": "^22.15.17",
35
- "@types/react": "^19.1.3",
36
- "@vitejs/plugin-react": "^4.3.4",
37
- "eslint": "^9.21.0",
38
- "eslint-plugin-react-hooks": "^5.1.0",
39
- "eslint-plugin-react-refresh": "^0.4.19",
40
- "globals": "^15.15.0",
41
- "typescript": "~5.7.2",
42
- "typescript-eslint": "^8.24.1",
43
- "vite": "^6.2.0"
33
+ "@eslint/js": "^10.0.1",
34
+ "@types/node": "^25.3.3",
35
+ "@types/react": "^19.2.14",
36
+ "@vitejs/plugin-react": "^5.1.4",
37
+ "eslint": "^10.0.2",
38
+ "eslint-plugin-react-hooks": "^7.0.1",
39
+ "eslint-plugin-react-refresh": "^0.5.2",
40
+ "globals": "^17.4.0",
41
+ "typescript": "~5.9.3",
42
+ "typescript-eslint": "^8.56.1",
43
+ "vite": "^7.3.1"
44
44
  },
45
45
  "files": [
46
46
  "dist",