cabbage-react 1.0.57 → 1.0.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCabbageMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageMessage.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAClC,aAAa,MAAM,EACnB,UAAU;IACT,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;;
|
|
1
|
+
{"version":3,"file":"useCabbageMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageMessage.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAClC,aAAa,MAAM,EACnB,UAAU;IACT,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;;CA+BD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,GAChC,WAAW,MAAM,EACjB,UAAU;IACT,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;IAC/D,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;;
|
|
1
|
+
{"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,GAChC,WAAW,MAAM,EACjB,UAAU;IACT,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;IAC/D,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;;CAoCD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAChC,WAAW,MAAM,EACjB,UAAU;IACT,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACnC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;;
|
|
1
|
+
{"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAChC,WAAW,MAAM,EACjB,UAAU;IACT,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACnC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;;sBAqBO,CAAC,YACC,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU;CAiFhD,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react");class U{static sendControlData({channel:e,value:s,gesture:a="complete"},t=null){const n={command:"controlData",channel:e,value:s,gesture:a};t!==null?t.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static isReadyToLoad(e=null,s={}){this.sendCustomCommand("isReadyToLoad",e)}static sendMidiMessageFromUI(e,s,a,t=null){var n={statusByte:e,dataByte1:s,dataByte2:a};const i={command:"midiMessage",obj:JSON.stringify(n)};t!==null?t.postMessage(i):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(i):window.parent!==window?window.parent.postMessage(i,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",i)}static MidiMessageFromHost(e,s,a){}static triggerFileOpenDialog(e,s,a={}){var t={channel:s,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.openAtLastKnownLocation:!0};const n={command:"fileOpen",obj:JSON.stringify(t)};e!==null?e.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static openUrl(e,s,a){var t={url:s,file:a};const n={command:"openUrl",obj:JSON.stringify(t)};e!==null?e.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static requestResize(e,s,a=null){const t={command:"requestResize",width:e,height:s};if(a!==null){console.warn("Cabbage: requestResize is not supported in VS Code extension mode");return}else typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(t):window.parent!==window?window.parent.postMessage(t,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",t)}static consumeKeypresses(e){typeof window.consumeKeypresses=="function"&&window.consumeKeypresses(e)}static sendChannelData(e,s,a=null){var t={channel:e};if(typeof s=="string")t.stringData=s;else if(typeof s=="number")t.floatData=s;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof s);return}const n={command:"channelData",obj:JSON.stringify(t)};a!==null?a.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static sendWidgetUpdate(e,s=null){const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};s!==null?s.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):window.parent!==window?window.parent.postMessage(a,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static addMessageListener(e){const s=a=>{a.source!==window&&e(a.data)};return window.addEventListener("message",s),window.hostMessageCallback=e,()=>{window.removeEventListener("message",s),window.hostMessageCallback===e&&(window.hostMessageCallback=null)}}static sendCustomCommand(e,s=null,a={}){const t={command:e,text:JSON.stringify(a)};if(s!==null)s.postMessage(t);else if(typeof window.sendMessageFromUI=="function")try{const n=window.sendMessageFromUI(t)}catch(n){console.error("Cabbage: sendMessageFromUI threw error:",n),console.error("Cabbage: Error stack:",n.stack)}else window.parent!==window?window.parent.postMessage(t,"*"):(console.error("Cabbage: window.sendMessageFromUI is not available yet. Message:",t),console.error("Cabbage: typeof window.sendMessageFromUI:",typeof window.sendMessageFromUI),console.error("Cabbage: window.sendMessageFromUI value:",window.sendMessageFromUI))}}const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react");class U{static sendControlData({channel:e,value:s,gesture:a="complete"},t=null){const n={command:"controlData",channel:e,value:s,gesture:a};t!==null?t.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static isReadyToLoad(e=null,s={}){this.sendCustomCommand("isReadyToLoad",e)}static sendMidiMessageFromUI(e,s,a,t=null){var n={statusByte:e,dataByte1:s,dataByte2:a};const i={command:"midiMessage",obj:JSON.stringify(n)};t!==null?t.postMessage(i):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(i):window.parent!==window?window.parent.postMessage(i,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",i)}static MidiMessageFromHost(e,s,a){}static triggerFileOpenDialog(e,s,a={}){var t={channel:s,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.openAtLastKnownLocation:!0};const n={command:"fileOpen",obj:JSON.stringify(t)};e!==null?e.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static openUrl(e,s,a){var t={url:s,file:a};const n={command:"openUrl",obj:JSON.stringify(t)};e!==null?e.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static requestResize(e,s,a=null){const t={command:"requestResize",width:e,height:s};if(a!==null){console.warn("Cabbage: requestResize is not supported in VS Code extension mode");return}else typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(t):window.parent!==window?window.parent.postMessage(t,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",t)}static consumeKeypresses(e){typeof window.consumeKeypresses=="function"&&window.consumeKeypresses(e)}static sendChannelData(e,s,a=null){var t={channel:e};if(typeof s=="string")t.stringData=s;else if(typeof s=="number")t.floatData=s;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof s);return}const n={command:"channelData",obj:JSON.stringify(t)};a!==null?a.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static sendWidgetUpdate(e,s=null){const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};s!==null?s.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):window.parent!==window?window.parent.postMessage(a,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static addMessageListener(e){const s=a=>{a.source!==window&&e(a.data)};return window.addEventListener("message",s),window.hostMessageCallback=e,()=>{window.removeEventListener("message",s),window.hostMessageCallback===e&&(window.hostMessageCallback=null)}}static sendCustomCommand(e,s=null,a={}){const t={command:e,text:JSON.stringify(a)};if(s!==null)s.postMessage(t);else if(typeof window.sendMessageFromUI=="function")try{const n=window.sendMessageFromUI(t)}catch(n){console.error("Cabbage: sendMessageFromUI threw error:",n),console.error("Cabbage: Error stack:",n.stack)}else window.parent!==window?window.parent.postMessage(t,"*"):(console.error("Cabbage: window.sendMessageFromUI is not available yet. Message:",t),console.error("Cabbage: typeof window.sendMessageFromUI:",typeof window.sendMessageFromUI),console.error("Cabbage: window.sendMessageFromUI value:",window.sendMessageFromUI))}}const b=(o,e)=>(...s)=>{e&&console.log(`[Cabbage-React][${o}]`,...s)},C=(o,e)=>{if(!o||e?.skip)return{properties:void 0};const s=d.useRef(void 0);s.current=b(o,e?.debug);const[a,t]=d.useState();return d.useEffect(()=>{const n=i=>{const{id:g,widgetJson:c,command:f}=i.data;if(g===o&&c&&f==="widgetUpdate"){const r=JSON.parse(c);s.current?.("Received properties",r),e?.onPropertiesUpdate&&e.onPropertiesUpdate(r),t(r)}};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[o,e?.onPropertiesUpdate]),{properties:a}},v=(o,e)=>{if(!o||e?.skip)return{value:void 0,setValue:()=>{}};const s=d.useRef(void 0);s.current=b(o,e?.debug);const{properties:a}=C(o,{debug:e?.debug}),[t,n]=d.useState(),[i,g]=d.useState(),c=(r,l="complete")=>{n(r),U.sendControlData({channel:o,value:r,gesture:l})},f=r=>{e?.onValueUpdate&&e.onValueUpdate(r),n(r)};return d.useEffect(()=>{const r=a?.channels.find(u=>u.id===o);if(!r)return;const l=r.parameterIndex;if(i===void 0&&l!==void 0&&(s.current?.("Received parameterIndex",l),g(l)),t!==void 0)return;const w=r.range?.value;w!=null&&(s.current?.("Received initial value",w),f(w))},[a]),d.useEffect(()=>{const r=l=>{const{command:w}=l.data;if(w==="parameterChange"){const{value:u,paramIdx:m}=l.data.data;if(m!==i||u===null)return;s.current?.("Received parameterChange",u),f(u)}else if(w==="batchWidgetUpdate"){const m=l.data.widgets?.find(p=>p.id===o);if(!m)return;const M=JSON.parse(m.widgetJson).channels.find(p=>p.id===o)?.range?.value;s.current?.("Received batchWidgetUpdate",M),f(M)}};return window.addEventListener("message",r),()=>window.removeEventListener("message",r)},[o,e?.onValueUpdate,i]),{value:t,setValue:c}},y=(o,e)=>{if(!o||e?.skip)return{message:void 0};const s=d.useRef(void 0);s.current=b(o,e?.debug);const[a,t]=d.useState();return d.useEffect(()=>{const n=i=>{const{data:g,type:c}=i;!g||c!=="message"||g.type===o&&(s.current?.("Received data",g),e?.onMessage&&e.onMessage(g),t(g))};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[o,e?.onMessage]),{message:a}};exports.Cabbage=U;exports.useCabbageMessage=y;exports.useCabbageProperties=C;exports.useCabbageState=v;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
class
|
|
1
|
+
import { useRef as b, useState as f, useEffect as p } from "react";
|
|
2
|
+
class C {
|
|
3
3
|
/**
|
|
4
4
|
* Send a widget value change to the Cabbage backend.
|
|
5
5
|
*
|
|
@@ -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,98 +287,89 @@ 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 =
|
|
294
|
+
const s = b(
|
|
295
295
|
void 0
|
|
296
296
|
);
|
|
297
|
-
s.current =
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
if (d === o && c && m === "widgetUpdate") {
|
|
306
|
-
const i = JSON.parse(c);
|
|
307
|
-
n("Received properties", i), e?.onPropertiesUpdate && e.onPropertiesUpdate(i), a(i);
|
|
297
|
+
s.current = U(o, e?.debug);
|
|
298
|
+
const [a, t] = f();
|
|
299
|
+
return p(() => {
|
|
300
|
+
const n = (i) => {
|
|
301
|
+
const { id: d, widgetJson: l, command: u } = i.data;
|
|
302
|
+
if (d === o && l && u === "widgetUpdate") {
|
|
303
|
+
const r = JSON.parse(l);
|
|
304
|
+
s.current?.("Received properties", r), e?.onPropertiesUpdate && e.onPropertiesUpdate(r), t(r);
|
|
308
305
|
}
|
|
309
306
|
};
|
|
310
|
-
return window.addEventListener("message",
|
|
311
|
-
}, [o, e?.onPropertiesUpdate]), { properties:
|
|
312
|
-
},
|
|
307
|
+
return window.addEventListener("message", n), () => window.removeEventListener("message", n);
|
|
308
|
+
}, [o, e?.onPropertiesUpdate]), { properties: a };
|
|
309
|
+
}, L = (o, e) => {
|
|
313
310
|
if (!o || e?.skip)
|
|
314
311
|
return { value: void 0, setValue: () => {
|
|
315
312
|
} };
|
|
316
|
-
const s =
|
|
313
|
+
const s = b(
|
|
317
314
|
void 0
|
|
318
315
|
);
|
|
319
|
-
s.current =
|
|
320
|
-
|
|
321
|
-
e?.debug
|
|
322
|
-
);
|
|
323
|
-
const n = s.current, { properties: t } = F(o, {
|
|
316
|
+
s.current = U(o, e?.debug);
|
|
317
|
+
const { properties: a } = y(o, {
|
|
324
318
|
debug: e?.debug
|
|
325
|
-
}), [
|
|
326
|
-
r
|
|
319
|
+
}), [t, n] = f(), [i, d] = f(), l = (r, g = "complete") => {
|
|
320
|
+
n(r), C.sendControlData({
|
|
327
321
|
channel: o,
|
|
328
|
-
value:
|
|
322
|
+
value: r,
|
|
329
323
|
gesture: g
|
|
330
324
|
});
|
|
331
|
-
},
|
|
332
|
-
e?.onValueUpdate && e.onValueUpdate(
|
|
325
|
+
}, u = (r) => {
|
|
326
|
+
e?.onValueUpdate && e.onValueUpdate(r), n(r);
|
|
333
327
|
};
|
|
334
|
-
return
|
|
335
|
-
const
|
|
336
|
-
(
|
|
328
|
+
return p(() => {
|
|
329
|
+
const r = a?.channels.find(
|
|
330
|
+
(c) => c.id === o
|
|
337
331
|
);
|
|
338
|
-
if (!
|
|
339
|
-
const g =
|
|
340
|
-
if (
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
}, [
|
|
344
|
-
const
|
|
345
|
-
const { command:
|
|
346
|
-
if (
|
|
347
|
-
const { value:
|
|
348
|
-
if (
|
|
349
|
-
|
|
350
|
-
} else if (
|
|
351
|
-
const
|
|
352
|
-
if (!
|
|
353
|
-
const v = JSON.parse(
|
|
332
|
+
if (!r) return;
|
|
333
|
+
const g = r.parameterIndex;
|
|
334
|
+
if (i === void 0 && g !== void 0 && (s.current?.("Received parameterIndex", g), d(g)), t !== void 0) return;
|
|
335
|
+
const w = r.range?.value;
|
|
336
|
+
w != null && (s.current?.("Received initial value", w), u(w));
|
|
337
|
+
}, [a]), p(() => {
|
|
338
|
+
const r = (g) => {
|
|
339
|
+
const { command: w } = g.data;
|
|
340
|
+
if (w === "parameterChange") {
|
|
341
|
+
const { value: c, paramIdx: m } = g.data.data;
|
|
342
|
+
if (m !== i || c === null) return;
|
|
343
|
+
s.current?.("Received parameterChange", c), u(c);
|
|
344
|
+
} else if (w === "batchWidgetUpdate") {
|
|
345
|
+
const m = g.data.widgets?.find((M) => M.id === o);
|
|
346
|
+
if (!m) return;
|
|
347
|
+
const v = JSON.parse(m.widgetJson).channels.find(
|
|
354
348
|
(M) => M.id === o
|
|
355
349
|
)?.range?.value;
|
|
356
|
-
|
|
350
|
+
s.current?.("Received batchWidgetUpdate", v), u(v);
|
|
357
351
|
}
|
|
358
352
|
};
|
|
359
|
-
return window.addEventListener("message",
|
|
360
|
-
}, [o, e?.onValueUpdate,
|
|
361
|
-
},
|
|
353
|
+
return window.addEventListener("message", r), () => window.removeEventListener("message", r);
|
|
354
|
+
}, [o, e?.onValueUpdate, i]), { value: t, setValue: l };
|
|
355
|
+
}, R = (o, e) => {
|
|
362
356
|
if (!o || e?.skip) return { message: void 0 };
|
|
363
|
-
const s =
|
|
357
|
+
const s = b(
|
|
364
358
|
void 0
|
|
365
359
|
);
|
|
366
|
-
s.current =
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
const r = (w) => {
|
|
373
|
-
const { data: d, type: c } = w;
|
|
374
|
-
!d || c !== "message" || d.type === o && (n("Received data", d), e?.onMessage && e.onMessage(d), a(d));
|
|
360
|
+
s.current = U(o, e?.debug);
|
|
361
|
+
const [a, t] = f();
|
|
362
|
+
return p(() => {
|
|
363
|
+
const n = (i) => {
|
|
364
|
+
const { data: d, type: l } = i;
|
|
365
|
+
!d || l !== "message" || d.type === o && (s.current?.("Received data", d), e?.onMessage && e.onMessage(d), t(d));
|
|
375
366
|
};
|
|
376
|
-
return window.addEventListener("message",
|
|
377
|
-
}, [o, e?.onMessage]), { message:
|
|
367
|
+
return window.addEventListener("message", n), () => window.removeEventListener("message", n);
|
|
368
|
+
}, [o, e?.onMessage]), { message: a };
|
|
378
369
|
};
|
|
379
370
|
export {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
371
|
+
C as Cabbage,
|
|
372
|
+
R as useCabbageMessage,
|
|
373
|
+
y as useCabbageProperties,
|
|
374
|
+
L as useCabbageState
|
|
384
375
|
};
|