cabbage-react 1.0.25 → 1.0.26
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 +25 -27
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,aACrB,MAAM,YACR,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU;;sBAOb,CAAC;;
|
|
1
|
+
{"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,aACrB,MAAM,YACR,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU;;sBAOb,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 p{static sendControlData({channel:o,value:e,gesture:a="complete"},n=null){const s={command:"controlData",channel:o,value:e,gesture:a};n!==null?n.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static isReadyToLoad(o=null,e={}){this.sendCustomCommand("isReadyToLoad",o)}static sendMidiMessageFromUI(o,e,a,n=null){var s={statusByte:o,dataByte1:e,dataByte2:a};const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react");console.log("Cabbage: loading cabbage.js");class p{static sendControlData({channel:o,value:e,gesture:a="complete"},n=null){const s={command:"controlData",channel:o,value:e,gesture:a};n!==null?n.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static isReadyToLoad(o=null,e={}){this.sendCustomCommand("isReadyToLoad",o)}static sendMidiMessageFromUI(o,e,a,n=null){var s={statusByte:o,dataByte1:e,dataByte2:a};const d={command:"midiMessage",obj:JSON.stringify(s)};n!==null?n.postMessage(d):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(d):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",d)}static MidiMessageFromHost(o,e,a){console.log("Cabbage: Got MIDI Message"+o+":"+e+":"+a)}static triggerFileOpenDialog(o,e,a={}){var n={channel:e,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.openAtLastKnownLocation:!0};const s={command:"fileOpen",obj:JSON.stringify(n)};o!==null?o.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static openUrl(o,e,a){var n={url:e,file:a};const s={command:"openUrl",obj:JSON.stringify(n)};o!==null?o.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static requestResize(o,e,a=null){const n={command:"requestResize",width:o,height:e};if(a!==null){console.warn("Cabbage: requestResize is not supported in VS Code extension mode");return}else typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static sendChannelData(o,e,a=null){var n={channel:o};if(typeof e=="string")n.stringData=e;else if(typeof e=="number")n.floatData=e;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof e);return}const s={command:"channelData",obj:JSON.stringify(n)};console.log("Cabbage: sending channel data from UI",n),a!==null?a.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static sendWidgetUpdate(o,e=null){const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(o))};e!==null?e.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static sendCustomCommand(o,e=null,a={}){const n={command:o,text:JSON.stringify(a)};if(e!==null)e.postMessage(n);else if(typeof window.sendMessageFromUI=="function"){console.log("Cabbage: Calling window.sendMessageFromUI with:",n);try{const s=window.sendMessageFromUI(n);console.log("Cabbage: sendMessageFromUI returned:",s)}catch(s){console.error("Cabbage: sendMessageFromUI threw error:",s),console.error("Cabbage: Error stack:",s.stack)}}else console.error("Cabbage: window.sendMessageFromUI is not available yet. Message:",n),console.error("Cabbage: typeof window.sendMessageFromUI:",typeof window.sendMessageFromUI),console.error("Cabbage: window.sendMessageFromUI value:",window.sendMessageFromUI)}}const C=r=>{const[o,e]=m.useState();return m.useEffect(()=>{const a=n=>{const{id:s,widgetJson:d,command:w}=n.data;if(s===r&&d&&w==="widgetUpdate"){const t=JSON.parse(d);console.log(`[Cabbage-React] Received properties for channelId ${s}`,t),e(t)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:o}},I=(r,o="complete")=>{const{properties:e}=C(r),[a,n]=m.useState(),[s,d]=m.useState(),w=t=>{n(t),p.sendControlData({channel:r,value:t,gesture:o})};return m.useEffect(()=>{var b;const t=e==null?void 0:e.channels.find(i=>i.id===r);if(!t)return;const l=t==null?void 0:t.parameterIndex;s===void 0&&l!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,l),d(l));const g=(b=t.range)==null?void 0:b.defaultValue;a===void 0&&g!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${t.id}"`,g),n(g))},[e]),m.useEffect(()=>{const t=l=>{var b;const{command:g}=l.data;if(g==="parameterChange"){const{value:i,paramIdx:c}=l.data.data;if(c!==s||i===null)return;console.log(`[Cabbage-React] Received parameterChange for parameterIndex ${c}`,i),n(i)}else if(g==="batchWidgetUpdate"){const i=l.data.widgets,c=i==null?void 0:i.find(f=>f.id===r);if(!c)return;const u=JSON.parse(c.widgetJson).channels.find(f=>f.id===r),M=(b=u==null?void 0:u.range)==null?void 0:b.value;console.log(`[Cabbage-React] Received batch widget update for channelId ${c.id}`,M),n(M)}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[s]),{value:a,setValue:w,parameterIndex:s}};exports.Cabbage=p;exports.useCabbageProperties=C;exports.useCabbageState=I;
|
package/dist/index.mjs
CHANGED
|
@@ -56,13 +56,13 @@ class I {
|
|
|
56
56
|
dataByte1: e,
|
|
57
57
|
dataByte2: a
|
|
58
58
|
};
|
|
59
|
-
const
|
|
59
|
+
const d = {
|
|
60
60
|
command: "midiMessage",
|
|
61
61
|
obj: JSON.stringify(s)
|
|
62
62
|
};
|
|
63
|
-
n !== null ? n.postMessage(
|
|
63
|
+
n !== null ? n.postMessage(d) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(d) : console.error(
|
|
64
64
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
65
|
-
|
|
65
|
+
d
|
|
66
66
|
);
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
@@ -236,13 +236,13 @@ class I {
|
|
|
236
236
|
);
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
|
-
const C = (
|
|
239
|
+
const C = (r) => {
|
|
240
240
|
const [o, e] = u();
|
|
241
241
|
return M(() => {
|
|
242
242
|
const a = (n) => {
|
|
243
|
-
const { id: s, widgetJson:
|
|
244
|
-
if (s ===
|
|
245
|
-
const t = JSON.parse(
|
|
243
|
+
const { id: s, widgetJson: d, command: w } = n.data;
|
|
244
|
+
if (s === r && d && w === "widgetUpdate") {
|
|
245
|
+
const t = JSON.parse(d);
|
|
246
246
|
console.log(
|
|
247
247
|
`[Cabbage-React] Received properties for channelId ${s}`,
|
|
248
248
|
t
|
|
@@ -255,48 +255,46 @@ const C = (d) => {
|
|
|
255
255
|
}, []), {
|
|
256
256
|
properties: o
|
|
257
257
|
};
|
|
258
|
-
}, y = (
|
|
259
|
-
const { properties: e } = C(
|
|
260
|
-
n(t)
|
|
261
|
-
|
|
262
|
-
channel: d,
|
|
258
|
+
}, y = (r, o = "complete") => {
|
|
259
|
+
const { properties: e } = C(r), [a, n] = u(), [s, d] = u(), w = (t) => {
|
|
260
|
+
n(t), I.sendControlData({
|
|
261
|
+
channel: r,
|
|
263
262
|
value: t,
|
|
264
263
|
gesture: o
|
|
265
|
-
};
|
|
266
|
-
I.sendControlData(i, null);
|
|
264
|
+
});
|
|
267
265
|
};
|
|
268
266
|
return M(() => {
|
|
269
267
|
var m;
|
|
270
268
|
const t = e == null ? void 0 : e.channels.find(
|
|
271
|
-
(
|
|
269
|
+
(i) => i.id === r
|
|
272
270
|
);
|
|
273
271
|
if (!t) return;
|
|
274
|
-
const
|
|
275
|
-
s === void 0 &&
|
|
272
|
+
const l = t == null ? void 0 : t.parameterIndex;
|
|
273
|
+
s === void 0 && l !== void 0 && (console.log(
|
|
276
274
|
`[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,
|
|
277
|
-
|
|
278
|
-
), l
|
|
275
|
+
l
|
|
276
|
+
), d(l));
|
|
279
277
|
const g = (m = t.range) == null ? void 0 : m.defaultValue;
|
|
280
278
|
a === void 0 && g !== void 0 && (console.log(
|
|
281
279
|
`[Cabbage-React] Received default value for channelId "${t.id}"`,
|
|
282
280
|
g
|
|
283
281
|
), n(g));
|
|
284
282
|
}, [e]), M(() => {
|
|
285
|
-
const t = (
|
|
283
|
+
const t = (l) => {
|
|
286
284
|
var m;
|
|
287
|
-
const { command: g } =
|
|
285
|
+
const { command: g } = l.data;
|
|
288
286
|
if (g === "parameterChange") {
|
|
289
|
-
const { value:
|
|
290
|
-
if (c !== s ||
|
|
287
|
+
const { value: i, paramIdx: c } = l.data.data;
|
|
288
|
+
if (c !== s || i === null) return;
|
|
291
289
|
console.log(
|
|
292
290
|
`[Cabbage-React] Received parameterChange for parameterIndex ${c}`,
|
|
293
|
-
|
|
294
|
-
), n(
|
|
291
|
+
i
|
|
292
|
+
), n(i);
|
|
295
293
|
} else if (g === "batchWidgetUpdate") {
|
|
296
|
-
const
|
|
294
|
+
const i = l.data.widgets, c = i == null ? void 0 : i.find((b) => b.id === r);
|
|
297
295
|
if (!c) return;
|
|
298
296
|
const f = JSON.parse(c.widgetJson).channels.find(
|
|
299
|
-
(b) => b.id ===
|
|
297
|
+
(b) => b.id === r
|
|
300
298
|
), p = (m = f == null ? void 0 : f.range) == null ? void 0 : m.value;
|
|
301
299
|
console.log(
|
|
302
300
|
`[Cabbage-React] Received batch widget update for channelId ${c.id}`,
|