cabbage-react 1.0.52 → 1.0.54

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.
@@ -3,12 +3,15 @@
3
3
  * This hook listens to messages sent from the backend and updates the local state
4
4
  * whenever new data is received.
5
5
  * @param messageType - The value of the `type` property in the incoming message object to listen for.
6
- * @param onMessage - Callback fires immediately when receiving a new message (synchronous - bypasses state batching)
7
6
  * @param options - Optional configuration
7
+ * @param options.onMessage - Callback fires immediately when receiving a new message (synchronous - bypasses state batching)
8
8
  * @param options.skip - When true, the hook returns a NOP state and never registers listeners
9
+ * @param options.debug - When true, logs incoming messages for this hook to the console for debugging
9
10
  */
10
- export declare const useCabbageMessage: <T>(messageType: string, onMessage?: (message: T) => void, options?: {
11
+ export declare const useCabbageMessage: <T>(messageType: string, options?: {
12
+ onMessage?: (message: T) => void;
11
13
  skip?: boolean;
14
+ debug?: boolean;
12
15
  }) => {
13
16
  message: T | undefined;
14
17
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useCabbageMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageMessage.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAClC,aAAa,MAAM,EACnB,YAAY,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,EAChC,UAAU;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE;;CA4B5B,CAAC"}
1
+ {"version":3,"file":"useCabbageMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageMessage.ts"],"names":[],"mappings":"AAEA;;;;;;;;;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;;CA6BD,CAAC"}
@@ -3,12 +3,15 @@
3
3
  * This hook listens for updates to parameter properties from the backend and updates the local state
4
4
  * whenever new data is received.
5
5
  * @param channelId
6
- * @param onPropertiesUpdate - Callback fires immediately when receiving an update to properties (synchronous - bypasses state batching)
7
6
  * @param options - Optional configuration
7
+ * @param options.onPropertiesUpdate - Callback fires immediately when receiving an update to properties (synchronous - bypasses state batching)
8
8
  * @param options.skip - When true, the hook returns a NOP state and never registers listeners
9
+ * @param options.debug - When true, logs incoming updates to properties for this hook to the console for debugging
9
10
  */
10
- export declare const useCabbageProperties: (channelId: string, onPropertiesUpdate?: (properties: Record<string, any>) => void, options?: {
11
+ export declare const useCabbageProperties: (channelId: string, options?: {
12
+ onPropertiesUpdate?: (properties: Record<string, any>) => void;
11
13
  skip?: boolean;
14
+ debug?: boolean;
12
15
  }) => {
13
16
  properties: Record<string, any> | undefined;
14
17
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,GAChC,WAAW,MAAM,EACjB,qBAAqB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,EAC9D,UAAU;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE;;CAiC5B,CAAC"}
1
+ {"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAEA;;;;;;;;;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;;CAkCD,CAAC"}
@@ -3,15 +3,17 @@
3
3
  * This hook listens for updates to a parameter value from the backend and
4
4
  * sends updates to the backend when the parameter value changes locally (e.g., through a UI slider).
5
5
  * @param channelId
6
- * @param gesture - The gesture type: "begin" (start of interaction), "value" (during interaction), "end" (end of continuous interaction), or "complete" (discrete action e.g. button click).
7
- * @param onValueUpdate - Callback fires immediately when receiving a value update (synchronous - bypasses state batching)
8
6
  * @param options - Optional configuration
7
+ * @param options.onValueUpdate - Callback fires immediately when receiving a value update (synchronous - bypasses state batching)
9
8
  * @param options.skip - When true, the hook returns a NOP state and never registers listeners
9
+ * @param options.debug - When true, logs incoming value updates for this hook to the console for debugging
10
10
  */
11
- export declare const useCabbageState: <T>(channelId: string, gesture?: "begin" | "value" | "end" | "complete", onValueUpdate?: (value: T) => void, options?: {
11
+ export declare const useCabbageState: <T>(channelId: string, options?: {
12
+ onValueUpdate?: (value: T) => void;
12
13
  skip?: boolean;
14
+ debug?: boolean;
13
15
  }) => {
14
16
  value: T | undefined;
15
- setValue: (value: T) => void;
17
+ setValue: (value: T, gesture?: "begin" | "value" | "end" | "complete") => void;
16
18
  };
17
19
  //# sourceMappingURL=useCabbageState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAChC,WAAW,MAAM,EACjB,UAAS,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,UAAuB,EAC5D,gBAAgB,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAClC,UAAU;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE;;sBAWM,CAAC;CA6FnC,CAAC"}
1
+ {"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;;;;;;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;;sBAYO,CAAC,YACC,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU;CAqGhD,CAAC"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react");class C{static sendControlData({channel:e,value:s,gesture:a="complete"},o=null){const n={command:"controlData",channel:e,value:s,gesture:a};o!==null?o.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,o=null){var n={statusByte:e,dataByte1:s,dataByte2:a};const d={command:"midiMessage",obj:JSON.stringify(n)};o!==null?o.postMessage(d):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(d):window.parent!==window?window.parent.postMessage(d,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",d)}static MidiMessageFromHost(e,s,a){}static triggerFileOpenDialog(e,s,a={}){var o={channel:s,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.openAtLastKnownLocation:!0};const n={command:"fileOpen",obj:JSON.stringify(o)};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 o={url:s,file:a};const n={command:"openUrl",obj:JSON.stringify(o)};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 o={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(o):window.parent!==window?window.parent.postMessage(o,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",o)}static consumeKeypresses(e){typeof window.consumeKeypresses=="function"&&window.consumeKeypresses(e)}static sendChannelData(e,s,a=null){var o={channel:e};if(typeof s=="string")o.stringData=s;else if(typeof s=="number")o.floatData=s;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof s);return}const n={command:"channelData",obj:JSON.stringify(o)};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 o={command:e,text:JSON.stringify(a)};if(s!==null)s.postMessage(o);else if(typeof window.sendMessageFromUI=="function")try{const n=window.sendMessageFromUI(o)}catch(n){console.error("Cabbage: sendMessageFromUI threw error:",n),console.error("Cabbage: Error stack:",n.stack)}else window.parent!==window?window.parent.postMessage(o,"*"):(console.error("Cabbage: window.sendMessageFromUI is not available yet. Message:",o),console.error("Cabbage: typeof window.sendMessageFromUI:",typeof window.sendMessageFromUI),console.error("Cabbage: window.sendMessageFromUI value:",window.sendMessageFromUI))}}const y=(t,e,s)=>{if(!t||s?.skip)return{properties:void 0};const[a,o]=l.useState();return l.useEffect(()=>{const n=d=>{const{id:r,widgetJson:m,command:p}=d.data;if(r===t&&m&&p==="widgetUpdate"){const g=JSON.parse(m);console.log(`[Cabbage-React] Received properties for channelId: ${r}`,g),e&&e(g),o(g)}};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[t,e]),{properties:a}},v=(t,e="complete",s,a)=>{if(!t||a?.skip)return{value:void 0,setValue:()=>{}};const{properties:o}=y(t),[n,d]=l.useState(),[r,m]=l.useState(),p=i=>{d(i),C.sendControlData({channel:t,value:i,gesture:e})},g=i=>{s&&s(i),d(i)};return l.useEffect(()=>{const i=o?.channels.find(f=>f.id===t);if(!i)return;const w=i.parameterIndex;if(r===void 0&&w!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId: ${i.id}`,w),m(w)),n!==void 0)return;const c=i.range?.value;c!=null&&(console.log(`[Cabbage-React] Received initial value for channelId: ${i.id}`,c),g(c))},[o]),l.useEffect(()=>{const i=w=>{const{command:c}=w.data;if(c==="parameterChange"){const{value:f,paramIdx:u}=w.data.data;if(u!==r||f===null)return;console.log(`[Cabbage-React] Received parameterChange for parameterIndex: ${u}`,f),g(f)}else if(c==="batchWidgetUpdate"){const u=w.data.widgets?.find(b=>b.id===t);if(!u)return;const M=JSON.parse(u.widgetJson).channels.find(b=>b.id===t)?.range?.value;console.log(`[Cabbage-React] Received batch widget update for channelId: ${u.id}`,M),g(M)}};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[t,s,r]),{value:n,setValue:p}},I=(t,e,s)=>{if(!t||s?.skip)return{message:void 0};const[a,o]=l.useState();return l.useEffect(()=>{const n=d=>{const{data:r,type:m}=d;!r||m!=="message"||r.type===t&&(console.log(`[Cabbage-React] Received data for messageType: ${r.type}`,r),e&&e(r),o(r))};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[t,e]),{message:a}};exports.Cabbage=C;exports.useCabbageMessage=I;exports.useCabbageProperties=y;exports.useCabbageState=v;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react");class b{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 r={command:"midiMessage",obj:JSON.stringify(n)};t!==null?t.postMessage(r):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(r):window.parent!==window?window.parent.postMessage(r,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",r)}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=(i,e)=>{if(!i||e?.skip)return{properties:void 0};const[s,a]=g.useState();return g.useEffect(()=>{const t=n=>{const{id:r,widgetJson:w,command:f}=n.data;if(r===i&&w&&f==="widgetUpdate"){const o=JSON.parse(w);e?.debug&&console.log(`[Cabbage-React] Received properties for channelId: ${r}`,o),e?.onPropertiesUpdate&&e.onPropertiesUpdate(o),a(o)}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[i,e?.onPropertiesUpdate]),{properties:s}},C=(i,e)=>{if(!i||e?.skip)return{value:void 0,setValue:()=>{}};const{properties:s}=M(i),[a,t]=g.useState(),[n,r]=g.useState(),w=(o,d="complete")=>{t(o),b.sendControlData({channel:i,value:o,gesture:d})},f=o=>{e?.onValueUpdate&&e.onValueUpdate(o),t(o)};return g.useEffect(()=>{const o=s?.channels.find(c=>c.id===i);if(!o)return;const d=o.parameterIndex;if(n===void 0&&d!==void 0&&(e?.debug&&console.log(`[Cabbage-React] Received parameterIndex for channelId: ${o.id}`,d),r(d)),a!==void 0)return;const l=o.range?.value;l!=null&&(e?.debug&&console.log(`[Cabbage-React] Received initial value for channelId: ${o.id}`,l),f(l))},[s]),g.useEffect(()=>{const o=d=>{const{command:l}=d.data;if(l==="parameterChange"){const{value:c,paramIdx:u}=d.data.data;if(u!==n||c===null)return;e?.debug&&console.log(`[Cabbage-React] Received parameterChange for parameterIndex: ${u}`,c),f(c)}else if(l==="batchWidgetUpdate"){const u=d.data.widgets?.find(m=>m.id===i);if(!u)return;const p=JSON.parse(u.widgetJson).channels.find(m=>m.id===i)?.range?.value;e?.debug&&console.log(`[Cabbage-React] Received batch widget update for channelId: ${u.id}`,p),f(p)}};return window.addEventListener("message",o),()=>window.removeEventListener("message",o)},[i,e?.onValueUpdate,n]),{value:a,setValue:w}},U=(i,e)=>{if(!i||e?.skip)return{message:void 0};const[s,a]=g.useState();return g.useEffect(()=>{const t=n=>{const{data:r,type:w}=n;!r||w!=="message"||r.type===i&&(e?.debug&&console.log(`[Cabbage-React] Received data for messageType: ${r.type}`,r),e?.onMessage&&e.onMessage(r),a(r))};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[i,e?.onMessage]),{message:s}};exports.Cabbage=b;exports.useCabbageMessage=U;exports.useCabbageProperties=M;exports.useCabbageState=C;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { useState as p, useEffect as u } from "react";
2
- class y {
1
+ import { useState as f, useEffect as u } from "react";
2
+ class M {
3
3
  /**
4
4
  * Send a widget value change to the Cabbage backend.
5
5
  *
@@ -55,13 +55,13 @@ class y {
55
55
  dataByte1: s,
56
56
  dataByte2: a
57
57
  };
58
- const d = {
58
+ const r = {
59
59
  command: "midiMessage",
60
60
  obj: JSON.stringify(n)
61
61
  };
62
- o !== null ? o.postMessage(d) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(d) : window.parent !== window ? window.parent.postMessage(d, "*") : console.error(
62
+ o !== null ? o.postMessage(r) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(r) : window.parent !== window ? window.parent.postMessage(r, "*") : console.error(
63
63
  "Cabbage: window.sendMessageFromUI is not available. Message:",
64
- d
64
+ r
65
65
  );
66
66
  }
67
67
  /**
@@ -287,91 +287,91 @@ class y {
287
287
  ));
288
288
  }
289
289
  }
290
- const v = (t, e, s) => {
291
- if (!t || s?.skip) return { properties: void 0 };
292
- const [a, o] = p();
290
+ const U = (i, e) => {
291
+ if (!i || e?.skip) return { properties: void 0 };
292
+ const [s, a] = f();
293
293
  return u(() => {
294
- const n = (d) => {
295
- const { id: r, widgetJson: c, command: b } = d.data;
296
- if (r === t && c && b === "widgetUpdate") {
297
- const l = JSON.parse(c);
298
- console.log(
294
+ const o = (n) => {
295
+ const { id: r, widgetJson: g, command: m } = n.data;
296
+ if (r === i && g && m === "widgetUpdate") {
297
+ const t = JSON.parse(g);
298
+ e?.debug && console.log(
299
299
  `[Cabbage-React] Received properties for channelId: ${r}`,
300
- l
301
- ), e && e(l), o(l);
300
+ t
301
+ ), e?.onPropertiesUpdate && e.onPropertiesUpdate(t), a(t);
302
302
  }
303
303
  };
304
- return window.addEventListener("message", n), () => window.removeEventListener("message", n);
305
- }, [t, e]), { properties: a };
306
- }, h = (t, e = "complete", s, a) => {
307
- if (!t || a?.skip)
304
+ return window.addEventListener("message", o), () => window.removeEventListener("message", o);
305
+ }, [i, e?.onPropertiesUpdate]), { properties: s };
306
+ }, I = (i, e) => {
307
+ if (!i || e?.skip)
308
308
  return { value: void 0, setValue: () => {
309
309
  } };
310
- const { properties: o } = v(t), [n, d] = p(), [r, c] = p(), b = (i) => {
311
- d(i), y.sendControlData({
312
- channel: t,
313
- value: i,
314
- gesture: e
310
+ const { properties: s } = U(i), [a, o] = f(), [n, r] = f(), g = (t, d = "complete") => {
311
+ o(t), M.sendControlData({
312
+ channel: i,
313
+ value: t,
314
+ gesture: d
315
315
  });
316
- }, l = (i) => {
317
- s && s(i), d(i);
316
+ }, m = (t) => {
317
+ e?.onValueUpdate && e.onValueUpdate(t), o(t);
318
318
  };
319
319
  return u(() => {
320
- const i = o?.channels.find(
321
- (m) => m.id === t
320
+ const t = s?.channels.find(
321
+ (w) => w.id === i
322
322
  );
323
- if (!i) return;
324
- const w = i.parameterIndex;
325
- if (r === void 0 && w !== void 0 && (console.log(
326
- `[Cabbage-React] Received parameterIndex for channelId: ${i.id}`,
327
- w
328
- ), c(w)), n !== void 0) return;
329
- const g = i.range?.value;
330
- g != null && (console.log(
331
- `[Cabbage-React] Received initial value for channelId: ${i.id}`,
332
- g
333
- ), l(g));
334
- }, [o]), u(() => {
335
- const i = (w) => {
336
- const { command: g } = w.data;
337
- if (g === "parameterChange") {
338
- const { value: m, paramIdx: f } = w.data.data;
339
- if (f !== r || m === null) return;
340
- console.log(
341
- `[Cabbage-React] Received parameterChange for parameterIndex: ${f}`,
342
- m
343
- ), l(m);
344
- } else if (g === "batchWidgetUpdate") {
345
- const f = w.data.widgets?.find((M) => M.id === t);
346
- if (!f) return;
347
- const C = JSON.parse(f.widgetJson).channels.find(
348
- (M) => M.id === t
323
+ if (!t) return;
324
+ const d = t.parameterIndex;
325
+ if (n === void 0 && d !== void 0 && (e?.debug && console.log(
326
+ `[Cabbage-React] Received parameterIndex for channelId: ${t.id}`,
327
+ d
328
+ ), r(d)), a !== void 0) return;
329
+ const l = t.range?.value;
330
+ l != null && (e?.debug && console.log(
331
+ `[Cabbage-React] Received initial value for channelId: ${t.id}`,
332
+ l
333
+ ), m(l));
334
+ }, [s]), u(() => {
335
+ const t = (d) => {
336
+ const { command: l } = d.data;
337
+ if (l === "parameterChange") {
338
+ const { value: w, paramIdx: c } = d.data.data;
339
+ if (c !== n || w === null) return;
340
+ e?.debug && console.log(
341
+ `[Cabbage-React] Received parameterChange for parameterIndex: ${c}`,
342
+ w
343
+ ), m(w);
344
+ } else if (l === "batchWidgetUpdate") {
345
+ const c = d.data.widgets?.find((p) => p.id === i);
346
+ if (!c) return;
347
+ const b = JSON.parse(c.widgetJson).channels.find(
348
+ (p) => p.id === i
349
349
  )?.range?.value;
350
- console.log(
351
- `[Cabbage-React] Received batch widget update for channelId: ${f.id}`,
352
- C
353
- ), l(C);
350
+ e?.debug && console.log(
351
+ `[Cabbage-React] Received batch widget update for channelId: ${c.id}`,
352
+ b
353
+ ), m(b);
354
354
  }
355
355
  };
356
- return window.addEventListener("message", i), () => window.removeEventListener("message", i);
357
- }, [t, s, r]), { value: n, setValue: b };
358
- }, L = (t, e, s) => {
359
- if (!t || s?.skip) return { message: void 0 };
360
- const [a, o] = p();
356
+ return window.addEventListener("message", t), () => window.removeEventListener("message", t);
357
+ }, [i, e?.onValueUpdate, n]), { value: a, setValue: g };
358
+ }, F = (i, e) => {
359
+ if (!i || e?.skip) return { message: void 0 };
360
+ const [s, a] = f();
361
361
  return u(() => {
362
- const n = (d) => {
363
- const { data: r, type: c } = d;
364
- !r || c !== "message" || r.type === t && (console.log(
362
+ const o = (n) => {
363
+ const { data: r, type: g } = n;
364
+ !r || g !== "message" || r.type === i && (e?.debug && console.log(
365
365
  `[Cabbage-React] Received data for messageType: ${r.type}`,
366
366
  r
367
- ), e && e(r), o(r));
367
+ ), e?.onMessage && e.onMessage(r), a(r));
368
368
  };
369
- return window.addEventListener("message", n), () => window.removeEventListener("message", n);
370
- }, [t, e]), { message: a };
369
+ return window.addEventListener("message", o), () => window.removeEventListener("message", o);
370
+ }, [i, e?.onMessage]), { message: s };
371
371
  };
372
372
  export {
373
- y as Cabbage,
374
- L as useCabbageMessage,
375
- v as useCabbageProperties,
376
- h as useCabbageState
373
+ M as Cabbage,
374
+ F as useCabbageMessage,
375
+ U as useCabbageProperties,
376
+ I as useCabbageState
377
377
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.52",
3
+ "version": "1.0.54",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",