cabbage-react 1.0.14 → 1.0.15

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.
@@ -21,5 +21,18 @@ export class Cabbage {
21
21
  static MidiMessageFromHost(statusByte: any, dataByte1: any, dataByte2: any): void;
22
22
  static triggerFileOpenDialog(vscode: any, channel: any, options?: {}): void;
23
23
  static openUrl(vscode: any, url: any, file: any): void;
24
+ /**
25
+ * Request a resize of the plugin GUI window.
26
+ * This is only supported in plugin mode (CLAP/VST3/AUv2).
27
+ * The host may accept or reject the resize request.
28
+ *
29
+ * @param {number} width - The requested width in pixels
30
+ * @param {number} height - The requested height in pixels
31
+ * @param {object} vscode - The vscode API object (null for plugin mode)
32
+ *
33
+ * The response will be sent via hostMessageCallback with:
34
+ * {command: "resizeResponse", accepted: boolean, width: number, height: number}
35
+ */
36
+ static requestResize(width: number, height: number, vscode?: object): void;
24
37
  }
25
38
  //# sourceMappingURL=cabbage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cabbage.d.ts","sourceRoot":"","sources":["../../src/cabbage/cabbage.js"],"names":[],"mappings":"AAMA;IACC;;;;;;;;;;;;OAYG;IACH,mFAYC;IAED,8DAsCC;IAED,iFAiCC;IAED,0DAiBC;IAED,mGA6BC;IAED,qEAoCC;IAED,kFASC;IAED,4EA2BC;IAED,uDAsBC;CACD"}
1
+ {"version":3,"file":"cabbage.d.ts","sourceRoot":"","sources":["../../src/cabbage/cabbage.js"],"names":[],"mappings":"AAMA;IACC;;;;;;;;;;;;OAYG;IACH,mFAYC;IAED,8DAsCC;IAED,iFAiCC;IAED,0DAiBC;IAED,mGA6BC;IAED,qEAoCC;IAED,kFASC;IAED,4EA2BC;IAED,uDAsBC;IAED;;;;;;;;;;;OAWG;IACH,4BAPW,MAAM,UACN,MAAM,WACN,MAAM,QA4BhB;CACD"}
@@ -0,0 +1,6 @@
1
+ interface CabbageContext {
2
+ devMode: boolean;
3
+ }
4
+ export declare const CabbageContext: import('react').Context<CabbageContext>;
5
+ export {};
6
+ //# sourceMappingURL=CabbageContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CabbageContext.d.ts","sourceRoot":"","sources":["../../src/context/CabbageContext.ts"],"names":[],"mappings":"AAEA,UAAU,cAAc;IACvB,OAAO,EAAE,OAAO,CAAC;CACjB;AAED,eAAO,MAAM,cAAc,yCAEzB,CAAC"}
@@ -6,5 +6,6 @@
6
6
  export declare const useCabbageState: <T>(channelId: string) => {
7
7
  value: T | undefined;
8
8
  setValue: (value: T) => void;
9
+ parameterIndex: number | undefined;
9
10
  };
10
11
  //# sourceMappingURL=useCabbageState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,aAAa,MAAM;;sBAMjB,CAAC;CAqGnC,CAAC"}
