cabbage-react 1.0.50 → 1.0.52
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 +5 -1
- package/dist/hooks/useCabbageMessage.d.ts.map +1 -1
- package/dist/hooks/useCabbageProperties.d.ts +5 -2
- package/dist/hooks/useCabbageProperties.d.ts.map +1 -1
- package/dist/hooks/useCabbageState.d.ts +5 -1
- package/dist/hooks/useCabbageState.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +113 -116
- package/package.json +14 -14
|
@@ -4,8 +4,12 @@
|
|
|
4
4
|
* whenever new data is received.
|
|
5
5
|
* @param messageType - The value of the `type` property in the incoming message object to listen for.
|
|
6
6
|
* @param onMessage - Callback fires immediately when receiving a new message (synchronous - bypasses state batching)
|
|
7
|
+
* @param options - Optional configuration
|
|
8
|
+
* @param options.skip - When true, the hook returns a NOP state and never registers listeners
|
|
7
9
|
*/
|
|
8
|
-
export declare const useCabbageMessage: <T>(messageType: string, onMessage?: (message: T) => void
|
|
10
|
+
export declare const useCabbageMessage: <T>(messageType: string, onMessage?: (message: T) => void, options?: {
|
|
11
|
+
skip?: boolean;
|
|
12
|
+
}) => {
|
|
9
13
|
message: T | undefined;
|
|
10
14
|
};
|
|
11
15
|
//# 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;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAClC,aAAa,MAAM,EACnB,YAAY,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,EAChC,UAAU;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE;;CA4B5B,CAAC"}
|
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
* whenever new data is received.
|
|
5
5
|
* @param channelId
|
|
6
6
|
* @param onPropertiesUpdate - Callback fires immediately when receiving an update to properties (synchronous - bypasses state batching)
|
|
7
|
+
* @param options - Optional configuration
|
|
8
|
+
* @param options.skip - When true, the hook returns a NOP state and never registers listeners
|
|
7
9
|
*/
|
|
8
|
-
export declare const useCabbageProperties: (channelId: string, onPropertiesUpdate?: (properties: Record<string, any>) => void
|
|
10
|
+
export declare const useCabbageProperties: (channelId: string, onPropertiesUpdate?: (properties: Record<string, any>) => void, options?: {
|
|
11
|
+
skip?: boolean;
|
|
12
|
+
}) => {
|
|
9
13
|
properties: Record<string, any> | undefined;
|
|
10
|
-
onPropertiesUpdate: ((properties: Record<string, any>) => void) | undefined;
|
|
11
14
|
};
|
|
12
15
|
//# 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;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,GAChC,WAAW,MAAM,EACjB,qBAAqB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,EAC9D,UAAU;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE;;CAiC5B,CAAC"}
|
|
@@ -5,8 +5,12 @@
|
|
|
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
7
|
* @param onValueUpdate - Callback fires immediately when receiving a value update (synchronous - bypasses state batching)
|
|
8
|
+
* @param options - Optional configuration
|
|
9
|
+
* @param options.skip - When true, the hook returns a NOP state and never registers listeners
|
|
8
10
|
*/
|
|
9
|
-
export declare const useCabbageState: <T>(channelId: string, gesture?: "begin" | "value" | "end" | "complete", onValueUpdate?: (value: T) => void
|
|
11
|
+
export declare const useCabbageState: <T>(channelId: string, gesture?: "begin" | "value" | "end" | "complete", onValueUpdate?: (value: T) => void, options?: {
|
|
12
|
+
skip?: boolean;
|
|
13
|
+
}) => {
|
|
10
14
|
value: T | undefined;
|
|
11
15
|
setValue: (value: T) => void;
|
|
12
16
|
};
|
|
@@ -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;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAChC,WAAW,MAAM,EACjB,UAAS,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,UAAuB,EAC5D,gBAAgB,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAClC,UAAU;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE;;sBAWM,CAAC;CA6FnC,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 C{static sendControlData({channel:e,value:s,gesture:a="complete"},o=null){const n={command:"controlData",channel:e,value:s,gesture:a};o!==null?o.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static isReadyToLoad(e=null,s={}){this.sendCustomCommand("isReadyToLoad",e)}static sendMidiMessageFromUI(e,s,a,o=null){var n={statusByte:e,dataByte1:s,dataByte2:a};const d={command:"midiMessage",obj:JSON.stringify(n)};o!==null?o.postMessage(d):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(d):window.parent!==window?window.parent.postMessage(d,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",d)}static MidiMessageFromHost(e,s,a){}static triggerFileOpenDialog(e,s,a={}){var o={channel:s,directory:a.directory||"",filters:a.filters||"*",openAtLastKnownLocation:a.openAtLastKnownLocation!==void 0?a.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,s,a){var o={url:s,file:a};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,s,a=null){const o={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(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,s,a=null){var o={channel:e};if(typeof s=="string")o.stringData=s;else if(typeof s=="number")o.floatData=s;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof s);return}const n={command:"channelData",obj:JSON.stringify(o)};a!==null?a.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static sendWidgetUpdate(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 o={command:e,text:JSON.stringify(a)};if(s!==null)s.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 y=(t,e,s)=>{if(!t||s?.skip)return{properties:void 0};const[a,o]=l.useState();return l.useEffect(()=>{const n=d=>{const{id:r,widgetJson:m,command:p}=d.data;if(r===t&&m&&p==="widgetUpdate"){const g=JSON.parse(m);console.log(`[Cabbage-React] Received properties for channelId: ${r}`,g),e&&e(g),o(g)}};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[t,e]),{properties:a}},v=(t,e="complete",s,a)=>{if(!t||a?.skip)return{value:void 0,setValue:()=>{}};const{properties:o}=y(t),[n,d]=l.useState(),[r,m]=l.useState(),p=i=>{d(i),C.sendControlData({channel:t,value:i,gesture:e})},g=i=>{s&&s(i),d(i)};return l.useEffect(()=>{const i=o?.channels.find(f=>f.id===t);if(!i)return;const w=i.parameterIndex;if(r===void 0&&w!==void 0&&(console.log(`[Cabbage-React] Received parameterIndex for channelId: ${i.id}`,w),m(w)),n!==void 0)return;const c=i.range?.value;c!=null&&(console.log(`[Cabbage-React] Received initial value for channelId: ${i.id}`,c),g(c))},[o]),l.useEffect(()=>{const i=w=>{const{command:c}=w.data;if(c==="parameterChange"){const{value:f,paramIdx:u}=w.data.data;if(u!==r||f===null)return;console.log(`[Cabbage-React] Received parameterChange for parameterIndex: ${u}`,f),g(f)}else if(c==="batchWidgetUpdate"){const u=w.data.widgets?.find(b=>b.id===t);if(!u)return;const M=JSON.parse(u.widgetJson).channels.find(b=>b.id===t)?.range?.value;console.log(`[Cabbage-React] Received batch widget update for channelId: ${u.id}`,M),g(M)}};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[t,s,r]),{value:n,setValue:p}},I=(t,e,s)=>{if(!t||s?.skip)return{message:void 0};const[a,o]=l.useState();return l.useEffect(()=>{const n=d=>{const{data:r,type:m}=d;!r||m!=="message"||r.type===t&&(console.log(`[Cabbage-React] Received data for messageType: ${r.type}`,r),e&&e(r),o(r))};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[t,e]),{message:a}};exports.Cabbage=C;exports.useCabbageMessage=I;exports.useCabbageProperties=y;exports.useCabbageState=v;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
class
|
|
1
|
+
import { useState as p, useEffect as u } from "react";
|
|
2
|
+
class y {
|
|
3
3
|
/**
|
|
4
4
|
* Send a widget value change to the Cabbage backend.
|
|
5
5
|
*
|
|
@@ -20,16 +20,16 @@ class I {
|
|
|
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:
|
|
24
|
-
const
|
|
23
|
+
static sendControlData({ channel: e, value: s, gesture: a = "complete" }, o = null) {
|
|
24
|
+
const n = {
|
|
25
25
|
command: "controlData",
|
|
26
26
|
channel: e,
|
|
27
|
-
value:
|
|
28
|
-
gesture:
|
|
27
|
+
value: s,
|
|
28
|
+
gesture: a
|
|
29
29
|
};
|
|
30
|
-
o !== null ? o.postMessage(
|
|
30
|
+
o !== null ? o.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
|
/**
|
|
@@ -38,7 +38,7 @@ class I {
|
|
|
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(e = null,
|
|
41
|
+
static isReadyToLoad(e = null, s = {}) {
|
|
42
42
|
this.sendCustomCommand("isReadyToLoad", e);
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
@@ -49,19 +49,19 @@ class I {
|
|
|
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,
|
|
53
|
-
var
|
|
52
|
+
static sendMidiMessageFromUI(e, s, a, o = null) {
|
|
53
|
+
var n = {
|
|
54
54
|
statusByte: e,
|
|
55
|
-
dataByte1:
|
|
56
|
-
dataByte2:
|
|
55
|
+
dataByte1: s,
|
|
56
|
+
dataByte2: a
|
|
57
57
|
};
|
|
58
|
-
const
|
|
58
|
+
const d = {
|
|
59
59
|
command: "midiMessage",
|
|
60
|
-
obj: JSON.stringify(
|
|
60
|
+
obj: JSON.stringify(n)
|
|
61
61
|
};
|
|
62
|
-
o !== null ? o.postMessage(
|
|
62
|
+
o !== null ? o.postMessage(d) : typeof window.sendMessageFromUI == "function" ? window.sendMessageFromUI(d) : window.parent !== window ? window.parent.postMessage(d, "*") : console.error(
|
|
63
63
|
"Cabbage: window.sendMessageFromUI is not available. Message:",
|
|
64
|
-
|
|
64
|
+
d
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
@@ -71,7 +71,7 @@ class I {
|
|
|
71
71
|
* @param {number} dataByte1 - First MIDI data byte
|
|
72
72
|
* @param {number} dataByte2 - Second MIDI data byte
|
|
73
73
|
*/
|
|
74
|
-
static MidiMessageFromHost(e,
|
|
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 I {
|
|
|
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,
|
|
86
|
+
static triggerFileOpenDialog(e, s, a = {}) {
|
|
87
87
|
var o = {
|
|
88
|
-
channel:
|
|
89
|
-
directory:
|
|
90
|
-
filters:
|
|
91
|
-
openAtLastKnownLocation:
|
|
88
|
+
channel: s,
|
|
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(o)
|
|
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 I {
|
|
|
106
106
|
* @param {string} url - URL to open
|
|
107
107
|
* @param {string} file - File path to open
|
|
108
108
|
*/
|
|
109
|
-
static openUrl(e,
|
|
109
|
+
static openUrl(e, s, a) {
|
|
110
110
|
var o = {
|
|
111
|
-
url:
|
|
112
|
-
file:
|
|
111
|
+
url: s,
|
|
112
|
+
file: a
|
|
113
113
|
};
|
|
114
|
-
const
|
|
114
|
+
const n = {
|
|
115
115
|
command: "openUrl",
|
|
116
116
|
obj: JSON.stringify(o)
|
|
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 I {
|
|
|
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,
|
|
135
|
+
static requestResize(e, s, a = null) {
|
|
136
136
|
const o = {
|
|
137
137
|
command: "requestResize",
|
|
138
138
|
width: e,
|
|
139
|
-
height:
|
|
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,28 +178,28 @@ class I {
|
|
|
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,
|
|
181
|
+
static sendChannelData(e, s, a = null) {
|
|
182
182
|
var o = {
|
|
183
183
|
channel: e
|
|
184
184
|
};
|
|
185
|
-
if (typeof
|
|
186
|
-
o.stringData =
|
|
187
|
-
else if (typeof
|
|
188
|
-
o.floatData =
|
|
185
|
+
if (typeof s == "string")
|
|
186
|
+
o.stringData = s;
|
|
187
|
+
else if (typeof s == "number")
|
|
188
|
+
o.floatData = s;
|
|
189
189
|
else {
|
|
190
190
|
console.warn(
|
|
191
191
|
"Cabbage: sendChannelData received unsupported data type:",
|
|
192
|
-
typeof
|
|
192
|
+
typeof s
|
|
193
193
|
);
|
|
194
194
|
return;
|
|
195
195
|
}
|
|
196
|
-
const
|
|
196
|
+
const n = {
|
|
197
197
|
command: "channelData",
|
|
198
198
|
obj: JSON.stringify(o)
|
|
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
|
/**
|
|
@@ -209,14 +209,14 @@ class I {
|
|
|
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(e,
|
|
213
|
-
const
|
|
212
|
+
static sendWidgetUpdate(e, s = null) {
|
|
213
|
+
const a = {
|
|
214
214
|
command: "widgetStateUpdate",
|
|
215
215
|
obj: JSON.stringify(CabbageUtils.sanitizeForEditor(e))
|
|
216
216
|
};
|
|
217
|
-
|
|
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 I {
|
|
|
255
255
|
* onDestroy(() => remove?.());
|
|
256
256
|
*/
|
|
257
257
|
static addMessageListener(e) {
|
|
258
|
-
const
|
|
259
|
-
|
|
258
|
+
const s = (a) => {
|
|
259
|
+
a.source !== window && e(a.data);
|
|
260
260
|
};
|
|
261
|
-
return window.addEventListener("message",
|
|
262
|
-
window.removeEventListener("message",
|
|
261
|
+
return window.addEventListener("message", s), window.hostMessageCallback = e, () => {
|
|
262
|
+
window.removeEventListener("message", s), window.hostMessageCallback === e && (window.hostMessageCallback = null);
|
|
263
263
|
};
|
|
264
264
|
}
|
|
265
|
-
static sendCustomCommand(e,
|
|
265
|
+
static sendCustomCommand(e, s = null, a = {}) {
|
|
266
266
|
const o = {
|
|
267
267
|
command: e,
|
|
268
|
-
text: JSON.stringify(
|
|
268
|
+
text: JSON.stringify(a)
|
|
269
269
|
};
|
|
270
|
-
if (
|
|
271
|
-
|
|
270
|
+
if (s !== null)
|
|
271
|
+
s.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 n = window.sendMessageFromUI(o);
|
|
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(o, "*") : (console.error(
|
|
279
279
|
"Cabbage: window.sendMessageFromUI is not available yet. Message:",
|
|
@@ -287,94 +287,91 @@ class I {
|
|
|
287
287
|
));
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
290
|
+
const v = (t, e, s) => {
|
|
291
|
+
if (!t || s?.skip) return { properties: void 0 };
|
|
292
|
+
const [a, o] = p();
|
|
293
|
+
return u(() => {
|
|
294
|
+
const n = (d) => {
|
|
295
|
+
const { id: r, widgetJson: c, command: b } = d.data;
|
|
296
|
+
if (r === t && c && b === "widgetUpdate") {
|
|
296
297
|
const l = JSON.parse(c);
|
|
297
298
|
console.log(
|
|
298
|
-
`[Cabbage-React] Received properties for channelId: ${
|
|
299
|
+
`[Cabbage-React] Received properties for channelId: ${r}`,
|
|
299
300
|
l
|
|
300
|
-
), e && e(l),
|
|
301
|
+
), e && e(l), o(l);
|
|
301
302
|
}
|
|
302
303
|
};
|
|
303
|
-
return window.addEventListener("message",
|
|
304
|
-
}, [
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
const { properties:
|
|
310
|
-
|
|
311
|
-
channel:
|
|
304
|
+
return window.addEventListener("message", n), () => window.removeEventListener("message", n);
|
|
305
|
+
}, [t, e]), { properties: a };
|
|
306
|
+
}, h = (t, e = "complete", s, a) => {
|
|
307
|
+
if (!t || a?.skip)
|
|
308
|
+
return { value: void 0, setValue: () => {
|
|
309
|
+
} };
|
|
310
|
+
const { properties: o } = v(t), [n, d] = p(), [r, c] = p(), b = (i) => {
|
|
311
|
+
d(i), y.sendControlData({
|
|
312
|
+
channel: t,
|
|
312
313
|
value: i,
|
|
313
314
|
gesture: e
|
|
314
315
|
});
|
|
315
316
|
}, l = (i) => {
|
|
316
|
-
|
|
317
|
+
s && s(i), d(i);
|
|
317
318
|
};
|
|
318
|
-
return
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
(d) => d.id === r
|
|
319
|
+
return u(() => {
|
|
320
|
+
const i = o?.channels.find(
|
|
321
|
+
(m) => m.id === t
|
|
322
322
|
);
|
|
323
323
|
if (!i) return;
|
|
324
324
|
const w = i.parameterIndex;
|
|
325
|
-
if (
|
|
325
|
+
if (r === void 0 && w !== void 0 && (console.log(
|
|
326
326
|
`[Cabbage-React] Received parameterIndex for channelId: ${i.id}`,
|
|
327
327
|
w
|
|
328
|
-
), c(w)),
|
|
329
|
-
const g =
|
|
328
|
+
), c(w)), n !== void 0) return;
|
|
329
|
+
const g = i.range?.value;
|
|
330
330
|
g != null && (console.log(
|
|
331
331
|
`[Cabbage-React] Received initial value for channelId: ${i.id}`,
|
|
332
332
|
g
|
|
333
333
|
), l(g));
|
|
334
|
-
}, [
|
|
334
|
+
}, [o]), u(() => {
|
|
335
335
|
const i = (w) => {
|
|
336
|
-
var f;
|
|
337
336
|
const { command: g } = w.data;
|
|
338
337
|
if (g === "parameterChange") {
|
|
339
|
-
const { value:
|
|
340
|
-
if (
|
|
338
|
+
const { value: m, paramIdx: f } = w.data.data;
|
|
339
|
+
if (f !== r || m === null) return;
|
|
341
340
|
console.log(
|
|
342
|
-
`[Cabbage-React] Received parameterChange for parameterIndex: ${
|
|
343
|
-
|
|
344
|
-
), l(
|
|
341
|
+
`[Cabbage-React] Received parameterChange for parameterIndex: ${f}`,
|
|
342
|
+
m
|
|
343
|
+
), l(m);
|
|
345
344
|
} else if (g === "batchWidgetUpdate") {
|
|
346
|
-
const
|
|
347
|
-
if (!
|
|
348
|
-
const
|
|
349
|
-
(
|
|
350
|
-
)
|
|
345
|
+
const f = w.data.widgets?.find((M) => M.id === t);
|
|
346
|
+
if (!f) return;
|
|
347
|
+
const C = JSON.parse(f.widgetJson).channels.find(
|
|
348
|
+
(M) => M.id === t
|
|
349
|
+
)?.range?.value;
|
|
351
350
|
console.log(
|
|
352
|
-
`[Cabbage-React] Received batch widget update for channelId: ${
|
|
353
|
-
|
|
354
|
-
), l(
|
|
351
|
+
`[Cabbage-React] Received batch widget update for channelId: ${f.id}`,
|
|
352
|
+
C
|
|
353
|
+
), l(C);
|
|
355
354
|
}
|
|
356
355
|
};
|
|
357
356
|
return window.addEventListener("message", i), () => window.removeEventListener("message", i);
|
|
358
|
-
}, [
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
t
|
|
370
|
-
), e && e(t), s(t));
|
|
357
|
+
}, [t, s, r]), { value: n, setValue: b };
|
|
358
|
+
}, L = (t, e, s) => {
|
|
359
|
+
if (!t || s?.skip) return { message: void 0 };
|
|
360
|
+
const [a, o] = p();
|
|
361
|
+
return u(() => {
|
|
362
|
+
const n = (d) => {
|
|
363
|
+
const { data: r, type: c } = d;
|
|
364
|
+
!r || c !== "message" || r.type === t && (console.log(
|
|
365
|
+
`[Cabbage-React] Received data for messageType: ${r.type}`,
|
|
366
|
+
r
|
|
367
|
+
), e && e(r), o(r));
|
|
371
368
|
};
|
|
372
|
-
return window.addEventListener("message",
|
|
373
|
-
}, [
|
|
369
|
+
return window.addEventListener("message", n), () => window.removeEventListener("message", n);
|
|
370
|
+
}, [t, e]), { message: a };
|
|
374
371
|
};
|
|
375
372
|
export {
|
|
376
|
-
|
|
373
|
+
y as Cabbage,
|
|
377
374
|
L as useCabbageMessage,
|
|
378
|
-
|
|
375
|
+
v as useCabbageProperties,
|
|
379
376
|
h as useCabbageState
|
|
380
377
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cabbage-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.52",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cabbage",
|
|
@@ -26,21 +26,21 @@
|
|
|
26
26
|
"build": "vite build"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"react": "^19.
|
|
30
|
-
"vite-plugin-dts": "^4.5.
|
|
29
|
+
"react": "^19.2.4",
|
|
30
|
+
"vite-plugin-dts": "^4.5.4"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@eslint/js": "^
|
|
34
|
-
"@types/node": "^
|
|
35
|
-
"@types/react": "^19.
|
|
36
|
-
"@vitejs/plugin-react": "^
|
|
37
|
-
"eslint": "^
|
|
38
|
-
"eslint-plugin-react-hooks": "^
|
|
39
|
-
"eslint-plugin-react-refresh": "^0.
|
|
40
|
-
"globals": "^
|
|
41
|
-
"typescript": "~5.
|
|
42
|
-
"typescript-eslint": "^8.
|
|
43
|
-
"vite": "^
|
|
33
|
+
"@eslint/js": "^10.0.1",
|
|
34
|
+
"@types/node": "^25.3.3",
|
|
35
|
+
"@types/react": "^19.2.14",
|
|
36
|
+
"@vitejs/plugin-react": "^5.1.4",
|
|
37
|
+
"eslint": "^10.0.2",
|
|
38
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
39
|
+
"eslint-plugin-react-refresh": "^0.5.2",
|
|
40
|
+
"globals": "^17.4.0",
|
|
41
|
+
"typescript": "~5.9.3",
|
|
42
|
+
"typescript-eslint": "^8.56.1",
|
|
43
|
+
"vite": "^7.3.1"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
46
|
"dist",
|