cabbage-react 1.0.56 → 1.0.58
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;;CAkCD,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;;CAuCD,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;;sBAwBO,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 C{static sendControlData({channel:e,value:s,gesture:n="complete"},t=null){const a={command:"controlData",channel:e,value:s,gesture:n};t!==null?t.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 isReadyToLoad(e=null,s={}){this.sendCustomCommand("isReadyToLoad",e)}static sendMidiMessageFromUI(e,s,n,t=null){var a={statusByte:e,dataByte1:s,dataByte2:n};const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react");class C{static sendControlData({channel:e,value:s,gesture:n="complete"},t=null){const a={command:"controlData",channel:e,value:s,gesture:n};t!==null?t.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 isReadyToLoad(e=null,s={}){this.sendCustomCommand("isReadyToLoad",e)}static sendMidiMessageFromUI(e,s,n,t=null){var a={statusByte:e,dataByte1:s,dataByte2:n};const i={command:"midiMessage",obj:JSON.stringify(a)};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,n){}static triggerFileOpenDialog(e,s,n={}){var t={channel:s,directory:n.directory||"",filters:n.filters||"*",openAtLastKnownLocation:n.openAtLastKnownLocation!==void 0?n.openAtLastKnownLocation:!0};const a={command:"fileOpen",obj:JSON.stringify(t)};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 openUrl(e,s,n){var t={url:s,file:n};const a={command:"openUrl",obj:JSON.stringify(t)};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 requestResize(e,s,n=null){const t={command:"requestResize",width:e,height:s};if(n!==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,n=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 a={command:"channelData",obj:JSON.stringify(t)};n!==null?n.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 sendWidgetUpdate(e,s=null){const n={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};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 addMessageListener(e){const s=n=>{n.source!==window&&e(n.data)};return window.addEventListener("message",s),window.hostMessageCallback=e,()=>{window.removeEventListener("message",s),window.hostMessageCallback===e&&(window.hostMessageCallback=null)}}static sendCustomCommand(e,s=null,n={}){const t={command:e,text:JSON.stringify(n)};if(s!==null)s.postMessage(t);else if(typeof window.sendMessageFromUI=="function")try{const a=window.sendMessageFromUI(t)}catch(a){console.error("Cabbage: sendMessageFromUI threw error:",a),console.error("Cabbage: Error stack:",a.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)},U=(o,e)=>{if(!o||e?.skip)return{properties:void 0};const s=d.useRef(void 0);s.current=b(`useCabbageProperties:${o}`,e?.debug);const[n,t]=d.useState();return d.useEffect(()=>{const a=i=>{const{id:g,widgetJson:u,command:f}=i.data;if(g===o&&u&&f==="widgetUpdate"){const r=JSON.parse(u);s.current?.("Received properties",r),e?.onPropertiesUpdate&&e.onPropertiesUpdate(r),t(r)}};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[o,e?.onPropertiesUpdate]),{properties:n}},v=(o,e)=>{if(!o||e?.skip)return{value:void 0,setValue:()=>{}};const s=d.useRef(void 0);s.current=b(`useCabbageState:${o}`,e?.debug);const{properties:n}=U(o,{debug:e?.debug}),[t,a]=d.useState(),[i,g]=d.useState(),u=(r,l="complete")=>{a(r),C.sendControlData({channel:o,value:r,gesture:l})},f=r=>{e?.onValueUpdate&&e.onValueUpdate(r),a(r)};return d.useEffect(()=>{const r=n?.channels.find(c=>c.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))},[n]),d.useEffect(()=>{const r=l=>{const{command:w}=l.data;if(w==="parameterChange"){const{value:c,paramIdx:m}=l.data.data;if(m!==i||c===null)return;s.current?.("Received parameterChange",c),f(c)}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:u}},y=(o,e)=>{if(!o||e?.skip)return{message:void 0};const s=d.useRef(void 0);s.current=b(`useCabbageMessage:${o}`,e?.debug);const[n,t]=d.useState();return d.useEffect(()=>{const a=i=>{const{data:g,type:u}=i;!g||u!=="message"||g.type===o&&(s.current?.("Received data",g),e?.onMessage&&e.onMessage(g),t(g))};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[o,e?.onMessage]),{message:n}};exports.Cabbage=C;exports.useCabbageMessage=y;exports.useCabbageProperties=U;exports.useCabbageState=v;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
class
|
|
1
|
+
import { useRef as M, useState as f, useEffect as p } from "react";
|
|
2
|
+
class v {
|
|
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: e, value: s, gesture:
|
|
24
|
-
const
|
|
23
|
+
static sendControlData({ channel: e, value: s, gesture: a = "complete" }, t = null) {
|
|
24
|
+
const n = {
|
|
25
25
|
command: "controlData",
|
|
26
26
|
channel: e,
|
|
27
27
|
value: s,
|
|
28
|
-
gesture:
|
|
28
|
+
gesture: a
|
|
29
29
|
};
|
|
30
|
-
t !== null ? t.postMessage(
|
|
30
|
+
t !== null ? t.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : window.parent !== window ? window.parent.postMessage(n, "*") : console.error(
|
|
31
31
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
32
|
-
|
|
32
|
+
n
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
@@ -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(e, s,
|
|
53
|
-
var
|
|
52
|
+
static sendMidiMessageFromUI(e, s, a, t = null) {
|
|
53
|
+
var n = {
|
|
54
54
|
statusByte: e,
|
|
55
55
|
dataByte1: s,
|
|
56
|
-
dataByte2:
|
|
56
|
+
dataByte2: a
|
|
57
57
|
};
|
|
58
|
-
const
|
|
58
|
+
const i = {
|
|
59
59
|
command: "midiMessage",
|
|
60
|
-
obj: JSON.stringify(
|
|
60
|
+
obj: JSON.stringify(n)
|
|
61
61
|
};
|
|
62
|
-
t !== null ? t.postMessage(
|
|
62
|
+
t !== null ? t.postMessage(i) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(i) : window.parent !== window ? window.parent.postMessage(i, "*") : console.error(
|
|
63
63
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
64
|
-
|
|
64
|
+
i
|
|
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(e, s,
|
|
74
|
+
static MidiMessageFromHost(e, s, a) {
|
|
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(e, s,
|
|
86
|
+
static triggerFileOpenDialog(e, s, a = {}) {
|
|
87
87
|
var t = {
|
|
88
88
|
channel: s,
|
|
89
|
-
directory:
|
|
90
|
-
filters:
|
|
91
|
-
openAtLastKnownLocation:
|
|
89
|
+
directory: a.directory || "",
|
|
90
|
+
filters: a.filters || "*",
|
|
91
|
+
openAtLastKnownLocation: a.openAtLastKnownLocation !== void 0 ? a.openAtLastKnownLocation : !0
|
|
92
92
|
};
|
|
93
|
-
const
|
|
93
|
+
const n = {
|
|
94
94
|
command: "fileOpen",
|
|
95
95
|
obj: JSON.stringify(t)
|
|
96
96
|
};
|
|
97
|
-
e !== null ? e.postMessage(
|
|
97
|
+
e !== null ? e.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : window.parent !== window ? window.parent.postMessage(n, "*") : console.error(
|
|
98
98
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
99
|
-
|
|
99
|
+
n
|
|
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(e, s,
|
|
109
|
+
static openUrl(e, s, a) {
|
|
110
110
|
var t = {
|
|
111
111
|
url: s,
|
|
112
|
-
file:
|
|
112
|
+
file: a
|
|
113
113
|
};
|
|
114
|
-
const
|
|
114
|
+
const n = {
|
|
115
115
|
command: "openUrl",
|
|
116
116
|
obj: JSON.stringify(t)
|
|
117
117
|
};
|
|
118
|
-
e !== null ? e.postMessage(
|
|
118
|
+
e !== null ? e.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : window.parent !== window ? window.parent.postMessage(n, "*") : console.error(
|
|
119
119
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
120
|
-
|
|
120
|
+
n
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
123
|
/**
|
|
@@ -132,13 +132,13 @@ 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(e, s,
|
|
135
|
+
static requestResize(e, s, a = null) {
|
|
136
136
|
const t = {
|
|
137
137
|
command: "requestResize",
|
|
138
138
|
width: e,
|
|
139
139
|
height: s
|
|
140
140
|
};
|
|
141
|
-
if (
|
|
141
|
+
if (a !== null) {
|
|
142
142
|
console.warn(
|
|
143
143
|
"Cabbage: requestResize is not supported in VS Code extension mode"
|
|
144
144
|
);
|
|
@@ -178,7 +178,7 @@ 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(e, s,
|
|
181
|
+
static sendChannelData(e, s, a = null) {
|
|
182
182
|
var t = {
|
|
183
183
|
channel: e
|
|
184
184
|
};
|
|
@@ -193,13 +193,13 @@ class y {
|
|
|
193
193
|
);
|
|
194
194
|
return;
|
|
195
195
|
}
|
|
196
|
-
const
|
|
196
|
+
const n = {
|
|
197
197
|
command: "channelData",
|
|
198
198
|
obj: JSON.stringify(t)
|
|
199
199
|
};
|
|
200
|
-
|
|
200
|
+
a !== null ? a.postMessage(n) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(n) : window.parent !== window ? window.parent.postMessage(n, "*") : console.error(
|
|
201
201
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
202
|
-
|
|
202
|
+
n
|
|
203
203
|
);
|
|
204
204
|
}
|
|
205
205
|
/**
|
|
@@ -210,13 +210,13 @@ class y {
|
|
|
210
210
|
* @param {Object|null} vscode - VS Code API object (null for plugin mode)
|
|
211
211
|
*/
|
|
212
212
|
static sendWidgetUpdate(e, s = null) {
|
|
213
|
-
const
|
|
213
|
+
const a = {
|
|
214
214
|
command: "widgetStateUpdate",
|
|
215
215
|
obj: JSON.stringify(CabbageUtils.sanitizeForEditor(e))
|
|
216
216
|
};
|
|
217
|
-
s !== null ? s.postMessage(
|
|
217
|
+
s !== null ? s.postMessage(a) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(a) : window.parent !== window ? window.parent.postMessage(a, "*") : console.error(
|
|
218
218
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
219
|
-
|
|
219
|
+
a
|
|
220
220
|
);
|
|
221
221
|
}
|
|
222
222
|
/**
|
|
@@ -255,25 +255,25 @@ class y {
|
|
|
255
255
|
* onDestroy(() => remove?.());
|
|
256
256
|
*/
|
|
257
257
|
static addMessageListener(e) {
|
|
258
|
-
const s = (
|
|
259
|
-
|
|
258
|
+
const s = (a) => {
|
|
259
|
+
a.source !== window && e(a.data);
|
|
260
260
|
};
|
|
261
261
|
return window.addEventListener("message", s), window.hostMessageCallback = e, () => {
|
|
262
262
|
window.removeEventListener("message", s), window.hostMessageCallback === e && (window.hostMessageCallback = null);
|
|
263
263
|
};
|
|
264
264
|
}
|
|
265
|
-
static sendCustomCommand(e, s = null,
|
|
265
|
+
static sendCustomCommand(e, s = null, a = {}) {
|
|
266
266
|
const t = {
|
|
267
267
|
command: e,
|
|
268
|
-
text: JSON.stringify(
|
|
268
|
+
text: JSON.stringify(a)
|
|
269
269
|
};
|
|
270
270
|
if (s !== null)
|
|
271
271
|
s.postMessage(t);
|
|
272
272
|
else if (typeof window.sendMessageFromUI == "function")
|
|
273
273
|
try {
|
|
274
|
-
const
|
|
275
|
-
} catch (
|
|
276
|
-
console.error("Cabbage: sendMessageFromUI threw error:",
|
|
274
|
+
const n = window.sendMessageFromUI(t);
|
|
275
|
+
} catch (n) {
|
|
276
|
+
console.error("Cabbage: sendMessageFromUI threw error:", n), console.error("Cabbage: Error stack:", n.stack);
|
|
277
277
|
}
|
|
278
278
|
else window.parent !== window ? window.parent.postMessage(t, "*") : (console.error(
|
|
279
279
|
"Cabbage: window.sendMessageFromUI is not available yet. Message:",
|
|
@@ -287,86 +287,98 @@ class y {
|
|
|
287
287
|
));
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
|
-
const
|
|
290
|
+
const U = (o, e) => (...s) => {
|
|
291
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 =
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
294
|
+
const s = M(
|
|
295
|
+
void 0
|
|
296
|
+
);
|
|
297
|
+
s.current = U(
|
|
298
|
+
`useCabbageProperties:${o}`,
|
|
299
|
+
e?.debug
|
|
300
|
+
);
|
|
301
|
+
const [a, t] = f();
|
|
298
302
|
return p(() => {
|
|
299
|
-
const
|
|
300
|
-
const { id: d, widgetJson: l, command: u } =
|
|
303
|
+
const n = (i) => {
|
|
304
|
+
const { id: d, widgetJson: l, command: u } = i.data;
|
|
301
305
|
if (d === o && l && u === "widgetUpdate") {
|
|
302
|
-
const
|
|
303
|
-
s("Received properties",
|
|
306
|
+
const r = JSON.parse(l);
|
|
307
|
+
s.current?.("Received properties", r), e?.onPropertiesUpdate && e.onPropertiesUpdate(r), t(r);
|
|
304
308
|
}
|
|
305
309
|
};
|
|
306
|
-
return window.addEventListener("message",
|
|
307
|
-
}, [o, e?.onPropertiesUpdate]), { properties:
|
|
310
|
+
return window.addEventListener("message", n), () => window.removeEventListener("message", n);
|
|
311
|
+
}, [o, e?.onPropertiesUpdate]), { properties: a };
|
|
308
312
|
}, L = (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 = M(
|
|
317
|
+
void 0
|
|
318
|
+
);
|
|
319
|
+
s.current = U(
|
|
320
|
+
`useCabbageState:${o}`,
|
|
321
|
+
e?.debug
|
|
322
|
+
);
|
|
323
|
+
const { properties: a } = y(o, {
|
|
316
324
|
debug: e?.debug
|
|
317
|
-
}), [t,
|
|
318
|
-
|
|
325
|
+
}), [t, n] = f(), [i, d] = f(), l = (r, g = "complete") => {
|
|
326
|
+
n(r), v.sendControlData({
|
|
319
327
|
channel: o,
|
|
320
|
-
value:
|
|
328
|
+
value: r,
|
|
321
329
|
gesture: g
|
|
322
330
|
});
|
|
323
|
-
}, u = (
|
|
324
|
-
e?.onValueUpdate && e.onValueUpdate(
|
|
331
|
+
}, u = (r) => {
|
|
332
|
+
e?.onValueUpdate && e.onValueUpdate(r), n(r);
|
|
325
333
|
};
|
|
326
334
|
return p(() => {
|
|
327
|
-
const
|
|
335
|
+
const r = a?.channels.find(
|
|
328
336
|
(c) => c.id === o
|
|
329
337
|
);
|
|
330
|
-
if (!
|
|
331
|
-
const g =
|
|
332
|
-
if (
|
|
333
|
-
const w =
|
|
334
|
-
w != null && (s("Received initial value", w), u(w));
|
|
335
|
-
}, [
|
|
336
|
-
const
|
|
338
|
+
if (!r) return;
|
|
339
|
+
const g = r.parameterIndex;
|
|
340
|
+
if (i === void 0 && g !== void 0 && (s.current?.("Received parameterIndex", g), d(g)), t !== void 0) return;
|
|
341
|
+
const w = r.range?.value;
|
|
342
|
+
w != null && (s.current?.("Received initial value", w), u(w));
|
|
343
|
+
}, [a]), p(() => {
|
|
344
|
+
const r = (g) => {
|
|
337
345
|
const { command: w } = g.data;
|
|
338
346
|
if (w === "parameterChange") {
|
|
339
347
|
const { value: c, paramIdx: m } = g.data.data;
|
|
340
|
-
if (m !==
|
|
341
|
-
s("Received parameterChange", c), u(c);
|
|
348
|
+
if (m !== i || c === null) return;
|
|
349
|
+
s.current?.("Received parameterChange", c), u(c);
|
|
342
350
|
} else if (w === "batchWidgetUpdate") {
|
|
343
351
|
const m = g.data.widgets?.find((b) => b.id === o);
|
|
344
352
|
if (!m) return;
|
|
345
|
-
const
|
|
353
|
+
const C = JSON.parse(m.widgetJson).channels.find(
|
|
346
354
|
(b) => b.id === o
|
|
347
355
|
)?.range?.value;
|
|
348
|
-
s("Received batchWidgetUpdate",
|
|
356
|
+
s.current?.("Received batchWidgetUpdate", C), u(C);
|
|
349
357
|
}
|
|
350
358
|
};
|
|
351
|
-
return window.addEventListener("message",
|
|
352
|
-
}, [o, e?.onValueUpdate,
|
|
353
|
-
},
|
|
359
|
+
return window.addEventListener("message", r), () => window.removeEventListener("message", r);
|
|
360
|
+
}, [o, e?.onValueUpdate, i]), { value: t, setValue: l };
|
|
361
|
+
}, R = (o, e) => {
|
|
354
362
|
if (!o || e?.skip) return { message: void 0 };
|
|
355
363
|
const s = M(
|
|
364
|
+
void 0
|
|
365
|
+
);
|
|
366
|
+
s.current = U(
|
|
356
367
|
`useCabbageMessage:${o}`,
|
|
357
368
|
e?.debug
|
|
358
|
-
)
|
|
369
|
+
);
|
|
370
|
+
const [a, t] = f();
|
|
359
371
|
return p(() => {
|
|
360
|
-
const
|
|
361
|
-
const { data: d, type: l } =
|
|
362
|
-
!d || l !== "message" || d.type === o && (s("Received data", d), e?.onMessage && e.onMessage(d), t(d));
|
|
372
|
+
const n = (i) => {
|
|
373
|
+
const { data: d, type: l } = i;
|
|
374
|
+
!d || l !== "message" || d.type === o && (s.current?.("Received data", d), e?.onMessage && e.onMessage(d), t(d));
|
|
363
375
|
};
|
|
364
|
-
return window.addEventListener("message",
|
|
365
|
-
}, [o, e?.onMessage]), { message:
|
|
376
|
+
return window.addEventListener("message", n), () => window.removeEventListener("message", n);
|
|
377
|
+
}, [o, e?.onMessage]), { message: a };
|
|
366
378
|
};
|
|
367
379
|
export {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
380
|
+
v as Cabbage,
|
|
381
|
+
R as useCabbageMessage,
|
|
382
|
+
y as useCabbageProperties,
|
|
371
383
|
L as useCabbageState
|
|
372
384
|
};
|