cabbage-react 1.0.57 → 1.0.58

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":"useCabbageMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageMessage.ts"],"names":[],"mappings":"AAGA;;;;;;;;;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;;CAmCD,CAAC"}
1
+ {"version":3,"file":"useCabbageMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageMessage.ts"],"names":[],"mappings":"AAGA;;;;;;;;;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;;CAkCD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAGA;;;;;;;;;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;;CAwCD,CAAC"}
1
+ {"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAGA;;;;;;;;;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;;CAuCD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAKA;;;;;;;;;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;;sBAyBO,CAAC,YACC,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU;CAiFhD,CAAC"}
1
+ {"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAKA;;;;;;;;;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;;sBAwBO,CAAC,YACC,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU;CAiFhD,CAAC"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react");class U{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 i={command:"midiMessage",obj:JSON.stringify(n)};t!==null?t.postMessage(i):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(i):window.parent!==window?window.parent.postMessage(i,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",i)}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=(o,e)=>(...s)=>{e&&console.log(`[Cabbage-React][${o}]`,...s)},v=(o,e)=>{if(!o||e?.skip)return{properties:void 0};const s=d.useRef(void 0);s.current=M(`useCabbageProperties:${o}`,e?.debug);const a=s.current,[t,n]=d.useState();return d.useEffect(()=>{const i=w=>{const{id:g,widgetJson:c,command:m}=w.data;if(g===o&&c&&m==="widgetUpdate"){const r=JSON.parse(c);a("Received properties",r),e?.onPropertiesUpdate&&e.onPropertiesUpdate(r),n(r)}};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[o,e?.onPropertiesUpdate]),{properties:t}},y=(o,e)=>{if(!o||e?.skip)return{value:void 0,setValue:()=>{}};const s=d.useRef(void 0);s.current=M(`useCabbageState:${o}`,e?.debug);const a=s.current,{properties:t}=v(o,{debug:e?.debug}),[n,i]=d.useState(),[w,g]=d.useState(),c=(r,l="complete")=>{i(r),U.sendControlData({channel:o,value:r,gesture:l})},m=r=>{e?.onValueUpdate&&e.onValueUpdate(r),i(r)};return d.useEffect(()=>{const r=t?.channels.find(f=>f.id===o);if(!r)return;const l=r.parameterIndex;if(w===void 0&&l!==void 0&&(a("Received parameterIndex",l),g(l)),n!==void 0)return;const u=r.range?.value;u!=null&&(a("Received initial value",u),m(u))},[t]),d.useEffect(()=>{const r=l=>{const{command:u}=l.data;if(u==="parameterChange"){const{value:f,paramIdx:p}=l.data.data;if(p!==w||f===null)return;a("Received parameterChange",f),m(f)}else if(u==="batchWidgetUpdate"){const p=l.data.widgets?.find(b=>b.id===o);if(!p)return;const C=JSON.parse(p.widgetJson).channels.find(b=>b.id===o)?.range?.value;a("Received batchWidgetUpdate",C),m(C)}};return window.addEventListener("message",r),()=>window.removeEventListener("message",r)},[o,e?.onValueUpdate,w]),{value:n,setValue:c}},F=(o,e)=>{if(!o||e?.skip)return{message:void 0};const s=d.useRef(void 0);s.current=M(`useCabbageMessage:${o}`,e?.debug);const a=s.current,[t,n]=d.useState();return d.useEffect(()=>{const i=w=>{const{data:g,type:c}=w;!g||c!=="message"||g.type===o&&(a("Received data",g),e?.onMessage&&e.onMessage(g),n(g))};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[o,e?.onMessage]),{message:t}};exports.Cabbage=U;exports.useCabbageMessage=F;exports.useCabbageProperties=v;exports.useCabbageState=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react");class C{static sendControlData({channel:e,value:s,gesture:n="complete"},t=null){const a={command:"controlData",channel:e,value:s,gesture:n};t!==null?t.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,t=null){var a={statusByte:e,dataByte1:s,dataByte2:n};const i={command:"midiMessage",obj:JSON.stringify(a)};t!==null?t.postMessage(i):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(i):window.parent!==window?window.parent.postMessage(i,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",i)}static MidiMessageFromHost(e,s,n){}static triggerFileOpenDialog(e,s,n={}){var t={channel:s,directory:n.directory||"",filters:n.filters||"*",openAtLastKnownLocation:n.openAtLastKnownLocation!==void 0?n.openAtLastKnownLocation:!0};const a={command:"fileOpen",obj:JSON.stringify(t)};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 t={url:s,file:n};const a={command:"openUrl",obj:JSON.stringify(t)};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 t={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(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,n=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 a={command:"channelData",obj:JSON.stringify(t)};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 t={command:e,text:JSON.stringify(n)};if(s!==null)s.postMessage(t);else if(typeof window.sendMessageFromUI=="function")try{const a=window.sendMessageFromUI(t)}catch(a){console.error("Cabbage: sendMessageFromUI threw error:",a),console.error("Cabbage: Error stack:",a.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 b=(o,e)=>(...s)=>{e&&console.log(`[Cabbage-React][${o}]`,...s)},U=(o,e)=>{if(!o||e?.skip)return{properties:void 0};const s=d.useRef(void 0);s.current=b(`useCabbageProperties:${o}`,e?.debug);const[n,t]=d.useState();return d.useEffect(()=>{const a=i=>{const{id:g,widgetJson:u,command:f}=i.data;if(g===o&&u&&f==="widgetUpdate"){const r=JSON.parse(u);s.current?.("Received properties",r),e?.onPropertiesUpdate&&e.onPropertiesUpdate(r),t(r)}};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[o,e?.onPropertiesUpdate]),{properties:n}},v=(o,e)=>{if(!o||e?.skip)return{value:void 0,setValue:()=>{}};const s=d.useRef(void 0);s.current=b(`useCabbageState:${o}`,e?.debug);const{properties:n}=U(o,{debug:e?.debug}),[t,a]=d.useState(),[i,g]=d.useState(),u=(r,l="complete")=>{a(r),C.sendControlData({channel:o,value:r,gesture:l})},f=r=>{e?.onValueUpdate&&e.onValueUpdate(r),a(r)};return d.useEffect(()=>{const r=n?.channels.find(c=>c.id===o);if(!r)return;const l=r.parameterIndex;if(i===void 0&&l!==void 0&&(s.current?.("Received parameterIndex",l),g(l)),t!==void 0)return;const w=r.range?.value;w!=null&&(s.current?.("Received initial value",w),f(w))},[n]),d.useEffect(()=>{const r=l=>{const{command:w}=l.data;if(w==="parameterChange"){const{value:c,paramIdx:m}=l.data.data;if(m!==i||c===null)return;s.current?.("Received parameterChange",c),f(c)}else if(w==="batchWidgetUpdate"){const m=l.data.widgets?.find(p=>p.id===o);if(!m)return;const M=JSON.parse(m.widgetJson).channels.find(p=>p.id===o)?.range?.value;s.current?.("Received batchWidgetUpdate",M),f(M)}};return window.addEventListener("message",r),()=>window.removeEventListener("message",r)},[o,e?.onValueUpdate,i]),{value:t,setValue:u}},y=(o,e)=>{if(!o||e?.skip)return{message:void 0};const s=d.useRef(void 0);s.current=b(`useCabbageMessage:${o}`,e?.debug);const[n,t]=d.useState();return d.useEffect(()=>{const a=i=>{const{data:g,type:u}=i;!g||u!=="message"||g.type===o&&(s.current?.("Received data",g),e?.onMessage&&e.onMessage(g),t(g))};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[o,e?.onMessage]),{message:n}};exports.Cabbage=C;exports.useCabbageMessage=y;exports.useCabbageProperties=U;exports.useCabbageState=v;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { useRef as U, useState as p, useEffect as b } from "react";
2
- class y {
1
+ import { useRef as M, useState as f, useEffect as p } from "react";
2
+ class v {
3
3
  /**
4
4
  * Send a widget value change to the Cabbage backend.
5
5
  *
@@ -20,16 +20,16 @@ class y {
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: s, gesture: n = "complete" }, t = null) {
24
- const a = {
23
+ static sendControlData({ channel: e, value: s, gesture: a = "complete" }, t = null) {
24
+ const n = {
25
25
  command: "controlData",
26
26
  channel: e,
27
27
  value: s,
28
- gesture: n
28
+ gesture: a
29
29
  };
30
- t !== null ? t.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : console.error(
30
+ t !== null ? t.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
- a
32
+ n
33
33
  );
34
34
  }
35
35
  /**
@@ -49,19 +49,19 @@ class y {
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, s, n, t = null) {
53
- var a = {
52
+ static sendMidiMessageFromUI(e, s, a, t = null) {
53
+ var n = {
54
54
  statusByte: e,
55
55
  dataByte1: s,
56
- dataByte2: n
56
+ dataByte2: a
57
57
  };
58
- const r = {
58
+ const i = {
59
59
  command: "midiMessage",
60
- obj: JSON.stringify(a)
60
+ obj: JSON.stringify(n)
61
61
  };
62
- t !== null ? t.postMessage(r) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(r) : window.parent !== window ? window.parent.postMessage(r, "*") : console.error(
62
+ t !== null ? t.postMessage(i) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(i) : window.parent !== window ? window.parent.postMessage(i, "*") : console.error(
63
63
  "Cabbage: window.sendMessageFromUI is not available. Message:",
64
- r
64
+ i
65
65
  );
66
66
  }
67
67
  /**
@@ -71,7 +71,7 @@ class y {
71
71
  * @param {number} dataByte1 - First MIDI data byte
72
72
  * @param {number} dataByte2 - Second MIDI data byte
73
73
  */
74
- static MidiMessageFromHost(e, s, 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 y {
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, s, n = {}) {
86
+ static triggerFileOpenDialog(e, s, a = {}) {
87
87
  var t = {
88
88
  channel: s,
89
- directory: n.directory || "",
90
- filters: n.filters || "*",
91
- openAtLastKnownLocation: n.openAtLastKnownLocation !== void 0 ? n.openAtLastKnownLocation : !0
89
+ directory: a.directory || "",
90
+ filters: a.filters || "*",
91
+ openAtLastKnownLocation: a.openAtLastKnownLocation !== void 0 ? a.openAtLastKnownLocation : !0
92
92
  };
93
- const a = {
93
+ const n = {
94
94
  command: "fileOpen",
95
95
  obj: JSON.stringify(t)
96
96
  };
97
- e !== null ? e.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : 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
- a
99
+ n
100
100
  );
101
101
  }
102
102
  /**
@@ -106,18 +106,18 @@ class y {
106
106
  * @param {string} url - URL to open
107
107
  * @param {string} file - File path to open
108
108
  */
109
- static openUrl(e, s, n) {
109
+ static openUrl(e, s, a) {
110
110
  var t = {
111
111
  url: s,
112
- file: n
112
+ file: a
113
113
  };
114
- const a = {
114
+ const n = {
115
115
  command: "openUrl",
116
116
  obj: JSON.stringify(t)
117
117
  };
118
- e !== null ? e.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : 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
- a
120
+ n
121
121
  );
122
122
  }
123
123
  /**
@@ -132,13 +132,13 @@ class y {
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, s, n = null) {
135
+ static requestResize(e, s, a = null) {
136
136
  const t = {
137
137
  command: "requestResize",
138
138
  width: e,
139
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,7 +178,7 @@ class y {
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, s, n = null) {
181
+ static sendChannelData(e, s, a = null) {
182
182
  var t = {
183
183
  channel: e
184
184
  };
@@ -193,13 +193,13 @@ class y {
193
193
  );
194
194
  return;
195
195
  }
196
- const a = {
196
+ const n = {
197
197
  command: "channelData",
198
198
  obj: JSON.stringify(t)
199
199
  };
200
- n !== null ? n.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : 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
- a
202
+ n
203
203
  );
204
204
  }
205
205
  /**
@@ -210,13 +210,13 @@ class y {
210
210
  * @param {Object|null} vscode - VS Code API object (null for plugin mode)
211
211
  */
212
212
  static sendWidgetUpdate(e, s = null) {
213
- const n = {
213
+ const a = {
214
214
  command: "widgetStateUpdate",
215
215
  obj: JSON.stringify(CabbageUtils.sanitizeForEditor(e))
216
216
  };
217
- s !== null ? s.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 y {
255
255
  * onDestroy(() => remove?.());
256
256
  */
257
257
  static addMessageListener(e) {
258
- const s = (n) => {
259
- n.source !== window && e(n.data);
258
+ const s = (a) => {
259
+ a.source !== window && e(a.data);
260
260
  };
261
261
  return window.addEventListener("message", s), window.hostMessageCallback = e, () => {
262
262
  window.removeEventListener("message", s), window.hostMessageCallback === e && (window.hostMessageCallback = null);
263
263
  };
264
264
  }
265
- static sendCustomCommand(e, s = null, n = {}) {
265
+ static sendCustomCommand(e, s = null, a = {}) {
266
266
  const t = {
267
267
  command: e,
268
- text: JSON.stringify(n)
268
+ text: JSON.stringify(a)
269
269
  };
270
270
  if (s !== null)
271
271
  s.postMessage(t);
272
272
  else if (typeof window.sendMessageFromUI == "function")
273
273
  try {
274
- const a = window.sendMessageFromUI(t);
275
- } catch (a) {
276
- console.error("Cabbage: sendMessageFromUI threw error:", a), console.error("Cabbage: Error stack:", a.stack);
274
+ const n = window.sendMessageFromUI(t);
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(t, "*") : (console.error(
279
279
  "Cabbage: window.sendMessageFromUI is not available yet. Message:",
@@ -287,98 +287,98 @@ class y {
287
287
  ));
288
288
  }
289
289
  }
290
- const C = (o, e) => (...s) => {
290
+ const U = (o, e) => (...s) => {
291
291
  e && console.log(`[Cabbage-React][${o}]`, ...s);
292
- }, F = (o, e) => {
292
+ }, y = (o, e) => {
293
293
  if (!o || e?.skip) return { properties: void 0 };
294
- const s = U(
294
+ const s = M(
295
295
  void 0
296
296
  );
297
- s.current = C(
297
+ s.current = U(
298
298
  `useCabbageProperties:${o}`,
299
299
  e?.debug
300
300
  );
301
- const n = s.current, [t, a] = p();
302
- return b(() => {
303
- const r = (w) => {
304
- const { id: d, widgetJson: c, command: m } = w.data;
305
- if (d === o && c && m === "widgetUpdate") {
306
- const i = JSON.parse(c);
307
- n("Received properties", i), e?.onPropertiesUpdate && e.onPropertiesUpdate(i), a(i);
301
+ const [a, t] = f();
302
+ return p(() => {
303
+ const n = (i) => {
304
+ const { id: d, widgetJson: l, command: u } = i.data;
305
+ if (d === o && l && u === "widgetUpdate") {
306
+ const r = JSON.parse(l);
307
+ s.current?.("Received properties", r), e?.onPropertiesUpdate && e.onPropertiesUpdate(r), t(r);
308
308
  }
309
309
  };
310
- return window.addEventListener("message", r), () => window.removeEventListener("message", r);
311
- }, [o, e?.onPropertiesUpdate]), { properties: t };
312
- }, R = (o, e) => {
310
+ return window.addEventListener("message", n), () => window.removeEventListener("message", n);
311
+ }, [o, e?.onPropertiesUpdate]), { properties: a };
312
+ }, L = (o, e) => {
313
313
  if (!o || e?.skip)
314
314
  return { value: void 0, setValue: () => {
315
315
  } };
316
- const s = U(
316
+ const s = M(
317
317
  void 0
318
318
  );
319
- s.current = C(
319
+ s.current = U(
320
320
  `useCabbageState:${o}`,
321
321
  e?.debug
322
322
  );
323
- const n = s.current, { properties: t } = F(o, {
323
+ const { properties: a } = y(o, {
324
324
  debug: e?.debug
325
- }), [a, r] = p(), [w, d] = p(), c = (i, g = "complete") => {
326
- r(i), y.sendControlData({
325
+ }), [t, n] = f(), [i, d] = f(), l = (r, g = "complete") => {
326
+ n(r), v.sendControlData({
327
327
  channel: o,
328
- value: i,
328
+ value: r,
329
329
  gesture: g
330
330
  });
331
- }, m = (i) => {
332
- e?.onValueUpdate && e.onValueUpdate(i), r(i);
331
+ }, u = (r) => {
332
+ e?.onValueUpdate && e.onValueUpdate(r), n(r);
333
333
  };
334
- return b(() => {
335
- const i = t?.channels.find(
336
- (u) => u.id === o
334
+ return p(() => {
335
+ const r = a?.channels.find(
336
+ (c) => c.id === o
337
337
  );
338
- if (!i) return;
339
- const g = i.parameterIndex;
340
- if (w === void 0 && g !== void 0 && (n("Received parameterIndex", g), d(g)), a !== void 0) return;
341
- const l = i.range?.value;
342
- l != null && (n("Received initial value", l), m(l));
343
- }, [t]), b(() => {
344
- const i = (g) => {
345
- const { command: l } = g.data;
346
- if (l === "parameterChange") {
347
- const { value: u, paramIdx: f } = g.data.data;
348
- if (f !== w || u === null) return;
349
- n("Received parameterChange", u), m(u);
350
- } else if (l === "batchWidgetUpdate") {
351
- const f = g.data.widgets?.find((M) => M.id === o);
352
- if (!f) return;
353
- const v = JSON.parse(f.widgetJson).channels.find(
354
- (M) => M.id === o
338
+ if (!r) return;
339
+ const g = r.parameterIndex;
340
+ if (i === void 0 && g !== void 0 && (s.current?.("Received parameterIndex", g), d(g)), t !== void 0) return;
341
+ const w = r.range?.value;
342
+ w != null && (s.current?.("Received initial value", w), u(w));
343
+ }, [a]), p(() => {
344
+ const r = (g) => {
345
+ const { command: w } = g.data;
346
+ if (w === "parameterChange") {
347
+ const { value: c, paramIdx: m } = g.data.data;
348
+ if (m !== i || c === null) return;
349
+ s.current?.("Received parameterChange", c), u(c);
350
+ } else if (w === "batchWidgetUpdate") {
351
+ const m = g.data.widgets?.find((b) => b.id === o);
352
+ if (!m) return;
353
+ const C = JSON.parse(m.widgetJson).channels.find(
354
+ (b) => b.id === o
355
355
  )?.range?.value;
356
- n("Received batchWidgetUpdate", v), m(v);
356
+ s.current?.("Received batchWidgetUpdate", C), u(C);
357
357
  }
358
358
  };
359
- return window.addEventListener("message", i), () => window.removeEventListener("message", i);
360
- }, [o, e?.onValueUpdate, w]), { value: a, setValue: c };
361
- }, S = (o, e) => {
359
+ return window.addEventListener("message", r), () => window.removeEventListener("message", r);
360
+ }, [o, e?.onValueUpdate, i]), { value: t, setValue: l };
361
+ }, R = (o, e) => {
362
362
  if (!o || e?.skip) return { message: void 0 };
363
- const s = U(
363
+ const s = M(
364
364
  void 0
365
365
  );
366
- s.current = C(
366
+ s.current = U(
367
367
  `useCabbageMessage:${o}`,
368
368
  e?.debug
369
369
  );
370
- const n = s.current, [t, a] = p();
371
- return b(() => {
372
- const r = (w) => {
373
- const { data: d, type: c } = w;
374
- !d || c !== "message" || d.type === o && (n("Received data", d), e?.onMessage && e.onMessage(d), a(d));
370
+ const [a, t] = f();
371
+ return p(() => {
372
+ const n = (i) => {
373
+ const { data: d, type: l } = i;
374
+ !d || l !== "message" || d.type === o && (s.current?.("Received data", d), e?.onMessage && e.onMessage(d), t(d));
375
375
  };
376
- return window.addEventListener("message", r), () => window.removeEventListener("message", r);
377
- }, [o, e?.onMessage]), { message: t };
376
+ return window.addEventListener("message", n), () => window.removeEventListener("message", n);
377
+ }, [o, e?.onMessage]), { message: a };
378
378
  };
379
379
  export {
380
- y as Cabbage,
381
- S as useCabbageMessage,
382
- F as useCabbageProperties,
383
- R as useCabbageState
380
+ v as Cabbage,
381
+ R as useCabbageMessage,
382
+ y as useCabbageProperties,
383
+ L as useCabbageState
384
384
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.57",
3
+ "version": "1.0.58",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",