cabbage-react 1.0.0-beta.31 → 1.0.0-beta.33
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/useCabbageState.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +75 -54
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,WAAW,MAAM,YAAY,MAAM;;yBAM9B,CAAC;
|
|
1
|
+
{"version":3,"file":"useCabbageState.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageState.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,WAAW,MAAM,YAAY,MAAM;;yBAM9B,CAAC;CAsFtC,CAAC"}
|
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 r=require("react");console.log("Cabbage: loading cabbage.js");class p{static sendParameterUpdate(s,e=null){const a={command:"parameterChange",obj:JSON.stringify(s)};e!==null?e.postMessage(a):(console.log("Cabbage: sending parameter change from UI",a),window.sendMessageFromUI(a))}static sendCustomCommand(s,e=null){const a={command:s,text:JSON.stringify({})};console.log("Cabbage: sending custom command from UI",a),e!==null?e.postMessage(a):window.sendMessageFromUI(a)}static sendWidgetUpdate(s,e=null){console.log("Cabbage: sending widget update from UI",s.props);const a={command:"widgetStateUpdate",obj:JSON.stringify(s.props)};e!==null?e.postMessage(a):window.sendMessageFromUI(a)}static sendMidiMessageFromUI(s,e,a,t=null){var o={statusByte:s,dataByte1:e,dataByte2:a};const i={command:"midiMessage",obj:JSON.stringify(o)};console.log("Cabbage: sending midi message from UI",o),t!==null?t.postMessage(i):window.sendMessageFromUI(i)}static MidiMessageFromHost(s,e,a){console.log("Cabbage: Got MIDI Message"+s+":"+e+":"+a)}static triggerFileOpenDialog(s,e){var a={channel:e};const t={command:"fileOpen",obj:JSON.stringify(a)};s!==null?s.postMessage(t):window.sendMessageFromUI(t)}}const C=l=>{const[s,e]=r.useState();return r.useEffect(()=>{const a=t=>{const{data:o}=t;if(o.channel===l&&o.data&&o.command==="widgetUpdate"){const i=JSON.parse(o.data);console.log(`[Cabbage-React] ${o.command}: Received properties for channel: ${o.channel}`,i),e(i)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:s}},w=(l,s)=>{const{properties:e}=C(l),[a,t]=r.useState(),[o,i]=r.useState(),h=n=>{t(n);const g={paramIdx:s,channelType:o,channel:l,value:n};p.sendParameterUpdate(g,null)},f=n=>{if(typeof n=="number")return"number";if(typeof n=="string")return"string"};return r.useEffect(()=>{var g;if((e==null?void 0:e.channel)!==l)return;const n=(g=e==null?void 0:e.range)==null?void 0:g.defaultValue;if(a===void 0&&n!==void 0){console.log(`[Cabbage-React]: Received default value for channel "${e==null?void 0:e.channel}"`,n),t(n);const d=f(n);d&&i(d)}},[e]),r.useEffect(()=>{const n=g=>{console.log("event",g);const{command:d,channel:b,value:m}=g.data;if(d==="widgetUpdate"){if(b!==l)return;if(console.log(`[Cabbage-React] ${d}: Received initial value for channel "${b}"`,m),m!==void 0){t(m);const c=f(m);c&&i(c)}}if(d==="parameterChange"){const{paramIdx:c,value:u}=g.data.data||{};c===s&&u!==void 0&&(console.log(`[Cabbage-React] ${d}: Received value change for paramIdx: ${c}`,u),t(u))}};return window.addEventListener("message",n),()=>{window.removeEventListener("message",n)}},[]),{value:a,setValue:h}};exports.Cabbage=p;exports.useCabbageProperties=C;exports.useCabbageState=w;
|
package/dist/index.mjs
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { useState as
|
|
1
|
+
import { useState as u, useEffect as f } from "react";
|
|
2
2
|
console.log("Cabbage: loading cabbage.js");
|
|
3
|
-
class
|
|
4
|
-
static sendParameterUpdate(
|
|
3
|
+
class h {
|
|
4
|
+
static sendParameterUpdate(n, e = null) {
|
|
5
5
|
const a = {
|
|
6
6
|
command: "parameterChange",
|
|
7
|
-
obj: JSON.stringify(
|
|
7
|
+
obj: JSON.stringify(n)
|
|
8
8
|
};
|
|
9
9
|
e !== null ? e.postMessage(a) : (console.log("Cabbage: sending parameter change from UI", a), window.sendMessageFromUI(a));
|
|
10
10
|
}
|
|
11
|
-
static sendCustomCommand(
|
|
11
|
+
static sendCustomCommand(n, e = null) {
|
|
12
12
|
const a = {
|
|
13
|
-
command:
|
|
13
|
+
command: n,
|
|
14
14
|
text: JSON.stringify({})
|
|
15
15
|
};
|
|
16
16
|
console.log("Cabbage: sending custom command from UI", a), e !== null ? e.postMessage(a) : window.sendMessageFromUI(a);
|
|
17
17
|
}
|
|
18
|
-
static sendWidgetUpdate(
|
|
19
|
-
console.log("Cabbage: sending widget update from UI",
|
|
18
|
+
static sendWidgetUpdate(n, e = null) {
|
|
19
|
+
console.log("Cabbage: sending widget update from UI", n.props);
|
|
20
20
|
const a = {
|
|
21
21
|
command: "widgetStateUpdate",
|
|
22
|
-
obj: JSON.stringify(
|
|
22
|
+
obj: JSON.stringify(n.props)
|
|
23
23
|
};
|
|
24
24
|
e !== null ? e.postMessage(a) : window.sendMessageFromUI(a);
|
|
25
25
|
}
|
|
26
|
-
static sendMidiMessageFromUI(
|
|
26
|
+
static sendMidiMessageFromUI(n, e, a, t = null) {
|
|
27
27
|
var o = {
|
|
28
|
-
statusByte:
|
|
28
|
+
statusByte: n,
|
|
29
29
|
dataByte1: e,
|
|
30
30
|
dataByte2: a
|
|
31
31
|
};
|
|
32
|
-
const
|
|
32
|
+
const i = {
|
|
33
33
|
command: "midiMessage",
|
|
34
34
|
obj: JSON.stringify(o)
|
|
35
35
|
};
|
|
36
|
-
console.log("Cabbage: sending midi message from UI", o), t !== null ? t.postMessage(
|
|
36
|
+
console.log("Cabbage: sending midi message from UI", o), t !== null ? t.postMessage(i) : window.sendMessageFromUI(i);
|
|
37
37
|
}
|
|
38
|
-
static MidiMessageFromHost(
|
|
39
|
-
console.log("Cabbage: Got MIDI Message" +
|
|
38
|
+
static MidiMessageFromHost(n, e, a) {
|
|
39
|
+
console.log("Cabbage: Got MIDI Message" + n + ":" + e + ":" + a);
|
|
40
40
|
}
|
|
41
|
-
static triggerFileOpenDialog(
|
|
41
|
+
static triggerFileOpenDialog(n, e) {
|
|
42
42
|
var a = {
|
|
43
43
|
channel: e
|
|
44
44
|
};
|
|
@@ -46,66 +46,87 @@ class C {
|
|
|
46
46
|
command: "fileOpen",
|
|
47
47
|
obj: JSON.stringify(a)
|
|
48
48
|
};
|
|
49
|
-
|
|
49
|
+
n !== null ? n.postMessage(t) : window.sendMessageFromUI(t);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
const
|
|
53
|
-
const [
|
|
54
|
-
return
|
|
52
|
+
const w = (g) => {
|
|
53
|
+
const [n, e] = u();
|
|
54
|
+
return f(() => {
|
|
55
55
|
const a = (t) => {
|
|
56
56
|
const { data: o } = t;
|
|
57
|
-
if (o.channel ===
|
|
58
|
-
const
|
|
57
|
+
if (o.channel === g && o.data && o.command === "widgetUpdate") {
|
|
58
|
+
const i = JSON.parse(o.data);
|
|
59
59
|
console.log(
|
|
60
60
|
`[Cabbage-React] ${o.command}: Received properties for channel: ${o.channel}`,
|
|
61
|
-
|
|
62
|
-
), e(
|
|
61
|
+
i
|
|
62
|
+
), e(i);
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
return window.addEventListener("message", a), () => {
|
|
66
66
|
window.removeEventListener("message", a);
|
|
67
67
|
};
|
|
68
68
|
}, []), {
|
|
69
|
-
properties:
|
|
69
|
+
properties: n
|
|
70
70
|
};
|
|
71
|
-
}, v = (
|
|
72
|
-
const { properties: e } =
|
|
73
|
-
t(
|
|
74
|
-
const
|
|
75
|
-
paramIdx:
|
|
71
|
+
}, v = (g, n) => {
|
|
72
|
+
const { properties: e } = w(g), [a, t] = u(), [o, i] = u(), C = (s) => {
|
|
73
|
+
t(s);
|
|
74
|
+
const l = {
|
|
75
|
+
paramIdx: n,
|
|
76
76
|
channelType: o,
|
|
77
|
-
channel:
|
|
78
|
-
value:
|
|
77
|
+
channel: g,
|
|
78
|
+
value: s
|
|
79
79
|
};
|
|
80
|
-
|
|
80
|
+
h.sendParameterUpdate(l, null);
|
|
81
|
+
}, b = (s) => {
|
|
82
|
+
if (typeof s == "number") return "number";
|
|
83
|
+
if (typeof s == "string") return "string";
|
|
81
84
|
};
|
|
82
|
-
return
|
|
83
|
-
var
|
|
84
|
-
if ((e == null ? void 0 : e.channel) !==
|
|
85
|
-
const
|
|
86
|
-
a === void 0 &&
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
85
|
+
return f(() => {
|
|
86
|
+
var l;
|
|
87
|
+
if ((e == null ? void 0 : e.channel) !== g) return;
|
|
88
|
+
const s = (l = e == null ? void 0 : e.range) == null ? void 0 : l.defaultValue;
|
|
89
|
+
if (a === void 0 && s !== void 0) {
|
|
90
|
+
console.log(
|
|
91
|
+
`[Cabbage-React]: Received default value for channel "${e == null ? void 0 : e.channel}"`,
|
|
92
|
+
s
|
|
93
|
+
), t(s);
|
|
94
|
+
const d = b(s);
|
|
95
|
+
d && i(d);
|
|
96
|
+
}
|
|
97
|
+
}, [e]), f(() => {
|
|
98
|
+
const s = (l) => {
|
|
99
|
+
console.log("event", l);
|
|
100
|
+
const { command: d, channel: p, value: c } = l.data;
|
|
101
|
+
if (d === "widgetUpdate") {
|
|
102
|
+
if (p !== g) return;
|
|
103
|
+
if (console.log(
|
|
104
|
+
`[Cabbage-React] ${d}: Received initial value for channel "${p}"`,
|
|
105
|
+
c
|
|
106
|
+
), c !== void 0) {
|
|
107
|
+
t(c);
|
|
108
|
+
const r = b(c);
|
|
109
|
+
r && i(r);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (d === "parameterChange") {
|
|
113
|
+
const { paramIdx: r, value: m } = l.data.data || {};
|
|
114
|
+
r === n && m !== void 0 && (console.log(
|
|
115
|
+
`[Cabbage-React] ${d}: Received value change for paramIdx: ${r}`,
|
|
116
|
+
m
|
|
117
|
+
), t(m));
|
|
118
|
+
}
|
|
98
119
|
};
|
|
99
|
-
return window.addEventListener("message",
|
|
100
|
-
window.removeEventListener("message",
|
|
120
|
+
return window.addEventListener("message", s), () => {
|
|
121
|
+
window.removeEventListener("message", s);
|
|
101
122
|
};
|
|
102
123
|
}, []), {
|
|
103
124
|
value: a,
|
|
104
|
-
setValue:
|
|
125
|
+
setValue: C
|
|
105
126
|
};
|
|
106
127
|
};
|
|
107
128
|
export {
|
|
108
|
-
|
|
109
|
-
|
|
129
|
+
h as Cabbage,
|
|
130
|
+
w as useCabbageProperties,
|
|
110
131
|
v as useCabbageState
|
|
111
132
|
};
|