1
+ {"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,aAAa,MAAM;;sBAQjB,CAAC;;CA0GnC,CAAC"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react");console.log("Cabbage: loading cabbage.js");class f{static sendChannelUpdate(e,n=null,a=!1){if(a===!0||a===1)f.sendParameterUpdate(e,n);else{const s=e.value!==void 0?e.value:e.stringData||e.floatData;f.sendChannelData(e.channel,s,n)}}static sendParameterUpdate(e,n=null){if(e.paramIdx===void 0||e.paramIdx===null){console.error("Cabbage.sendParameterUpdate: message missing paramIdx!",e);return}if(e.paramIdx<0){console.warn("Cabbage.sendParameterUpdate: paramIdx is -1, skipping (non-automatable widget)",e);return}const a={command:"parameterChange",paramIdx:e.paramIdx,channel:e.channel,value:e.value,channelType:e.channelType||"number"};n!==null?n.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static sendCustomCommand(e,n=null,a={}){const s={command:e,text:JSON.stringify(a)};if(n!==null)n.postMessage(s);else if(typeof window.sendMessageFromUI=="function"){console.log("Cabbage: Calling window.sendMessageFromUI with:",s);try{const o=window.sendMessageFromUI(s);console.log("Cabbage: sendMessageFromUI returned:",o)}catch(o){console.error("Cabbage: sendMessageFromUI threw error:",o),console.error("Cabbage: Error stack:",o.stack)}}else console.error("Cabbage: window.sendMessageFromUI is not available yet. Message:",s),console.error("Cabbage: typeof window.sendMessageFromUI:",typeof window.sendMessageFromUI),console.error("Cabbage: window.sendMessageFromUI value:",window.sendMessageFromUI)}static sendWidgetUpdate(e,n=null){const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};n!==null?n.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static sendMidiMessageFromUI(e,n,a,s=null){var o={statusByte:e,dataByte1:n,dataByte2:a};const l={command:"midiMessage",obj:JSON.stringify(o)};s!==null?s.postMessage(l):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(l):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",l)}static sendChannelData(e,n,a=null){var s={channel:e};if(typeof n=="string")s.stringData=n;else if(typeof n=="number")s.floatData=n;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof n);return}const o={command:"channelData",obj:JSON.stringify(s)};console.log("Cabbage: sending channel data from UI",s),a!==null?a.postMessage(o):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(o):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",o)}static MidiMessageFromHost(e,n,a){console.log("Cabbage: Got MIDI Message"+e+":"+n+":"+a)}static triggerFileOpenDialog(e,n,a={}){var s={channel:n,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.openAtLastKnownLocation:!0};const o={command:"fileOpen",obj:JSON.stringify(s)};e!==null?e.postMessage(o):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(o):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",o)}static openUrl(e,n,a){var s={url:n,file:a};const o={command:"openUrl",obj:JSON.stringify(s)};e!==null?e.postMessage(o):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(o):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",o)}}const M=d=>{const[e,n]=u.useState();return u.useEffect(()=>{const a=s=>{const{id:o,widgetJson:l,command:t}=s.data;if(o===d&&l&&t==="widgetUpdate"){const r=JSON.parse(l);console.log(`[Cabbage-React] Received properties for channelId ${o}`,r),n(r)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:e}},I=d=>{const{properties:e}=M(d),[n,a]=u.useState(),[s,o]=u.useState(),l=t=>{a(t);const r={channel:d,paramIdx:s,value:t};f.sendParameterUpdate(r,null)};return u.useEffect(()=>{var i;const t=e==null?void 0:e.channels.find(g=>g.id===d);if(!t)return;const r=t==null?void 0:t.parameterIndex;s===void 0&&r!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,r),o(r));const c=e==null?void 0:e.value;c!=null&&(console.log(`[Cabbage-React] Received initial value for channelId "${d}"`,c),a(c));const m=(i=t.range)==null?void 0:i.defaultValue;n===void 0&&m!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${t.id}"`,m),a(m))},[e]),u.useEffect(()=>{const t=r=>{var m;const{command:c}=r.data;if(c==="parameterChange"){const{value:i,paramIdx:g}=r.data.data;if(g!==s||i===null)return;console.log(`[Cabbage-React] Received parameterChange for parameterIndex ${g}`,i),a(i)}else if(c==="batchWidgetUpdate"){const i=r.data.widgets,g=i==null?void 0:i.find(w=>w.id===d);if(!g)return;const b=JSON.parse(g.widgetJson).channels.find(w=>w.id===d),p=(m=b==null?void 0:b.range)==null?void 0:m.value;console.log(`[Cabbage-React] Received batch widget update for channelId ${g.id}`,p),a(p)}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[s]),{value:n,setValue:l}};exports.Cabbage=f;exports.useCabbageProperties=M;exports.useCabbageState=I;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),C=c.createContext({devMode:!1});console.log("Cabbage: loading cabbage.js");class f{static sendChannelUpdate(e,a=null,n=!1){if(n===!0||n===1)f.sendParameterUpdate(e,a);else{const s=e.value!==void 0?e.value:e.stringData||e.floatData;f.sendChannelData(e.channel,s,a)}}static sendParameterUpdate(e,a=null){if(e.paramIdx===void 0||e.paramIdx===null){console.error("Cabbage.sendParameterUpdate: message missing paramIdx!",e);return}if(e.paramIdx<0){console.warn("Cabbage.sendParameterUpdate: paramIdx is -1, skipping (non-automatable widget)",e);return}const n={command:"parameterChange",paramIdx:e.paramIdx,channel:e.channel,value:e.value,channelType:e.channelType||"number"};a!==null?a.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static sendCustomCommand(e,a=null,n={}){const s={command:e,text:JSON.stringify(n)};if(a!==null)a.postMessage(s);else if(typeof window.sendMessageFromUI=="function"){console.log("Cabbage: Calling window.sendMessageFromUI with:",s);try{const o=window.sendMessageFromUI(s);console.log("Cabbage: sendMessageFromUI returned:",o)}catch(o){console.error("Cabbage: sendMessageFromUI threw error:",o),console.error("Cabbage: Error stack:",o.stack)}}else console.error("Cabbage: window.sendMessageFromUI is not available yet. Message:",s),console.error("Cabbage: typeof window.sendMessageFromUI:",typeof window.sendMessageFromUI),console.error("Cabbage: window.sendMessageFromUI value:",window.sendMessageFromUI)}static sendWidgetUpdate(e,a=null){const n={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};a!==null?a.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static sendMidiMessageFromUI(e,a,n,s=null){var o={statusByte:e,dataByte1:a,dataByte2:n};const l={command:"midiMessage",obj:JSON.stringify(o)};s!==null?s.postMessage(l):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(l):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",l)}static sendChannelData(e,a,n=null){var s={channel:e};if(typeof a=="string")s.stringData=a;else if(typeof a=="number")s.floatData=a;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof a);return}const o={command:"channelData",obj:JSON.stringify(s)};console.log("Cabbage: sending channel data from UI",s),n!==null?n.postMessage(o):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(o):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",o)}static MidiMessageFromHost(e,a,n){console.log("Cabbage: Got MIDI Message"+e+":"+a+":"+n)}static triggerFileOpenDialog(e,a,n={}){var s={channel:a,directory:n.directory||"",filters:n.filters||"*",openAtLastKnownLocation:n.openAtLastKnownLocation!==void 0?n.openAtLastKnownLocation:!0};const o={command:"fileOpen",obj:JSON.stringify(s)};e!==null?e.postMessage(o):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(o):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",o)}static openUrl(e,a,n){var s={url:a,file:n};const o={command:"openUrl",obj:JSON.stringify(s)};e!==null?e.postMessage(o):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(o):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",o)}static requestResize(e,a,n=null){const s={command:"requestResize",width:e,height:a};if(n!==null){console.warn("Cabbage: requestResize is not supported in VS Code extension mode");return}else typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}}const I=i=>{const[e,a]=c.useState();return c.useEffect(()=>{const n=s=>{const{id:o,widgetJson:l,command:b}=s.data;if(o===i&&l&&b==="widgetUpdate"){const t=JSON.parse(l);console.log(`[Cabbage-React] Received properties for channelId ${o}`,t),a(t)}};return window.addEventListener("message",n),()=>{window.removeEventListener("message",n)}},[]),{properties:e}},U=i=>{const{devMode:e}=c.useContext(C),{properties:a}=I(i),[n,s]=c.useState(),[o,l]=c.useState(),b=t=>{if(e)s(t);else{if(o===void 0){console.warn(`[Cabbage-React] parameterIndex not ready for "${i}"`);return}const d={channel:i,paramIdx:o,value:t};f.sendParameterUpdate(d,null)}};return c.useEffect(()=>{var r;const t=a==null?void 0:a.channels.find(g=>g.id===i);if(!t)return;const d=t==null?void 0:t.parameterIndex;o===void 0&&d!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,d),l(d));const m=a==null?void 0:a.value;m!=null&&(console.log(`[Cabbage-React] Received initial value for channelId "${i}"`,m),s(m));const u=(r=t.range)==null?void 0:r.defaultValue;n===void 0&&u!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${t.id}"`,u),s(u))},[a]),c.useEffect(()=>{const t=d=>{var u;const{command:m}=d.data;if(m==="parameterChange"){const{value:r,paramIdx:g}=d.data.data;if(g!==o||r===null)return;console.log(`[Cabbage-React] Received parameterChange for parameterIndex ${g}`,r),s(r)}else if(m==="batchWidgetUpdate"){const r=d.data.widgets,g=r==null?void 0:r.find(p=>p.id===i);if(!g)return;const w=JSON.parse(g.widgetJson).channels.find(p=>p.id===i),M=(u=w==null?void 0:w.range)==null?void 0:u.value;console.log(`[Cabbage-React] Received batch widget update for channelId ${g.id}`,M),s(M)}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[o]),{value:n,setValue:b,parameterIndex:o}};exports.Cabbage=f;exports.CabbageContext=C;exports.useCabbageProperties=I;exports.useCabbageState=U;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { CabbageContext } from './context/CabbageContext';
1
2
  export { useCabbageState } from './hooks/useCabbageState';
2
3
  export { useCabbageProperties } from './hooks/useCabbageProperties';
3
4
  export { Cabbage } from './cabbage/cabbage';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,7 @@
1
- import { useState as b, useEffect as p } from "react";
1
+ import { createContext as C, useState as p, useEffect as M, useContext as U } from "react";
2
+ const F = C({
3
+ devMode: !1
4
+ });
2
5
  console.log("Cabbage: loading cabbage.js");
3
6
  class f {
4
7
  /**
@@ -14,15 +17,15 @@ class f {
14
17
  * All widget interactions should use this function instead of calling the lower-level
15
18
  * sendParameterUpdate or sendChannelData functions directly.
16
19
  */
17
- static sendChannelUpdate(e, n = null, a = !1) {
18
- if (a === !0 || a === 1)
19
- f.sendParameterUpdate(e, n);
20
+ static sendChannelUpdate(e, a = null, n = !1) {
21
+ if (n === !0 || n === 1)
22
+ f.sendParameterUpdate(e, a);
20
23
  else {
21
24
  const s = e.value !== void 0 ? e.value : e.stringData || e.floatData;
22
- f.sendChannelData(e.channel, s, n);
25
+ f.sendChannelData(e.channel, s, a);
23
26
  }
24
27
  }
25
- static sendParameterUpdate(e, n = null) {
28
+ static sendParameterUpdate(e, a = null) {
26
29
  if (e.paramIdx === void 0 || e.paramIdx === null) {
27
30
  console.error(
28
31
  "Cabbage.sendParameterUpdate: message missing paramIdx!",
@@ -37,25 +40,25 @@ class f {
37
40
  );
38
41
  return;
39
42
  }
40
- const a = {
43
+ const n = {
41
44
  command: "parameterChange",
42
45
  paramIdx: e.paramIdx,
43
46
  channel: e.channel,
44
47
  value: e.value,
45
48
  channelType: e.channelType || "number"
46
49
  };
47
- n !== null ? n.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : console.error(
50
+ a !== null ? a.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : console.error(
48
51
  "Cabbage: window.sendMessageFromUI is not available. Message:",
49
- a
52
+ n
50
53
  );
51
54
  }
52
- static sendCustomCommand(e, n = null, a = {}) {
55
+ static sendCustomCommand(e, a = null, n = {}) {
53
56
  const s = {
54
57
  command: e,
55
- text: JSON.stringify(a)
58
+ text: JSON.stringify(n)
56
59
  };
57
- if (n !== null)
58
- n.postMessage(s);
60
+ if (a !== null)
61
+ a.postMessage(s);
59
62
  else if (typeof window.sendMessageFromUI == "function") {
60
63
  console.log("Cabbage: Calling window.sendMessageFromUI with:", s);
61
64
  try {
@@ -76,21 +79,21 @@ class f {
76
79
  window.sendMessageFromUI
77
80
  );
78
81
  }
79
- static sendWidgetUpdate(e, n = null) {
80
- const a = {
82
+ static sendWidgetUpdate(e, a = null) {
83
+ const n = {
81
84
  command: "widgetStateUpdate",
82
85
  obj: JSON.stringify(CabbageUtils.sanitizeForEditor(e))
83
86
  };
84
- n !== null ? n.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : console.error(
87
+ a !== null ? a.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : console.error(
85
88
  "Cabbage: window.sendMessageFromUI is not available. Message:",
86
- a
89
+ n
87
90
  );
88
91
  }
89
- static sendMidiMessageFromUI(e, n, a, s = null) {
92
+ static sendMidiMessageFromUI(e, a, n, s = null) {
90
93
  var o = {
91
94
  statusByte: e,
92
- dataByte1: n,
93
- dataByte2: a
95
+ dataByte1: a,
96
+ dataByte2: n
94
97
  };
95
98
  const l = {
96
99
  command: "midiMessage",
@@ -101,18 +104,18 @@ class f {
101
104
  l
102
105
  );
103
106
  }
104
- static sendChannelData(e, n, a = null) {
107
+ static sendChannelData(e, a, n = null) {
105
108
  var s = {
106
109
  channel: e
107
110
  };
108
- if (typeof n == "string")
109
- s.stringData = n;
110
- else if (typeof n == "number")
111
- s.floatData = n;
111
+ if (typeof a == "string")
112
+ s.stringData = a;
113
+ else if (typeof a == "number")
114
+ s.floatData = a;
112
115
  else {
113
116
  console.warn(
114
117
  "Cabbage: sendChannelData received unsupported data type:",
115
- typeof n
118
+ typeof a
116
119
  );
117
120
  return;
118
121
  }
@@ -120,22 +123,22 @@ class f {
120
123
  command: "channelData",
121
124
  obj: JSON.stringify(s)
122
125
  };
123
- console.log("Cabbage: sending channel data from UI", s), a !== null ? a.postMessage(o) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(o) : console.error(
126
+ console.log("Cabbage: sending channel data from UI", s), n !== null ? n.postMessage(o) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(o) : console.error(
124
127
  "Cabbage: window.sendMessageFromUI is not available. Message:",
125
128
  o
126
129
  );
127
130
  }
128
- static MidiMessageFromHost(e, n, a) {
131
+ static MidiMessageFromHost(e, a, n) {
129
132
  console.log(
130
- "Cabbage: Got MIDI Message" + e + ":" + n + ":" + a
133
+ "Cabbage: Got MIDI Message" + e + ":" + a + ":" + n
131
134
  );
132
135
  }
133
- static triggerFileOpenDialog(e, n, a = {}) {
136
+ static triggerFileOpenDialog(e, a, n = {}) {
134
137
  var s = {
135
- channel: n,
136
- directory: a.directory || "",
137
- filters: a.filters || "*",
138
- openAtLastKnownLocation: a.openAtLastKnownLocation !== void 0 ? a.openAtLastKnownLocation : !0
138
+ channel: a,
139
+ directory: n.directory || "",
140
+ filters: n.filters || "*",
141
+ openAtLastKnownLocation: n.openAtLastKnownLocation !== void 0 ? n.openAtLastKnownLocation : !0
139
142
  };
140
143
  const o = {
141
144
  command: "fileOpen",
@@ -146,10 +149,10 @@ class f {
146
149
  o
147
150
  );
148
151
  }
149
- static openUrl(e, n, a) {
152
+ static openUrl(e, a, n) {
150
153
  var s = {
151
- url: n,
152
- file: a
154
+ url: a,
155
+ file: n
153
156
  };
154
157
  const o = {
155
158
  command: "openUrl",
@@ -160,90 +163,126 @@ class f {
160
163
  o
161
164
  );
162
165
  }
166
+ /**
167
+ * Request a resize of the plugin GUI window.
168
+ * This is only supported in plugin mode (CLAP/VST3/AUv2).
169
+ * The host may accept or reject the resize request.
170
+ *
171
+ * @param {number} width - The requested width in pixels
172
+ * @param {number} height - The requested height in pixels
173
+ * @param {object} vscode - The vscode API object (null for plugin mode)
174
+ *
175
+ * The response will be sent via hostMessageCallback with:
176
+ * {command: "resizeResponse", accepted: boolean, width: number, height: number}
177
+ */
178
+ static requestResize(e, a, n = null) {
179
+ const s = {
180
+ command: "requestResize",
181
+ width: e,
182
+ height: a
183
+ };
184
+ if (n !== null) {
185
+ console.warn(
186
+ "Cabbage: requestResize is not supported in VS Code extension mode"
187
+ );
188
+ return;
189
+ } else
190
+ typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(s) : console.error(
191
+ "Cabbage: window.sendMessageFromUI is not available. Message:",
192
+ s
193
+ );
194
+ }
163
195
  }
164
- const I = (d) => {
165
- const [e, n] = b();
166
- return p(() => {
167
- const a = (s) => {
168
- const { id: o, widgetJson: l, command: t } = s.data;
169
- if (o === d && l && t === "widgetUpdate") {
170
- const r = JSON.parse(l);
196
+ const v = (i) => {
197
+ const [e, a] = p();
198
+ return M(() => {
199
+ const n = (s) => {
200
+ const { id: o, widgetJson: l, command: u } = s.data;
201
+ if (o === i && l && u === "widgetUpdate") {
202
+ const t = JSON.parse(l);
171
203
  console.log(
172
204
  `[Cabbage-React] Received properties for channelId ${o}`,
173
- r
174
- ), n(r);
205
+ t
206
+ ), a(t);
175
207
  }
176
208
  };
177
- return window.addEventListener("message", a), () => {
178
- window.removeEventListener("message", a);
209
+ return window.addEventListener("message", n), () => {
210
+ window.removeEventListener("message", n);
179
211
  };
180
212
  }, []), {
181
213
  properties: e
182
214
  };
183
- }, F = (d) => {
184
- const { properties: e } = I(d), [n, a] = b(), [s, o] = b(), l = (t) => {
185
- a(t);
186
- const r = {
187
- channel: d,
188
- paramIdx: s,
189
- value: t
190
- };
191
- f.sendParameterUpdate(r, null);
215
+ }, x = (i) => {
216
+ const { devMode: e } = U(F), { properties: a } = v(i), [n, s] = p(), [o, l] = p(), u = (t) => {
217
+ if (e)
218
+ s(t);
219
+ else {
220
+ if (o === void 0) {
221
+ console.warn(
222
+ `[Cabbage-React] parameterIndex not ready for "${i}"`
223
+ );
224
+ return;
225
+ }
226
+ const d = { channel: i, paramIdx: o, value: t };
227
+ f.sendParameterUpdate(d, null);
228
+ }
192
229
  };
193
- return p(() => {
194
- var i;
195
- const t = e == null ? void 0 : e.channels.find(
196
- (g) => g.id === d
230
+ return M(() => {
231
+ var r;
232
+ const t = a == null ? void 0 : a.channels.find(
233
+ (g) => g.id === i
197
234
  );
198
235
  if (!t) return;
199
- const r = t == null ? void 0 : t.parameterIndex;
200
- s === void 0 && r !== void 0 && (console.log(
236
+ const d = t == null ? void 0 : t.parameterIndex;
237
+ o === void 0 && d !== void 0 && (console.log(
201
238
  `[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,
202
- r
203
- ), o(r));
204
- const c = e == null ? void 0 : e.value;
239
+ d
240
+ ), l(d));
241
+ const c = a == null ? void 0 : a.value;
205
242
  c != null && (console.log(
206
- `[Cabbage-React] Received initial value for channelId "${d}"`,
243
+ `[Cabbage-React] Received initial value for channelId "${i}"`,
207
244
  c
208
- ), a(c));
209
- const m = (i = t.range) == null ? void 0 : i.defaultValue;
245
+ ), s(c));
246
+ const m = (r = t.range) == null ? void 0 : r.defaultValue;
210
247
  n === void 0 && m !== void 0 && (console.log(
211
248
  `[Cabbage-React] Received default value for channelId "${t.id}"`,
212
249
  m
213
- ), a(m));
214
- }, [e]), p(() => {
215
- const t = (r) => {
250
+ ), s(m));
251
+ }, [a]), M(() => {
252
+ const t = (d) => {
216
253
  var m;
217
- const { command: c } = r.data;
254
+ const { command: c } = d.data;
218
255
  if (c === "parameterChange") {
219
- const { value: i, paramIdx: g } = r.data.data;
220
- if (g !== s || i === null) return;
256
+ const { value: r, paramIdx: g } = d.data.data;
257
+ if (g !== o || r === null) return;
221
258
  console.log(
222
259
  `[Cabbage-React] Received parameterChange for parameterIndex ${g}`,
223
- i
224
- ), a(i);
260
+ r
261
+ ), s(r);
225
262
  } else if (c === "batchWidgetUpdate") {
226
- const i = r.data.widgets, g = i == null ? void 0 : i.find((w) => w.id === d);
263
+ const r = d.data.widgets, g = r == null ? void 0 : r.find((b) => b.id === i);
227
264
  if (!g) return;
228
- const u = JSON.parse(g.widgetJson).channels.find(
229
- (w) => w.id === d
230
- ), M = (m = u == null ? void 0 : u.range) == null ? void 0 : m.value;
265
+ const w = JSON.parse(g.widgetJson).channels.find(
266
+ (b) => b.id === i
267
+ ), I = (m = w == null ? void 0 : w.range) == null ? void 0 : m.value;
231
268
  console.log(
232
269
  `[Cabbage-React] Received batch widget update for channelId ${g.id}`,
233
- M
234
- ), a(M);
270
+ I
271
+ ), s(I);
235
272
  }
236
273
  };
237
274
  return window.addEventListener("message", t), () => {
238
275
  window.removeEventListener("message", t);
239
276
  };
240
- }, [s]), {
277
+ }, [o]), {
241
278
  value: n,
242
- setValue: l
279
+ setValue: u,
280
+ parameterIndex: o
243
281
  };
244
282
  };
245
283
  export {
246
284
  f as Cabbage,
247
- I as useCabbageProperties,
248
- F as useCabbageState
285
+ F as CabbageContext,
286
+ v as useCabbageProperties,
287
+ x as useCabbageState
249
288
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",