cabbage-react 1.0.34 → 1.0.35
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 +1 -1
- package/dist/hooks/useCabbageMessage.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +123 -125
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCabbageMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageMessage.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,aAAa,MAAM;;
|
|
1
|
+
{"version":3,"file":"useCabbageMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageMessage.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,aAAa,MAAM;;CA8BrD,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react");console.log("Cabbage: loading cabbage.js");class p{static sendControlData({channel:o,value:
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react");console.log("Cabbage: loading cabbage.js");class p{static sendControlData({channel:o,value:s,gesture:a="complete"},n=null){const e={command:"controlData",channel:o,value:s,gesture:a};n!==null?n.postMessage(e):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(e):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",e)}static isReadyToLoad(o=null,s={}){this.sendCustomCommand("isReadyToLoad",o)}static sendMidiMessageFromUI(o,s,a,n=null){var e={statusByte:o,dataByte1:s,dataByte2:a};const r={command:"midiMessage",obj:JSON.stringify(e)};n!==null?n.postMessage(r):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(r):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",r)}static MidiMessageFromHost(o,s,a){console.log("Cabbage: Got MIDI Message"+o+":"+s+":"+a)}static triggerFileOpenDialog(o,s,a={}){var n={channel:s,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.openAtLastKnownLocation:!0};const e={command:"fileOpen",obj:JSON.stringify(n)};o!==null?o.postMessage(e):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(e):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",e)}static openUrl(o,s,a){var n={url:s,file:a};const e={command:"openUrl",obj:JSON.stringify(n)};o!==null?o.postMessage(e):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(e):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",e)}static requestResize(o,s,a=null){const n={command:"requestResize",width:o,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(n):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static sendChannelData(o,s,a=null){var n={channel:o};if(typeof s=="string")n.stringData=s;else if(typeof s=="number")n.floatData=s;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof s);return}const e={command:"channelData",obj:JSON.stringify(n)};console.log("Cabbage: sending channel data from UI",n),a!==null?a.postMessage(e):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(e):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",e)}static sendWidgetUpdate(o,s=null){const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(o))};s!==null?s.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static sendCustomCommand(o,s=null,a={}){const n={command:o,text:JSON.stringify(a)};if(s!==null)s.postMessage(n);else if(typeof window.sendMessageFromUI=="function"){console.log("Cabbage: Calling window.sendMessageFromUI with:",n);try{const e=window.sendMessageFromUI(n);console.log("Cabbage: sendMessageFromUI returned:",e)}catch(e){console.error("Cabbage: sendMessageFromUI threw error:",e),console.error("Cabbage: Error stack:",e.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=i=>{const[o,s]=l.useState();return l.useEffect(()=>{const a=n=>{const{id:e,widgetJson:r,command:u}=n.data;if(e===i&&r&&u==="widgetUpdate"){const t=JSON.parse(r);console.log(`[Cabbage-React] Received properties for channelId ${e}`,t),s(t)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:o}},I=(i,o="complete")=>{const{properties:s}=C(i),[a,n]=l.useState(),[e,r]=l.useState(),u=t=>{n(t),p.sendControlData({channel:i,value:t,gesture:o})};return l.useEffect(()=>{var b;const t=s==null?void 0:s.channels.find(d=>d.id===i);if(!t)return;const g=t==null?void 0:t.parameterIndex;e===void 0&&g!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,g),r(g));const c=(b=t.range)==null?void 0:b.defaultValue;a===void 0&&c!==void 0&&(console.log(`[Cabbage-React] Received default value for channelId "${t.id}"`,c),n(c))},[s]),l.useEffect(()=>{const t=g=>{var b;const{command:c}=g.data;if(c==="parameterChange"){const{value:d,paramIdx:m}=g.data.data;if(m!==e||d===null)return;console.log(`[Cabbage-React] Received parameterChange for parameterIndex ${m}`,d),n(d)}else if(c==="batchWidgetUpdate"){const d=g.data.widgets,m=d==null?void 0:d.find(f=>f.id===i);if(!m)return;const w=JSON.parse(m.widgetJson).channels.find(f=>f.id===i),M=(b=w==null?void 0:w.range)==null?void 0:b.value;console.log(`[Cabbage-React] Received batch widget update for channelId ${m.id}`,M),n(M)}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[e]),{value:a,setValue:u}},U=i=>{const[o,s]=l.useState();return l.useEffect(()=>{const a=n=>{const{data:e,type:r}=n.data;if(e&&r==="message"){if(e.id!==i)return;console.log(`[Cabbage-React] Received data for messageId ${e.id}`,e),s(e)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{data:o}};exports.Cabbage=p;exports.useCabbageMessage=U;exports.useCabbageProperties=C;exports.useCabbageState=I;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState as
|
|
1
|
+
import { useState as w, useEffect as f } from "react";
|
|
2
2
|
console.log("Cabbage: loading cabbage.js");
|
|
3
3
|
class C {
|
|
4
4
|
/**
|
|
@@ -21,16 +21,16 @@ class C {
|
|
|
21
21
|
* @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).
|
|
22
22
|
* @param {Object|null} vscode - VS Code API object (null for plugin mode)
|
|
23
23
|
*/
|
|
24
|
-
static sendControlData({ channel: o, value:
|
|
25
|
-
const
|
|
24
|
+
static sendControlData({ channel: o, value: s, gesture: a = "complete" }, n = null) {
|
|
25
|
+
const e = {
|
|
26
26
|
command: "controlData",
|
|
27
27
|
channel: o,
|
|
28
|
-
value:
|
|
29
|
-
gesture:
|
|
28
|
+
value: s,
|
|
29
|
+
gesture: a
|
|
30
30
|
};
|
|
31
|
-
|
|
31
|
+
n !== null ? n.postMessage(e) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(e) : console.error(
|
|
32
32
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
33
|
-
|
|
33
|
+
e
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
@@ -39,7 +39,7 @@ class C {
|
|
|
39
39
|
* @param {Object|null} vscode - VS Code API object (null for plugin mode)
|
|
40
40
|
* @param {Object} additionalData - Additional initialization data
|
|
41
41
|
*/
|
|
42
|
-
static isReadyToLoad(o = null,
|
|
42
|
+
static isReadyToLoad(o = null, s = {}) {
|
|
43
43
|
this.sendCustomCommand("isReadyToLoad", o);
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
@@ -50,17 +50,17 @@ class C {
|
|
|
50
50
|
* @param {number} dataByte2 - Second MIDI data byte
|
|
51
51
|
* @param {Object|null} vscode - VS Code API object (null for plugin mode)
|
|
52
52
|
*/
|
|
53
|
-
static sendMidiMessageFromUI(o,
|
|
54
|
-
var
|
|
53
|
+
static sendMidiMessageFromUI(o, s, a, n = null) {
|
|
54
|
+
var e = {
|
|
55
55
|
statusByte: o,
|
|
56
|
-
dataByte1:
|
|
57
|
-
dataByte2:
|
|
56
|
+
dataByte1: s,
|
|
57
|
+
dataByte2: a
|
|
58
58
|
};
|
|
59
59
|
const r = {
|
|
60
60
|
command: "midiMessage",
|
|
61
|
-
obj: JSON.stringify(
|
|
61
|
+
obj: JSON.stringify(e)
|
|
62
62
|
};
|
|
63
|
-
|
|
63
|
+
n !== null ? n.postMessage(r) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(r) : console.error(
|
|
64
64
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
65
65
|
r
|
|
66
66
|
);
|
|
@@ -72,9 +72,9 @@ class C {
|
|
|
72
72
|
* @param {number} dataByte1 - First MIDI data byte
|
|
73
73
|
* @param {number} dataByte2 - Second MIDI data byte
|
|
74
74
|
*/
|
|
75
|
-
static MidiMessageFromHost(o,
|
|
75
|
+
static MidiMessageFromHost(o, s, a) {
|
|
76
76
|
console.log(
|
|
77
|
-
"Cabbage: Got MIDI Message" + o + ":" +
|
|
77
|
+
"Cabbage: Got MIDI Message" + o + ":" + s + ":" + a
|
|
78
78
|
);
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
@@ -87,20 +87,20 @@ class C {
|
|
|
87
87
|
* @param {string} [options.filters="*"] - File filters (e.g., "*.wav;*.aiff")
|
|
88
88
|
* @param {boolean} [options.openAtLastKnownLocation=true] - Whether to open at last known location
|
|
89
89
|
*/
|
|
90
|
-
static triggerFileOpenDialog(o,
|
|
91
|
-
var
|
|
92
|
-
channel:
|
|
93
|
-
directory:
|
|
94
|
-
filters:
|
|
95
|
-
openAtLastKnownLocation:
|
|
90
|
+
static triggerFileOpenDialog(o, s, a = {}) {
|
|
91
|
+
var n = {
|
|
92
|
+
channel: s,
|
|
93
|
+
directory: a.directory || "",
|
|
94
|
+
filters: a.filters || "*",
|
|
95
|
+
openAtLastKnownLocation: a.openAtLastKnownLocation !== void 0 ? a.openAtLastKnownLocation : !0
|
|
96
96
|
};
|
|
97
|
-
const
|
|
97
|
+
const e = {
|
|
98
98
|
command: "fileOpen",
|
|
99
|
-
obj: JSON.stringify(
|
|
99
|
+
obj: JSON.stringify(n)
|
|
100
100
|
};
|
|
101
|
-
o !== null ? o.postMessage(
|
|
101
|
+
o !== null ? o.postMessage(e) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(e) : console.error(
|
|
102
102
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
103
|
-
|
|
103
|
+
e
|
|
104
104
|
);
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
@@ -110,18 +110,18 @@ class C {
|
|
|
110
110
|
* @param {string} url - URL to open
|
|
111
111
|
* @param {string} file - File path to open
|
|
112
112
|
*/
|
|
113
|
-
static openUrl(o,
|
|
114
|
-
var
|
|
115
|
-
url:
|
|
116
|
-
file:
|
|
113
|
+
static openUrl(o, s, a) {
|
|
114
|
+
var n = {
|
|
115
|
+
url: s,
|
|
116
|
+
file: a
|
|
117
117
|
};
|
|
118
|
-
const
|
|
118
|
+
const e = {
|
|
119
119
|
command: "openUrl",
|
|
120
|
-
obj: JSON.stringify(
|
|
120
|
+
obj: JSON.stringify(n)
|
|
121
121
|
};
|
|
122
|
-
o !== null ? o.postMessage(
|
|
122
|
+
o !== null ? o.postMessage(e) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(e) : console.error(
|
|
123
123
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
124
|
-
|
|
124
|
+
e
|
|
125
125
|
);
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
@@ -136,21 +136,21 @@ class C {
|
|
|
136
136
|
* The response will be sent via hostMessageCallback with:
|
|
137
137
|
* {command: "resizeResponse", accepted: boolean, width: number, height: number}
|
|
138
138
|
*/
|
|
139
|
-
static requestResize(o,
|
|
140
|
-
const
|
|
139
|
+
static requestResize(o, s, a = null) {
|
|
140
|
+
const n = {
|
|
141
141
|
command: "requestResize",
|
|
142
142
|
width: o,
|
|
143
|
-
height:
|
|
143
|
+
height: s
|
|
144
144
|
};
|
|
145
|
-
if (
|
|
145
|
+
if (a !== null) {
|
|
146
146
|
console.warn(
|
|
147
147
|
"Cabbage: requestResize is not supported in VS Code extension mode"
|
|
148
148
|
);
|
|
149
149
|
return;
|
|
150
150
|
} else
|
|
151
|
-
typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(
|
|
151
|
+
typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : console.error(
|
|
152
152
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
153
|
-
|
|
153
|
+
n
|
|
154
154
|
);
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
@@ -160,28 +160,28 @@ class C {
|
|
|
160
160
|
* @param {number|string} data - The data to send (number or string)
|
|
161
161
|
* @param {Object|null} vscode - VS Code API object (null for plugin mode)
|
|
162
162
|
*/
|
|
163
|
-
static sendChannelData(o,
|
|
164
|
-
var
|
|
163
|
+
static sendChannelData(o, s, a = null) {
|
|
164
|
+
var n = {
|
|
165
165
|
channel: o
|
|
166
166
|
};
|
|
167
|
-
if (typeof
|
|
168
|
-
|
|
169
|
-
else if (typeof
|
|
170
|
-
|
|
167
|
+
if (typeof s == "string")
|
|
168
|
+
n.stringData = s;
|
|
169
|
+
else if (typeof s == "number")
|
|
170
|
+
n.floatData = s;
|
|
171
171
|
else {
|
|
172
172
|
console.warn(
|
|
173
173
|
"Cabbage: sendChannelData received unsupported data type:",
|
|
174
|
-
typeof
|
|
174
|
+
typeof s
|
|
175
175
|
);
|
|
176
176
|
return;
|
|
177
177
|
}
|
|
178
|
-
const
|
|
178
|
+
const e = {
|
|
179
179
|
command: "channelData",
|
|
180
|
-
obj: JSON.stringify(
|
|
180
|
+
obj: JSON.stringify(n)
|
|
181
181
|
};
|
|
182
|
-
console.log("Cabbage: sending channel data from UI",
|
|
182
|
+
console.log("Cabbage: sending channel data from UI", n), a !== null ? a.postMessage(e) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(e) : console.error(
|
|
183
183
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
184
|
-
|
|
184
|
+
e
|
|
185
185
|
);
|
|
186
186
|
}
|
|
187
187
|
/**
|
|
@@ -191,14 +191,14 @@ class C {
|
|
|
191
191
|
* @param {Object} widget - The widget configuration object to update
|
|
192
192
|
* @param {Object|null} vscode - VS Code API object (null for plugin mode)
|
|
193
193
|
*/
|
|
194
|
-
static sendWidgetUpdate(o,
|
|
195
|
-
const
|
|
194
|
+
static sendWidgetUpdate(o, s = null) {
|
|
195
|
+
const a = {
|
|
196
196
|
command: "widgetStateUpdate",
|
|
197
197
|
obj: JSON.stringify(CabbageUtils.sanitizeForEditor(o))
|
|
198
198
|
};
|
|
199
|
-
|
|
199
|
+
s !== null ? s.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : console.error(
|
|
200
200
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
201
|
-
|
|
201
|
+
a
|
|
202
202
|
);
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
@@ -208,25 +208,25 @@ class C {
|
|
|
208
208
|
* @param {Object|null} vscode - VS Code API object (null for plugin mode)
|
|
209
209
|
* @param {Object} additionalData - Additional data to include in the command
|
|
210
210
|
*/
|
|
211
|
-
static sendCustomCommand(o,
|
|
212
|
-
const
|
|
211
|
+
static sendCustomCommand(o, s = null, a = {}) {
|
|
212
|
+
const n = {
|
|
213
213
|
command: o,
|
|
214
|
-
text: JSON.stringify(
|
|
214
|
+
text: JSON.stringify(a)
|
|
215
215
|
};
|
|
216
|
-
if (
|
|
217
|
-
|
|
216
|
+
if (s !== null)
|
|
217
|
+
s.postMessage(n);
|
|
218
218
|
else if (typeof window.sendMessageFromUI == "function") {
|
|
219
|
-
console.log("Cabbage: Calling window.sendMessageFromUI with:",
|
|
219
|
+
console.log("Cabbage: Calling window.sendMessageFromUI with:", n);
|
|
220
220
|
try {
|
|
221
|
-
const
|
|
222
|
-
console.log("Cabbage: sendMessageFromUI returned:",
|
|
223
|
-
} catch (
|
|
224
|
-
console.error("Cabbage: sendMessageFromUI threw error:",
|
|
221
|
+
const e = window.sendMessageFromUI(n);
|
|
222
|
+
console.log("Cabbage: sendMessageFromUI returned:", e);
|
|
223
|
+
} catch (e) {
|
|
224
|
+
console.error("Cabbage: sendMessageFromUI threw error:", e), console.error("Cabbage: Error stack:", e.stack);
|
|
225
225
|
}
|
|
226
226
|
} else
|
|
227
227
|
console.error(
|
|
228
228
|
"Cabbage: window.sendMessageFromUI is not available yet. Message:",
|
|
229
|
-
|
|
229
|
+
n
|
|
230
230
|
), console.error(
|
|
231
231
|
"Cabbage: typeof window.sendMessageFromUI:",
|
|
232
232
|
typeof window.sendMessageFromUI
|
|
@@ -237,103 +237,101 @@ class C {
|
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
const I = (i) => {
|
|
240
|
-
const [o,
|
|
241
|
-
return
|
|
242
|
-
const
|
|
243
|
-
const { id:
|
|
244
|
-
if (
|
|
240
|
+
const [o, s] = w();
|
|
241
|
+
return f(() => {
|
|
242
|
+
const a = (n) => {
|
|
243
|
+
const { id: e, widgetJson: r, command: b } = n.data;
|
|
244
|
+
if (e === i && r && b === "widgetUpdate") {
|
|
245
245
|
const t = JSON.parse(r);
|
|
246
246
|
console.log(
|
|
247
|
-
`[Cabbage-React] Received properties for channelId ${
|
|
247
|
+
`[Cabbage-React] Received properties for channelId ${e}`,
|
|
248
248
|
t
|
|
249
|
-
),
|
|
249
|
+
), s(t);
|
|
250
250
|
}
|
|
251
251
|
};
|
|
252
|
-
return window.addEventListener("message",
|
|
253
|
-
window.removeEventListener("message",
|
|
252
|
+
return window.addEventListener("message", a), () => {
|
|
253
|
+
window.removeEventListener("message", a);
|
|
254
254
|
};
|
|
255
255
|
}, []), {
|
|
256
256
|
properties: o
|
|
257
257
|
};
|
|
258
|
-
},
|
|
259
|
-
const { properties:
|
|
260
|
-
|
|
258
|
+
}, y = (i, o = "complete") => {
|
|
259
|
+
const { properties: s } = I(i), [a, n] = w(), [e, r] = w(), b = (t) => {
|
|
260
|
+
n(t), C.sendControlData({
|
|
261
261
|
channel: i,
|
|
262
262
|
value: t,
|
|
263
263
|
gesture: o
|
|
264
264
|
});
|
|
265
265
|
};
|
|
266
|
-
return
|
|
267
|
-
var
|
|
268
|
-
const t =
|
|
266
|
+
return f(() => {
|
|
267
|
+
var m;
|
|
268
|
+
const t = s == null ? void 0 : s.channels.find(
|
|
269
269
|
(d) => d.id === i
|
|
270
270
|
);
|
|
271
271
|
if (!t) return;
|
|
272
|
-
const
|
|
273
|
-
|
|
272
|
+
const l = t == null ? void 0 : t.parameterIndex;
|
|
273
|
+
e === void 0 && l !== void 0 && (console.log(
|
|
274
274
|
`[Cabbage-React] Received parameterIndex for channelId "${t.id}"`,
|
|
275
|
-
|
|
276
|
-
), r(
|
|
277
|
-
const
|
|
278
|
-
|
|
275
|
+
l
|
|
276
|
+
), r(l));
|
|
277
|
+
const g = (m = t.range) == null ? void 0 : m.defaultValue;
|
|
278
|
+
a === void 0 && g !== void 0 && (console.log(
|
|
279
279
|
`[Cabbage-React] Received default value for channelId "${t.id}"`,
|
|
280
|
-
|
|
281
|
-
),
|
|
282
|
-
}, [
|
|
283
|
-
const t = (
|
|
284
|
-
var
|
|
285
|
-
const { command:
|
|
286
|
-
if (
|
|
287
|
-
const { value: d, paramIdx:
|
|
288
|
-
if (
|
|
280
|
+
g
|
|
281
|
+
), n(g));
|
|
282
|
+
}, [s]), f(() => {
|
|
283
|
+
const t = (l) => {
|
|
284
|
+
var m;
|
|
285
|
+
const { command: g } = l.data;
|
|
286
|
+
if (g === "parameterChange") {
|
|
287
|
+
const { value: d, paramIdx: c } = l.data.data;
|
|
288
|
+
if (c !== e || d === null) return;
|
|
289
289
|
console.log(
|
|
290
|
-
`[Cabbage-React] Received parameterChange for parameterIndex ${
|
|
290
|
+
`[Cabbage-React] Received parameterChange for parameterIndex ${c}`,
|
|
291
291
|
d
|
|
292
|
-
),
|
|
293
|
-
} else if (
|
|
294
|
-
const d =
|
|
295
|
-
if (!
|
|
296
|
-
const u = JSON.parse(
|
|
292
|
+
), n(d);
|
|
293
|
+
} else if (g === "batchWidgetUpdate") {
|
|
294
|
+
const d = l.data.widgets, c = d == null ? void 0 : d.find((M) => M.id === i);
|
|
295
|
+
if (!c) return;
|
|
296
|
+
const u = JSON.parse(c.widgetJson).channels.find(
|
|
297
297
|
(M) => M.id === i
|
|
298
|
-
), p = (
|
|
298
|
+
), p = (m = u == null ? void 0 : u.range) == null ? void 0 : m.value;
|
|
299
299
|
console.log(
|
|
300
|
-
`[Cabbage-React] Received batch widget update for channelId ${
|
|
300
|
+
`[Cabbage-React] Received batch widget update for channelId ${c.id}`,
|
|
301
301
|
p
|
|
302
|
-
),
|
|
302
|
+
), n(p);
|
|
303
303
|
}
|
|
304
304
|
};
|
|
305
305
|
return window.addEventListener("message", t), () => {
|
|
306
306
|
window.removeEventListener("message", t);
|
|
307
307
|
};
|
|
308
|
-
}, [
|
|
309
|
-
value:
|
|
310
|
-
setValue:
|
|
308
|
+
}, [e]), {
|
|
309
|
+
value: a,
|
|
310
|
+
setValue: b
|
|
311
311
|
};
|
|
312
|
-
},
|
|
313
|
-
const [o,
|
|
314
|
-
return
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
const l = JSON.parse(n);
|
|
320
|
-
if (l.id !== i) return;
|
|
312
|
+
}, v = (i) => {
|
|
313
|
+
const [o, s] = w();
|
|
314
|
+
return f(() => {
|
|
315
|
+
const a = (n) => {
|
|
316
|
+
const { data: e, type: r } = n.data;
|
|
317
|
+
if (e && r === "message") {
|
|
318
|
+
if (e.id !== i) return;
|
|
321
319
|
console.log(
|
|
322
|
-
`[Cabbage-React] Received
|
|
323
|
-
|
|
324
|
-
), e
|
|
320
|
+
`[Cabbage-React] Received data for messageId ${e.id}`,
|
|
321
|
+
e
|
|
322
|
+
), s(e);
|
|
325
323
|
}
|
|
326
324
|
};
|
|
327
|
-
return window.addEventListener("message",
|
|
328
|
-
window.removeEventListener("message",
|
|
325
|
+
return window.addEventListener("message", a), () => {
|
|
326
|
+
window.removeEventListener("message", a);
|
|
329
327
|
};
|
|
330
328
|
}, []), {
|
|
331
|
-
|
|
329
|
+
data: o
|
|
332
330
|
};
|
|
333
331
|
};
|
|
334
332
|
export {
|
|
335
333
|
C as Cabbage,
|
|
336
|
-
|
|
334
|
+
v as useCabbageMessage,
|
|
337
335
|
I as useCabbageProperties,
|
|
338
|
-
|
|
336
|
+
y as useCabbageState
|
|
339
337
|
};
|