cabbage-react 1.0.12 → 1.0.13
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 +53 -42
- 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;CAqGnC,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react");console.log("Cabbage: loading cabbage.js");class f{static sendChannelUpdate(e,n=null,a=!1){if(a===!0||a===1)f.sendParameterUpdate(e,n);else{const s=e.value!==void 0?e.value:e.stringData||e.floatData;f.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 l={command:"midiMessage",obj:JSON.stringify(o)};s!==null?s.postMessage(l):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(l):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",l)}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 M=d=>{const[e,n]=u.useState();return u.useEffect(()=>{const a=s=>{const{id:o,widgetJson:l,command:t}=s.data;if(o===d&&l&&t==="widgetUpdate"){const r=JSON.parse(l);console.log(`[Cabbage-React] Received properties for channelId ${o}`,r),n(r)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:e}},I=d=>{const{properties:e}=M(d),[n,a]=u.useState(),[s,o]=u.useState(),l=t=>{a(t);const r={channel:d,paramIdx:s,value:t};f.sendParameterUpdate(r,null)};return u.useEffect(()=>{var i;const t=e==null?void 0:e.channels.find(g=>g.id===d);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 c=e==null?void 0:e.value;c!=null&&(console.log(`[Cabbage-React] Received initial value for channelId "${d}"`,c),a(c));const m=(i=t.range)==null?void 0:i.defaultValue;n===void 0&&m!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${t.id}"`,m),a(m))},[e]),u.useEffect(()=>{const t=r=>{var m;const{command:c}=r.data;if(c==="parameterChange"){const{value:i,paramIdx:g}=r.data.data;if(g!==s||i===null)return;console.log(`[Cabbage-React] Received value change for parameterIndex ${g}`,i),a(i)}else if(c==="batchWidgetUpdate"){const i=r.data.widgets,g=i==null?void 0:i.find(w=>w.id===d);if(!g)return;const b=JSON.parse(g.widgetJson).channels.find(w=>w.id===d),p=(m=b==null?void 0:b.range)==null?void 0:m.value;console.log(`[Cabbage-React] Received batch widget update for channelId ${g.id}`,p),a(p)}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[s]),{value:n,setValue:l}};exports.Cabbage=f;exports.useCabbageProperties=M;exports.useCabbageState=I;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useState as
|
|
1
|
+
import { useState as b, useEffect as p } from "react";
|
|
2
2
|
console.log("Cabbage: loading cabbage.js");
|
|
3
|
-
class
|
|
3
|
+
class f {
|
|
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 m {
|
|
|
16
16
|
*/
|
|
17
17
|
static sendChannelUpdate(e, n = null, a = !1) {
|
|
18
18
|
if (a === !0 || a === 1)
|
|
19
|
-
|
|
19
|
+
f.sendParameterUpdate(e, n);
|
|
20
20
|
else {
|
|
21
21
|
const s = e.value !== void 0 ? e.value : e.stringData || e.floatData;
|
|
22
|
-
|
|
22
|
+
f.sendChannelData(e.channel, s, n);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
static sendParameterUpdate(e, n = null) {
|
|
@@ -92,13 +92,13 @@ class m {
|
|
|
92
92
|
dataByte1: n,
|
|
93
93
|
dataByte2: a
|
|
94
94
|
};
|
|
95
|
-
const
|
|
95
|
+
const l = {
|
|
96
96
|
command: "midiMessage",
|
|
97
97
|
obj: JSON.stringify(o)
|
|
98
98
|
};
|
|
99
|
-
s !== null ? s.postMessage(
|
|
99
|
+
s !== null ? s.postMessage(l) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(l) : console.error(
|
|
100
100
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
101
|
-
|
|
101
|
+
l
|
|
102
102
|
);
|
|
103
103
|
}
|
|
104
104
|
static sendChannelData(e, n, a = null) {
|
|
@@ -161,13 +161,13 @@ class m {
|
|
|
161
161
|
);
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
const
|
|
165
|
-
const [e, n] =
|
|
166
|
-
return
|
|
164
|
+
const I = (d) => {
|
|
165
|
+
const [e, n] = b();
|
|
166
|
+
return p(() => {
|
|
167
167
|
const a = (s) => {
|
|
168
|
-
const { id: o, widgetJson:
|
|
169
|
-
if (o ===
|
|
170
|
-
const r = JSON.parse(
|
|
168
|
+
const { id: o, widgetJson: l, command: t } = s.data;
|
|
169
|
+
if (o === d && l && t === "widgetUpdate") {
|
|
170
|
+
const r = JSON.parse(l);
|
|
171
171
|
console.log(
|
|
172
172
|
`[Cabbage-React] Received properties for channelId ${o}`,
|
|
173
173
|
r
|
|
@@ -180,20 +180,20 @@ const b = (g) => {
|
|
|
180
180
|
}, []), {
|
|
181
181
|
properties: e
|
|
182
182
|
};
|
|
183
|
-
},
|
|
184
|
-
const { properties: e } =
|
|
183
|
+
}, F = (d) => {
|
|
184
|
+
const { properties: e } = I(d), [n, a] = b(), [s, o] = b(), l = (t) => {
|
|
185
185
|
a(t);
|
|
186
186
|
const r = {
|
|
187
|
-
channel:
|
|
187
|
+
channel: d,
|
|
188
188
|
paramIdx: s,
|
|
189
189
|
value: t
|
|
190
190
|
};
|
|
191
|
-
|
|
191
|
+
f.sendParameterUpdate(r, null);
|
|
192
192
|
};
|
|
193
|
-
return
|
|
194
|
-
var
|
|
193
|
+
return p(() => {
|
|
194
|
+
var i;
|
|
195
195
|
const t = e == null ? void 0 : e.channels.find(
|
|
196
|
-
(
|
|
196
|
+
(g) => g.id === d
|
|
197
197
|
);
|
|
198
198
|
if (!t) return;
|
|
199
199
|
const r = t == null ? void 0 : t.parameterIndex;
|
|
@@ -201,38 +201,49 @@ const b = (g) => {
|
|
|
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(
|
|
209
|
-
const
|
|
210
|
-
n === void 0 &&
|
|
204
|
+
const c = e == null ? void 0 : e.value;
|
|
205
|
+
c != null && (console.log(
|
|
206
|
+
`[Cabbage-React] Received initial value for channelId "${d}"`,
|
|
207
|
+
c
|
|
208
|
+
), a(c));
|
|
209
|
+
const m = (i = t.range) == null ? void 0 : i.defaultValue;
|
|
210
|
+
n === void 0 && m !== void 0 && (console.log(
|
|
211
211
|
`[Cabbage-React] Received default value for channelId "${t.id}"`,
|
|
212
|
-
|
|
213
|
-
), a(
|
|
214
|
-
}, [e]),
|
|
212
|
+
m
|
|
213
|
+
), a(m));
|
|
214
|
+
}, [e]), p(() => {
|
|
215
215
|
const t = (r) => {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
var m;
|
|
217
|
+
const { command: c } = r.data;
|
|
218
|
+
if (c === "parameterChange") {
|
|
219
|
+
const { value: i, paramIdx: g } = r.data.data;
|
|
220
|
+
if (g !== s || i === null) return;
|
|
220
221
|
console.log(
|
|
221
|
-
`[Cabbage-React] Received value change for parameterIndex ${
|
|
222
|
-
|
|
223
|
-
), a(
|
|
224
|
-
} else
|
|
222
|
+
`[Cabbage-React] Received value change for parameterIndex ${g}`,
|
|
223
|
+
i
|
|
224
|
+
), a(i);
|
|
225
|
+
} else if (c === "batchWidgetUpdate") {
|
|
226
|
+
const i = r.data.widgets, g = i == null ? void 0 : i.find((w) => w.id === d);
|
|
227
|
+
if (!g) return;
|
|
228
|
+
const u = JSON.parse(g.widgetJson).channels.find(
|
|
229
|
+
(w) => w.id === d
|
|
230
|
+
), M = (m = u == null ? void 0 : u.range) == null ? void 0 : m.value;
|
|
231
|
+
console.log(
|
|
232
|
+
`[Cabbage-React] Received batch widget update for channelId ${g.id}`,
|
|
233
|
+
M
|
|
234
|
+
), a(M);
|
|
235
|
+
}
|
|
225
236
|
};
|
|
226
237
|
return window.addEventListener("message", t), () => {
|
|
227
238
|
window.removeEventListener("message", t);
|
|
228
239
|
};
|
|
229
240
|
}, [s]), {
|
|
230
241
|
value: n,
|
|
231
|
-
setValue:
|
|
242
|
+
setValue: l
|
|
232
243
|
};
|
|
233
244
|
};
|
|
234
245
|
export {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
246
|
+
f as Cabbage,
|
|
247
|
+
I as useCabbageProperties,
|
|
248
|
+
F as useCabbageState
|
|
238
249
|
};
|