cabbage-react 1.0.3 → 1.0.5

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.
@@ -5,6 +5,6 @@
5
5
  */
6
6
  export declare const useCabbageState: <T>(channelId: string) => {
7
7
  value: T | undefined;
8
- setValue: (newValue: T, stringData?: string) => void;
8
+ setValue: (value?: 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,aAAa,MAAM;;yBAKd,CAAC,eAAe,MAAM;CA4E3D,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;;uBAKhB,CAAC,eAAe,MAAM;CA6EzD,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 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:i}=t.data;if(s===r&&o&&i==="widgetUpdate"){const l=JSON.parse(o);console.log(`[Cabbage-React] Received properties for channelId ${s}`,l),n(l)}};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 i={channel:r,...s!==void 0&&{value:s},...o!==void 0&&{stringData:o}};g.sendParameterUpdate(i,null)};return d.useEffect(()=>{var l;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 i=(l=o.range)==null?void 0:l.defaultValue;n===void 0&&i!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${o.id}"`,i),a(i))},[e]),d.useEffect(()=>{const s=o=>{const{command:i}=o.data;if(i==="parameterChange"){const{value:l,paramIdx:c}=o.data;if(l===null)return;console.log(`[Cabbage-React] Received value change for parameterIndex ${c}`,l),a(l)}};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
1
  import { useState as m, useEffect as c } from "react";
2
2
  console.log("Cabbage: loading cabbage.js");
3
- class d {
3
+ class r {
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
@@ -16,10 +16,10 @@ class d {
16
16
  */
17
17
  static sendChannelUpdate(e, a = null, n = 0) {
18
18
  if (n === 1)
19
- d.sendParameterUpdate(e, a);
19
+ r.sendParameterUpdate(e, a);
20
20
  else {
21
21
  const t = e.value !== void 0 ? e.value : e.stringData || e.floatData;
22
- d.sendChannelData(e.channel, t, a);
22
+ r.sendChannelData(e.channel, t, a);
23
23
  }
24
24
  }
25
25
  static sendParameterUpdate(e, a = null) {
@@ -102,17 +102,17 @@ class d {
102
102
  e !== null ? e.postMessage(s) : window.sendMessageFromUI(s);
103
103
  }
104
104
  }
105
- const u = (r) => {
105
+ const u = (d) => {
106
106
  const [e, a] = m();
107
107
  return c(() => {
108
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);
109
+ const { id: s, widgetJson: o, command: i } = t.data;
110
+ if (s === d && o && i === "widgetUpdate") {
111
+ const l = JSON.parse(o);
112
112
  console.log(
113
113
  `[Cabbage-React] Received properties for channelId ${s}`,
114
- i
115
- ), a(i);
114
+ l
115
+ ), a(l);
116
116
  }
117
117
  };
118
118
  return window.addEventListener("message", n), () => {
@@ -121,45 +121,45 @@ const u = (r) => {
121
121
  }, []), {
122
122
  properties: e
123
123
  };
124
- }, p = (r) => {
125
- const { properties: e } = u(r), [a, n] = m(), t = (s, o) => {
124
+ }, p = (d) => {
125
+ const { properties: e } = u(d), [a, n] = m(), t = (s, o) => {
126
126
  n(s);
127
- const l = {
128
- channel: r,
129
- value: s,
130
- stringData: o
127
+ const i = {
128
+ channel: d,
129
+ ...s !== void 0 && { value: s },
130
+ ...o !== void 0 && { stringData: o }
131
131
  };
132
- d.sendParameterUpdate(l, null);
132
+ r.sendParameterUpdate(i, null);
133
133
  };
134
134
  return c(() => {
135
- var i;
135
+ var l;
136
136
  const s = e == null ? void 0 : e.value;
137
137
  if (s != null) {
138
138
  console.log(
139
- `[Cabbage-React] Received initial value for channelId "${r}"`,
139
+ `[Cabbage-React] Received initial value for channelId "${d}"`,
140
140
  s
141
141
  ), n(s);
142
142
  return;
143
143
  }
144
144
  const o = e == null ? void 0 : e.channels.find(
145
- (g) => g.id === r
145
+ (g) => g.id === d
146
146
  );
147
147
  if (!o) return;
148
- const l = (i = o.range) == null ? void 0 : i.defaultValue;
149
- a === void 0 && l !== void 0 && (console.log(
148
+ const i = (l = o.range) == null ? void 0 : l.defaultValue;
149
+ a === void 0 && i !== void 0 && (console.log(
150
150
  `[Cabbage-React] Received default value for channelId "${o.id}"`,
151
- l
152
- ), n(l));
151
+ i
152
+ ), n(i));
153
153
  }, [e]), c(() => {
154
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;
155
+ const { command: i } = o.data;
156
+ if (i === "parameterChange") {
157
+ const { value: l, paramIdx: g } = o.data;
158
+ if (l === null) return;
159
159
  console.log(
160
160
  `[Cabbage-React] Received value change for parameterIndex ${g}`,
161
- i
162
- ), n(i);
161
+ l
162
+ ), n(l);
163
163
  }
164
164
  };
165
165
  return window.addEventListener("message", s), () => {
@@ -171,7 +171,7 @@ const u = (r) => {
171
171
  };
172
172
  };
173
173
  export {
174
- d as Cabbage,
174
+ r as Cabbage,
175
175
  u as useCabbageProperties,
176
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.3",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",