cabbage-react 1.0.23 → 1.0.24

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":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,aAAa,MAAM,eAAe,OAAO;;sBAMvC,CAAC;;CA+GnC,CAAC"}
1
+ {"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,aAAa,MAAM,eAAe,OAAO;;sBAMvC,CAAC;;CAoGnC,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,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]=u.useState();return u.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}},C=(i,e)=>{const{properties:a}=I(i),[n,s]=u.useState(),[o,l]=u.useState(),b=t=>{if(s(t),o===void 0){console.warn(`[Cabbage-React] parameterIndex not ready for "${i}"`);return}const d={paramIdx:o,channel:i,value:t,channelType:"number"};f.sendParameterUpdate(d,null)};return u.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 c=a==null?void 0:a.value;c!=null&&(console.log(`[Cabbage-React] Received initial value for channelId "${i}"`,c),s(c));const m=(r=t.range)==null?void 0:r.defaultValue;n===void 0&&m!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${t.id}"`,m),s(m))},[a]),u.useEffect(()=>{const t=d=>{var m;const{command:c}=d.data;if(c==="parameterChange"){if(e===!0)return;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(c==="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=(m=w==null?void 0:w.range)==null?void 0:m.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,e]),{value:n,setValue:b,parameterIndex:o}};exports.Cabbage=f;exports.useCabbageProperties=I;exports.useCabbageState=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react");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=d=>{const[e,a]=m.useState();return m.useEffect(()=>{const n=s=>{const{id:o,widgetJson:l,command:b}=s.data;if(o===d&&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}},C=(d,e)=>{const{properties:a}=I(d),[n,s]=m.useState(),[o,l]=m.useState(),b=t=>{if(s(t),o===void 0){console.warn(`[Cabbage-React] parameterIndex not ready for "${d}"`);return}const r={paramIdx:o,channel:d,value:t,channelType:"number"};f.sendParameterUpdate(r,null)};return m.useEffect(()=>{var u;const t=a==null?void 0:a.channels.find(i=>i.id===d);if(!t)return;const r=t==null?void 0:t.parameterIndex;o===void 0&&r!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,r),l(r));const g=(u=t.range)==null?void 0:u.defaultValue;n===void 0&&g!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${t.id}"`,g),s(g))},[a]),m.useEffect(()=>{const t=r=>{var u;const{command:g}=r.data;if(g==="parameterChange"){if(e===!0)return;const{value:i,paramIdx:c}=r.data.data;if(c!==o||i===null)return;console.log(`[Cabbage-React] Received parameterChange for parameterIndex ${c}`,i),s(i)}else if(g==="batchWidgetUpdate"){const i=r.data.widgets,c=i==null?void 0:i.find(p=>p.id===d);if(!c)return;const w=JSON.parse(c.widgetJson).channels.find(p=>p.id===d),M=(u=w==null?void 0:w.range)==null?void 0:u.value;console.log(`[Cabbage-React] Received batch widget update for channelId ${c.id}`,M),s(M)}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[o,e]),{value:n,setValue:b,parameterIndex:o}};exports.Cabbage=f;exports.useCabbageProperties=I;exports.useCabbageState=C;
package/dist/index.mjs CHANGED
@@ -236,12 +236,12 @@ class f {
236
236
  );
237
237
  }
238
238
  }
