cabbage-react 1.0.48 → 1.0.50
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/useCabbageMessage.d.ts +4 -3
- package/dist/hooks/useCabbageMessage.d.ts.map +1 -1
- package/dist/hooks/useCabbageProperties.d.ts +3 -1
- package/dist/hooks/useCabbageProperties.d.ts.map +1 -1
- package/dist/hooks/useCabbageState.d.ts +2 -1
- package/dist/hooks/useCabbageState.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +140 -148
- package/package.json +1 -1
|
@@ -2,9 +2,10 @@
|
|
|
2
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 when receiving a new message (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;;CAyBhC,CAAC"}
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
* This hook listens for updates to parameter properties from the backend and updates the local state
|
|
4
4
|
* whenever new data is received.
|
|
5
5
|
* @param channelId
|
|
6
|
+
* @param onPropertiesUpdate - Callback fires immediately when receiving an update to properties (synchronous - bypasses state batching)
|
|
6
7
|
*/
|
|
7
|
-
export declare const useCabbageProperties: (channelId: string) => {
|
|
8
|
+
export declare const useCabbageProperties: (channelId: string, onPropertiesUpdate?: (properties: Record<string, any>) => void) => {
|
|
8
9
|
properties: Record<string, any> | undefined;
|
|
10
|
+
onPropertiesUpdate: ((properties: Record<string, any>) => void) | undefined;
|
|
9
11
|
};
|
|
10
12
|
//# sourceMappingURL=useCabbageProperties.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,cACrB,MAAM,uBACI,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI;;sCAA5B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI;CAiC9D,CAAC"}
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* sends updates to the backend when the parameter value changes locally (e.g., through a UI slider).
|
|
5
5
|
* @param channelId
|
|
6
6
|
* @param gesture - The gesture type: "begin" (start of interaction), "value" (during interaction), "end" (end of continuous interaction), or "complete" (discrete action e.g. button click).
|
|
7
|
+
* @param onValueUpdate - Callback fires immediately when receiving a value update (synchronous - bypasses state batching)
|
|
7
8
|
*/
|
|
8
|
-
export declare const useCabbageState: <T>(channelId: string, gesture?: "begin" | "value" | "end" | "complete") => {
|
|
9
|
+
export declare const useCabbageState: <T>(channelId: string, gesture?: "begin" | "value" | "end" | "complete", onValueUpdate?: (value: T) => void) => {
|
|
9
10
|
value: T | undefined;
|
|
10
11
|
setValue: (value: T) => void;
|
|
11
12
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,aACrB,MAAM,YACR,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,kBAC/B,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI;;sBAOA,CAAC;CAgGnC,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react");class
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react");class y{static sendControlData({channel:e,value:a,gesture:s="complete"},o=null){const n={command:"controlData",channel:e,value:a,gesture:s};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(e=null,a={}){this.sendCustomCommand("isReadyToLoad",e)}static sendMidiMessageFromUI(e,a,s,o=null){var n={statusByte:e,dataByte1:a,dataByte2:s};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(e,a,s){}static triggerFileOpenDialog(e,a,s={}){var o={channel:a,directory:s.directory||"",filters:s.filters||"*",openAtLastKnownLocation:s.openAtLastKnownLocation!==void 0?s.openAtLastKnownLocation:!0};const n={command:"fileOpen",obj:JSON.stringify(o)};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,a,s){var o={url:a,file:s};const n={command:"openUrl",obj:JSON.stringify(o)};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,a,s=null){const o={command:"requestResize",width:e,height:a};if(s!==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(e){typeof window.consumeKeypresses=="function"&&window.consumeKeypresses(e)}static sendChannelData(e,a,s=null){var o={channel:e};if(typeof a=="string")o.stringData=a;else if(typeof a=="number")o.floatData=a;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof a);return}const n={command:"channelData",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 sendWidgetUpdate(e,a=null){const s={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};a!==null?a.postMessage(s):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(s):window.parent!==window?window.parent.postMessage(s,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",s)}static addMessageListener(e){const a=s=>{s.source!==window&&e(s.data)};return window.addEventListener("message",a),window.hostMessageCallback=e,()=>{window.removeEventListener("message",a),window.hostMessageCallback===e&&(window.hostMessageCallback=null)}}static sendCustomCommand(e,a=null,s={}){const o={command:e,text:JSON.stringify(s)};if(a!==null)a.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 I=(r,e)=>{const[a,s]=l.useState();return l.useEffect(()=>{const o=n=>{const{id:t,widgetJson:m,command:p}=n.data;if(t===r&&m&&p==="widgetUpdate"){const g=JSON.parse(m);console.log(`[Cabbage-React] Received properties for channelId: ${t}`,g),e&&e(g),s(g)}};return window.addEventListener("message",o),()=>window.removeEventListener("message",o)},[r,e]),{properties:a,onPropertiesUpdate:e}},F=(r,e="complete",a)=>{const{properties:s}=I(r),[o,n]=l.useState(),[t,m]=l.useState(),p=i=>{n(i),y.sendControlData({channel:r,value:i,gesture:e})},g=i=>{a&&a(i),n(i)};return l.useEffect(()=>{var u;const i=s==null?void 0:s.channels.find(d=>d.id===r);if(!i)return;const w=i.parameterIndex;if(t===void 0&&w!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId: ${i.id}`,w),m(w)),o!==void 0)return;const c=(u=i.range)==null?void 0:u.value;c!=null&&(console.log(`[Cabbage-React] Received initial value for channelId: ${i.id}`,c),g(c))},[s]),l.useEffect(()=>{const i=w=>{var u;const{command:c}=w.data;if(c==="parameterChange"){const{value:d,paramIdx:f}=w.data.data;if(f!==t||d===null)return;console.log(`[Cabbage-React] Received parameterChange for parameterIndex: ${f}`,d),g(d)}else if(c==="batchWidgetUpdate"){const d=w.data.widgets,f=d==null?void 0:d.find(M=>M.id===r);if(!f)return;const b=JSON.parse(f.widgetJson).channels.find(M=>M.id===r),C=(u=b==null?void 0:b.range)==null?void 0:u.value;console.log(`[Cabbage-React] Received batch widget update for channelId: ${f.id}`,C),g(C)}};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[r,a,t]),{value:o,setValue:p}},U=(r,e)=>{const[a,s]=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),e&&e(t),s(t))};return window.addEventListener("message",o),()=>window.removeEventListener("message",o)},[r,e]),{message:a}};exports.Cabbage=y;exports.useCabbageMessage=U;exports.useCabbageProperties=I;exports.useCabbageState=F;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
class
|
|
1
|
+
import { useState as u, useEffect as p } from "react";
|
|
2
|
+
class I {
|
|
3
3
|
/**
|
|
4
4
|
* Send a widget value change to the Cabbage backend.
|
|
5
5
|
*
|
|
@@ -20,16 +20,16 @@ class C {
|
|
|
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: e, value: n, gesture: s = "complete" }, o = null) {
|
|
24
|
+
const a = {
|
|
25
25
|
command: "controlData",
|
|
26
|
-
channel:
|
|
27
|
-
value:
|
|
28
|
-
gesture:
|
|
26
|
+
channel: e,
|
|
27
|
+
value: n,
|
|
28
|
+
gesture: s
|
|
29
29
|
};
|
|
30
|
-
o !== null ? o.postMessage(
|
|
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 C {
|
|
|
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(e = null, n = {}) {
|
|
42
|
+
this.sendCustomCommand("isReadyToLoad", e);
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* Send a MIDI message from the UI to the Cabbage backend.
|
|
@@ -49,19 +49,19 @@ class C {
|
|
|
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(e, n, s, o = null) {
|
|
53
|
+
var a = {
|
|
54
|
+
statusByte: e,
|
|
55
|
+
dataByte1: n,
|
|
56
|
+
dataByte2: s
|
|
57
57
|
};
|
|
58
|
-
const
|
|
58
|
+
const t = {
|
|
59
59
|
command: "midiMessage",
|
|
60
|
-
obj: JSON.stringify(
|
|
60
|
+
obj: JSON.stringify(a)
|
|
61
61
|
};
|
|
62
|
-
o !== null ? o.postMessage(
|
|
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 C {
|
|
|
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(e, n, s) {
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
77
|
* Trigger a native file open dialog for file selection widgets.
|
|
@@ -83,20 +83,20 @@ class C {
|
|
|
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(
|
|
86
|
+
static triggerFileOpenDialog(e, n, s = {}) {
|
|
87
87
|
var o = {
|
|
88
|
-
channel:
|
|
89
|
-
directory:
|
|
90
|
-
filters:
|
|
91
|
-
openAtLastKnownLocation:
|
|
88
|
+
channel: n,
|
|
89
|
+
directory: s.directory || "",
|
|
90
|
+
filters: s.filters || "*",
|
|
91
|
+
openAtLastKnownLocation: s.openAtLastKnownLocation !== void 0 ? s.openAtLastKnownLocation : !0
|
|
92
92
|
};
|
|
93
|
-
const
|
|
93
|
+
const a = {
|
|
94
94
|
command: "fileOpen",
|
|
95
95
|
obj: JSON.stringify(o)
|
|
96
96
|
};
|
|
97
|
-
|
|
97
|
+
e !== null ? e.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 C {
|
|
|
106
106
|
* @param {string} url - URL to open
|
|
107
107
|
* @param {string} file - File path to open
|
|
108
108
|
*/
|
|
109
|
-
static openUrl(
|
|
109
|
+
static openUrl(e, n, s) {
|
|
110
110
|
var o = {
|
|
111
|
-
url:
|
|
112
|
-
file:
|
|
111
|
+
url: n,
|
|
112
|
+
file: s
|
|
113
113
|
};
|
|
114
|
-
const
|
|
114
|
+
const a = {
|
|
115
115
|
command: "openUrl",
|
|
116
116
|
obj: JSON.stringify(o)
|
|
117
117
|
};
|
|
118
|
-
|
|
118
|
+
e !== null ? e.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,13 +132,13 @@ class C {
|
|
|
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(
|
|
135
|
+
static requestResize(e, n, s = null) {
|
|
136
136
|
const o = {
|
|
137
137
|
command: "requestResize",
|
|
138
|
-
width:
|
|
139
|
-
height:
|
|
138
|
+
width: e,
|
|
139
|
+
height: n
|
|
140
140
|
};
|
|
141
|
-
if (
|
|
141
|
+
if (s !== null) {
|
|
142
142
|
console.warn(
|
|
143
143
|
"Cabbage: requestResize is not supported in VS Code extension mode"
|
|
144
144
|
);
|
|
@@ -168,8 +168,8 @@ class C {
|
|
|
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(e) {
|
|
172
|
+
typeof window.consumeKeypresses == "function" && window.consumeKeypresses(e);
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
175
175
|
* Send channel data directly to Csound without DAW automation involvement.
|
|
@@ -178,28 +178,28 @@ class C {
|
|
|
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(
|
|
181
|
+
static sendChannelData(e, n, s = null) {
|
|
182
182
|
var o = {
|
|
183
|
-
channel:
|
|
183
|
+
channel: e
|
|
184
184
|
};
|
|
185
|
-
if (typeof
|
|
186
|
-
o.stringData =
|
|
187
|
-
else if (typeof
|
|
188
|
-
o.floatData =
|
|
185
|
+
if (typeof n == "string")
|
|
186
|
+
o.stringData = n;
|
|
187
|
+
else if (typeof n == "number")
|
|
188
|
+
o.floatData = n;
|
|
189
189
|
else {
|
|
190
190
|
console.warn(
|
|
191
191
|
"Cabbage: sendChannelData received unsupported data type:",
|
|
192
|
-
typeof
|
|
192
|
+
typeof n
|
|
193
193
|
);
|
|
194
194
|
return;
|
|
195
195
|
}
|
|
196
|
-
const
|
|
196
|
+
const a = {
|
|
197
197
|
command: "channelData",
|
|
198
198
|
obj: JSON.stringify(o)
|
|
199
199
|
};
|
|
200
|
-
|
|
200
|
+
s !== null ? s.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 C {
|
|
|
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(e, n = null) {
|
|
213
|
+
const s = {
|
|
214
214
|
command: "widgetStateUpdate",
|
|
215
|
-
obj: JSON.stringify(CabbageUtils.sanitizeForEditor(
|
|
215
|
+
obj: JSON.stringify(CabbageUtils.sanitizeForEditor(e))
|
|
216
216
|
};
|
|
217
|
-
|
|
217
|
+
n !== null ? n.postMessage(s) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(s) : window.parent !== window ? window.parent.postMessage(s, "*") : console.error(
|
|
218
218
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
219
|
-
|
|
219
|
+
s
|
|
220
220
|
);
|
|
221
221
|
}
|
|
222
222
|
/**
|
|
@@ -254,26 +254,26 @@ class C {
|
|
|
254
254
|
* onMount(() => { remove = Cabbage.addMessageListener((msg) => { ... }); });
|
|
255
255
|
* onDestroy(() => remove?.());
|
|
256
256
|
*/
|
|
257
|
-
static addMessageListener(
|
|
258
|
-
const
|
|
259
|
-
|
|
257
|
+
static addMessageListener(e) {
|
|
258
|
+
const n = (s) => {
|
|
259
|
+
s.source !== window && e(s.data);
|
|
260
260
|
};
|
|
261
|
-
return window.addEventListener("message",
|
|
262
|
-
window.removeEventListener("message",
|
|
261
|
+
return window.addEventListener("message", n), window.hostMessageCallback = e, () => {
|
|
262
|
+
window.removeEventListener("message", n), window.hostMessageCallback === e && (window.hostMessageCallback = null);
|
|
263
263
|
};
|
|
264
264
|
}
|
|
265
|
-
static sendCustomCommand(
|
|
265
|
+
static sendCustomCommand(e, n = null, s = {}) {
|
|
266
266
|
const o = {
|
|
267
|
-
command:
|
|
268
|
-
text: JSON.stringify(
|
|
267
|
+
command: e,
|
|
268
|
+
text: JSON.stringify(s)
|
|
269
269
|
};
|
|
270
|
-
if (
|
|
271
|
-
|
|
270
|
+
if (n !== null)
|
|
271
|
+
n.postMessage(o);
|
|
272
272
|
else if (typeof window.sendMessageFromUI == "function")
|
|
273
273
|
try {
|
|
274
|
-
const
|
|
275
|
-
} catch (
|
|
276
|
-
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);
|
|
277
277
|
}
|
|
278
278
|
else window.parent !== window ? window.parent.postMessage(o, "*") : (console.error(
|
|
279
279
|
"Cabbage: window.sendMessageFromUI is not available yet. Message:",
|
|
@@ -287,102 +287,94 @@ class C {
|
|
|
287
287
|
));
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
|
-
const
|
|
291
|
-
const [
|
|
292
|
-
return
|
|
293
|
-
const
|
|
294
|
-
const { id:
|
|
295
|
-
if (
|
|
296
|
-
const
|
|
290
|
+
const F = (r, e) => {
|
|
291
|
+
const [n, s] = u();
|
|
292
|
+
return p(() => {
|
|
293
|
+
const o = (a) => {
|
|
294
|
+
const { id: t, widgetJson: c, command: b } = a.data;
|
|
295
|
+
if (t === r && c && b === "widgetUpdate") {
|
|
296
|
+
const l = JSON.parse(c);
|
|
297
297
|
console.log(
|
|
298
|
-
`[Cabbage-React] Received properties for channelId: ${
|
|
299
|
-
|
|
300
|
-
), s(
|
|
298
|
+
`[Cabbage-React] Received properties for channelId: ${t}`,
|
|
299
|
+
l
|
|
300
|
+
), e && e(l), s(l);
|
|
301
301
|
}
|
|
302
302
|
};
|
|
303
|
-
return window.addEventListener("message",
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
properties: a
|
|
303
|
+
return window.addEventListener("message", o), () => window.removeEventListener("message", o);
|
|
304
|
+
}, [r, e]), {
|
|
305
|
+
properties: n,
|
|
306
|
+
onPropertiesUpdate: e
|
|
308
307
|
};
|
|
309
|
-
},
|
|
310
|
-
const { properties: s } =
|
|
311
|
-
|
|
308
|
+
}, h = (r, e = "complete", n) => {
|
|
309
|
+
const { properties: s } = F(r), [o, a] = u(), [t, c] = u(), b = (i) => {
|
|
310
|
+
a(i), I.sendControlData({
|
|
312
311
|
channel: r,
|
|
313
|
-
value:
|
|
314
|
-
gesture:
|
|
312
|
+
value: i,
|
|
313
|
+
gesture: e
|
|
315
314
|
});
|
|
315
|
+
}, l = (i) => {
|
|
316
|
+
n && n(i), a(i);
|
|
316
317
|
};
|
|
317
|
-
return
|
|
318
|
-
var
|
|
319
|
-
const
|
|
318
|
+
return p(() => {
|
|
319
|
+
var f;
|
|
320
|
+
const i = s == null ? void 0 : s.channels.find(
|
|
320
321
|
(d) => d.id === r
|
|
321
322
|
);
|
|
322
|
-
if (!
|
|
323
|
-
const
|
|
324
|
-
if (
|
|
325
|
-
`[Cabbage-React] Received parameterIndex for channelId: ${
|
|
326
|
-
l
|
|
327
|
-
), i(l)), n !== void 0) return;
|
|
328
|
-
const w = (c = t.range) == null ? void 0 : c.value;
|
|
329
|
-
w != null && (console.log(
|
|
330
|
-
`[Cabbage-React] Received initial value for channelId: ${t.id}`,
|
|
323
|
+
if (!i) return;
|
|
324
|
+
const w = i.parameterIndex;
|
|
325
|
+
if (t === void 0 && w !== void 0 && (console.log(
|
|
326
|
+
`[Cabbage-React] Received parameterIndex for channelId: ${i.id}`,
|
|
331
327
|
w
|
|
332
|
-
),
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
328
|
+
), c(w)), o !== void 0) return;
|
|
329
|
+
const g = (f = i.range) == null ? void 0 : f.value;
|
|
330
|
+
g != null && (console.log(
|
|
331
|
+
`[Cabbage-React] Received initial value for channelId: ${i.id}`,
|
|
332
|
+
g
|
|
333
|
+
), l(g));
|
|
334
|
+
}, [s]), p(() => {
|
|
335
|
+
const i = (w) => {
|
|
336
|
+
var f;
|
|
337
|
+
const { command: g } = w.data;
|
|
338
|
+
if (g === "parameterChange") {
|
|
339
|
+
const { value: d, paramIdx: m } = w.data.data;
|
|
340
|
+
if (m !== t || d === null) return;
|
|
340
341
|
console.log(
|
|
341
|
-
`[Cabbage-React] Received parameterChange for parameterIndex: ${
|
|
342
|
+
`[Cabbage-React] Received parameterChange for parameterIndex: ${m}`,
|
|
342
343
|
d
|
|
343
|
-
),
|
|
344
|
-
} else if (
|
|
345
|
-
const d =
|
|
346
|
-
if (!
|
|
347
|
-
const
|
|
348
|
-
(
|
|
349
|
-
),
|
|
344
|
+
), l(d);
|
|
345
|
+
} else if (g === "batchWidgetUpdate") {
|
|
346
|
+
const d = w.data.widgets, m = d == null ? void 0 : d.find((C) => C.id === r);
|
|
347
|
+
if (!m) return;
|
|
348
|
+
const M = JSON.parse(m.widgetJson).channels.find(
|
|
349
|
+
(C) => C.id === r
|
|
350
|
+
), y = (f = M == null ? void 0 : M.range) == null ? void 0 : f.value;
|
|
350
351
|
console.log(
|
|
351
|
-
`[Cabbage-React] Received batch widget update for channelId: ${
|
|
352
|
-
|
|
353
|
-
),
|
|
352
|
+
`[Cabbage-React] Received batch widget update for channelId: ${m.id}`,
|
|
353
|
+
y
|
|
354
|
+
), l(y);
|
|
354
355
|
}
|
|
355
356
|
};
|
|
356
|
-
return window.addEventListener("message",
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
value: n,
|
|
361
|
-
setValue: p
|
|
357
|
+
return window.addEventListener("message", i), () => window.removeEventListener("message", i);
|
|
358
|
+
}, [r, n, t]), {
|
|
359
|
+
value: o,
|
|
360
|
+
setValue: b
|
|
362
361
|
};
|
|
363
|
-
},
|
|
364
|
-
const [
|
|
365
|
-
return
|
|
366
|
-
const
|
|
367
|
-
const { data:
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
e
|
|
373
|
-
), s(e);
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
return window.addEventListener("message", n), () => {
|
|
377
|
-
window.removeEventListener("message", n);
|
|
362
|
+
}, L = (r, e) => {
|
|
363
|
+
const [n, s] = u();
|
|
364
|
+
return p(() => {
|
|
365
|
+
const o = (a) => {
|
|
366
|
+
const { data: t, type: c } = a;
|
|
367
|
+
!t || c !== "message" || t.type === r && (console.log(
|
|
368
|
+
`[Cabbage-React] Received data for messageType: ${t.type}`,
|
|
369
|
+
t
|
|
370
|
+
), e && e(t), s(t));
|
|
378
371
|
};
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
};
|
|
372
|
+
return window.addEventListener("message", o), () => window.removeEventListener("message", o);
|
|
373
|
+
}, [r, e]), { message: n };
|
|
382
374
|
};
|
|
383
375
|
export {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
376
|
+
I as Cabbage,
|
|
377
|
+
L as useCabbageMessage,
|
|
378
|
+
F as useCabbageProperties,
|
|
379
|
+
h as useCabbageState
|
|
388
380
|
};
|