cabbage-react 1.0.0 → 1.0.1
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/README.md +4 -4
- package/dist/cabbage/cabbage.d.ts +2 -0
- package/dist/cabbage/cabbage.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +105 -76
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,12 +42,12 @@ const HorizontalSlider = ({
|
|
|
42
42
|
paramIdx,
|
|
43
43
|
inputProps,
|
|
44
44
|
}: {
|
|
45
|
-
channel: string
|
|
46
|
-
paramIdx: number
|
|
47
|
-
inputProps?: InputHTMLAttributes<HTMLInputElement
|
|
45
|
+
channel: string;
|
|
46
|
+
paramIdx: number;
|
|
47
|
+
inputProps?: InputHTMLAttributes<HTMLInputElement>;
|
|
48
48
|
}) => {
|
|
49
49
|
const { properties } = useCabbageProperties(channel);
|
|
50
|
-
const { value, setValue } = useCabbageState
|
|
50
|
+
const { value, setValue } = useCabbageState<number>(channel, paramIdx);
|
|
51
51
|
|
|
52
52
|
return (
|
|
53
53
|
<div>
|
|
@@ -3,7 +3,9 @@ export class Cabbage {
|
|
|
3
3
|
static sendCustomCommand(command: any, vscode?: null): void;
|
|
4
4
|
static sendWidgetUpdate(widget: any, vscode?: null): void;
|
|
5
5
|
static sendMidiMessageFromUI(statusByte: any, dataByte1: any, dataByte2: any, vscode?: null): void;
|
|
6
|
+
static sendChannelData(channel: any, data: any, vscode?: null): void;
|
|
6
7
|
static MidiMessageFromHost(statusByte: any, dataByte1: any, dataByte2: any): void;
|
|
7
8
|
static triggerFileOpenDialog(vscode: any, channel: any): void;
|
|
9
|
+
static openUrl(vscode: any, url: any, file: any): void;
|
|
8
10
|
}
|
|
9
11
|
//# sourceMappingURL=cabbage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cabbage.d.ts","sourceRoot":"","sources":["../../src/cabbage/cabbage.js"],"names":[],"mappings":"AAMA;IAEE,
|
|
1
|
+
{"version":3,"file":"cabbage.d.ts","sourceRoot":"","sources":["../../src/cabbage/cabbage.js"],"names":[],"mappings":"AAMA;IAEE,8DAcC;IAED,4DAYC;IAED,0DAYC;IAED,mGAmBC;IAED,qEA2BC;IAED,kFAEC;IAED,8DAeC;IAED,uDAgBC;CAGF"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react");console.log("Cabbage: loading cabbage.js");class p{static sendParameterUpdate(n,e=null){const a={command:"parameterChange",obj:JSON.stringify(n)};console.log("Cabbage.sendParameterUpdate:",n,"vscode:",e,"msg:",a),e!==null?(console.log("Sending via vscode.postMessage"),e.postMessage(a)):(console.log("Sending via window.sendMessageFromUI"),window.sendMessageFromUI(a))}static sendCustomCommand(n,e=null){const a={command:n,text:JSON.stringify({})};console.log("Cabbage: sending custom command from UI",a),e!==null?e.postMessage(a):window.sendMessageFromUI(a)}static sendWidgetUpdate(n,e=null){console.log("Cabbage: sending widget update from UI",n.props);const a={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(n))};e!==null?e.postMessage(a):window.sendMessageFromUI(a)}static sendMidiMessageFromUI(n,e,a,s=null){var t={statusByte:n,dataByte1:e,dataByte2:a};const i={command:"midiMessage",obj:JSON.stringify(t)};console.log("Cabbage: sending midi message from UI",t),s!==null?s.postMessage(i):window.sendMessageFromUI(i)}static sendChannelData(n,e,a=null){var s={channel:n};if(typeof e=="string")s.stringData=e;else if(typeof e=="number")s.floatData=e;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof e);return}const t={command:"channelStringData",obj:JSON.stringify(s)};console.log("Cabbage: sending channel data from UI",s),a!==null?a.postMessage(t):window.sendMessageFromUI(t)}static MidiMessageFromHost(n,e,a){console.log("Cabbage: Got MIDI Message"+n+":"+e+":"+a)}static triggerFileOpenDialog(n,e){var a={channel:e};const s={command:"fileOpen",obj:JSON.stringify(a)};n!==null?n.postMessage(s):window.sendMessageFromUI(s)}static openUrl(n,e,a){var s={url:e,file:a};const t={command:"openUrl",obj:JSON.stringify(s)};n!==null?n.postMessage(t):window.sendMessageFromUI(t)}}const C=r=>{const[n,e]=c.useState();return c.useEffect(()=>{const a=s=>{const{channel:t,data:i,command:f}=s.data;if(t===r&&i&&f==="widgetUpdate"){const m=JSON.parse(i);console.log(`[Cabbage-React] ${f}: Received properties for channel: ${t}`,m),e(m)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:n}},w=(r,n)=>{const{properties:e}=C(r),[a,s]=c.useState(),[t,i]=c.useState(),f=o=>{s(o);const l={paramIdx:n,channelType:t,channel:r,value:o};p.sendParameterUpdate(l,null)},m=o=>{if(typeof o=="number")return"number";if(typeof o=="string")return"string"};return c.useEffect(()=>{var l;if((e==null?void 0:e.channel)!==r)return;const o=(l=e==null?void 0:e.range)==null?void 0:l.defaultValue;if(a===void 0&&o!==void 0){console.log(`[Cabbage-React]: Received default value for channel "${e==null?void 0:e.channel}"`,o),s(o);const d=m(o);d&&i(d)}},[e]),c.useEffect(()=>{const o=l=>{const{command:d}=l.data;if(d==="widgetUpdate"){const{channel:u,value:g}=l.data;if(u!==r)return;if(console.log(`[Cabbage-React] ${d}: Received initial value for channel "${u}"`,g),g!==void 0){s(g);const b=m(g);b&&i(b)}}if(d==="parameterChange"){const{paramIdx:u,value:g}=l.data.data||{};u===n&&g!==void 0&&(console.log(`[Cabbage-React] ${d}: Received value change for paramIdx: ${u}`,g),s(g))}};return window.addEventListener("message",o),()=>{window.removeEventListener("message",o)}},[]),{value:a,setValue:f}};exports.Cabbage=p;exports.useCabbageProperties=C;exports.useCabbageState=w;
|
package/dist/index.mjs
CHANGED
|
@@ -1,132 +1,161 @@
|
|
|
1
1
|
import { useState as f, useEffect as b } from "react";
|
|
2
2
|
console.log("Cabbage: loading cabbage.js");
|
|
3
3
|
class C {
|
|
4
|
-
static sendParameterUpdate(
|
|
5
|
-
const
|
|
4
|
+
static sendParameterUpdate(a, e = null) {
|
|
5
|
+
const n = {
|
|
6
6
|
command: "parameterChange",
|
|
7
|
-
obj: JSON.stringify(
|
|
7
|
+
obj: JSON.stringify(a)
|
|
8
8
|
};
|
|
9
|
-
e !== null ? e.postMessage(
|
|
9
|
+
console.log("Cabbage.sendParameterUpdate:", a, "vscode:", e, "msg:", n), e !== null ? (console.log("Sending via vscode.postMessage"), e.postMessage(n)) : (console.log("Sending via window.sendMessageFromUI"), window.sendMessageFromUI(n));
|
|
10
10
|
}
|
|
11
|
-
static sendCustomCommand(
|
|
12
|
-
const
|
|
13
|
-
command:
|
|
11
|
+
static sendCustomCommand(a, e = null) {
|
|
12
|
+
const n = {
|
|
13
|
+
command: a,
|
|
14
14
|
text: JSON.stringify({})
|
|
15
15
|
};
|
|
16
|
-
console.log("Cabbage: sending custom command from UI",
|
|
16
|
+
console.log("Cabbage: sending custom command from UI", n), e !== null ? e.postMessage(n) : window.sendMessageFromUI(n);
|
|
17
17
|
}
|
|
18
|
-
static sendWidgetUpdate(
|
|
19
|
-
console.log("Cabbage: sending widget update from UI",
|
|
20
|
-
const
|
|
18
|
+
static sendWidgetUpdate(a, e = null) {
|
|
19
|
+
console.log("Cabbage: sending widget update from UI", a.props);
|
|
20
|
+
const n = {
|
|
21
21
|
command: "widgetStateUpdate",
|
|
22
|
-
obj: JSON.stringify(
|
|
22
|
+
obj: JSON.stringify(CabbageUtils.sanitizeForEditor(a))
|
|
23
23
|
};
|
|
24
|
-
e !== null ? e.postMessage(
|
|
24
|
+
e !== null ? e.postMessage(n) : window.sendMessageFromUI(n);
|
|
25
25
|
}
|
|
26
|
-
static sendMidiMessageFromUI(
|
|
27
|
-
var
|
|
28
|
-
statusByte:
|
|
26
|
+
static sendMidiMessageFromUI(a, e, n, s = null) {
|
|
27
|
+
var t = {
|
|
28
|
+
statusByte: a,
|
|
29
29
|
dataByte1: e,
|
|
30
|
-
dataByte2:
|
|
30
|
+
dataByte2: n
|
|
31
31
|
};
|
|
32
|
-
const
|
|
32
|
+
const i = {
|
|
33
33
|
command: "midiMessage",
|
|
34
|
-
obj: JSON.stringify(
|
|
34
|
+
obj: JSON.stringify(t)
|
|
35
35
|
};
|
|
36
|
-
console.log("Cabbage: sending midi message from UI",
|
|
36
|
+
console.log("Cabbage: sending midi message from UI", t), s !== null ? s.postMessage(i) : window.sendMessageFromUI(i);
|
|
37
37
|
}
|
|
38
|
-
static
|
|
39
|
-
|
|
38
|
+
static sendChannelData(a, e, n = null) {
|
|
39
|
+
var s = {
|
|
40
|
+
channel: a
|
|
41
|
+
};
|
|
42
|
+
if (typeof e == "string")
|
|
43
|
+
s.stringData = e;
|
|
44
|
+
else if (typeof e == "number")
|
|
45
|
+
s.floatData = e;
|
|
46
|
+
else {
|
|
47
|
+
console.warn("Cabbage: sendChannelData received unsupported data type:", typeof e);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const t = {
|
|
51
|
+
command: "channelStringData",
|
|
52
|
+
obj: JSON.stringify(s)
|
|
53
|
+
};
|
|
54
|
+
console.log("Cabbage: sending channel data from UI", s), n !== null ? n.postMessage(t) : window.sendMessageFromUI(t);
|
|
40
55
|
}
|
|
41
|
-
static
|
|
42
|
-
|
|
56
|
+
static MidiMessageFromHost(a, e, n) {
|
|
57
|
+
console.log("Cabbage: Got MIDI Message" + a + ":" + e + ":" + n);
|
|
58
|
+
}
|
|
59
|
+
static triggerFileOpenDialog(a, e) {
|
|
60
|
+
var n = {
|
|
43
61
|
channel: e
|
|
44
62
|
};
|
|
45
|
-
const
|
|
63
|
+
const s = {
|
|
46
64
|
command: "fileOpen",
|
|
47
|
-
obj: JSON.stringify(
|
|
65
|
+
obj: JSON.stringify(n)
|
|
66
|
+
};
|
|
67
|
+
a !== null ? a.postMessage(s) : window.sendMessageFromUI(s);
|
|
68
|
+
}
|
|
69
|
+
static openUrl(a, e, n) {
|
|
70
|
+
var s = {
|
|
71
|
+
url: e,
|
|
72
|
+
file: n
|
|
48
73
|
};
|
|
49
|
-
|
|
74
|
+
const t = {
|
|
75
|
+
command: "openUrl",
|
|
76
|
+
obj: JSON.stringify(s)
|
|
77
|
+
};
|
|
78
|
+
a !== null ? a.postMessage(t) : window.sendMessageFromUI(t);
|
|
50
79
|
}
|
|
51
80
|
}
|
|
52
|
-
const
|
|
53
|
-
const [
|
|
81
|
+
const w = (r) => {
|
|
82
|
+
const [a, e] = f();
|
|
54
83
|
return b(() => {
|
|
55
|
-
const
|
|
56
|
-
const { channel:
|
|
57
|
-
if (
|
|
58
|
-
const c = JSON.parse(
|
|
84
|
+
const n = (s) => {
|
|
85
|
+
const { channel: t, data: i, command: u } = s.data;
|
|
86
|
+
if (t === r && i && u === "widgetUpdate") {
|
|
87
|
+
const c = JSON.parse(i);
|
|
59
88
|
console.log(
|
|
60
|
-
`[Cabbage-React] ${u}: Received properties for channel: ${
|
|
89
|
+
`[Cabbage-React] ${u}: Received properties for channel: ${t}`,
|
|
61
90
|
c
|
|
62
91
|
), e(c);
|
|
63
92
|
}
|
|
64
93
|
};
|
|
65
|
-
return window.addEventListener("message",
|
|
66
|
-
window.removeEventListener("message",
|
|
94
|
+
return window.addEventListener("message", n), () => {
|
|
95
|
+
window.removeEventListener("message", n);
|
|
67
96
|
};
|
|
68
97
|
}, []), {
|
|
69
|
-
properties:
|
|
98
|
+
properties: a
|
|
70
99
|
};
|
|
71
|
-
},
|
|
72
|
-
const { properties: e } =
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
paramIdx:
|
|
76
|
-
channelType:
|
|
77
|
-
channel:
|
|
78
|
-
value:
|
|
79
|
-
};
|
|
80
|
-
C.sendParameterUpdate(
|
|
81
|
-
}, c = (
|
|
82
|
-
if (typeof
|
|
83
|
-
if (typeof
|
|
100
|
+
}, h = (r, a) => {
|
|
101
|
+
const { properties: e } = w(r), [n, s] = f(), [t, i] = f(), u = (o) => {
|
|
102
|
+
s(o);
|
|
103
|
+
const l = {
|
|
104
|
+
paramIdx: a,
|
|
105
|
+
channelType: t,
|
|
106
|
+
channel: r,
|
|
107
|
+
value: o
|
|
108
|
+
};
|
|
109
|
+
C.sendParameterUpdate(l, null);
|
|
110
|
+
}, c = (o) => {
|
|
111
|
+
if (typeof o == "number") return "number";
|
|
112
|
+
if (typeof o == "string") return "string";
|
|
84
113
|
};
|
|
85
114
|
return b(() => {
|
|
86
|
-
var
|
|
87
|
-
if ((e == null ? void 0 : e.channel) !==
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
115
|
+
var l;
|
|
116
|
+
if ((e == null ? void 0 : e.channel) !== r) return;
|
|
117
|
+
const o = (l = e == null ? void 0 : e.range) == null ? void 0 : l.defaultValue;
|
|
118
|
+
if (n === void 0 && o !== void 0) {
|
|
90
119
|
console.log(
|
|
91
120
|
`[Cabbage-React]: Received default value for channel "${e == null ? void 0 : e.channel}"`,
|
|
92
|
-
|
|
93
|
-
),
|
|
94
|
-
const
|
|
95
|
-
|
|
121
|
+
o
|
|
122
|
+
), s(o);
|
|
123
|
+
const d = c(o);
|
|
124
|
+
d && i(d);
|
|
96
125
|
}
|
|
97
126
|
}, [e]), b(() => {
|
|
98
|
-
const
|
|
99
|
-
const { command:
|
|
100
|
-
if (
|
|
101
|
-
const { channel: m, value: g } =
|
|
102
|
-
if (m !==
|
|
127
|
+
const o = (l) => {
|
|
128
|
+
const { command: d } = l.data;
|
|
129
|
+
if (d === "widgetUpdate") {
|
|
130
|
+
const { channel: m, value: g } = l.data;
|
|
131
|
+
if (m !== r) return;
|
|
103
132
|
if (console.log(
|
|
104
|
-
`[Cabbage-React] ${
|
|
133
|
+
`[Cabbage-React] ${d}: Received initial value for channel "${m}"`,
|
|
105
134
|
g
|
|
106
135
|
), g !== void 0) {
|
|
107
|
-
|
|
136
|
+
s(g);
|
|
108
137
|
const p = c(g);
|
|
109
|
-
p &&
|
|
138
|
+
p && i(p);
|
|
110
139
|
}
|
|
111
140
|
}
|
|
112
|
-
if (
|
|
113
|
-
const { paramIdx: m, value: g } =
|
|
114
|
-
m ===
|
|
115
|
-
`[Cabbage-React] ${
|
|
141
|
+
if (d === "parameterChange") {
|
|
142
|
+
const { paramIdx: m, value: g } = l.data.data || {};
|
|
143
|
+
m === a && g !== void 0 && (console.log(
|
|
144
|
+
`[Cabbage-React] ${d}: Received value change for paramIdx: ${m}`,
|
|
116
145
|
g
|
|
117
|
-
),
|
|
146
|
+
), s(g));
|
|
118
147
|
}
|
|
119
148
|
};
|
|
120
|
-
return window.addEventListener("message",
|
|
121
|
-
window.removeEventListener("message",
|
|
149
|
+
return window.addEventListener("message", o), () => {
|
|
150
|
+
window.removeEventListener("message", o);
|
|
122
151
|
};
|
|
123
152
|
}, []), {
|
|
124
|
-
value:
|
|
153
|
+
value: n,
|
|
125
154
|
setValue: u
|
|
126
155
|
};
|
|
127
156
|
};
|
|
128
157
|
export {
|
|
129
158
|
C as Cabbage,
|
|
130
|
-
|
|
131
|
-
|
|
159
|
+
w as useCabbageProperties,
|
|
160
|
+
h as useCabbageState
|
|
132
161
|
};
|