cabbage-react 1.0.1 → 1.0.3

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.
package/README.md CHANGED
@@ -20,8 +20,10 @@ npm install cabbage-react
20
20
 
21
21
  Synchronize a parameter with Cabbage. This hook:
22
22
 
23
- - Listens for value updates from Cabbage.
24
- - Sends local changes (e.g., via sliders, knobs) back to Cabbage.
23
+ - Identifies and sets the default value defined in Cabbage to a state.
24
+ - Handles initialization when opening an existing session, or reopening the plugin window.
25
+ - Listens for value updates from the host (DAW), or from Csound.
26
+ - Sends changes back to Cabbage when using the provided value-setter.
25
27
 
26
28
  ### useCabbageProperties
27
29
 
@@ -33,21 +35,28 @@ This hook:
33
35
 
34
36
  ## Usage
35
37
 
36
- ```jsx
38
+ ```tsx
37
39
  import { InputHTMLAttributes } from "react";
38
40
  import { useCabbageProperties, useCabbageState } from "cabbage-react";
39
41
 
40
42
  const HorizontalSlider = ({
41
- channel,
42
- paramIdx,
43
+ channelId,
44
+ parameterIndex,
43
45
  inputProps,
44
46
  }: {
45
- channel: string;
46
- paramIdx: number;
47
+ channelId: string;
48
+ parameterIndex: number;
47
49
  inputProps?: InputHTMLAttributes<HTMLInputElement>;
48
50
  }) => {
49
- const { properties } = useCabbageProperties(channel);
50
- const { value, setValue } = useCabbageState<number>(channel, paramIdx);
51
+ const { properties } = useCabbageProperties(channelId);
52
+ const channelProperties = properties?.channels.find(
53
+ (c: any) => c.id === channelId
54
+ );
55
+
56
+ const { value, setValue } = useCabbageState<number>(
57
+ channelId,
58
+ parameterIndex
59
+ );
51
60
 
52
61
  return (
53
62
  <div>
@@ -56,9 +65,9 @@ const HorizontalSlider = ({
56
65
 
57
66
  <input
58
67
  type="range"
59
- min={properties?.range?.min ?? 0}
60
- max={properties?.range?.max ?? 1}
61
- step={properties?.range?.increment ?? 0.01}
68
+ min={channelProperties?.range?.min ?? 0}
69
+ max={channelProperties?.range?.max ?? 1}
70
+ step={channelProperties?.range?.increment ?? 0.01}
62
71
  value={value}
63
72
  onChange={(e) => setValue(e.target.valueAsNumber)}
64
73
  {...inputProps}
@@ -1,11 +1,25 @@
1
1
  export class Cabbage {
2
+ /**
3
+ * Main entry point for sending any data from UI widgets to the Cabbage backend.
4
+ * This function automatically routes messages to the appropriate backend function
5
+ * based on the automatable flag:
6
+ *
7
+ * - automatable=1: Routes to sendParameterUpdate for real-time parameter control /
8
+ * this also sends the value as channel data to Csound
9
+ *
10
+ * - automatable=0: Routes to sendChannelData for string/numeric data transmission
11
+ *
12
+ * All widget interactions should use this function instead of calling the lower-level
13
+ * sendParameterUpdate or sendChannelData functions directly.
14
+ */
15
+ static sendChannelUpdate(message: any, vscode?: null, automatable?: number): void;
2
16
  static sendParameterUpdate(message: any, vscode?: null): void;
3
17
  static sendCustomCommand(command: any, vscode?: null): void;
4
18
  static sendWidgetUpdate(widget: any, vscode?: null): void;
5
19
  static sendMidiMessageFromUI(statusByte: any, dataByte1: any, dataByte2: any, vscode?: null): void;
6
20
  static sendChannelData(channel: any, data: any, vscode?: null): void;
7
21
  static MidiMessageFromHost(statusByte: any, dataByte1: any, dataByte2: any): void;
8
- static triggerFileOpenDialog(vscode: any, channel: any): void;
22
+ static triggerFileOpenDialog(vscode: any, channel: any, options?: {}): void;
9
23
  static openUrl(vscode: any, url: any, file: any): void;
10
24
  }
11
25
  //# sourceMappingURL=cabbage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cabbage.d.ts","sourceRoot":"","sources":["../../src/cabbage/cabbage.js"],"names":[],"mappings":"AAMA;IAEE,8DAcC;IAED,4DAYC;IAED,0DAYC;IAED,mGAmBC;IAED,qEA2BC;IAED,kFAEC;IAED,8DAeC;IAED,uDAgBC;CAGF"}
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"}
@@ -3,7 +3,7 @@
3
3
  * This hook listens for updates to parameter properties via Cabbage and updates the local state
4
4
  * whenever new data is received.
5
5
  */
6
- export declare const useCabbageProperties: (channel: string) => {
6
+ export declare const useCabbageProperties: (channelId: string) => {
7
7
  properties: Record<string, any> | undefined;
8
8
  };
9
9
  //# sourceMappingURL=useCabbageProperties.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,YAAa,MAAM;;CAgCnD,CAAC"}
1
+ {"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,cAAe,MAAM;;CAgCrD,CAAC"}
@@ -3,8 +3,8 @@
3
3
  * This hook listens for updates to a parameter value from Cabbage and
4
4
  * sends updates to Cabbage when the parameter value changes locally (e.g., through a UI slider).
5
5
  */
6
- export declare const useCabbageState: <T>(channel: string, paramIdx: number) => {
6
+ export declare const useCabbageState: <T>(channelId: string) => {
7
7
  value: T | undefined;
8
- setValue: (newValue: T) => void;
8
+ setValue: (newValue: T, stringData?: string) => 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,WAAW,MAAM,YAAY,MAAM;;yBAM9B,CAAC;CAwFtC,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;;yBAKd,CAAC,eAAe,MAAM;CA4E3D,CAAC"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react");console.log("Cabbage: loading cabbage.js");class p{static sendParameterUpdate(n,e=null){const a={command:"parameterChange",obj:JSON.stringify(n)};console.log("Cabbage.sendParameterUpdate:",n,"vscode:",e,"msg:",a),e!==null?(console.log("Sending via vscode.postMessage"),e.postMessage(a)):(console.log("Sending via window.sendMessageFromUI"),window.sendMessageFromUI(a))}static sendCustomCommand(n,e=null){const a={command:n,text:JSON.stringify({})};console.log("Cabbage: sending custom command from UI",a),e!==null?e.postMessage(a):window.sendMessageFromUI(a)}static sendWidgetUpdate(n,e=null){console.log("Cabbage: sending widget update from UI",n.props);const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(n))};e!==null?e.postMessage(a):window.sendMessageFromUI(a)}static sendMidiMessageFromUI(n,e,a,s=null){var t={statusByte:n,dataByte1:e,dataByte2:a};const i={command:"midiMessage",obj:JSON.stringify(t)};console.log("Cabbage: sending midi message from UI",t),s!==null?s.postMessage(i):window.sendMessageFromUI(i)}static sendChannelData(n,e,a=null){var s={channel:n};if(typeof e=="string")s.stringData=e;else if(typeof e=="number")s.floatData=e;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof e);return}const t={command:"channelStringData",obj:JSON.stringify(s)};console.log("Cabbage: sending channel data from UI",s),a!==null?a.postMessage(t):window.sendMessageFromUI(t)}static MidiMessageFromHost(n,e,a){console.log("Cabbage: Got MIDI Message"+n+":"+e+":"+a)}static triggerFileOpenDialog(n,e){var a={channel:e};const s={command:"fileOpen",obj:JSON.stringify(a)};n!==null?n.postMessage(s):window.sendMessageFromUI(s)}static openUrl(n,e,a){var s={url:e,file:a};const t={command:"openUrl",obj:JSON.stringify(s)};n!==null?n.postMessage(t):window.sendMessageFromUI(t)}}const C=r=>{const[n,e]=c.useState();return c.useEffect(()=>{const a=s=>{const{channel:t,data:i,command:f}=s.data;if(t===r&&i&&f==="widgetUpdate"){const m=JSON.parse(i);console.log(`[Cabbage-React] ${f}: Received properties for channel: ${t}`,m),e(m)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:n}},w=(r,n)=>{const{properties:e}=C(r),[a,s]=c.useState(),[t,i]=c.useState(),f=o=>{s(o);const l={paramIdx:n,channelType:t,channel:r,value:o};p.sendParameterUpdate(l,null)},m=o=>{if(typeof o=="number")return"number";if(typeof o=="string")return"string"};return c.useEffect(()=>{var l;if((e==null?void 0:e.channel)!==r)return;const o=(l=e==null?void 0:e.range)==null?void 0:l.defaultValue;if(a===void 0&&o!==void 0){console.log(`[Cabbage-React]: Received default value for channel "${e==null?void 0:e.channel}"`,o),s(o);const d=m(o);d&&i(d)}},[e]),c.useEffect(()=>{const o=l=>{const{command:d}=l.data;if(d==="widgetUpdate"){const{channel:u,value:g}=l.data;if(u!==r)return;if(console.log(`[Cabbage-React] ${d}: Received initial value for channel "${u}"`,g),g!==void 0){s(g);const b=m(g);b&&i(b)}}if(d==="parameterChange"){const{paramIdx:u,value:g}=l.data.data||{};u===n&&g!==void 0&&(console.log(`[Cabbage-React] ${d}: Received value change for paramIdx: ${u}`,g),s(g))}};return window.addEventListener("message",o),()=>{window.removeEventListener("message",o)}},[]),{value:a,setValue:f}};exports.Cabbage=p;exports.useCabbageProperties=C;exports.useCabbageState=w;
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;
package/dist/index.mjs CHANGED
@@ -1,161 +1,177 @@
1
- import { useState as f, useEffect as b } from "react";
1
+ import { useState as m, useEffect as c } from "react";
2
2
  console.log("Cabbage: loading cabbage.js");
3
- class C {
4
- static sendParameterUpdate(a, e = null) {
3
+ class d {
4
+ /**
5
+ * Main entry point for sending any data from UI widgets to the Cabbage backend.
6
+ * This function automatically routes messages to the appropriate backend function
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
+ *
14
+ * All widget interactions should use this function instead of calling the lower-level
15
+ * sendParameterUpdate or sendChannelData functions directly.
16
+ */
17
+ static sendChannelUpdate(e, a = null, n = 0) {
18
+ if (n === 1)
19
+ d.sendParameterUpdate(e, a);
20
+ else {
21
+ const t = e.value !== void 0 ? e.value : e.stringData || e.floatData;
22
+ d.sendChannelData(e.channel, t, a);
23
+ }
24
+ }
25
+ static sendParameterUpdate(e, a = null) {
5
26
  const n = {
6
27
  command: "parameterChange",
7
- obj: JSON.stringify(a)
28
+ ...e
8
29
  };
9
- console.log("Cabbage.sendParameterUpdate:", a, "vscode:", e, "msg:", n), e !== null ? (console.log("Sending via vscode.postMessage"), e.postMessage(n)) : (console.log("Sending via window.sendMessageFromUI"), window.sendMessageFromUI(n));
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));
10
31
  }
11
- static sendCustomCommand(a, e = null) {
32
+ static sendCustomCommand(e, a = null) {
12
33
  const n = {
13
- command: a,
34
+ command: e,
14
35
  text: JSON.stringify({})
15
36
  };
16
- console.log("Cabbage: sending custom command from UI", n), e !== null ? e.postMessage(n) : window.sendMessageFromUI(n);
37
+ console.log("Cabbage: sending custom command from UI", n), a !== null ? a.postMessage(n) : window.sendMessageFromUI(n);
17
38
  }
18
- static sendWidgetUpdate(a, e = null) {
19
- console.log("Cabbage: sending widget update from UI", a.props);
39
+ static sendWidgetUpdate(e, a = null) {
40
+ console.log("Cabbage: sending widget update from UI", e.props);
20
41
  const n = {
21
42
  command: "widgetStateUpdate",
22
- obj: JSON.stringify(CabbageUtils.sanitizeForEditor(a))
43
+ obj: JSON.stringify(CabbageUtils.sanitizeForEditor(e))
23
44
  };
24
- e !== null ? e.postMessage(n) : window.sendMessageFromUI(n);
45
+ a !== null ? a.postMessage(n) : window.sendMessageFromUI(n);
25
46
  }
26
- static sendMidiMessageFromUI(a, e, n, s = null) {
27
- var t = {
28
- statusByte: a,
29
- dataByte1: e,
47
+ static sendMidiMessageFromUI(e, a, n, t = null) {
48
+ var s = {
49
+ statusByte: e,
50
+ dataByte1: a,
30
51
  dataByte2: n
31
52
  };
32
- const i = {
53
+ const o = {
33
54
  command: "midiMessage",
34
- obj: JSON.stringify(t)
55
+ obj: JSON.stringify(s)
35
56
  };
36
- console.log("Cabbage: sending midi message from UI", t), s !== null ? s.postMessage(i) : window.sendMessageFromUI(i);
57
+ console.log("Cabbage: sending midi message from UI", s), t !== null ? t.postMessage(o) : window.sendMessageFromUI(o);
37
58
  }
38
- static sendChannelData(a, e, n = null) {
39
- var s = {
40
- channel: a
59
+ static sendChannelData(e, a, n = null) {
60
+ var t = {
61
+ channel: e
41
62
  };
42
- if (typeof e == "string")
43
- s.stringData = e;
44
- else if (typeof e == "number")
45
- s.floatData = e;
63
+ if (typeof a == "string")
64
+ t.stringData = a;
65
+ else if (typeof a == "number")
66
+ t.floatData = a;
46
67
  else {
47
- console.warn("Cabbage: sendChannelData received unsupported data type:", typeof e);
68
+ console.warn("Cabbage: sendChannelData received unsupported data type:", typeof a);
48
69
  return;
49
70
  }
50
- const t = {
51
- command: "channelStringData",
52
- obj: JSON.stringify(s)
71
+ const s = {
72
+ command: "channelData",
73
+ obj: JSON.stringify(t)
53
74
  };
54
- console.log("Cabbage: sending channel data from UI", s), n !== null ? n.postMessage(t) : window.sendMessageFromUI(t);
75
+ console.log("Cabbage: sending channel data from UI", t), n !== null ? n.postMessage(s) : window.sendMessageFromUI(s);
55
76
  }
56
- static MidiMessageFromHost(a, e, n) {
57
- console.log("Cabbage: Got MIDI Message" + a + ":" + e + ":" + n);
77
+ static MidiMessageFromHost(e, a, n) {
78
+ console.log("Cabbage: Got MIDI Message" + e + ":" + a + ":" + n);
58
79
  }
59
- static triggerFileOpenDialog(a, e) {
60
- var n = {
61
- channel: e
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
62
86
  };
63
87
  const s = {
64
88
  command: "fileOpen",
65
- obj: JSON.stringify(n)
89
+ obj: JSON.stringify(t)
66
90
  };
67
- a !== null ? a.postMessage(s) : window.sendMessageFromUI(s);
91
+ e !== null ? e.postMessage(s) : window.sendMessageFromUI(s);
68
92
  }
69
- static openUrl(a, e, n) {
70
- var s = {
71
- url: e,
93
+ static openUrl(e, a, n) {
94
+ var t = {
95
+ url: a,
72
96
  file: n
73
97
  };
74
- const t = {
98
+ const s = {
75
99
  command: "openUrl",
76
- obj: JSON.stringify(s)
100
+ obj: JSON.stringify(t)
77
101
  };
78
- a !== null ? a.postMessage(t) : window.sendMessageFromUI(t);
102
+ e !== null ? e.postMessage(s) : window.sendMessageFromUI(s);
79
103
  }
80
104
  }
81
- const w = (r) => {
82
- const [a, e] = f();
83
- return b(() => {
84
- const n = (s) => {
85
- const { channel: t, data: i, command: u } = s.data;
86
- if (t === r && i && u === "widgetUpdate") {
87
- const c = JSON.parse(i);
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);
88
112
  console.log(
89
- `[Cabbage-React] ${u}: Received properties for channel: ${t}`,
90
- c
91
- ), e(c);
113
+ `[Cabbage-React] Received properties for channelId ${s}`,
114
+ i
115
+ ), a(i);
92
116
  }
93
117
  };
94
118
  return window.addEventListener("message", n), () => {
95
119
  window.removeEventListener("message", n);
96
120
  };
97
121
  }, []), {
98
- properties: a
122
+ properties: e
99
123
  };
100
- }, h = (r, a) => {
101
- const { properties: e } = w(r), [n, s] = f(), [t, i] = f(), u = (o) => {
102
- s(o);
124
+ }, p = (r) => {
125
+ const { properties: e } = u(r), [a, n] = m(), t = (s, o) => {
126
+ n(s);
103
127
  const l = {
104
- paramIdx: a,
105
- channelType: t,
106
128
  channel: r,
107
- value: o
129
+ value: s,
130
+ stringData: o
108
131
  };
109
- C.sendParameterUpdate(l, null);
110
- }, c = (o) => {
111
- if (typeof o == "number") return "number";
112
- if (typeof o == "string") return "string";
132
+ d.sendParameterUpdate(l, null);
113
133
  };
114
- return b(() => {
115
- var l;
116
- if ((e == null ? void 0 : e.channel) !== r) return;
117
- const o = (l = e == null ? void 0 : e.range) == null ? void 0 : l.defaultValue;
118
- if (n === void 0 && o !== void 0) {
134
+ return c(() => {
135
+ var i;
136
+ const s = e == null ? void 0 : e.value;
137
+ if (s != null) {
119
138
  console.log(
120
- `[Cabbage-React]: Received default value for channel "${e == null ? void 0 : e.channel}"`,
121
- o
122
- ), s(o);
123
- const d = c(o);
124
- d && i(d);
139
+ `[Cabbage-React] Received initial value for channelId "${r}"`,
140
+ s
141
+ ), n(s);
142
+ return;
125
143
  }
126
- }, [e]), b(() => {
127
- const o = (l) => {
128
- const { command: d } = l.data;
129
- if (d === "widgetUpdate") {
130
- const { channel: m, value: g } = l.data;
131
- if (m !== r) return;
132
- if (console.log(
133
- `[Cabbage-React] ${d}: Received initial value for channel "${m}"`,
134
- g
135
- ), g !== void 0) {
136
- s(g);
137
- const p = c(g);
138
- p && i(p);
139
- }
140
- }
141
- if (d === "parameterChange") {
142
- const { paramIdx: m, value: g } = l.data.data || {};
143
- m === a && g !== void 0 && (console.log(
144
- `[Cabbage-React] ${d}: Received value change for paramIdx: ${m}`,
145
- g
146
- ), s(g));
144
+ const o = e == null ? void 0 : e.channels.find(
145
+ (g) => g.id === r
146
+ );
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}"`,
151
+ 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;
159
+ console.log(
160
+ `[Cabbage-React] Received value change for parameterIndex ${g}`,
161
+ i
162
+ ), n(i);
147
163
  }
148
164
  };
149
- return window.addEventListener("message", o), () => {
150
- window.removeEventListener("message", o);
165
+ return window.addEventListener("message", s), () => {
166
+ window.removeEventListener("message", s);
151
167
  };
152
168
  }, []), {
153
- value: n,
154
- setValue: u
169
+ value: a,
170
+ setValue: t
155
171
  };
156
172
  };
157
173
  export {
158
- C as Cabbage,
159
- w as useCabbageProperties,
160
- h as useCabbageState
174
+ d as Cabbage,
175
+ u as useCabbageProperties,
176
+ p as useCabbageState
161
177
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",