cabbage-react 1.0.58 → 1.0.60
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;;CA+BD,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;;CAoCD,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;;sBAqBO,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 b=(o,e)=>(...s)=>{e&&console.log(`[Cabbage-React] ${o}:`,...s)},C=(o,e)=>{if(!o||e?.skip)return{properties:void 0};const s=d.useRef(void 0);s.current=b(o,e?.debug);const[a,t]=d.useState();return d.useEffect(()=>{const n=i=>{const{id:g,widgetJson:c,command:f}=i.data;if(g===o&&c&&f==="widgetUpdate"){const r=JSON.parse(c);s.current?.("Received properties",r),e?.onPropertiesUpdate&&e.onPropertiesUpdate(r),t(r)}};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[o,e?.onPropertiesUpdate]),{properties:a}},v=(o,e)=>{if(!o||e?.skip)return{value:void 0,setValue:()=>{}};const s=d.useRef(void 0);s.current=b(o,e?.debug);const{properties:a}=C(o,{debug:e?.debug}),[t,n]=d.useState(),[i,g]=d.useState(),c=(r,l="complete")=>{n(r),U.sendControlData({channel:o,value:r,gesture:l})},f=r=>{e?.onValueUpdate&&e.onValueUpdate(r),n(r)};return d.useEffect(()=>{const r=a?.channels.find(u=>u.id===o);if(!r)return;const l=r.parameterIndex;if(i===void 0&&l!==void 0&&(s.current?.("Received parameterIndex",l),g(l)),t!==void 0)return;const w=r.range?.value;w!=null&&(s.current?.("Received initial value",w),f(w))},[a]),d.useEffect(()=>{const r=l=>{const{command:w}=l.data;if(w==="parameterChange"){const{value:u,paramIdx:m}=l.data.data;if(m!==i||u===null)return;s.current?.("Received parameterChange",u),f(u)}else if(w==="batchWidgetUpdate"){const m=l.data.widgets?.find(p=>p.id===o);if(!m)return;const M=JSON.parse(m.widgetJson).channels.find(p=>p.id===o)?.range?.value;s.current?.("Received batchWidgetUpdate",M),f(M)}};return window.addEventListener("message",r),()=>window.removeEventListener("message",r)},[o,e?.onValueUpdate,i]),{value:t,setValue:c}},y=(o,e)=>{if(!o||e?.skip)return{message:void 0};const s=d.useRef(void 0);s.current=b(o,e?.debug);const[a,t]=d.useState();return d.useEffect(()=>{const n=i=>{const{data:g,type:c}=i;!g||c!=="message"||g.type===o&&(s.current?.("Received data",g),e?.onMessage&&e.onMessage(g),t(g))};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[o,e?.onMessage]),{message:a}};exports.Cabbage=U;exports.useCabbageMessage=y;exports.useCabbageProperties=C;exports.useCabbageState=v;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
class
|
|
1
|
+
import { useRef as b, useState as f, useEffect as p } from "react";
|
|
2
|
+
class C {
|
|
3
3
|
/**
|
|
4
4
|
* Send a widget value change to the Cabbage backend.
|
|
5
5
|
*
|
|
@@ -288,16 +288,13 @@ class v {
|
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
290
|
const U = (o, e) => (...s) => {
|
|
291
|
-
e && console.log(`[Cabbage-React]
|
|
291
|
+
e && console.log(`[Cabbage-React] ${o}:`, ...s);
|
|
292
292
|
}, y = (o, e) => {
|
|
293
293
|
if (!o || e?.skip) return { properties: void 0 };
|
|
294
|
-
const s =
|
|
294
|
+
const s = b(
|
|
295
295
|
void 0
|
|
296
296
|
);
|
|
297
|
-
s.current = U(
|
|
298
|
-
`useCabbageProperties:${o}`,
|
|
299
|
-
e?.debug
|
|
300
|
-
);
|
|
297
|
+
s.current = U(o, e?.debug);
|
|
301
298
|
const [a, t] = f();
|
|
302
299
|
return p(() => {
|
|
303
300
|
const n = (i) => {
|
|
@@ -313,17 +310,14 @@ const U = (o, e) => (...s) => {
|
|
|
313
310
|
if (!o || e?.skip)
|
|
314
311
|
return { value: void 0, setValue: () => {
|
|
315
312
|
} };
|
|
316
|
-
const s =
|
|
313
|
+
const s = b(
|
|
317
314
|
void 0
|
|
318
315
|
);
|
|
319
|
-
s.current = U(
|
|
320
|
-
`useCabbageState:${o}`,
|
|
321
|
-
e?.debug
|
|
322
|
-
);
|
|
316
|
+
s.current = U(o, e?.debug);
|
|
323
317
|
const { properties: a } = y(o, {
|
|
324
318
|
debug: e?.debug
|
|
325
319
|
}), [t, n] = f(), [i, d] = f(), l = (r, g = "complete") => {
|
|
326
|
-
n(r),
|
|
320
|
+
n(r), C.sendControlData({
|
|
327
321
|
channel: o,
|
|
328
322
|
value: r,
|
|
329
323
|
gesture: g
|
|
@@ -348,25 +342,22 @@ const U = (o, e) => (...s) => {
|
|
|
348
342
|
if (m !== i || c === null) return;
|
|
349
343
|
s.current?.("Received parameterChange", c), u(c);
|
|
350
344
|
} else if (w === "batchWidgetUpdate") {
|
|
351
|
-
const m = g.data.widgets?.find((
|
|
345
|
+
const m = g.data.widgets?.find((M) => M.id === o);
|
|
352
346
|
if (!m) return;
|
|
353
|
-
const
|
|
354
|
-
(
|
|
347
|
+
const v = JSON.parse(m.widgetJson).channels.find(
|
|
348
|
+
(M) => M.id === o
|
|
355
349
|
)?.range?.value;
|
|
356
|
-
s.current?.("Received batchWidgetUpdate",
|
|
350
|
+
s.current?.("Received batchWidgetUpdate", v), u(v);
|
|
357
351
|
}
|
|
358
352
|
};
|
|
359
353
|
return window.addEventListener("message", r), () => window.removeEventListener("message", r);
|
|
360
354
|
}, [o, e?.onValueUpdate, i]), { value: t, setValue: l };
|
|
361
355
|
}, R = (o, e) => {
|
|
362
356
|
if (!o || e?.skip) return { message: void 0 };
|
|
363
|
-
const s =
|
|
357
|
+
const s = b(
|
|
364
358
|
void 0
|
|
365
359
|
);
|
|
366
|
-
s.current = U(
|
|
367
|
-
`useCabbageMessage:${o}`,
|
|
368
|
-
e?.debug
|
|
369
|
-
);
|
|
360
|
+
s.current = U(o, e?.debug);
|
|
370
361
|
const [a, t] = f();
|
|
371
362
|
return p(() => {
|
|
372
363
|
const n = (i) => {
|
|
@@ -377,7 +368,7 @@ const U = (o, e) => (...s) => {
|
|
|
377
368
|
}, [o, e?.onMessage]), { message: a };
|
|
378
369
|
};
|
|
379
370
|
export {
|
|
380
|
-
|
|
371
|
+
C as Cabbage,
|
|
381
372
|
R as useCabbageMessage,
|
|
382
373
|
y as useCabbageProperties,
|
|
383
374
|
L as useCabbageState
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cabbageDebug.d.ts","sourceRoot":"","sources":["../../src/utils/cabbageDebug.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"cabbageDebug.d.ts","sourceRoot":"","sources":["../../src/utils/cabbageDebug.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,EAAE,UAAU,OAAO,MAC7D,GAAG,MAAM,GAAG,EAAE,SAKtB,CAAC"}
|