cabbage-react 1.0.2 → 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,7 +20,7 @@ npm install cabbage-react
20
20
 
21
21
  Synchronize a parameter with Cabbage. This hook:
22
22
 
23
- - Identifies and sets the default value defined in Cabbage to the state.
23
+ - Identifies and sets the default value defined in Cabbage to a state.
24
24
  - Handles initialization when opening an existing session, or reopening the plugin window.
25
25
  - Listens for value updates from the host (DAW), or from Csound.
26
26
  - Sends changes back to Cabbage when using the provided value-setter.
@@ -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>(channelId: string, parameterIndex: 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,aACrB,MAAM,kBACD,MAAM;;yBAMe,CAAC;CA6EtC,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 g=require("react");console.log("Cabbage: loading cabbage.js");class c{static sendChannelUpdate(n,e=null,a=0){if(a===1)c.sendParameterUpdate(n,e);else{const s=n.value!==void 0?n.value:n.stringData||n.floatData;c.sendChannelData(n.channel,s,e)}}static sendParameterUpdate(n,e=null){const a={command:"parameterChange",...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 o={command:"midiMessage",obj:JSON.stringify(t)};console.log("Cabbage: sending midi message from UI",t),s!==null?s.postMessage(o):window.sendMessageFromUI(o)}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:"channelData",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,a={}){var s={channel:e,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.openAtLastKnownLocation:!0};const t={command:"fileOpen",obj:JSON.stringify(s)};n!==null?n.postMessage(t):window.sendMessageFromUI(t)}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 u=r=>{const[n,e]=g.useState();return g.useEffect(()=>{const a=s=>{const{id:t,widgetJson:o,command:l}=s.data;if(t===r&&o&&l==="widgetUpdate"){const i=JSON.parse(o);console.log(`[Cabbage-React] Received properties for channelId ${t}`,i),e(i)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:n}},f=(r,n)=>{const{properties:e}=u(r),[a,s]=g.useState(),t=o=>{s(o);const l={paramIdx:n,channel:r,value:o};c.sendParameterUpdate(l,null)};return g.useEffect(()=>{var d;const o=e==null?void 0:e.value;if(o!=null){console.log(`[Cabbage-React] Received initial value for channelId "${r}"`,o),s(o);return}const l=e==null?void 0:e.channels.find(m=>m.id===r);if(!l)return;const i=(d=l.range)==null?void 0:d.defaultValue;a===void 0&&i!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${l.id}"`,i),s(i))},[e]),g.useEffect(()=>{const o=l=>{const{command:i}=l.data;if(i==="parameterChange"){const{value:d,paramIdx:m}=l.data;if(m!==n||d===null)return;console.log(`[Cabbage-React] Received value change for parameterIndex ${m}`,d),s(d)}};return window.addEventListener("message",o),()=>{window.removeEventListener("message",o)}},[]),{value:a,setValue:t}};exports.Cabbage=c;exports.useCabbageProperties=u;exports.useCabbageState=f;
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,6 +1,6 @@
1
- import { useState as u, useEffect as m } from "react";
1
+ import { useState as m, useEffect as c } from "react";
2
2
  console.log("Cabbage: loading cabbage.js");
3
- class c {
3
+ class d {
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
@@ -14,164 +14,164 @@ class c {
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(a, e = null, n = 0) {
17
+ static sendChannelUpdate(e, a = null, n = 0) {
18
18
  if (n === 1)
19
- c.sendParameterUpdate(a, e);
19
+ d.sendParameterUpdate(e, a);
20
20
  else {
21
- const s = a.value !== void 0 ? a.value : a.stringData || a.floatData;
22
- c.sendChannelData(a.channel, s, e);
21
+ const t = e.value !== void 0 ? e.value : e.stringData || e.floatData;
22
+ d.sendChannelData(e.channel, t, a);
23
23
  }
24
24
  }
25
- static sendParameterUpdate(a, e = null) {
25
+ static sendParameterUpdate(e, a = null) {
26
26
  const n = {
27
27
  command: "parameterChange",
28
- ...a
28
+ ...e
29
29
  };
30
- 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));
31
31
  }
32
- static sendCustomCommand(a, e = null) {
32
+ static sendCustomCommand(e, a = null) {
33
33
  const n = {
34
- command: a,
34
+ command: e,
35
35
  text: JSON.stringify({})
36
36
  };
37
- 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);
38
38
  }
39
- static sendWidgetUpdate(a, e = null) {
40
- 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);
41
41
  const n = {
42
42
  command: "widgetStateUpdate",
43
- obj: JSON.stringify(CabbageUtils.sanitizeForEditor(a))
43
+ obj: JSON.stringify(CabbageUtils.sanitizeForEditor(e))
44
44
  };
45
- e !== null ? e.postMessage(n) : window.sendMessageFromUI(n);
45
+ a !== null ? a.postMessage(n) : window.sendMessageFromUI(n);
46
46
  }
47
- static sendMidiMessageFromUI(a, e, n, s = null) {
48
- var t = {
49
- statusByte: a,
50
- dataByte1: e,
47
+ static sendMidiMessageFromUI(e, a, n, t = null) {
48
+ var s = {
49
+ statusByte: e,
50
+ dataByte1: a,
51
51
  dataByte2: n
52
52
  };
53
53
  const o = {
54
54
  command: "midiMessage",
55
- obj: JSON.stringify(t)
55
+ obj: JSON.stringify(s)
56
56
  };
57
- console.log("Cabbage: sending midi message from UI", t), s !== null ? s.postMessage(o) : window.sendMessageFromUI(o);
57
+ console.log("Cabbage: sending midi message from UI", s), t !== null ? t.postMessage(o) : window.sendMessageFromUI(o);
58
58
  }
59
- static sendChannelData(a, e, n = null) {
60
- var s = {
61
- channel: a
59
+ static sendChannelData(e, a, n = null) {
60
+ var t = {
61
+ channel: e
62
62
  };
63
- if (typeof e == "string")
64
- s.stringData = e;
65
- else if (typeof e == "number")
66
- s.floatData = e;
63
+ if (typeof a == "string")
64
+ t.stringData = a;
65
+ else if (typeof a == "number")
66
+ t.floatData = a;
67
67
  else {
68
- console.warn("Cabbage: sendChannelData received unsupported data type:", typeof e);
68
+ console.warn("Cabbage: sendChannelData received unsupported data type:", typeof a);
69
69
  return;
70
70
  }
71
- const t = {
71
+ const s = {
72
72
  command: "channelData",
73
- obj: JSON.stringify(s)
73
+ obj: JSON.stringify(t)
74
74
  };
75
- 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);
76
76
  }
77
- static MidiMessageFromHost(a, e, n) {
78
- 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);
79
79
  }
80
- static triggerFileOpenDialog(a, e, n = {}) {
81
- var s = {
82
- channel: e,
80
+ static triggerFileOpenDialog(e, a, n = {}) {
81
+ var t = {
82
+ channel: a,
83
83
  directory: n.directory || "",
84
84
  filters: n.filters || "*",
85
85
  openAtLastKnownLocation: n.openAtLastKnownLocation !== void 0 ? n.openAtLastKnownLocation : !0
86
86
  };
87
- const t = {
87
+ const s = {
88
88
  command: "fileOpen",
89
- obj: JSON.stringify(s)
89
+ obj: JSON.stringify(t)
90
90
  };
91
- a !== null ? a.postMessage(t) : window.sendMessageFromUI(t);
91
+ e !== null ? e.postMessage(s) : window.sendMessageFromUI(s);
92
92
  }
93
- static openUrl(a, e, n) {
94
- var s = {
95
- url: e,
93
+ static openUrl(e, a, n) {
94
+ var t = {
95
+ url: a,
96
96
  file: n
97
97
  };
98
- const t = {
98
+ const s = {
99
99
  command: "openUrl",
100
- obj: JSON.stringify(s)
100
+ obj: JSON.stringify(t)
101
101
  };
102
- a !== null ? a.postMessage(t) : window.sendMessageFromUI(t);
102
+ e !== null ? e.postMessage(s) : window.sendMessageFromUI(s);
103
103
  }
104
104
  }
105
- const f = (r) => {
106
- const [a, e] = u();
107
- return m(() => {
108
- const n = (s) => {
109
- const { id: t, widgetJson: o, command: l } = s.data;
110
- if (t === r && o && l === "widgetUpdate") {
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
111
  const i = JSON.parse(o);
112
112
  console.log(
113
- `[Cabbage-React] Received properties for channelId ${t}`,
113
+ `[Cabbage-React] Received properties for channelId ${s}`,
114
114
  i
115
- ), e(i);
115
+ ), a(i);
116
116
  }
117
117
  };
118
118
  return window.addEventListener("message", n), () => {
119
119
  window.removeEventListener("message", n);
120
120
  };
121
121
  }, []), {
122
- properties: a
122
+ properties: e
123
123
  };
124
- }, b = (r, a) => {
125
- const { properties: e } = f(r), [n, s] = u(), t = (o) => {
126
- s(o);
124
+ }, p = (r) => {
125
+ const { properties: e } = u(r), [a, n] = m(), t = (s, o) => {
126
+ n(s);
127
127
  const l = {
128
- paramIdx: a,
129
128
  channel: r,
130
- value: o
129
+ value: s,
130
+ stringData: o
131
131
  };
132
- c.sendParameterUpdate(l, null);
132
+ d.sendParameterUpdate(l, null);
133
133
  };
134
- return m(() => {
135
- var d;
136
- const o = e == null ? void 0 : e.value;
137
- if (o != null) {
134
+ return c(() => {
135
+ var i;
136
+ const s = e == null ? void 0 : e.value;
137
+ if (s != null) {
138
138
  console.log(
139
139
  `[Cabbage-React] Received initial value for channelId "${r}"`,
140
- o
141
- ), s(o);
140
+ s
141
+ ), n(s);
142
142
  return;
143
143
  }
144
- const l = e == null ? void 0 : e.channels.find(
144
+ const o = e == null ? void 0 : e.channels.find(
145
145
  (g) => g.id === r
146
146
  );
147
- if (!l) return;
148
- const i = (d = l.range) == null ? void 0 : d.defaultValue;
149
- n === void 0 && i !== void 0 && (console.log(
150
- `[Cabbage-React] Received default value for channelId "${l.id}"`,
151
- i
152
- ), s(i));
153
- }, [e]), m(() => {
154
- const o = (l) => {
155
- const { command: i } = l.data;
156
- if (i === "parameterChange") {
157
- const { value: d, paramIdx: g } = l.data;
158
- if (g !== a || d === null) return;
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
159
  console.log(
160
160
  `[Cabbage-React] Received value change for parameterIndex ${g}`,
161
- d
162
- ), s(d);
161
+ i
162
+ ), n(i);
163
163
  }
164
164
  };
165
- return window.addEventListener("message", o), () => {
166
- window.removeEventListener("message", o);
165
+ return window.addEventListener("message", s), () => {
166
+ window.removeEventListener("message", s);
167
167
  };
168
168
  }, []), {
169
- value: n,
169
+ value: a,
170
170
  setValue: t
171
171
  };
172
172
  };
173
173
  export {
174
- c as Cabbage,
175
- f as useCabbageProperties,
176
- b as useCabbageState
174
+ d as Cabbage,
175
+ u as useCabbageProperties,
176
+ p as useCabbageState
177
177
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",