cabbage-react 1.0.54 → 1.0.56

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":"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"}
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;;CA6BD,CAAC"}
@@ -1 +1 @@
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"}
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;;CAkCD,CAAC"}
@@ -1 +1 @@
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"}
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;;sBAmBO,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 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;
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 r={command:"midiMessage",obj:JSON.stringify(a)};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,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.useMemo(()=>b(`useCabbageProperties:${o}`,e?.debug),[o,e?.debug]),[n,t]=d.useState();return d.useEffect(()=>{const a=r=>{const{id:g,widgetJson:u,command:m}=r.data;if(g===o&&u&&m==="widgetUpdate"){const i=JSON.parse(u);s("Received properties",i),e?.onPropertiesUpdate&&e.onPropertiesUpdate(i),t(i)}};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[o,e?.onPropertiesUpdate]),{properties:n}},y=(o,e)=>{if(!o||e?.skip)return{value:void 0,setValue:()=>{}};const s=d.useMemo(()=>b(`useCabbageState:${o}`,e?.debug),[o,e?.debug]),{properties:n}=U(o,{debug:e?.debug}),[t,a]=d.useState(),[r,g]=d.useState(),u=(i,w="complete")=>{a(i),C.sendControlData({channel:o,value:i,gesture:w})},m=i=>{e?.onValueUpdate&&e.onValueUpdate(i),a(i)};return d.useEffect(()=>{const i=n?.channels.find(c=>c.id===o);if(!i)return;const w=i.parameterIndex;if(r===void 0&&w!==void 0&&(s("Received parameterIndex",w),g(w)),t!==void 0)return;const l=i.range?.value;l!=null&&(s("Received initial value",l),m(l))},[n]),d.useEffect(()=>{const i=w=>{const{command:l}=w.data;if(l==="parameterChange"){const{value:c,paramIdx:f}=w.data.data;if(f!==r||c===null)return;s("Received parameterChange",c),m(c)}else if(l==="batchWidgetUpdate"){const f=w.data.widgets?.find(p=>p.id===o);if(!f)return;const M=JSON.parse(f.widgetJson).channels.find(p=>p.id===o)?.range?.value;s("Received batchWidgetUpdate",M),m(M)}};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[o,e?.onValueUpdate,r]),{value:t,setValue:u}},v=(o,e)=>{if(!o||e?.skip)return{message:void 0};const s=b(`useCabbageMessage:${o}`,e?.debug),[n,t]=d.useState();return d.useEffect(()=>{const a=r=>{const{data:g,type:u}=r;!g||u!=="message"||g.type===o&&(s("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=v;exports.useCabbageProperties=U;exports.useCabbageState=y;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { useState as f, useEffect as u } from "react";
2
- class M {
1
+ import { useMemo as C, useState as f, useEffect as p } from "react";
2
+ class y {
3
3
  /**
4
4
  * Send a widget value change to the Cabbage backend.
5
5
  *
@@ -20,16 +20,16 @@ class M {
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: a = "complete" }, o = null) {
24
- const n = {
23
+ static sendControlData({ channel: e, value: s, gesture: n = "complete" }, t = null) {
24
+ const a = {
25
25
  command: "controlData",
26
26
  channel: e,
27
27
  value: s,
28
- gesture: a
28
+ gesture: n
29
29
  };
30
- o !== null ? o.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : window.parent !== window ? window.parent.postMessage(n, "*") : console.error(
30
+ t !== null ? t.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : console.error(
31
31
  "Cabbage: window.sendMessageFromUI is not available. Message:",
32
- n
32
+ a
33
33
  );
34
34
  }
35
35
  /**
@@ -49,17 +49,17 @@ class M {
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, a, o = null) {
53
- var n = {
52
+ static sendMidiMessageFromUI(e, s, n, t = null) {
53
+ var a = {
54
54
  statusByte: e,
55
55
  dataByte1: s,
56
- dataByte2: a
56
+ dataByte2: n
57
57
  };
58
58
  const r = {
59
59
  command: "midiMessage",
60
- obj: JSON.stringify(n)
60
+ obj: JSON.stringify(a)
61
61
  };
62
- o !== null ? o.postMessage(r) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(r) : window.parent !== window ? window.parent.postMessage(r, "*") : console.error(
62
+ t !== null ? t.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:",
64
64
  r
65
65
  );
@@ -71,7 +71,7 @@ class M {
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, a) {
74
+ static MidiMessageFromHost(e, s, n) {
75
75
  }
76
76
  /**
77
77
  * Trigger a native file open dialog for file selection widgets.
@@ -83,20 +83,20 @@ class M {
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, a = {}) {
87
- var o = {
86
+ static triggerFileOpenDialog(e, s, n = {}) {
87
+ var t = {
88
88
  channel: s,
89
- directory: a.directory || "",
90
- filters: a.filters || "*",
91
- openAtLastKnownLocation: a.openAtLastKnownLocation !== void 0 ? a.openAtLastKnownLocation : !0
89
+ directory: n.directory || "",
90
+ filters: n.filters || "*",
91
+ openAtLastKnownLocation: n.openAtLastKnownLocation !== void 0 ? n.openAtLastKnownLocation : !0
92
92
  };
93
- const n = {
93
+ const a = {
94
94
  command: "fileOpen",
95
- obj: JSON.stringify(o)
95
+ obj: JSON.stringify(t)
96
96
  };
97
- e !== null ? e.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : window.parent !== window ? window.parent.postMessage(n, "*") : 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
- n
99
+ a
100
100
  );
101
101
  }
102
102
  /**
@@ -106,18 +106,18 @@ class M {
106
106
  * @param {string} url - URL to open
107
107
  * @param {string} file - File path to open
108
108
  */
109
- static openUrl(e, s, a) {
110
- var o = {
109
+ static openUrl(e, s, n) {
110
+ var t = {
111
111
  url: s,
112
- file: a
112
+ file: n
113
113
  };
114
- const n = {
114
+ const a = {
115
115
  command: "openUrl",
116
- obj: JSON.stringify(o)
116
+ obj: JSON.stringify(t)
117
117
  };
118
- e !== null ? e.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : window.parent !== window ? window.parent.postMessage(n, "*") : 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
- n
120
+ a
121
121
  );
122
122
  }
123
123
  /**
@@ -132,21 +132,21 @@ class M {
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, a = null) {
136
- const o = {
135
+ static requestResize(e, s, n = null) {
136
+ const t = {
137
137
  command: "requestResize",
138
138
  width: e,
139
139
  height: s
140
140
  };
141
- if (a !== null) {
141
+ if (n !== null) {
142
142
  console.warn(
143
143
  "Cabbage: requestResize is not supported in VS Code extension mode"
144
144
  );
145
145
  return;
146
146
  } else
147
- typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(o) : window.parent !== window ? window.parent.postMessage(o, "*") : console.error(
147
+ typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(t) : window.parent !== window ? window.parent.postMessage(t, "*") : console.error(
148
148
  "Cabbage: window.sendMessageFromUI is not available. Message:",
149
- o
149
+ t
150
150
  );
151
151
  }
152
152
  /**
@@ -178,14 +178,14 @@ class M {
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, a = null) {
182
- var o = {
181
+ static sendChannelData(e, s, n = null) {
182
+ var t = {
183
183
  channel: e
184
184
  };
185
185
  if (typeof s == "string")
186
- o.stringData = s;
186
+ t.stringData = s;
187
187
  else if (typeof s == "number")
188
- o.floatData = s;
188
+ t.floatData = s;
189
189
  else {
190
190
  console.warn(
191
191
  "Cabbage: sendChannelData received unsupported data type:",
@@ -193,13 +193,13 @@ class M {
193
193
  );
194
194
  return;
195
195
  }
196
- const n = {
196
+ const a = {
197
197
  command: "channelData",
198
- obj: JSON.stringify(o)
198
+ obj: JSON.stringify(t)
199
199
  };
200
- a !== null ? a.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : window.parent !== window ? window.parent.postMessage(n, "*") : console.error(
200
+ n !== null ? n.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : console.error(
201
201
  "Cabbage: window.sendMessageFromUI is not available. Message:",
202
- n
202
+ a
203
203
  );
204
204
  }
205
205
  /**
@@ -210,13 +210,13 @@ class M {
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 a = {
213
+ const n = {
214
214
  command: "widgetStateUpdate",
215
215
  obj: JSON.stringify(CabbageUtils.sanitizeForEditor(e))
216
216
  };
217
- s !== null ? s.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : 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
- a
219
+ n
220
220
  );
221
221
  }
222
222
  /**
@@ -255,29 +255,29 @@ class M {
255
255
  * onDestroy(() => remove?.());
256
256
  */
257
257
  static addMessageListener(e) {
258
- const s = (a) => {
259
- a.source !== window && e(a.data);
258
+ const s = (n) => {
259
+ n.source !== window && e(n.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, a = {}) {
266
- const o = {
265
+ static sendCustomCommand(e, s = null, n = {}) {
266
+ const t = {
267
267
  command: e,
268
- text: JSON.stringify(a)
268
+ text: JSON.stringify(n)
269
269
  };
270
270
  if (s !== null)
271
- s.postMessage(o);
271
+ s.postMessage(t);
272
272
  else if (typeof window.sendMessageFromUI == "function")
273
273
  try {
274
- const n = window.sendMessageFromUI(o);
275
- } catch (n) {
276
- console.error("Cabbage: sendMessageFromUI threw error:", n), console.error("Cabbage: Error stack:", n.stack);
274
+ const a = window.sendMessageFromUI(t);
275
+ } catch (a) {
276
+ console.error("Cabbage: sendMessageFromUI threw error:", a), console.error("Cabbage: Error stack:", a.stack);
277
277
  }
278
- else window.parent !== window ? window.parent.postMessage(o, "*") : (console.error(
278
+ else window.parent !== window ? window.parent.postMessage(t, "*") : (console.error(
279
279
  "Cabbage: window.sendMessageFromUI is not available yet. Message:",
280
- o
280
+ t
281
281
  ), console.error(
282
282
  "Cabbage: typeof window.sendMessageFromUI:",
283
283
  typeof window.sendMessageFromUI
@@ -287,91 +287,86 @@ class M {
287
287
  ));
288
288
  }
289
289
  }
290
- const U = (i, e) => {
291
- if (!i || e?.skip) return { properties: void 0 };
292
- const [s, a] = f();
293
- return u(() => {
294
- const o = (n) => {
295
- const { id: r, widgetJson: g, command: m } = n.data;
296
- if (r === i && g && m === "widgetUpdate") {
297
- const t = JSON.parse(g);
298
- e?.debug && console.log(
299
- `[Cabbage-React] Received properties for channelId: ${r}`,
300
- t
301
- ), e?.onPropertiesUpdate && e.onPropertiesUpdate(t), a(t);
290
+ const M = (o, e) => (...s) => {
291
+ e && console.log(`[Cabbage-React][${o}]`, ...s);
292
+ }, v = (o, e) => {
293
+ if (!o || e?.skip) return { properties: void 0 };
294
+ const s = C(
295
+ () => M(`useCabbageProperties:${o}`, e?.debug),
296
+ [o, e?.debug]
297
+ ), [n, t] = f();
298
+ return p(() => {
299
+ const a = (r) => {
300
+ const { id: d, widgetJson: l, command: u } = r.data;
301
+ if (d === o && l && u === "widgetUpdate") {
302
+ const i = JSON.parse(l);
303
+ s("Received properties", i), e?.onPropertiesUpdate && e.onPropertiesUpdate(i), t(i);
302
304
  }
303
305
  };
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)
306
+ return window.addEventListener("message", a), () => window.removeEventListener("message", a);
307
+ }, [o, e?.onPropertiesUpdate]), { properties: n };
308
+ }, L = (o, e) => {
309
+ if (!o || e?.skip)
308
310
  return { value: void 0, setValue: () => {
309
311
  } };
310
- const { properties: s } = U(i), [a, o] = f(), [n, r] = f(), g = (t, d = "complete") => {
311
- o(t), M.sendControlData({
312
- channel: i,
313
- value: t,
314
- gesture: d
312
+ const s = C(
313
+ () => M(`useCabbageState:${o}`, e?.debug),
314
+ [o, e?.debug]
315
+ ), { properties: n } = v(o, {
316
+ debug: e?.debug
317
+ }), [t, a] = f(), [r, d] = f(), l = (i, g = "complete") => {
318
+ a(i), y.sendControlData({
319
+ channel: o,
320
+ value: i,
321
+ gesture: g
315
322
  });
316
- }, m = (t) => {
317
- e?.onValueUpdate && e.onValueUpdate(t), o(t);
323
+ }, u = (i) => {
324
+ e?.onValueUpdate && e.onValueUpdate(i), a(i);
318
325
  };
319
- return u(() => {
320
- const t = s?.channels.find(
321
- (w) => w.id === i
326
+ return p(() => {
327
+ const i = n?.channels.find(
328
+ (c) => c.id === o
322
329
  );
323
- if (!t) return;
324
- const d = t.parameterIndex;
325
- if (n === void 0 && d !== void 0 && (e?.debug && console.log(
326
- `[Cabbage-React] Received parameterIndex for channelId: ${t.id}`,
327
- d
328
- ), r(d)), a !== void 0) return;
329
- const l = t.range?.value;
330
- l != null && (e?.debug && console.log(
331
- `[Cabbage-React] Received initial value for channelId: ${t.id}`,
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
330
+ if (!i) return;
331
+ const g = i.parameterIndex;
332
+ if (r === void 0 && g !== void 0 && (s("Received parameterIndex", g), d(g)), t !== void 0) return;
333
+ const w = i.range?.value;
334
+ w != null && (s("Received initial value", w), u(w));
335
+ }, [n]), p(() => {
336
+ const i = (g) => {
337
+ const { command: w } = g.data;
338
+ if (w === "parameterChange") {
339
+ const { value: c, paramIdx: m } = g.data.data;
340
+ if (m !== r || c === null) return;
341
+ s("Received parameterChange", c), u(c);
342
+ } else if (w === "batchWidgetUpdate") {
343
+ const m = g.data.widgets?.find((b) => b.id === o);
344
+ if (!m) return;
345
+ const U = JSON.parse(m.widgetJson).channels.find(
346
+ (b) => b.id === o
349
347
  )?.range?.value;
350
- e?.debug && console.log(
351
- `[Cabbage-React] Received batch widget update for channelId: ${c.id}`,
352
- b
353
- ), m(b);
348
+ s("Received batchWidgetUpdate", U), u(U);
354
349
  }
355
350
  };
356
- return window.addEventListener("message", t), () => window.removeEventListener("message", t);
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
- return u(() => {
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));
351
+ return window.addEventListener("message", i), () => window.removeEventListener("message", i);
352
+ }, [o, e?.onValueUpdate, r]), { value: t, setValue: l };
353
+ }, S = (o, e) => {
354
+ if (!o || e?.skip) return { message: void 0 };
355
+ const s = M(
356
+ `useCabbageMessage:${o}`,
357
+ e?.debug
358
+ ), [n, t] = f();
359
+ return p(() => {
360
+ const a = (r) => {
361
+ const { data: d, type: l } = r;
362
+ !d || l !== "message" || d.type === o && (s("Received data", d), e?.onMessage && e.onMessage(d), t(d));
368
363
  };
369
- return window.addEventListener("message", o), () => window.removeEventListener("message", o);
370
- }, [i, e?.onMessage]), { message: s };
364
+ return window.addEventListener("message", a), () => window.removeEventListener("message", a);
365
+ }, [o, e?.onMessage]), { message: n };
371
366
  };
372
367
  export {
373
- M as Cabbage,
374
- F as useCabbageMessage,
375
- U as useCabbageProperties,
376
- I as useCabbageState
368
+ y as Cabbage,
369
+ S as useCabbageMessage,
370
+ v as useCabbageProperties,
371
+ L as useCabbageState
377
372
  };
@@ -0,0 +1,2 @@
1
+ export declare const createCabbageDebugger: (scope: string, enabled?: boolean) => (...args: any[]) => void;
2
+ //# sourceMappingURL=cabbageDebug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cabbageDebug.d.ts","sourceRoot":"","sources":["../../src/utils/cabbageDebug.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,GACjC,OAAO,MAAM,EACb,UAAU,OAAO,MAET,GAAG,MAAM,GAAG,EAAE,SAKtB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.54",
3
+ "version": "1.0.56",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",