cabbage-react 1.0.47 → 1.0.49
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/cabbage/cabbage.d.ts +30 -1
- package/dist/cabbage/cabbage.d.ts.map +1 -1
- package/dist/hooks/useCabbageMessage.d.ts +5 -4
- package/dist/hooks/useCabbageMessage.d.ts.map +1 -1
- package/dist/hooks/useCabbageProperties.d.ts.map +1 -1
- package/dist/hooks/useCabbageState.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +184 -160
- package/package.json +1 -1
|
@@ -212,6 +212,35 @@ export class Cabbage {
|
|
|
212
212
|
* @param {Object|null} vscode - VS Code API object (null for plugin mode)
|
|
213
213
|
* @param {Object} additionalData - Additional data to include in the command
|
|
214
214
|
*/
|
|
215
|
-
|
|
215
|
+
/**
|
|
216
|
+
* Register a listener for incoming messages from the Cabbage backend.
|
|
217
|
+
*
|
|
218
|
+
* Abstracts the two environments so that the same UI code works everywhere:
|
|
219
|
+
* - **VS Code (iframe relay)**: messages arrive as window `message` events
|
|
220
|
+
* - **Native plugin (DAW)**: messages arrive via `window.hostMessageCallback`
|
|
221
|
+
*
|
|
222
|
+
* @param {function(Object): void} callback - Called with the message object.
|
|
223
|
+
* Common message shapes:
|
|
224
|
+
* - `{ command: "parameterChange", data: { paramIdx, value } }` (data may be top-level or nested)
|
|
225
|
+
* - `{ command: "widgetUpdate", id, value }` (from cabbageSetValue / cabbageSet)
|
|
226
|
+
* - `{ command: "widgetUpdate", id, widgetJson }` (full widget update)
|
|
227
|
+
* - `{ command: "channelDataUpdate", data: { channel, value } }`
|
|
228
|
+
* @returns {function(): void} Cleanup function — call it when the UI is torn down.
|
|
229
|
+
*
|
|
230
|
+
* @example <caption>Vanilla HTML</caption>
|
|
231
|
+
* import { Cabbage } from './cabbage/cabbage.js';
|
|
232
|
+
* Cabbage.addMessageListener((msg) => {
|
|
233
|
+
* const data = msg.data ?? msg;
|
|
234
|
+
* if (msg.command === 'parameterChange') { ... }
|
|
235
|
+
* });
|
|
236
|
+
*
|
|
237
|
+
* @example <caption>Svelte</caption>
|
|
238
|
+
* import { onMount, onDestroy } from 'svelte';
|
|
239
|
+
* let remove;
|
|
240
|
+
* onMount(() => { remove = Cabbage.addMessageListener((msg) => { ... }); });
|
|
241
|
+
* onDestroy(() => remove?.());
|
|
242
|
+
*/
|
|
243
|
+
static addMessageListener(callback: (arg0: Object) => void): () => void;
|
|
244
|
+
static sendCustomCommand(command: any, vscode?: null, additionalData?: {}): void;
|
|
216
245
|
}
|
|
217
246
|
//# sourceMappingURL=cabbage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cabbage.d.ts","sourceRoot":"","sources":["../../src/cabbage/cabbage.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoFG;AAEH;IACC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,oDALG;QAAqB,OAAO,EAApB,MAAM;QACc,KAAK,EAAzB,MAAM,GAAC,MAAM;QACC,OAAO;KAC7B,WAAQ,MAAM,GAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"cabbage.d.ts","sourceRoot":"","sources":["../../src/cabbage/cabbage.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoFG;AAEH;IACC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,oDALG;QAAqB,OAAO,EAApB,MAAM;QACc,KAAK,EAAzB,MAAM,GAAC,MAAM;QACC,OAAO;KAC7B,WAAQ,MAAM,GAAC,IAAI,QA2BrB;IAED;;;;;OAKG;IACH,8BAHW,MAAM,GAAC,IAAI,mBACX,MAAM,QAIhB;IACD;;;;;;;OAOG;IACH,yCALW,MAAM,aACN,MAAM,aACN,MAAM,WACN,MAAM,GAAC,IAAI,QAiCrB;IAED;;;;;;OAMG;IACH,uCAJW,MAAM,aACN,MAAM,aACN,MAAM,QAE8C;IAE/D;;;;;;;;;OASG;IACH,qCAPW,MAAM,GAAC,IAAI,WACX,MAAM,YAEd;QAAyB,SAAS;QACT,OAAO;QACN,uBAAuB;KACnD,QA8BA;IAED;;;;;;OAMG;IACH,uBAJW,MAAM,GAAC,IAAI,OACX,MAAM,QACN,MAAM,QA0BhB;IAED;;;;;;;;;;;OAWG;IACH,4BAPW,MAAM,UACN,MAAM,WACN,MAAM,QA8BhB;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,kCANW,OAAO,QAUjB;IAED;;;;;;OAMG;IACH,gCAJW,MAAM,QACN,MAAM,GAAC,MAAM,WACb,MAAM,GAAC,IAAI,QAuCrB;IAED;;;;;;OAMG;IACH,gCAmBC;IAED;;;;;;OAMG;IACH;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,oCArBW,CAAS,IAAM,EAAN,MAAM,KAAG,IAAI,GAMpB,MAAY,IAAI,CAkC5B;IAED,iFAiCC;CACD"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Custom hook to get
|
|
2
|
+
* Custom hook to get the latest message for a specific type from Cabbage backend.
|
|
3
3
|
* This hook listens to messages sent from the backend and updates the local state
|
|
4
4
|
* whenever new data is received.
|
|
5
|
-
* @param messageType
|
|
5
|
+
* @param messageType - The value of the `type` property in the incoming message object to listen for.
|
|
6
|
+
* @param onMessage - Callback fires immediately (synchronous - bypasses state batching)
|
|
6
7
|
*/
|
|
7
|
-
export declare const useCabbageMessage: <T>(messageType: string) => {
|
|
8
|
-
|
|
8
|
+
export declare const useCabbageMessage: <T>(messageType: string, onMessage?: (message: T) => void) => {
|
|
9
|
+
message: T | undefined;
|
|
9
10
|
};
|
|
10
11
|
//# sourceMappingURL=useCabbageMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCabbageMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageMessage.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"useCabbageMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageMessage.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,eACrB,MAAM,cACP,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI;;CA0BhC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,cAAe,MAAM;;
|
|
1
|
+
{"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,cAAe,MAAM;;CA8BrD,CAAC"}
|
|
@@ -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;CA2FnC,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react");class M{static sendControlData({channel:
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react");class M{static sendControlData({channel:s,value:e,gesture:a="complete"},o=null){const n={command:"controlData",channel:s,value:e,gesture:a};o!==null?o.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(s=null,e={}){this.sendCustomCommand("isReadyToLoad",s)}static sendMidiMessageFromUI(s,e,a,o=null){var n={statusByte:s,dataByte1:e,dataByte2:a};const t={command:"midiMessage",obj:JSON.stringify(n)};o!==null?o.postMessage(t):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 MidiMessageFromHost(s,e,a){}static triggerFileOpenDialog(s,e,a={}){var o={channel:e,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.openAtLastKnownLocation:!0};const n={command:"fileOpen",obj:JSON.stringify(o)};s!==null?s.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(s,e,a){var o={url:e,file:a};const n={command:"openUrl",obj:JSON.stringify(o)};s!==null?s.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(s,e,a=null){const o={command:"requestResize",width:s,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(o):window.parent!==window?window.parent.postMessage(o,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",o)}static consumeKeypresses(s){typeof window.consumeKeypresses=="function"&&window.consumeKeypresses(s)}static sendChannelData(s,e,a=null){var o={channel:s};if(typeof e=="string")o.stringData=e;else if(typeof e=="number")o.floatData=e;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof e);return}const n={command:"channelData",obj:JSON.stringify(o)};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(s,e=null){const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(s))};e!==null?e.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(s){const e=a=>{a.source!==window&&s(a.data)};return window.addEventListener("message",e),window.hostMessageCallback=s,()=>{window.removeEventListener("message",e),window.hostMessageCallback===s&&(window.hostMessageCallback=null)}}static sendCustomCommand(s,e=null,a={}){const o={command:s,text:JSON.stringify(a)};if(e!==null)e.postMessage(o);else if(typeof window.sendMessageFromUI=="function")try{const n=window.sendMessageFromUI(o)}catch(n){console.error("Cabbage: sendMessageFromUI threw error:",n),console.error("Cabbage: Error stack:",n.stack)}else window.parent!==window?window.parent.postMessage(o,"*"):(console.error("Cabbage: window.sendMessageFromUI is not available yet. Message:",o),console.error("Cabbage: typeof window.sendMessageFromUI:",typeof window.sendMessageFromUI),console.error("Cabbage: window.sendMessageFromUI value:",window.sendMessageFromUI))}}const C=r=>{const[s,e]=l.useState();return l.useEffect(()=>{const a=o=>{const{id:n,widgetJson:t,command:m}=o.data;if(n===r&&t&&m==="widgetUpdate"){const i=JSON.parse(t);console.log(`[Cabbage-React] Received properties for channelId: ${n}`,i),e(i)}};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[]),{properties:s}},y=(r,s="complete")=>{const{properties:e}=C(r),[a,o]=l.useState(),[n,t]=l.useState(),m=i=>{o(i),M.sendControlData({channel:r,value:i,gesture:s})};return l.useEffect(()=>{var f;const i=e==null?void 0:e.channels.find(d=>d.id===r);if(!i)return;const g=i.parameterIndex;if(n===void 0&&g!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId: ${i.id}`,g),t(g)),a!==void 0)return;const w=(f=i.range)==null?void 0:f.value;w!=null&&(console.log(`[Cabbage-React] Received initial value for channelId: ${i.id}`,w),o(w))},[e]),l.useEffect(()=>{const i=g=>{var f;const{command:w}=g.data;if(w==="parameterChange"){const{value:d,paramIdx:c}=g.data.data;if(c!==n||d===null)return;console.log(`[Cabbage-React] Received parameterChange for parameterIndex: ${c}`,d),o(d)}else if(w==="batchWidgetUpdate"){const d=g.data.widgets,c=d==null?void 0:d.find(p=>p.id===r);if(!c)return;const u=JSON.parse(c.widgetJson).channels.find(p=>p.id===r),b=(f=u==null?void 0:u.range)==null?void 0:f.value;console.log(`[Cabbage-React] Received batch widget update for channelId: ${c.id}`,b),o(b)}};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[n]),{value:a,setValue:m}},I=(r,s)=>{const[e,a]=l.useState();return l.useEffect(()=>{const o=n=>{const{data:t,type:m}=n;!t||m!=="message"||t.type===r&&(console.log(`[Cabbage-React] Received data for messageType: ${t.type}`,t),s&&s(t),a(t))};return window.addEventListener("message",o),()=>window.removeEventListener("message",o)},[r,s]),{message:e}};exports.Cabbage=M;exports.useCabbageMessage=I;exports.useCabbageProperties=C;exports.useCabbageState=y;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
class
|
|
1
|
+
import { 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
|
*
|
|
@@ -20,16 +20,16 @@ class y {
|
|
|
20
20
|
* @param {string} [data.gesture="complete"] - The gesture type: "begin" (start of interaction), "value" (during interaction), "end" (end of continuous interaction), or "complete" (discrete action e.g. button click).
|
|
21
21
|
* @param {Object|null} vscode - VS Code API object (null for plugin mode)
|
|
22
22
|
*/
|
|
23
|
-
static sendControlData({ channel:
|
|
24
|
-
const
|
|
23
|
+
static sendControlData({ channel: s, value: e, gesture: n = "complete" }, o = null) {
|
|
24
|
+
const a = {
|
|
25
25
|
command: "controlData",
|
|
26
|
-
channel:
|
|
27
|
-
value:
|
|
28
|
-
gesture:
|
|
26
|
+
channel: s,
|
|
27
|
+
value: e,
|
|
28
|
+
gesture: n
|
|
29
29
|
};
|
|
30
|
-
|
|
30
|
+
o !== null ? o.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : console.error(
|
|
31
31
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
32
|
-
|
|
32
|
+
a
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
@@ -38,8 +38,8 @@ class y {
|
|
|
38
38
|
* @param {Object|null} vscode - VS Code API object (null for plugin mode)
|
|
39
39
|
* @param {Object} additionalData - Additional initialization data
|
|
40
40
|
*/
|
|
41
|
-
static isReadyToLoad(
|
|
42
|
-
this.sendCustomCommand("isReadyToLoad",
|
|
41
|
+
static isReadyToLoad(s = null, e = {}) {
|
|
42
|
+
this.sendCustomCommand("isReadyToLoad", s);
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* Send a MIDI message from the UI to the Cabbage backend.
|
|
@@ -49,19 +49,19 @@ class y {
|
|
|
49
49
|
* @param {number} dataByte2 - Second MIDI data byte
|
|
50
50
|
* @param {Object|null} vscode - VS Code API object (null for plugin mode)
|
|
51
51
|
*/
|
|
52
|
-
static sendMidiMessageFromUI(
|
|
53
|
-
var
|
|
54
|
-
statusByte:
|
|
55
|
-
dataByte1:
|
|
56
|
-
dataByte2:
|
|
52
|
+
static sendMidiMessageFromUI(s, e, n, o = null) {
|
|
53
|
+
var a = {
|
|
54
|
+
statusByte: s,
|
|
55
|
+
dataByte1: e,
|
|
56
|
+
dataByte2: n
|
|
57
57
|
};
|
|
58
|
-
const
|
|
58
|
+
const t = {
|
|
59
59
|
command: "midiMessage",
|
|
60
|
-
obj: JSON.stringify(
|
|
60
|
+
obj: JSON.stringify(a)
|
|
61
61
|
};
|
|
62
|
-
|
|
62
|
+
o !== null ? o.postMessage(t) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(t) : window.parent !== window ? window.parent.postMessage(t, "*") : console.error(
|
|
63
63
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
64
|
-
|
|
64
|
+
t
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
@@ -71,7 +71,7 @@ class y {
|
|
|
71
71
|
* @param {number} dataByte1 - First MIDI data byte
|
|
72
72
|
* @param {number} dataByte2 - Second MIDI data byte
|
|
73
73
|
*/
|
|
74
|
-
static MidiMessageFromHost(
|
|
74
|
+
static MidiMessageFromHost(s, e, n) {
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
77
|
* Trigger a native file open dialog for file selection widgets.
|
|
@@ -83,20 +83,20 @@ class y {
|
|
|
83
83
|
* @param {string} [options.filters="*"] - File filters (e.g., "*.wav;*.aiff")
|
|
84
84
|
* @param {boolean} [options.openAtLastKnownLocation=true] - Whether to open at last known location
|
|
85
85
|
*/
|
|
86
|
-
static triggerFileOpenDialog(
|
|
87
|
-
var
|
|
88
|
-
channel:
|
|
89
|
-
directory:
|
|
90
|
-
filters:
|
|
91
|
-
openAtLastKnownLocation:
|
|
86
|
+
static triggerFileOpenDialog(s, e, n = {}) {
|
|
87
|
+
var o = {
|
|
88
|
+
channel: e,
|
|
89
|
+
directory: n.directory || "",
|
|
90
|
+
filters: n.filters || "*",
|
|
91
|
+
openAtLastKnownLocation: n.openAtLastKnownLocation !== void 0 ? n.openAtLastKnownLocation : !0
|
|
92
92
|
};
|
|
93
|
-
const
|
|
93
|
+
const a = {
|
|
94
94
|
command: "fileOpen",
|
|
95
|
-
obj: JSON.stringify(
|
|
95
|
+
obj: JSON.stringify(o)
|
|
96
96
|
};
|
|
97
|
-
|
|
97
|
+
s !== null ? s.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : console.error(
|
|
98
98
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
99
|
-
|
|
99
|
+
a
|
|
100
100
|
);
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
@@ -106,18 +106,18 @@ class y {
|
|
|
106
106
|
* @param {string} url - URL to open
|
|
107
107
|
* @param {string} file - File path to open
|
|
108
108
|
*/
|
|
109
|
-
static openUrl(
|
|
110
|
-
var
|
|
111
|
-
url:
|
|
112
|
-
file:
|
|
109
|
+
static openUrl(s, e, n) {
|
|
110
|
+
var o = {
|
|
111
|
+
url: e,
|
|
112
|
+
file: n
|
|
113
113
|
};
|
|
114
|
-
const
|
|
114
|
+
const a = {
|
|
115
115
|
command: "openUrl",
|
|
116
|
-
obj: JSON.stringify(
|
|
116
|
+
obj: JSON.stringify(o)
|
|
117
117
|
};
|
|
118
|
-
|
|
118
|
+
s !== null ? s.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : console.error(
|
|
119
119
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
120
|
-
|
|
120
|
+
a
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
123
|
/**
|
|
@@ -132,21 +132,21 @@ class y {
|
|
|
132
132
|
* The response will be sent via hostMessageCallback with:
|
|
133
133
|
* {command: "resizeResponse", accepted: boolean, width: number, height: number}
|
|
134
134
|
*/
|
|
135
|
-
static requestResize(
|
|
136
|
-
const
|
|
135
|
+
static requestResize(s, e, n = null) {
|
|
136
|
+
const o = {
|
|
137
137
|
command: "requestResize",
|
|
138
|
-
width:
|
|
139
|
-
height:
|
|
138
|
+
width: s,
|
|
139
|
+
height: e
|
|
140
140
|
};
|
|
141
|
-
if (
|
|
141
|
+
if (n !== null) {
|
|
142
142
|
console.warn(
|
|
143
143
|
"Cabbage: requestResize is not supported in VS Code extension mode"
|
|
144
144
|
);
|
|
145
145
|
return;
|
|
146
146
|
} else
|
|
147
|
-
typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(
|
|
147
|
+
typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(o) : window.parent !== window ? window.parent.postMessage(o, "*") : console.error(
|
|
148
148
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
149
|
-
|
|
149
|
+
o
|
|
150
150
|
);
|
|
151
151
|
}
|
|
152
152
|
/**
|
|
@@ -168,8 +168,8 @@ class y {
|
|
|
168
168
|
* myCustomEditor.addEventListener('focus', () => Cabbage.consumeKeypresses(true));
|
|
169
169
|
* myCustomEditor.addEventListener('blur', () => Cabbage.consumeKeypresses(false));
|
|
170
170
|
*/
|
|
171
|
-
static consumeKeypresses(
|
|
172
|
-
typeof window.consumeKeypresses == "function" && window.consumeKeypresses(
|
|
171
|
+
static consumeKeypresses(s) {
|
|
172
|
+
typeof window.consumeKeypresses == "function" && window.consumeKeypresses(s);
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
175
175
|
* Send channel data directly to Csound without DAW automation involvement.
|
|
@@ -178,28 +178,28 @@ class y {
|
|
|
178
178
|
* @param {number|string} data - The data to send (number or string)
|
|
179
179
|
* @param {Object|null} vscode - VS Code API object (null for plugin mode)
|
|
180
180
|
*/
|
|
181
|
-
static sendChannelData(
|
|
182
|
-
var
|
|
183
|
-
channel:
|
|
181
|
+
static sendChannelData(s, e, n = null) {
|
|
182
|
+
var o = {
|
|
183
|
+
channel: s
|
|
184
184
|
};
|
|
185
|
-
if (typeof
|
|
186
|
-
|
|
187
|
-
else if (typeof
|
|
188
|
-
|
|
185
|
+
if (typeof e == "string")
|
|
186
|
+
o.stringData = e;
|
|
187
|
+
else if (typeof e == "number")
|
|
188
|
+
o.floatData = e;
|
|
189
189
|
else {
|
|
190
190
|
console.warn(
|
|
191
191
|
"Cabbage: sendChannelData received unsupported data type:",
|
|
192
|
-
typeof
|
|
192
|
+
typeof e
|
|
193
193
|
);
|
|
194
194
|
return;
|
|
195
195
|
}
|
|
196
|
-
const
|
|
196
|
+
const a = {
|
|
197
197
|
command: "channelData",
|
|
198
|
-
obj: JSON.stringify(
|
|
198
|
+
obj: JSON.stringify(o)
|
|
199
199
|
};
|
|
200
|
-
|
|
200
|
+
n !== null ? n.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : console.error(
|
|
201
201
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
202
|
-
|
|
202
|
+
a
|
|
203
203
|
);
|
|
204
204
|
}
|
|
205
205
|
/**
|
|
@@ -209,14 +209,14 @@ class y {
|
|
|
209
209
|
* @param {Object} widget - The widget configuration object to update
|
|
210
210
|
* @param {Object|null} vscode - VS Code API object (null for plugin mode)
|
|
211
211
|
*/
|
|
212
|
-
static sendWidgetUpdate(
|
|
213
|
-
const
|
|
212
|
+
static sendWidgetUpdate(s, e = null) {
|
|
213
|
+
const n = {
|
|
214
214
|
command: "widgetStateUpdate",
|
|
215
|
-
obj: JSON.stringify(CabbageUtils.sanitizeForEditor(
|
|
215
|
+
obj: JSON.stringify(CabbageUtils.sanitizeForEditor(s))
|
|
216
216
|
};
|
|
217
|
-
|
|
217
|
+
e !== null ? e.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : window.parent !== window ? window.parent.postMessage(n, "*") : console.error(
|
|
218
218
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
219
|
-
|
|
219
|
+
n
|
|
220
220
|
);
|
|
221
221
|
}
|
|
222
222
|
/**
|
|
@@ -226,128 +226,152 @@ class y {
|
|
|
226
226
|
* @param {Object|null} vscode - VS Code API object (null for plugin mode)
|
|
227
227
|
* @param {Object} additionalData - Additional data to include in the command
|
|
228
228
|
*/
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
229
|
+
/**
|
|
230
|
+
* Register a listener for incoming messages from the Cabbage backend.
|
|
231
|
+
*
|
|
232
|
+
* Abstracts the two environments so that the same UI code works everywhere:
|
|
233
|
+
* - **VS Code (iframe relay)**: messages arrive as window `message` events
|
|
234
|
+
* - **Native plugin (DAW)**: messages arrive via `window.hostMessageCallback`
|
|
235
|
+
*
|
|
236
|
+
* @param {function(Object): void} callback - Called with the message object.
|
|
237
|
+
* Common message shapes:
|
|
238
|
+
* - `{ command: "parameterChange", data: { paramIdx, value } }` (data may be top-level or nested)
|
|
239
|
+
* - `{ command: "widgetUpdate", id, value }` (from cabbageSetValue / cabbageSet)
|
|
240
|
+
* - `{ command: "widgetUpdate", id, widgetJson }` (full widget update)
|
|
241
|
+
* - `{ command: "channelDataUpdate", data: { channel, value } }`
|
|
242
|
+
* @returns {function(): void} Cleanup function — call it when the UI is torn down.
|
|
243
|
+
*
|
|
244
|
+
* @example <caption>Vanilla HTML</caption>
|
|
245
|
+
* import { Cabbage } from './cabbage/cabbage.js';
|
|
246
|
+
* Cabbage.addMessageListener((msg) => {
|
|
247
|
+
* const data = msg.data ?? msg;
|
|
248
|
+
* if (msg.command === 'parameterChange') { ... }
|
|
249
|
+
* });
|
|
250
|
+
*
|
|
251
|
+
* @example <caption>Svelte</caption>
|
|
252
|
+
* import { onMount, onDestroy } from 'svelte';
|
|
253
|
+
* let remove;
|
|
254
|
+
* onMount(() => { remove = Cabbage.addMessageListener((msg) => { ... }); });
|
|
255
|
+
* onDestroy(() => remove?.());
|
|
256
|
+
*/
|
|
257
|
+
static addMessageListener(s) {
|
|
258
|
+
const e = (n) => {
|
|
259
|
+
n.source !== window && s(n.data);
|
|
260
|
+
};
|
|
261
|
+
return window.addEventListener("message", e), window.hostMessageCallback = s, () => {
|
|
262
|
+
window.removeEventListener("message", e), window.hostMessageCallback === s && (window.hostMessageCallback = null);
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
static sendCustomCommand(s, e = null, n = {}) {
|
|
266
|
+
const o = {
|
|
267
|
+
command: s,
|
|
268
|
+
text: JSON.stringify(n)
|
|
233
269
|
};
|
|
234
|
-
if (
|
|
235
|
-
|
|
270
|
+
if (e !== null)
|
|
271
|
+
e.postMessage(o);
|
|
236
272
|
else if (typeof window.sendMessageFromUI == "function")
|
|
237
273
|
try {
|
|
238
|
-
const
|
|
239
|
-
} catch (
|
|
240
|
-
console.error("Cabbage: sendMessageFromUI threw error:",
|
|
274
|
+
const a = window.sendMessageFromUI(o);
|
|
275
|
+
} catch (a) {
|
|
276
|
+
console.error("Cabbage: sendMessageFromUI threw error:", a), console.error("Cabbage: Error stack:", a.stack);
|
|
241
277
|
}
|
|
242
|
-
else
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
);
|
|
278
|
+
else window.parent !== window ? window.parent.postMessage(o, "*") : (console.error(
|
|
279
|
+
"Cabbage: window.sendMessageFromUI is not available yet. Message:",
|
|
280
|
+
o
|
|
281
|
+
), console.error(
|
|
282
|
+
"Cabbage: typeof window.sendMessageFromUI:",
|
|
283
|
+
typeof window.sendMessageFromUI
|
|
284
|
+
), console.error(
|
|
285
|
+
"Cabbage: window.sendMessageFromUI value:",
|
|
286
|
+
window.sendMessageFromUI
|
|
287
|
+
));
|
|
253
288
|
}
|
|
254
289
|
}
|
|
255
|
-
const
|
|
256
|
-
const [
|
|
257
|
-
return
|
|
258
|
-
const
|
|
259
|
-
const { id:
|
|
260
|
-
if (
|
|
261
|
-
const
|
|
290
|
+
const y = (r) => {
|
|
291
|
+
const [s, e] = f();
|
|
292
|
+
return p(() => {
|
|
293
|
+
const n = (o) => {
|
|
294
|
+
const { id: a, widgetJson: t, command: c } = o.data;
|
|
295
|
+
if (a === r && t && c === "widgetUpdate") {
|
|
296
|
+
const i = JSON.parse(t);
|
|
262
297
|
console.log(
|
|
263
|
-
`[Cabbage-React] Received properties for channelId: ${
|
|
264
|
-
|
|
265
|
-
),
|
|
298
|
+
`[Cabbage-React] Received properties for channelId: ${a}`,
|
|
299
|
+
i
|
|
300
|
+
), e(i);
|
|
266
301
|
}
|
|
267
302
|
};
|
|
268
|
-
return window.addEventListener("message",
|
|
269
|
-
window.removeEventListener("message", a);
|
|
270
|
-
};
|
|
303
|
+
return window.addEventListener("message", n), () => window.removeEventListener("message", n);
|
|
271
304
|
}, []), {
|
|
272
|
-
properties:
|
|
305
|
+
properties: s
|
|
273
306
|
};
|
|
274
|
-
}, F = (
|
|
275
|
-
const { properties:
|
|
276
|
-
|
|
277
|
-
channel:
|
|
278
|
-
value:
|
|
279
|
-
gesture:
|
|
307
|
+
}, F = (r, s = "complete") => {
|
|
308
|
+
const { properties: e } = y(r), [n, o] = f(), [a, t] = f(), c = (i) => {
|
|
309
|
+
o(i), C.sendControlData({
|
|
310
|
+
channel: r,
|
|
311
|
+
value: i,
|
|
312
|
+
gesture: s
|
|
280
313
|
});
|
|
281
314
|
};
|
|
282
|
-
return
|
|
315
|
+
return p(() => {
|
|
283
316
|
var m;
|
|
284
|
-
const
|
|
285
|
-
(d) => d.id ===
|
|
317
|
+
const i = e == null ? void 0 : e.channels.find(
|
|
318
|
+
(d) => d.id === r
|
|
286
319
|
);
|
|
287
|
-
if (!
|
|
288
|
-
const l =
|
|
289
|
-
if (
|
|
290
|
-
`[Cabbage-React] Received parameterIndex for channelId: ${
|
|
320
|
+
if (!i) return;
|
|
321
|
+
const l = i.parameterIndex;
|
|
322
|
+
if (a === void 0 && l !== void 0 && (console.log(
|
|
323
|
+
`[Cabbage-React] Received parameterIndex for channelId: ${i.id}`,
|
|
291
324
|
l
|
|
292
|
-
),
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
`[Cabbage-React] Received initial value for channelId: ${
|
|
296
|
-
|
|
297
|
-
),
|
|
298
|
-
}, [
|
|
299
|
-
const
|
|
325
|
+
), t(l)), n !== void 0) return;
|
|
326
|
+
const w = (m = i.range) == null ? void 0 : m.value;
|
|
327
|
+
w != null && (console.log(
|
|
328
|
+
`[Cabbage-React] Received initial value for channelId: ${i.id}`,
|
|
329
|
+
w
|
|
330
|
+
), o(w));
|
|
331
|
+
}, [e]), p(() => {
|
|
332
|
+
const i = (l) => {
|
|
300
333
|
var m;
|
|
301
|
-
const { command:
|
|
302
|
-
if (
|
|
303
|
-
const { value: d, paramIdx:
|
|
304
|
-
if (
|
|
334
|
+
const { command: w } = l.data;
|
|
335
|
+
if (w === "parameterChange") {
|
|
336
|
+
const { value: d, paramIdx: g } = l.data.data;
|
|
337
|
+
if (g !== a || d === null) return;
|
|
305
338
|
console.log(
|
|
306
|
-
`[Cabbage-React] Received parameterChange for parameterIndex: ${
|
|
339
|
+
`[Cabbage-React] Received parameterChange for parameterIndex: ${g}`,
|
|
307
340
|
d
|
|
308
|
-
),
|
|
309
|
-
} else if (
|
|
310
|
-
const d = l.data.widgets,
|
|
311
|
-
if (!
|
|
312
|
-
const
|
|
313
|
-
(
|
|
314
|
-
), M = (m =
|
|
341
|
+
), o(d);
|
|
342
|
+
} else if (w === "batchWidgetUpdate") {
|
|
343
|
+
const d = l.data.widgets, g = d == null ? void 0 : d.find((b) => b.id === r);
|
|
344
|
+
if (!g) return;
|
|
345
|
+
const u = JSON.parse(g.widgetJson).channels.find(
|
|
346
|
+
(b) => b.id === r
|
|
347
|
+
), M = (m = u == null ? void 0 : u.range) == null ? void 0 : m.value;
|
|
315
348
|
console.log(
|
|
316
|
-
`[Cabbage-React] Received batch widget update for channelId: ${
|
|
349
|
+
`[Cabbage-React] Received batch widget update for channelId: ${g.id}`,
|
|
317
350
|
M
|
|
318
|
-
),
|
|
351
|
+
), o(M);
|
|
319
352
|
}
|
|
320
353
|
};
|
|
321
|
-
return window.addEventListener("message",
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
value: a,
|
|
326
|
-
setValue: u
|
|
354
|
+
return window.addEventListener("message", i), () => window.removeEventListener("message", i);
|
|
355
|
+
}, [a]), {
|
|
356
|
+
value: n,
|
|
357
|
+
setValue: c
|
|
327
358
|
};
|
|
328
|
-
}, v = (
|
|
329
|
-
const [
|
|
330
|
-
return
|
|
331
|
-
const
|
|
332
|
-
const { data:
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
e
|
|
338
|
-
), s(e);
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
return window.addEventListener("message", a), () => {
|
|
342
|
-
window.removeEventListener("message", a);
|
|
359
|
+
}, v = (r, s) => {
|
|
360
|
+
const [e, n] = f();
|
|
361
|
+
return p(() => {
|
|
362
|
+
const o = (a) => {
|
|
363
|
+
const { data: t, type: c } = a;
|
|
364
|
+
!t || c !== "message" || t.type === r && (console.log(
|
|
365
|
+
`[Cabbage-React] Received data for messageType: ${t.type}`,
|
|
366
|
+
t
|
|
367
|
+
), s && s(t), n(t));
|
|
343
368
|
};
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
};
|
|
369
|
+
return window.addEventListener("message", o), () => window.removeEventListener("message", o);
|
|
370
|
+
}, [r, s]), { message: e };
|
|
347
371
|
};
|
|
348
372
|
export {
|
|
349
|
-
|
|
373
|
+
C as Cabbage,
|
|
350
374
|
v as useCabbageMessage,
|
|
351
|
-
|
|
375
|
+
y as useCabbageProperties,
|
|
352
376
|
F as useCabbageState
|
|
353
377
|
};
|