cabbage-react 1.0.22 → 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(o===void 0){console.warn(`[Cabbage-React] parameterIndex not ready for "${i}"`);return}s(t);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,64 +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) => {
260
- if (o === void 0) {
258
+ }, h = (d, e) => {
259
+ const { properties: a } = U(d), [n, s] = p(), [o, l] = p(), w = (t) => {
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
- s(t);
267
- const d = {
266
+ const r = {
268
267
  paramIdx: o,
269
- channel: i,
268
+ channel: d,
270
269
  value: t,
271
270
  channelType: "number"
272
271
  };
273
- f.sendParameterUpdate(d, null);
272
+ f.sendParameterUpdate(r, null);
274
273
  };
275
274
  return M(() => {
276
- var r;
275
+ var m;
277
276
  const t = a == null ? void 0 : a.channels.find(
278
- (g) => g.id === i
277
+ (i) => i.id === d
279
278
  );
280
279
  if (!t) return;
281
- const d = t == null ? void 0 : t.parameterIndex;
282
- 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(
283
282
  `[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,
284
- d
285
- ), l(d));
286
- const c = a == null ? void 0 : a.value;
287
- c != null && (console.log(
288
- `[Cabbage-React] Received initial value for channelId "${i}"`,
289
- c
290
- ), s(c));
291
- const m = (r = t.range) == null ? void 0 : r.defaultValue;
292
- 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(
293
287
  `[Cabbage-React] Received default value for channelId "${t.id}"`,
294
- m
295
- ), s(m));
288
+ g
289
+ ), s(g));
296
290
  }, [a]), M(() => {
297
- const t = (d) => {
291
+ const t = (r) => {
298
292
  var m;
299
- const { command: c } = d.data;
300
- if (c === "parameterChange") {
293
+ const { command: g } = r.data;
294
+ if (g === "parameterChange") {
301
295
  if (e === !0) return;
302
- const { value: r, paramIdx: g } = d.data.data;
303
- if (g !== o || r === null) return;
296
+ const { value: i, paramIdx: c } = r.data.data;
297
+ if (c !== o || i === null) return;
304
298
  console.log(
305
- `[Cabbage-React] Received parameterChange for parameterIndex ${g}`,
306
- r
307
- ), s(r);
308
- } else if (c === "batchWidgetUpdate") {
309
- const r = d.data.widgets, g = r == null ? void 0 : r.find((b) => b.id === i);
310
- if (!g) return;
311
- const w = JSON.parse(g.widgetJson).channels.find(
312
- (b) => b.id === i
313
- ), 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;
314
308
  console.log(
315
- `[Cabbage-React] Received batch widget update for channelId ${g.id}`,
309
+ `[Cabbage-React] Received batch widget update for channelId ${c.id}`,
316
310
  I
317
311
  ), s(I);
318
312
  }
@@ -322,7 +316,7 @@ const U = (i) => {
322
316
  };
323
317
  }, [o, e]), {
324
318
  value: n,
325
- setValue: u,
319
+ setValue: w,
326
320
  parameterIndex: o
327
321
  };
328
322
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",