cabbage-react 1.0.10 → 1.0.12
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/dist/hooks/useCabbageState.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +15 -17
- package/package.json +1 -1
|
@@ -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;;
|
|
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;CAyFnC,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=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=
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=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=g=>{const[e,n]=m.useState();return m.useEffect(()=>{const a=s=>{const{id:o,widgetJson:i,command:t}=s.data;if(o===g&&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=g=>{const{properties:e}=f(g),[n,a]=m.useState(),[s,o]=m.useState(),i=t=>{a(t);const r={channel:g,paramIdx:s,value:t};u.sendParameterUpdate(r,null)};return m.useEffect(()=>{var c;const t=e==null?void 0:e.channels.find(b=>b.id===g);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 d=e==null?void 0:e.value;d!=null&&(console.log(`[Cabbage-React] Received initial value for channelId "${g}"`,d),a(d));const l=(c=t.range)==null?void 0:c.defaultValue;n===void 0&&l!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${t.id}"`,l),a(l))},[e]),m.useEffect(()=>{const t=r=>{const{command:d}=r.data;if(d==="parameterChange"){const{value:l,paramIdx:c}=r.data.data;if(console.log("paramIdx",s),console.log("value",l),console.log("incomingParameterIndex",c),console.log("event.data.data",r.data.data),c!==s||l===null)return;console.log(`[Cabbage-React] Received value change for parameterIndex ${c}`,l),a(l)}else d==="batchWidgetUpdate"&&console.log("batchWidgetUpdate",r)};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[s]),{value:n,setValue:i}};exports.Cabbage=u;exports.useCabbageProperties=f;exports.useCabbageState=w;
|
package/dist/index.mjs
CHANGED
|
@@ -161,12 +161,12 @@ class m {
|
|
|
161
161
|
);
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
const b = (
|
|
164
|
+
const b = (g) => {
|
|
165
165
|
const [e, n] = f();
|
|
166
166
|
return u(() => {
|
|
167
167
|
const a = (s) => {
|
|
168
168
|
const { id: o, widgetJson: i, command: t } = s.data;
|
|
169
|
-
if (o ===
|
|
169
|
+
if (o === g && i && t === "widgetUpdate") {
|
|
170
170
|
const r = JSON.parse(i);
|
|
171
171
|
console.log(
|
|
172
172
|
`[Cabbage-React] Received properties for channelId ${o}`,
|
|
@@ -180,13 +180,11 @@ const b = (d) => {
|
|
|
180
180
|
}, []), {
|
|
181
181
|
properties: e
|
|
182
182
|
};
|
|
183
|
-
}, I = (
|
|
184
|
-
const { properties: e } = b(
|
|
185
|
-
console.log("paramIdx-test-log", s);
|
|
186
|
-
const i = (t) => {
|
|
183
|
+
}, I = (g) => {
|
|
184
|
+
const { properties: e } = b(g), [n, a] = f(), [s, o] = f(), i = (t) => {
|
|
187
185
|
a(t);
|
|
188
186
|
const r = {
|
|
189
|
-
channel:
|
|
187
|
+
channel: g,
|
|
190
188
|
paramIdx: s,
|
|
191
189
|
value: t
|
|
192
190
|
};
|
|
@@ -195,7 +193,7 @@ const b = (d) => {
|
|
|
195
193
|
return u(() => {
|
|
196
194
|
var c;
|
|
197
195
|
const t = e == null ? void 0 : e.channels.find(
|
|
198
|
-
(w) => w.id ===
|
|
196
|
+
(w) => w.id === g
|
|
199
197
|
);
|
|
200
198
|
if (!t) return;
|
|
201
199
|
const r = t == null ? void 0 : t.parameterIndex;
|
|
@@ -203,11 +201,11 @@ const b = (d) => {
|
|
|
203
201
|
`[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,
|
|
204
202
|
r
|
|
205
203
|
), o(r));
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
`[Cabbage-React] Received initial value for channelId "${
|
|
209
|
-
|
|
210
|
-
), a(
|
|
204
|
+
const d = e == null ? void 0 : e.value;
|
|
205
|
+
d != null && (console.log(
|
|
206
|
+
`[Cabbage-React] Received initial value for channelId "${g}"`,
|
|
207
|
+
d
|
|
208
|
+
), a(d));
|
|
211
209
|
const l = (c = t.range) == null ? void 0 : c.defaultValue;
|
|
212
210
|
n === void 0 && l !== void 0 && (console.log(
|
|
213
211
|
`[Cabbage-React] Received default value for channelId "${t.id}"`,
|
|
@@ -215,20 +213,20 @@ const b = (d) => {
|
|
|
215
213
|
), a(l));
|
|
216
214
|
}, [e]), u(() => {
|
|
217
215
|
const t = (r) => {
|
|
218
|
-
const { command:
|
|
219
|
-
if (
|
|
216
|
+
const { command: d } = r.data;
|
|
217
|
+
if (d === "parameterChange") {
|
|
220
218
|
const { value: l, paramIdx: c } = r.data.data;
|
|
221
219
|
if (console.log("paramIdx", s), console.log("value", l), console.log("incomingParameterIndex", c), console.log("event.data.data", r.data.data), c !== s || l === null) return;
|
|
222
220
|
console.log(
|
|
223
221
|
`[Cabbage-React] Received value change for parameterIndex ${c}`,
|
|
224
222
|
l
|
|
225
223
|
), a(l);
|
|
226
|
-
}
|
|
224
|
+
} else d === "batchWidgetUpdate" && console.log("batchWidgetUpdate", r);
|
|
227
225
|
};
|
|
228
226
|
return window.addEventListener("message", t), () => {
|
|
229
227
|
window.removeEventListener("message", t);
|
|
230
228
|
};
|
|
231
|
-
}, []), {
|
|
229
|
+
}, [s]), {
|
|
232
230
|
value: n,
|
|
233
231
|
setValue: i
|
|
234
232
|
};
|