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