cabbage-react 1.0.4 → 1.0.6

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.
@@ -4,17 +4,17 @@ export class Cabbage {
4
4
  * This function automatically routes messages to the appropriate backend function
5
5
  * based on the automatable flag:
6
6
  *
7
- * - automatable=1: Routes to sendParameterUpdate for real-time parameter control /
8
- * this also sends the value as channel data to Csound
7
+ * - automatable=true: Routes to sendParameterUpdate for real-time parameter control /
8
+ * this also sends the value as channel data to Csound
9
9
  *
10
- * - automatable=0: Routes to sendChannelData for string/numeric data transmission
10
+ * - automatable=false: Routes to sendChannelData for string/numeric data transmission
11
11
  *
12
12
  * All widget interactions should use this function instead of calling the lower-level
13
13
  * sendParameterUpdate or sendChannelData functions directly.
14
14
  */
15
- static sendChannelUpdate(message: any, vscode?: null, automatable?: number): void;
15
+ static sendChannelUpdate(message: any, vscode?: null, automatable?: boolean): void;
16
16
  static sendParameterUpdate(message: any, vscode?: null): void;
17
- static sendCustomCommand(command: any, vscode?: null): void;
17
+ static sendCustomCommand(command: any, vscode?: null, additionalData?: {}): void;
18
18
  static sendWidgetUpdate(widget: any, vscode?: null): void;
19
19
  static sendMidiMessageFromUI(statusByte: any, dataByte1: any, dataByte2: any, vscode?: null): void;
20
20
  static sendChannelData(channel: any, data: any, vscode?: null): void;
@@ -1 +1 @@
1
- {"version":3,"file":"cabbage.d.ts","sourceRoot":"","sources":["../../src/cabbage/cabbage.js"],"names":[],"mappings":"AAMA;IAEE;;;;;;;;;;;;OAYG;IACH,kFASC;IAED,8DAcC;IAED,4DAYC;IAED,0DAYC;IAED,mGAmBC;IAED,qEA2BC;IAED,kFAEC;IAED,4EAkBC;IAED,uDAgBC;CAGF"}
1
+ {"version":3,"file":"cabbage.d.ts","sourceRoot":"","sources":["../../src/cabbage/cabbage.js"],"names":[],"mappings":"AAMA;IACC;;;;;;;;;;;;OAYG;IACH,mFAYC;IAED,8DAsCC;IAED,iFAiCC;IAED,0DAiBC;IAED,mGA6BC;IAED,qEAoCC;IAED,kFASC;IAED,4EA2BC;IAED,uDAsBC;CACD"}
@@ -5,6 +5,6 @@
5
5
  */
6
6
  export declare const useCabbageState: <T>(channelId: string) => {
7
7
  value: T | undefined;
8
- setValue: (value?: T, stringData?: string) => void;
8
+ setValue: (value: T) => void;
9
9
  };
10
10
  //# sourceMappingURL=useCabbageState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,aAAa,MAAM;;uBAKhB,CAAC,eAAe,MAAM;CA4EzD,CAAC"}
1
+ {"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,aAAa,MAAM;;sBAMjB,CAAC;CAmFnC,CAAC"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react");console.log("Cabbage: loading cabbage.js");class g{static sendChannelUpdate(e,n=null,a=0){if(a===1)g.sendParameterUpdate(e,n);else{const t=e.value!==void 0?e.value:e.stringData||e.floatData;g.sendChannelData(e.channel,t,n)}}static sendParameterUpdate(e,n=null){const a={command:"parameterChange",...e};console.log("Cabbage.sendParameterUpdate:",e,"vscode:",n,"msg:",a),n!==null?(console.log("Sending via vscode.postMessage"),n.postMessage(a)):(console.log("Sending via window.sendMessageFromUI"),window.sendMessageFromUI(a))}static sendCustomCommand(e,n=null){const a={command:e,text:JSON.stringify({})};console.log("Cabbage: sending custom command from UI",a),n!==null?n.postMessage(a):window.sendMessageFromUI(a)}static sendWidgetUpdate(e,n=null){console.log("Cabbage: sending widget update from UI",e.props);const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};n!==null?n.postMessage(a):window.sendMessageFromUI(a)}static sendMidiMessageFromUI(e,n,a,t=null){var s={statusByte:e,dataByte1:n,dataByte2:a};const o={command:"midiMessage",obj:JSON.stringify(s)};console.log("Cabbage: sending midi message from UI",s),t!==null?t.postMessage(o):window.sendMessageFromUI(o)}static sendChannelData(e,n,a=null){var t={channel:e};if(typeof n=="string")t.stringData=n;else if(typeof n=="number")t.floatData=n;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof n);return}const s={command:"channelData",obj:JSON.stringify(t)};console.log("Cabbage: sending channel data from UI",t),a!==null?a.postMessage(s):window.sendMessageFromUI(s)}static MidiMessageFromHost(e,n,a){console.log("Cabbage: Got MIDI Message"+e+":"+n+":"+a)}static triggerFileOpenDialog(e,n,a={}){var t={channel:n,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.openAtLastKnownLocation:!0};const s={command:"fileOpen",obj:JSON.stringify(t)};e!==null?e.postMessage(s):window.sendMessageFromUI(s)}static openUrl(e,n,a){var t={url:n,file:a};const s={command:"openUrl",obj:JSON.stringify(t)};e!==null?e.postMessage(s):window.sendMessageFromUI(s)}}const m=r=>{const[e,n]=d.useState();return d.useEffect(()=>{const a=t=>{const{id:s,widgetJson:o,command:l}=t.data;if(s===r&&o&&l==="widgetUpdate"){const i=JSON.parse(o);console.log(`[Cabbage-React] Received properties for channelId ${s}`,i),n(i)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:e}},u=r=>{const{properties:e}=m(r),[n,a]=d.useState(),t=(s,o)=>{a(s);const l={channel:r,value:s,stringData:o};g.sendParameterUpdate(l,null)};return d.useEffect(()=>{var i;const s=e==null?void 0:e.value;if(s!=null){console.log(`[Cabbage-React] Received initial value for channelId "${r}"`,s),a(s);return}const o=e==null?void 0:e.channels.find(c=>c.id===r);if(!o)return;const l=(i=o.range)==null?void 0:i.defaultValue;n===void 0&&l!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${o.id}"`,l),a(l))},[e]),d.useEffect(()=>{const s=o=>{const{command:l}=o.data;if(l==="parameterChange"){const{value:i,paramIdx:c}=o.data;if(i===null)return;console.log(`[Cabbage-React] Received value change for parameterIndex ${c}`,i),a(i)}};return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},[]),{value:n,setValue:t}};exports.Cabbage=g;exports.useCabbageProperties=m;exports.useCabbageState=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react");console.log("Cabbage: loading cabbage.js");class u{static sendChannelUpdate(e,n=null,a=!1){if(a===!0||a===1)u.sendParameterUpdate(e,n);else{const s=e.value!==void 0?e.value:e.stringData||e.floatData;u.sendChannelData(e.channel,s,n)}}static sendParameterUpdate(e,n=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 a={command:"parameterChange",paramIdx:e.paramIdx,channel:e.channel,value:e.value,channelType:e.channelType||"number"};n!==null?n.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static sendCustomCommand(e,n=null,a={}){const s={command:e,text:JSON.stringify(a)};if(n!==null)n.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,n=null){const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};n!==null?n.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static sendMidiMessageFromUI(e,n,a,s=null){var o={statusByte:e,dataByte1:n,dataByte2:a};const i={command:"midiMessage",obj:JSON.stringify(o)};s!==null?s.postMessage(i):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(i):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",i)}static sendChannelData(e,n,a=null){var s={channel:e};if(typeof n=="string")s.stringData=n;else if(typeof n=="number")s.floatData=n;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof n);return}const o={command:"channelData",obj:JSON.stringify(s)};console.log("Cabbage: sending channel data from UI",s),a!==null?a.postMessage(o):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(o):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",o)}static MidiMessageFromHost(e,n,a){console.log("Cabbage: Got MIDI Message"+e+":"+n+":"+a)}static triggerFileOpenDialog(e,n,a={}){var s={channel:n,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.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,n,a){var s={url:n,file:a};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)}}const f=d=>{const[e,n]=c.useState();return c.useEffect(()=>{const a=s=>{const{id:o,widgetJson:i,command:t}=s.data;if(o===d&&i&&t==="widgetUpdate"){const r=JSON.parse(i);console.log(`[Cabbage-React] Received properties for channelId ${o}`,r),n(r)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:e}},w=d=>{const{properties:e}=f(d),[n,a]=c.useState(),[s,o]=c.useState(),i=t=>{a(t);const r={channel:d,paramIdx:s,value:t};u.sendParameterUpdate(r,null)};return c.useEffect(()=>{var m;const t=e==null?void 0:e.channels.find(b=>b.id===d);if(!t)return;const r=t==null?void 0:t.parameterIndex;s===void 0&&r!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,r),o(r));const g=e==null?void 0:e.value;g!=null&&(console.log(`[Cabbage-React] Received initial value for channelId "${d}"`,g),a(g));const l=(m=t.range)==null?void 0:m.defaultValue;n===void 0&&l!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${t.id}"`,l),a(l))},[e]),c.useEffect(()=>{const t=r=>{const{command:g}=r.data;if(g==="parameterChange"){const{value:l,paramIdx:m}=r.data;if(m!==s||l===null)return;console.log(`[Cabbage-React] Received value change for parameterIndex ${m}`,l),a(l)}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[]),{value:n,setValue:i}};exports.Cabbage=u;exports.useCabbageProperties=f;exports.useCabbageState=w;
package/dist/index.mjs CHANGED
@@ -1,177 +1,238 @@
1
- import { useState as m, useEffect as c } from "react";
1
+ import { useState as f, useEffect as u } from "react";
2
2
  console.log("Cabbage: loading cabbage.js");
3
- class d {
3
+ class m {
4
4
  /**
5
5
  * Main entry point for sending any data from UI widgets to the Cabbage backend.
6
6
  * This function automatically routes messages to the appropriate backend function
7
7
  * based on the automatable flag:
8
- *
9
- * - automatable=1: Routes to sendParameterUpdate for real-time parameter control /
10
- * this also sends the value as channel data to Csound
11
- *
12
- * - automatable=0: Routes to sendChannelData for string/numeric data transmission
13
- *
8
+ *
9
+ * - automatable=true: Routes to sendParameterUpdate for real-time parameter control /
10
+ * this also sends the value as channel data to Csound
11
+ *
12
+ * - automatable=false: Routes to sendChannelData for string/numeric data transmission
13
+ *
14
14
  * All widget interactions should use this function instead of calling the lower-level
15
15
  * sendParameterUpdate or sendChannelData functions directly.
16
16
  */
17
- static sendChannelUpdate(e, a = null, n = 0) {
18
- if (n === 1)
19
- d.sendParameterUpdate(e, a);
17
+ static sendChannelUpdate(e, n = null, a = !1) {
18
+ if (a === !0 || a === 1)
19
+ m.sendParameterUpdate(e, n);
20
20
  else {
21
- const t = e.value !== void 0 ? e.value : e.stringData || e.floatData;
22
- d.sendChannelData(e.channel, t, a);
21
+ const s = e.value !== void 0 ? e.value : e.stringData || e.floatData;
22
+ m.sendChannelData(e.channel, s, n);
23
23
  }
24
24
  }
25
- static sendParameterUpdate(e, a = null) {
26
- const n = {
25
+ static sendParameterUpdate(e, n = null) {
26
+ if (e.paramIdx === void 0 || e.paramIdx === null) {
27
+ console.error(
28
+ "Cabbage.sendParameterUpdate: message missing paramIdx!",
29
+ e
30
+ );
31
+ return;
32
+ }
33
+ if (e.paramIdx < 0) {
34
+ console.warn(
35
+ "Cabbage.sendParameterUpdate: paramIdx is -1, skipping (non-automatable widget)",
36
+ e
37
+ );
38
+ return;
39
+ }
40
+ const a = {
27
41
  command: "parameterChange",
28
- ...e
29
- };
30
- console.log("Cabbage.sendParameterUpdate:", e, "vscode:", a, "msg:", n), a !== null ? (console.log("Sending via vscode.postMessage"), a.postMessage(n)) : (console.log("Sending via window.sendMessageFromUI"), window.sendMessageFromUI(n));
42
+ paramIdx: e.paramIdx,
43
+ channel: e.channel,
44
+ value: e.value,
45
+ channelType: e.channelType || "number"
46
+ };
47
+ n !== null ? n.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : console.error(
48
+ "Cabbage: window.sendMessageFromUI is not available. Message:",
49
+ a
50
+ );
31
51
  }
32
- static sendCustomCommand(e, a = null) {
33
- const n = {
52
+ static sendCustomCommand(e, n = null, a = {}) {
53
+ const s = {
34
54
  command: e,
35
- text: JSON.stringify({})
36
- };
37
- console.log("Cabbage: sending custom command from UI", n), a !== null ? a.postMessage(n) : window.sendMessageFromUI(n);
55
+ text: JSON.stringify(a)
56
+ };
57
+ if (n !== null)
58
+ n.postMessage(s);
59
+ else if (typeof window.sendMessageFromUI == "function") {
60
+ console.log("Cabbage: Calling window.sendMessageFromUI with:", s);
61
+ try {
62
+ const o = window.sendMessageFromUI(s);
63
+ console.log("Cabbage: sendMessageFromUI returned:", o);
64
+ } catch (o) {
65
+ console.error("Cabbage: sendMessageFromUI threw error:", o), console.error("Cabbage: Error stack:", o.stack);
66
+ }
67
+ } else
68
+ console.error(
69
+ "Cabbage: window.sendMessageFromUI is not available yet. Message:",
70
+ s
71
+ ), console.error(
72
+ "Cabbage: typeof window.sendMessageFromUI:",
73
+ typeof window.sendMessageFromUI
74
+ ), console.error(
75
+ "Cabbage: window.sendMessageFromUI value:",
76
+ window.sendMessageFromUI
77
+ );
38
78
  }
39
- static sendWidgetUpdate(e, a = null) {
40
- console.log("Cabbage: sending widget update from UI", e.props);
41
- const n = {
79
+ static sendWidgetUpdate(e, n = null) {
80
+ const a = {
42
81
  command: "widgetStateUpdate",
43
82
  obj: JSON.stringify(CabbageUtils.sanitizeForEditor(e))
44
83
  };
45
- a !== null ? a.postMessage(n) : window.sendMessageFromUI(n);
84
+ n !== null ? n.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : console.error(
85
+ "Cabbage: window.sendMessageFromUI is not available. Message:",
86
+ a
87
+ );
46
88
  }
47
- static sendMidiMessageFromUI(e, a, n, t = null) {
48
- var s = {
89
+ static sendMidiMessageFromUI(e, n, a, s = null) {
90
+ var o = {
49
91
  statusByte: e,
50
- dataByte1: a,
51
- dataByte2: n
92
+ dataByte1: n,
93
+ dataByte2: a
52
94
  };
53
- const o = {
95
+ const i = {
54
96
  command: "midiMessage",
55
- obj: JSON.stringify(s)
97
+ obj: JSON.stringify(o)
56
98
  };
57
- console.log("Cabbage: sending midi message from UI", s), t !== null ? t.postMessage(o) : window.sendMessageFromUI(o);
99
+ s !== null ? s.postMessage(i) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(i) : console.error(
100
+ "Cabbage: window.sendMessageFromUI is not available. Message:",
101
+ i
102
+ );
58
103
  }
59
- static sendChannelData(e, a, n = null) {
60
- var t = {
104
+ static sendChannelData(e, n, a = null) {
105
+ var s = {
61
106
  channel: e
62
107
  };
63
- if (typeof a == "string")
64
- t.stringData = a;
65
- else if (typeof a == "number")
66
- t.floatData = a;
108
+ if (typeof n == "string")
109
+ s.stringData = n;
110
+ else if (typeof n == "number")
111
+ s.floatData = n;
67
112
  else {
68
- console.warn("Cabbage: sendChannelData received unsupported data type:", typeof a);
113
+ console.warn(
114
+ "Cabbage: sendChannelData received unsupported data type:",
115
+ typeof n
116
+ );
69
117
  return;
70
118
  }
71
- const s = {
119
+ const o = {
72
120
  command: "channelData",
73
- obj: JSON.stringify(t)
121
+ obj: JSON.stringify(s)
74
122
  };
75
- console.log("Cabbage: sending channel data from UI", t), n !== null ? n.postMessage(s) : window.sendMessageFromUI(s);
123
+ console.log("Cabbage: sending channel data from UI", s), a !== null ? a.postMessage(o) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(o) : console.error(
124
+ "Cabbage: window.sendMessageFromUI is not available. Message:",
125
+ o
126
+ );
76
127
  }
77
- static MidiMessageFromHost(e, a, n) {
78
- console.log("Cabbage: Got MIDI Message" + e + ":" + a + ":" + n);
128
+ static MidiMessageFromHost(e, n, a) {
129
+ console.log(
130
+ "Cabbage: Got MIDI Message" + e + ":" + n + ":" + a
131
+ );
79
132
  }
80
- static triggerFileOpenDialog(e, a, n = {}) {
81
- var t = {
82
- channel: a,
83
- directory: n.directory || "",
84
- filters: n.filters || "*",
85
- openAtLastKnownLocation: n.openAtLastKnownLocation !== void 0 ? n.openAtLastKnownLocation : !0
133
+ static triggerFileOpenDialog(e, n, a = {}) {
134
+ var s = {
135
+ channel: n,
136
+ directory: a.directory || "",
137
+ filters: a.filters || "*",
138
+ openAtLastKnownLocation: a.openAtLastKnownLocation !== void 0 ? a.openAtLastKnownLocation : !0
86
139
  };
87
- const s = {
140
+ const o = {
88
141
  command: "fileOpen",
89
- obj: JSON.stringify(t)
142
+ obj: JSON.stringify(s)
90
143
  };
91
- e !== null ? e.postMessage(s) : window.sendMessageFromUI(s);
144
+ e !== null ? e.postMessage(o) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(o) : console.error(
145
+ "Cabbage: window.sendMessageFromUI is not available. Message:",
146
+ o
147
+ );
92
148
  }
93
- static openUrl(e, a, n) {
94
- var t = {
95
- url: a,
96
- file: n
149
+ static openUrl(e, n, a) {
150
+ var s = {
151
+ url: n,
152
+ file: a
97
153
  };
98
- const s = {
154
+ const o = {
99
155
  command: "openUrl",
100
- obj: JSON.stringify(t)
156
+ obj: JSON.stringify(s)
101
157
  };
102
- e !== null ? e.postMessage(s) : window.sendMessageFromUI(s);
158
+ e !== null ? e.postMessage(o) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(o) : console.error(
159
+ "Cabbage: window.sendMessageFromUI is not available. Message:",
160
+ o
161
+ );
103
162
  }
104
163
  }
105
- const u = (r) => {
106
- const [e, a] = m();
107
- return c(() => {
108
- const n = (t) => {
109
- const { id: s, widgetJson: o, command: l } = t.data;
110
- if (s === r && o && l === "widgetUpdate") {
111
- const i = JSON.parse(o);
164
+ const b = (d) => {
165
+ const [e, n] = f();
166
+ return u(() => {
167
+ const a = (s) => {
168
+ const { id: o, widgetJson: i, command: t } = s.data;
169
+ if (o === d && i && t === "widgetUpdate") {
170
+ const r = JSON.parse(i);
112
171
  console.log(
113
- `[Cabbage-React] Received properties for channelId ${s}`,
114
- i
115
- ), a(i);
172
+ `[Cabbage-React] Received properties for channelId ${o}`,
173
+ r
174
+ ), n(r);
116
175
  }
117
176
  };
118
- return window.addEventListener("message", n), () => {
119
- window.removeEventListener("message", n);
177
+ return window.addEventListener("message", a), () => {
178
+ window.removeEventListener("message", a);
120
179
  };
121
180
  }, []), {
122
181
  properties: e
123
182
  };
124
- }, p = (r) => {
125
- const { properties: e } = u(r), [a, n] = m(), t = (s, o) => {
126
- n(s);
127
- const l = {
128
- channel: r,
129
- value: s,
130
- stringData: o
131
- };
132
- d.sendParameterUpdate(l, null);
183
+ }, M = (d) => {
184
+ const { properties: e } = b(d), [n, a] = f(), [s, o] = f(), i = (t) => {
185
+ a(t);
186
+ const r = {
187
+ channel: d,
188
+ paramIdx: s,
189
+ value: t
190
+ };
191
+ m.sendParameterUpdate(r, null);
133
192
  };
134
- return c(() => {
135
- var i;
136
- const s = e == null ? void 0 : e.value;
137
- if (s != null) {
138
- console.log(
139
- `[Cabbage-React] Received initial value for channelId "${r}"`,
140
- s
141
- ), n(s);
142
- return;
143
- }
144
- const o = e == null ? void 0 : e.channels.find(
145
- (g) => g.id === r
193
+ return u(() => {
194
+ var c;
195
+ const t = e == null ? void 0 : e.channels.find(
196
+ (w) => w.id === d
146
197
  );
147
- if (!o) return;
148
- const l = (i = o.range) == null ? void 0 : i.defaultValue;
149
- a === void 0 && l !== void 0 && (console.log(
150
- `[Cabbage-React] Received default value for channelId "${o.id}"`,
198
+ if (!t) return;
199
+ const r = t == null ? void 0 : t.parameterIndex;
200
+ s === void 0 && r !== void 0 && (console.log(
201
+ `[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,
202
+ r
203
+ ), o(r));
204
+ const g = e == null ? void 0 : e.value;
205
+ g != null && (console.log(
206
+ `[Cabbage-React] Received initial value for channelId "${d}"`,
207
+ g
208
+ ), a(g));
209
+ const l = (c = t.range) == null ? void 0 : c.defaultValue;
210
+ n === void 0 && l !== void 0 && (console.log(
211
+ `[Cabbage-React] Received default value for channelId "${t.id}"`,
151
212
  l
152
- ), n(l));
153
- }, [e]), c(() => {
154
- const s = (o) => {
155
- const { command: l } = o.data;
156
- if (l === "parameterChange") {
157
- const { value: i, paramIdx: g } = o.data;
158
- if (i === null) return;
213
+ ), a(l));
214
+ }, [e]), u(() => {
215
+ const t = (r) => {
216
+ const { command: g } = r.data;
217
+ if (g === "parameterChange") {
218
+ const { value: l, paramIdx: c } = r.data;
219
+ if (c !== s || l === null) return;
159
220
  console.log(
160
- `[Cabbage-React] Received value change for parameterIndex ${g}`,
161
- i
162
- ), n(i);
221
+ `[Cabbage-React] Received value change for parameterIndex ${c}`,
222
+ l
223
+ ), a(l);
163
224
  }
164
225
  };
165
- return window.addEventListener("message", s), () => {
166
- window.removeEventListener("message", s);
226
+ return window.addEventListener("message", t), () => {
227
+ window.removeEventListener("message", t);
167
228
  };
168
229
  }, []), {
169
- value: a,
170
- setValue: t
230
+ value: n,
231
+ setValue: i
171
232
  };
172
233
  };
173
234
  export {
174
- d as Cabbage,
175
- u as useCabbageProperties,
176
- p as useCabbageState
235
+ m as Cabbage,
236
+ b as useCabbageProperties,
237
+ M as useCabbageState
177
238
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",