cabbage-react 1.0.58 → 1.0.59

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":"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;;CAkCD,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;;CA+BD,CAAC"}
@@ -1 +1 @@
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;;CAuCD,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;;CAoCD,CAAC"}
@@ -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;;sBAwBO,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;CAiFhD,CAAC"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
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 i={command:"midiMessage",obj:JSON.stringify(a)};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,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.useRef(void 0);s.current=b(`useCabbageProperties:${o}`,e?.debug);const[n,t]=d.useState();return d.useEffect(()=>{const a=i=>{const{id:g,widgetJson:u,command:f}=i.data;if(g===o&&u&&f==="widgetUpdate"){const r=JSON.parse(u);s.current?.("Received properties",r),e?.onPropertiesUpdate&&e.onPropertiesUpdate(r),t(r)}};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[o,e?.onPropertiesUpdate]),{properties:n}},v=(o,e)=>{if(!o||e?.skip)return{value:void 0,setValue:()=>{}};const s=d.useRef(void 0);s.current=b(`useCabbageState:${o}`,e?.debug);const{properties:n}=U(o,{debug:e?.debug}),[t,a]=d.useState(),[i,g]=d.useState(),u=(r,l="complete")=>{a(r),C.sendControlData({channel:o,value:r,gesture:l})},f=r=>{e?.onValueUpdate&&e.onValueUpdate(r),a(r)};return d.useEffect(()=>{const r=n?.channels.find(c=>c.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))},[n]),d.useEffect(()=>{const r=l=>{const{command:w}=l.data;if(w==="parameterChange"){const{value:c,paramIdx:m}=l.data.data;if(m!==i||c===null)return;s.current?.("Received parameterChange",c),f(c)}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:u}},y=(o,e)=>{if(!o||e?.skip)return{message:void 0};const s=d.useRef(void 0);s.current=b(`useCabbageMessage:${o}`,e?.debug);const[n,t]=d.useState();return d.useEffect(()=>{const a=i=>{const{data:g,type:u}=i;!g||u!=="message"||g.type===o&&(s.current?.("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=y;exports.useCabbageProperties=U;exports.useCabbageState=v;
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;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { useRef as M, useState as f, useEffect as p } from "react";
2
- class v {
1
+ import { useRef as b, useState as f, useEffect as p } from "react";
2
+ class C {
3
3
  /**
4
4
  * Send a widget value change to the Cabbage backend.
5
5
  *
@@ -291,13 +291,10 @@ const U = (o, e) => (...s) => {
291
291
  e && console.log(`[Cabbage-React][${o}]`, ...s);
292
292
  }, y = (o, e) => {
293
293
  if (!o || e?.skip) return { properties: void 0 };
294
- const s = M(
294
+ const s = b(
295
295
  void 0
296
296
  );
297
- s.current = U(
298
- `useCabbageProperties:${o}`,
299
- e?.debug
300
- );
297
+ s.current = U(o, e?.debug);
301
298
  const [a, t] = f();
302
299
  return p(() => {
303
300
  const n = (i) => {
@@ -313,17 +310,14 @@ const U = (o, e) => (...s) => {
313
310
  if (!o || e?.skip)
314
311
  return { value: void 0, setValue: () => {
315
312
  } };
316
- const s = M(
313
+ const s = b(
317
314
  void 0
318
315
  );
319
- s.current = U(
320
- `useCabbageState:${o}`,
321
- e?.debug
322
- );
316
+ s.current = U(o, e?.debug);
323
317
  const { properties: a } = y(o, {
324
318
  debug: e?.debug
325
319
  }), [t, n] = f(), [i, d] = f(), l = (r, g = "complete") => {
326
- n(r), v.sendControlData({
320
+ n(r), C.sendControlData({
327
321
  channel: o,
328
322
  value: r,
329
323
  gesture: g
@@ -348,25 +342,22 @@ const U = (o, e) => (...s) => {
348
342
  if (m !== i || c === null) return;
349
343
  s.current?.("Received parameterChange", c), u(c);
350
344
  } else if (w === "batchWidgetUpdate") {
351
- const m = g.data.widgets?.find((b) => b.id === o);
345
+ const m = g.data.widgets?.find((M) => M.id === o);
352
346
  if (!m) return;
353
- const C = JSON.parse(m.widgetJson).channels.find(
354
- (b) => b.id === o
347
+ const v = JSON.parse(m.widgetJson).channels.find(
348
+ (M) => M.id === o
355
349
  )?.range?.value;
356
- s.current?.("Received batchWidgetUpdate", C), u(C);
350
+ s.current?.("Received batchWidgetUpdate", v), u(v);
357
351
  }
358
352
  };
359
353
  return window.addEventListener("message", r), () => window.removeEventListener("message", r);
360
354
  }, [o, e?.onValueUpdate, i]), { value: t, setValue: l };
361
355
  }, R = (o, e) => {
362
356
  if (!o || e?.skip) return { message: void 0 };
363
- const s = M(
357
+ const s = b(
364
358
  void 0
365
359
  );
366
- s.current = U(
367
- `useCabbageMessage:${o}`,
368
- e?.debug
369
- );
360
+ s.current = U(o, e?.debug);
370
361
  const [a, t] = f();
371
362
  return p(() => {
372
363
  const n = (i) => {
@@ -377,7 +368,7 @@ const U = (o, e) => (...s) => {
377
368
  }, [o, e?.onMessage]), { message: a };
378
369
  };
379
370
  export {
380
- v as Cabbage,
371
+ C as Cabbage,
381
372
  R as useCabbageMessage,
382
373
  y as useCabbageProperties,
383
374
  L as useCabbageState
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.58",
3
+ "version": "1.0.59",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",