cabbage-react 1.0.60 → 1.0.61

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":"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;;sBAqBO,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;;sBAqBO,CAAC,YACC,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU;CAuFhD,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 b=(o,e)=>(...s)=>{e&&console.log(`[Cabbage-React] ${o}:`,...s)},C=(o,e)=>{if(!o||e?.skip)return{properties:void 0};const s=d.useRef(void 0);s.current=b(o,e?.debug);const[a,t]=d.useState();return d.useEffect(()=>{const n=i=>{const{id:g,widgetJson:c,command:f}=i.data;if(g===o&&c&&f==="widgetUpdate"){const r=JSON.parse(c);s.current?.("Received properties",r),e?.onPropertiesUpdate&&e.onPropertiesUpdate(r),t(r)}};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[o,e?.onPropertiesUpdate]),{properties:a}},v=(o,e)=>{if(!o||e?.skip)return{value:void 0,setValue:()=>{}};const s=d.useRef(void 0);s.current=b(o,e?.debug);const{properties:a}=C(o,{debug:e?.debug}),[t,n]=d.useState(),[i,g]=d.useState(),c=(r,l="complete")=>{n(r),U.sendControlData({channel:o,value:r,gesture:l})},f=r=>{e?.onValueUpdate&&e.onValueUpdate(r),n(r)};return d.useEffect(()=>{const r=a?.channels.find(u=>u.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))},[a]),d.useEffect(()=>{const r=l=>{const{command:w}=l.data;if(w==="parameterChange"){const{value:u,paramIdx:m}=l.data.data;if(m!==i||u===null)return;s.current?.("Received parameterChange",u),f(u)}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:c}},y=(o,e)=>{if(!o||e?.skip)return{message:void 0};const s=d.useRef(void 0);s.current=b(o,e?.debug);const[a,t]=d.useState();return d.useEffect(()=>{const n=i=>{const{data:g,type:c}=i;!g||c!=="message"||g.type===o&&(s.current?.("Received data",g),e?.onMessage&&e.onMessage(g),t(g))};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[o,e?.onMessage]),{message:a}};exports.Cabbage=U;exports.useCabbageMessage=y;exports.useCabbageProperties=C;exports.useCabbageState=v;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react");class v{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)},y=(o,e)=>{if(!o||e?.skip)return{properties:void 0};const s=d.useRef(void 0);s.current=M(o,e?.debug);const[a,t]=d.useState();return d.useEffect(()=>{const n=i=>{const{id:g,widgetJson:c,command:u}=i.data;if(g===o&&c&&u==="widgetUpdate"){const r=JSON.parse(c);s.current?.("Received properties",r),e?.onPropertiesUpdate&&e.onPropertiesUpdate(r),t(r)}};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[o,e?.onPropertiesUpdate]),{properties:a}},F=(o,e)=>{if(!o||e?.skip)return{value:void 0,setValue:()=>{}};const s=d.useRef(void 0);s.current=M(o,e?.debug);const{properties:a}=y(o,{debug:e?.debug}),[t,n]=d.useState(),[i,g]=d.useState(),c=(r,l="complete")=>{n(r),v.sendControlData({channel:o,value:r,gesture:l})},u=r=>{e?.onValueUpdate&&e.onValueUpdate(r),n(r)};return d.useEffect(()=>{const r=a?.channels.find(f=>f.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),u(w))},[a]),d.useEffect(()=>{const r=l=>{const{command:w}=l.data;if(w==="parameterChange"){const{value:f,paramIdx:m}=l.data.data;if(m!==i||f===null)return;s.current?.("Received parameterChange",f),u(f)}else if(w==="batchWidgetUpdate"){const m=l.data.widgets?.find(b=>b.id===o);if(!m)return;const p=JSON.parse(m.widgetJson).channels.find(b=>b.id===o),U=p?.range?.value,C=p?.stringValue;p?.type==="string"?(s.current?.("Received batchWidgetUpdate",C),u(C)):(s.current?.("Received batchWidgetUpdate",U),u(U))}};return window.addEventListener("message",r),()=>window.removeEventListener("message",r)},[o,e?.onValueUpdate,i]),{value:t,setValue:c}},I=(o,e)=>{if(!o||e?.skip)return{message:void 0};const s=d.useRef(void 0);s.current=M(o,e?.debug);const[a,t]=d.useState();return d.useEffect(()=>{const n=i=>{const{data:g,type:c}=i;!g||c!=="message"||g.type===o&&(s.current?.("Received data",g),e?.onMessage&&e.onMessage(g),t(g))};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[o,e?.onMessage]),{message:a}};exports.Cabbage=v;exports.useCabbageMessage=I;exports.useCabbageProperties=y;exports.useCabbageState=F;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { useRef as b, useState as f, useEffect as p } from "react";
2
- class C {
1
+ import { useRef as U, useState as f, useEffect as p } from "react";
2
+ class F {
3
3
  /**
4
4
  * Send a widget value change to the Cabbage backend.
5
5
  *
@@ -287,77 +287,77 @@ class C {
287
287
  ));
288
288
  }
289
289
  }
290
- const U = (o, e) => (...s) => {
290
+ const v = (o, e) => (...s) => {
291
291
  e && console.log(`[Cabbage-React] ${o}:`, ...s);
292
- }, y = (o, e) => {
292
+ }, I = (o, e) => {
293
293
  if (!o || e?.skip) return { properties: void 0 };
294
- const s = b(
294
+ const s = U(
295
295
  void 0
296
296
  );
297
- s.current = U(o, e?.debug);
297
+ s.current = v(o, e?.debug);
298
298
  const [a, t] = f();
299
299
  return p(() => {
300
300
  const n = (i) => {
301
- const { id: d, widgetJson: l, command: u } = i.data;
302
- if (d === o && l && u === "widgetUpdate") {
301
+ const { id: d, widgetJson: l, command: c } = i.data;
302
+ if (d === o && l && c === "widgetUpdate") {
303
303
  const r = JSON.parse(l);
304
304
  s.current?.("Received properties", r), e?.onPropertiesUpdate && e.onPropertiesUpdate(r), t(r);
305
305
  }
306
306
  };
307
307
  return window.addEventListener("message", n), () => window.removeEventListener("message", n);
308
308
  }, [o, e?.onPropertiesUpdate]), { properties: a };
309
- }, L = (o, e) => {
309
+ }, R = (o, e) => {
310
310
  if (!o || e?.skip)
311
311
  return { value: void 0, setValue: () => {
312
312
  } };
313
- const s = b(
313
+ const s = U(
314
314
  void 0
315
315
  );
316
- s.current = U(o, e?.debug);
317
- const { properties: a } = y(o, {
316
+ s.current = v(o, e?.debug);
317
+ const { properties: a } = I(o, {
318
318
  debug: e?.debug
319
319
  }), [t, n] = f(), [i, d] = f(), l = (r, g = "complete") => {
320
- n(r), C.sendControlData({
320
+ n(r), F.sendControlData({
321
321
  channel: o,
322
322
  value: r,
323
323
  gesture: g
324
324
  });
325
- }, u = (r) => {
325
+ }, c = (r) => {
326
326
  e?.onValueUpdate && e.onValueUpdate(r), n(r);
327
327
  };
328
328
  return p(() => {
329
329
  const r = a?.channels.find(
330
- (c) => c.id === o
330
+ (u) => u.id === o
331
331
  );
332
332
  if (!r) return;
333
333
  const g = r.parameterIndex;
334
334
  if (i === void 0 && g !== void 0 && (s.current?.("Received parameterIndex", g), d(g)), t !== void 0) return;
335
335
  const w = r.range?.value;
336
- w != null && (s.current?.("Received initial value", w), u(w));
336
+ w != null && (s.current?.("Received initial value", w), c(w));
337
337
  }, [a]), p(() => {
338
338
  const r = (g) => {
339
339
  const { command: w } = g.data;
340
340
  if (w === "parameterChange") {
341
- const { value: c, paramIdx: m } = g.data.data;
342
- if (m !== i || c === null) return;
343
- s.current?.("Received parameterChange", c), u(c);
341
+ const { value: u, paramIdx: m } = g.data.data;
342
+ if (m !== i || u === null) return;
343
+ s.current?.("Received parameterChange", u), c(u);
344
344
  } else if (w === "batchWidgetUpdate") {
345
345
  const m = g.data.widgets?.find((M) => M.id === o);
346
346
  if (!m) return;
347
- const v = JSON.parse(m.widgetJson).channels.find(
347
+ const b = JSON.parse(m.widgetJson).channels.find(
348
348
  (M) => M.id === o
349
- )?.range?.value;
350
- s.current?.("Received batchWidgetUpdate", v), u(v);
349
+ ), C = b?.range?.value, y = b?.stringValue;
350
+ b?.type === "string" ? (s.current?.("Received batchWidgetUpdate", y), c(y)) : (s.current?.("Received batchWidgetUpdate", C), c(C));
351
351
  }
352
352
  };
353
353
  return window.addEventListener("message", r), () => window.removeEventListener("message", r);
354
354
  }, [o, e?.onValueUpdate, i]), { value: t, setValue: l };
355
- }, R = (o, e) => {
355
+ }, V = (o, e) => {
356
356
  if (!o || e?.skip) return { message: void 0 };
357
- const s = b(
357
+ const s = U(
358
358
  void 0
359
359
  );
360
- s.current = U(o, e?.debug);
360
+ s.current = v(o, e?.debug);
361
361
  const [a, t] = f();
362
362
  return p(() => {
363
363
  const n = (i) => {
@@ -368,8 +368,8 @@ const U = (o, e) => (...s) => {
368
368
  }, [o, e?.onMessage]), { message: a };
369
369
  };
370
370
  export {
371
- C as Cabbage,
372
- R as useCabbageMessage,
373
- y as useCabbageProperties,
374
- L as useCabbageState
371
+ F as Cabbage,
372
+ V as useCabbageMessage,
373
+ I as useCabbageProperties,
374
+ R as useCabbageState
375
375
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.60",
3
+ "version": "1.0.61",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",