cabbage-react 1.0.11 → 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 +14 -14
- 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;;sBAMjB,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;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,11 +180,11 @@ const b = (d) => {
|
|
|
180
180
|
}, []), {
|
|
181
181
|
properties: e
|
|
182
182
|
};
|
|
183
|
-
}, I = (
|
|
184
|
-
const { properties: e } = b(
|
|
183
|
+
}, I = (g) => {
|
|
184
|
+
const { properties: e } = b(g), [n, a] = f(), [s, o] = f(), i = (t) => {
|
|
185
185
|
a(t);
|
|
186
186
|
const r = {
|
|
187
|
-
channel:
|
|
187
|
+
channel: g,
|
|
188
188
|
paramIdx: s,
|
|
189
189
|
value: t
|
|
190
190
|
};
|
|
@@ -193,7 +193,7 @@ const b = (d) => {
|
|
|
193
193
|
return u(() => {
|
|
194
194
|
var c;
|
|
195
195
|
const t = e == null ? void 0 : e.channels.find(
|
|
196
|
-
(w) => w.id ===
|
|
196
|
+
(w) => w.id === g
|
|
197
197
|
);
|
|
198
198
|
if (!t) return;
|
|
199
199
|
const r = t == null ? void 0 : t.parameterIndex;
|
|
@@ -201,11 +201,11 @@ const b = (d) => {
|
|
|
201
201
|
`[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,
|
|
202
202
|
r
|
|
203
203
|
), o(r));
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
`[Cabbage-React] Received initial value for channelId "${
|
|
207
|
-
|
|
208
|
-
), 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));
|
|
209
209
|
const l = (c = t.range) == null ? void 0 : c.defaultValue;
|
|
210
210
|
n === void 0 && l !== void 0 && (console.log(
|
|
211
211
|
`[Cabbage-React] Received default value for channelId "${t.id}"`,
|
|
@@ -213,15 +213,15 @@ const b = (d) => {
|
|
|
213
213
|
), a(l));
|
|
214
214
|
}, [e]), u(() => {
|
|
215
215
|
const t = (r) => {
|
|
216
|
-
const { command:
|
|
217
|
-
if (
|
|
216
|
+
const { command: d } = r.data;
|
|
217
|
+
if (d === "parameterChange") {
|
|
218
218
|
const { value: l, paramIdx: c } = r.data.data;
|
|
219
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;
|
|
220
220
|
console.log(
|
|
221
221
|
`[Cabbage-React] Received value change for parameterIndex ${c}`,
|
|
222
222
|
l
|
|
223
223
|
), a(l);
|
|
224
|
-
}
|
|
224
|
+
} else d === "batchWidgetUpdate" && console.log("batchWidgetUpdate", r);
|
|
225
225
|
};
|
|
226
226
|
return window.addEventListener("message", t), () => {
|
|
227
227
|
window.removeEventListener("message", t);
|