cabbage-react 1.0.56 → 1.0.57
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCabbageMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageMessage.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAClC,aAAa,MAAM,EACnB,UAAU;IACT,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;;
|
|
1
|
+
{"version":3,"file":"useCabbageMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageMessage.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAClC,aAAa,MAAM,EACnB,UAAU;IACT,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;;CAmCD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,GAChC,WAAW,MAAM,EACjB,UAAU;IACT,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;IAC/D,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;;
|
|
1
|
+
{"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,GAChC,WAAW,MAAM,EACjB,UAAU;IACT,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;IAC/D,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;;CAwCD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAChC,WAAW,MAAM,EACjB,UAAU;IACT,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACnC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;;
|
|
1
|
+
{"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAChC,WAAW,MAAM,EACjB,UAAU;IACT,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACnC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;;sBAyBO,CAAC,YACC,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU;CAiFhD,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react");class
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react");class U{static sendControlData({channel:e,value:s,gesture:a="complete"},t=null){const n={command:"controlData",channel:e,value:s,gesture:a};t!==null?t.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static isReadyToLoad(e=null,s={}){this.sendCustomCommand("isReadyToLoad",e)}static sendMidiMessageFromUI(e,s,a,t=null){var n={statusByte:e,dataByte1:s,dataByte2:a};const i={command:"midiMessage",obj:JSON.stringify(n)};t!==null?t.postMessage(i):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(i):window.parent!==window?window.parent.postMessage(i,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",i)}static MidiMessageFromHost(e,s,a){}static triggerFileOpenDialog(e,s,a={}){var t={channel:s,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.openAtLastKnownLocation:!0};const n={command:"fileOpen",obj:JSON.stringify(t)};e!==null?e.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static openUrl(e,s,a){var t={url:s,file:a};const n={command:"openUrl",obj:JSON.stringify(t)};e!==null?e.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static requestResize(e,s,a=null){const t={command:"requestResize",width:e,height:s};if(a!==null){console.warn("Cabbage: requestResize is not supported in VS Code extension mode");return}else typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(t):window.parent!==window?window.parent.postMessage(t,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",t)}static consumeKeypresses(e){typeof window.consumeKeypresses=="function"&&window.consumeKeypresses(e)}static sendChannelData(e,s,a=null){var t={channel:e};if(typeof s=="string")t.stringData=s;else if(typeof s=="number")t.floatData=s;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof s);return}const n={command:"channelData",obj:JSON.stringify(t)};a!==null?a.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static sendWidgetUpdate(e,s=null){const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};s!==null?s.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):window.parent!==window?window.parent.postMessage(a,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static addMessageListener(e){const s=a=>{a.source!==window&&e(a.data)};return window.addEventListener("message",s),window.hostMessageCallback=e,()=>{window.removeEventListener("message",s),window.hostMessageCallback===e&&(window.hostMessageCallback=null)}}static sendCustomCommand(e,s=null,a={}){const t={command:e,text:JSON.stringify(a)};if(s!==null)s.postMessage(t);else if(typeof window.sendMessageFromUI=="function")try{const n=window.sendMessageFromUI(t)}catch(n){console.error("Cabbage: sendMessageFromUI threw error:",n),console.error("Cabbage: Error stack:",n.stack)}else window.parent!==window?window.parent.postMessage(t,"*"):(console.error("Cabbage: window.sendMessageFromUI is not available yet. Message:",t),console.error("Cabbage: typeof window.sendMessageFromUI:",typeof window.sendMessageFromUI),console.error("Cabbage: window.sendMessageFromUI value:",window.sendMessageFromUI))}}const M=(o,e)=>(...s)=>{e&&console.log(`[Cabbage-React][${o}]`,...s)},v=(o,e)=>{if(!o||e?.skip)return{properties:void 0};const s=d.useRef(void 0);s.current=M(`useCabbageProperties:${o}`,e?.debug);const a=s.current,[t,n]=d.useState();return d.useEffect(()=>{const i=w=>{const{id:g,widgetJson:c,command:m}=w.data;if(g===o&&c&&m==="widgetUpdate"){const r=JSON.parse(c);a("Received properties",r),e?.onPropertiesUpdate&&e.onPropertiesUpdate(r),n(r)}};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[o,e?.onPropertiesUpdate]),{properties:t}},y=(o,e)=>{if(!o||e?.skip)return{value:void 0,setValue:()=>{}};const s=d.useRef(void 0);s.current=M(`useCabbageState:${o}`,e?.debug);const a=s.current,{properties:t}=v(o,{debug:e?.debug}),[n,i]=d.useState(),[w,g]=d.useState(),c=(r,l="complete")=>{i(r),U.sendControlData({channel:o,value:r,gesture:l})},m=r=>{e?.onValueUpdate&&e.onValueUpdate(r),i(r)};return d.useEffect(()=>{const r=t?.channels.find(f=>f.id===o);if(!r)return;const l=r.parameterIndex;if(w===void 0&&l!==void 0&&(a("Received parameterIndex",l),g(l)),n!==void 0)return;const u=r.range?.value;u!=null&&(a("Received initial value",u),m(u))},[t]),d.useEffect(()=>{const r=l=>{const{command:u}=l.data;if(u==="parameterChange"){const{value:f,paramIdx:p}=l.data.data;if(p!==w||f===null)return;a("Received parameterChange",f),m(f)}else if(u==="batchWidgetUpdate"){const p=l.data.widgets?.find(b=>b.id===o);if(!p)return;const C=JSON.parse(p.widgetJson).channels.find(b=>b.id===o)?.range?.value;a("Received batchWidgetUpdate",C),m(C)}};return window.addEventListener("message",r),()=>window.removeEventListener("message",r)},[o,e?.onValueUpdate,w]),{value:n,setValue:c}},F=(o,e)=>{if(!o||e?.skip)return{message:void 0};const s=d.useRef(void 0);s.current=M(`useCabbageMessage:${o}`,e?.debug);const a=s.current,[t,n]=d.useState();return d.useEffect(()=>{const i=w=>{const{data:g,type:c}=w;!g||c!=="message"||g.type===o&&(a("Received data",g),e?.onMessage&&e.onMessage(g),n(g))};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[o,e?.onMessage]),{message:t}};exports.Cabbage=U;exports.useCabbageMessage=F;exports.useCabbageProperties=v;exports.useCabbageState=y;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useRef as U, useState as p, useEffect as b } from "react";
|
|
2
2
|
class y {
|
|
3
3
|
/**
|
|
4
4
|
* Send a widget value change to the Cabbage backend.
|
|
@@ -287,86 +287,98 @@ class y {
|
|
|
287
287
|
));
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
|
-
const
|
|
290
|
+
const C = (o, e) => (...s) => {
|
|
291
291
|
e && console.log(`[Cabbage-React][${o}]`, ...s);
|
|
292
|
-
},
|
|
292
|
+
}, F = (o, e) => {
|
|
293
293
|
if (!o || e?.skip) return { properties: void 0 };
|
|
294
|
-
const s =
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
294
|
+
const s = U(
|
|
295
|
+
void 0
|
|
296
|
+
);
|
|
297
|
+
s.current = C(
|
|
298
|
+
`useCabbageProperties:${o}`,
|
|
299
|
+
e?.debug
|
|
300
|
+
);
|
|
301
|
+
const n = s.current, [t, a] = p();
|
|
302
|
+
return b(() => {
|
|
303
|
+
const r = (w) => {
|
|
304
|
+
const { id: d, widgetJson: c, command: m } = w.data;
|
|
305
|
+
if (d === o && c && m === "widgetUpdate") {
|
|
306
|
+
const i = JSON.parse(c);
|
|
307
|
+
n("Received properties", i), e?.onPropertiesUpdate && e.onPropertiesUpdate(i), a(i);
|
|
304
308
|
}
|
|
305
309
|
};
|
|
306
|
-
return window.addEventListener("message",
|
|
307
|
-
}, [o, e?.onPropertiesUpdate]), { properties:
|
|
308
|
-
},
|
|
310
|
+
return window.addEventListener("message", r), () => window.removeEventListener("message", r);
|
|
311
|
+
}, [o, e?.onPropertiesUpdate]), { properties: t };
|
|
312
|
+
}, R = (o, e) => {
|
|
309
313
|
if (!o || e?.skip)
|
|
310
314
|
return { value: void 0, setValue: () => {
|
|
311
315
|
} };
|
|
312
|
-
const s =
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
+
const s = U(
|
|
317
|
+
void 0
|
|
318
|
+
);
|
|
319
|
+
s.current = C(
|
|
320
|
+
`useCabbageState:${o}`,
|
|
321
|
+
e?.debug
|
|
322
|
+
);
|
|
323
|
+
const n = s.current, { properties: t } = F(o, {
|
|
316
324
|
debug: e?.debug
|
|
317
|
-
}), [
|
|
318
|
-
|
|
325
|
+
}), [a, r] = p(), [w, d] = p(), c = (i, g = "complete") => {
|
|
326
|
+
r(i), y.sendControlData({
|
|
319
327
|
channel: o,
|
|
320
328
|
value: i,
|
|
321
329
|
gesture: g
|
|
322
330
|
});
|
|
323
|
-
},
|
|
324
|
-
e?.onValueUpdate && e.onValueUpdate(i),
|
|
331
|
+
}, m = (i) => {
|
|
332
|
+
e?.onValueUpdate && e.onValueUpdate(i), r(i);
|
|
325
333
|
};
|
|
326
|
-
return
|
|
327
|
-
const i =
|
|
328
|
-
(
|
|
334
|
+
return b(() => {
|
|
335
|
+
const i = t?.channels.find(
|
|
336
|
+
(u) => u.id === o
|
|
329
337
|
);
|
|
330
338
|
if (!i) return;
|
|
331
339
|
const g = i.parameterIndex;
|
|
332
|
-
if (
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
}, [
|
|
340
|
+
if (w === void 0 && g !== void 0 && (n("Received parameterIndex", g), d(g)), a !== void 0) return;
|
|
341
|
+
const l = i.range?.value;
|
|
342
|
+
l != null && (n("Received initial value", l), m(l));
|
|
343
|
+
}, [t]), b(() => {
|
|
336
344
|
const i = (g) => {
|
|
337
|
-
const { command:
|
|
338
|
-
if (
|
|
339
|
-
const { value:
|
|
340
|
-
if (
|
|
341
|
-
|
|
342
|
-
} else if (
|
|
343
|
-
const
|
|
344
|
-
if (!
|
|
345
|
-
const
|
|
346
|
-
(
|
|
345
|
+
const { command: l } = g.data;
|
|
346
|
+
if (l === "parameterChange") {
|
|
347
|
+
const { value: u, paramIdx: f } = g.data.data;
|
|
348
|
+
if (f !== w || u === null) return;
|
|
349
|
+
n("Received parameterChange", u), m(u);
|
|
350
|
+
} else if (l === "batchWidgetUpdate") {
|
|
351
|
+
const f = g.data.widgets?.find((M) => M.id === o);
|
|
352
|
+
if (!f) return;
|
|
353
|
+
const v = JSON.parse(f.widgetJson).channels.find(
|
|
354
|
+
(M) => M.id === o
|
|
347
355
|
)?.range?.value;
|
|
348
|
-
|
|
356
|
+
n("Received batchWidgetUpdate", v), m(v);
|
|
349
357
|
}
|
|
350
358
|
};
|
|
351
359
|
return window.addEventListener("message", i), () => window.removeEventListener("message", i);
|
|
352
|
-
}, [o, e?.onValueUpdate,
|
|
360
|
+
}, [o, e?.onValueUpdate, w]), { value: a, setValue: c };
|
|
353
361
|
}, S = (o, e) => {
|
|
354
362
|
if (!o || e?.skip) return { message: void 0 };
|
|
355
|
-
const s =
|
|
363
|
+
const s = U(
|
|
364
|
+
void 0
|
|
365
|
+
);
|
|
366
|
+
s.current = C(
|
|
356
367
|
`useCabbageMessage:${o}`,
|
|
357
368
|
e?.debug
|
|
358
|
-
)
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
369
|
+
);
|
|
370
|
+
const n = s.current, [t, a] = p();
|
|
371
|
+
return b(() => {
|
|
372
|
+
const r = (w) => {
|
|
373
|
+
const { data: d, type: c } = w;
|
|
374
|
+
!d || c !== "message" || d.type === o && (n("Received data", d), e?.onMessage && e.onMessage(d), a(d));
|
|
363
375
|
};
|
|
364
|
-
return window.addEventListener("message",
|
|
365
|
-
}, [o, e?.onMessage]), { message:
|
|
376
|
+
return window.addEventListener("message", r), () => window.removeEventListener("message", r);
|
|
377
|
+
}, [o, e?.onMessage]), { message: t };
|
|
366
378
|
};
|
|
367
379
|
export {
|
|
368
380
|
y as Cabbage,
|
|
369
381
|
S as useCabbageMessage,
|
|
370
|
-
|
|
371
|
-
|
|
382
|
+
F as useCabbageProperties,
|
|
383
|
+
R as useCabbageState
|
|
372
384
|
};
|