239
- const U = (i) => {
239
+ const U = (d) => {
240
240
  const [e, a] = p();
241
241
  return M(() => {
242
242
  const n = (s) => {
243
- const { id: o, widgetJson: l, command: u } = s.data;
244
- if (o === i && l && u === "widgetUpdate") {
243
+ const { id: o, widgetJson: l, command: w } = s.data;
244
+ if (o === d && l && w === "widgetUpdate") {
245
245
  const t = JSON.parse(l);
246
246
  console.log(
247
247
  `[Cabbage-React] Received properties for channelId ${o}`,
@@ -255,63 +255,58 @@ const U = (i) => {
255
255
  }, []), {
256
256
  properties: e
257
257
  };
258
- }, h = (i, e) => {
259
- const { properties: a } = U(i), [n, s] = p(), [o, l] = p(), u = (t) => {
258
+ }, h = (d, e) => {
259
+ const { properties: a } = U(d), [n, s] = p(), [o, l] = p(), w = (t) => {
260
260
  if (s(t), o === void 0) {
261
261
  console.warn(
262
- `[Cabbage-React] parameterIndex not ready for "${i}"`
262
+ `[Cabbage-React] parameterIndex not ready for "${d}"`
263
263
  );
264
264
  return;
265
265
  }
266
- const d = {
266
+ const r = {
267
267
  paramIdx: o,
268
- channel: i,
268
+ channel: d,
269
269
  value: t,
270
270
  channelType: "number"
271
271
  };
272
- f.sendParameterUpdate(d, null);
272
+ f.sendParameterUpdate(r, null);
273
273
  };
274
274
  return M(() => {
275
- var r;
275
+ var m;
276
276
  const t = a == null ? void 0 : a.channels.find(
277
- (g) => g.id === i
277
+ (i) => i.id === d
278
278
  );
279
279
  if (!t) return;
280
- const d = t == null ? void 0 : t.parameterIndex;
281
- o === void 0 && d !== void 0 && (console.log(
280
+ const r = t == null ? void 0 : t.parameterIndex;
281
+ o === void 0 && r !== void 0 && (console.log(
282
282
  `[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,
283
- d
284
- ), l(d));
285
- const c = a == null ? void 0 : a.value;
286
- c != null && (console.log(
287
- `[Cabbage-React] Received initial value for channelId "${i}"`,
288
- c
289
- ), s(c));
290
- const m = (r = t.range) == null ? void 0 : r.defaultValue;
291
- n === void 0 && m !== void 0 && (console.log(
283
+ r
284
+ ), l(r));
285
+ const g = (m = t.range) == null ? void 0 : m.defaultValue;
286
+ n === void 0 && g !== void 0 && (console.log(
292
287
  `[Cabbage-React] Received default value for channelId "${t.id}"`,
293
- m
294
- ), s(m));
288
+ g
289
+ ), s(g));
295
290
  }, [a]), M(() => {
296
- const t = (d) => {
291
+ const t = (r) => {
297
292
  var m;
298
- const { command: c } = d.data;
299
- if (c === "parameterChange") {
293
+ const { command: g } = r.data;
294
+ if (g === "parameterChange") {
300
295
  if (e === !0) return;
301
- const { value: r, paramIdx: g } = d.data.data;
302
- if (g !== o || r === null) return;
296
+ const { value: i, paramIdx: c } = r.data.data;
297
+ if (c !== o || i === null) return;
303
298
  console.log(
304
- `[Cabbage-React] Received parameterChange for parameterIndex ${g}`,
305
- r
306
- ), s(r);
307
- } else if (c === "batchWidgetUpdate") {
308
- const r = d.data.widgets, g = r == null ? void 0 : r.find((b) => b.id === i);
309
- if (!g) return;
310
- const w = JSON.parse(g.widgetJson).channels.find(
311
- (b) => b.id === i
312
- ), I = (m = w == null ? void 0 : w.range) == null ? void 0 : m.value;
299
+ `[Cabbage-React] Received parameterChange for parameterIndex ${c}`,
300
+ i
301
+ ), s(i);
302
+ } else if (g === "batchWidgetUpdate") {
303
+ const i = r.data.widgets, c = i == null ? void 0 : i.find((b) => b.id === d);
304
+ if (!c) return;
305
+ const u = JSON.parse(c.widgetJson).channels.find(
306
+ (b) => b.id === d
307
+ ), I = (m = u == null ? void 0 : u.range) == null ? void 0 : m.value;
313
308
  console.log(
314
- `[Cabbage-React] Received batch widget update for channelId ${g.id}`,
309
+ `[Cabbage-React] Received batch widget update for channelId ${c.id}`,
315
310
  I
316
311
  ), s(I);
317
312
  }
@@ -321,7 +316,7 @@ const U = (i) => {
321
316
  };
322
317
  }, [o, e]), {
323
318
  value: n,
324
- setValue: u,
319
+ setValue: w,
325
320
  parameterIndex: o
326
321
  };
327
322
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",