cabbage-react 1.0.0-beta.33 → 1.0.0-beta.34
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 +50 -50
- 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;CAwFtC,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 r={statusByte:n,dataByte1:e,dataByte2:a};const o={command:"midiMessage",obj:JSON.stringify(r)};console.log("Cabbage: sending midi message from UI",r),t!==null?t.postMessage(o):window.sendMessageFromUI(o)}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 C=l=>{const[n,e]=d.useState();return d.useEffect(()=>{const a=t=>{const{channel:r,data:o,command:f}=t.data;if(r===l&&o&&f==="widgetUpdate"){const m=JSON.parse(o);console.log(`[Cabbage-React] ${f}: Received properties for channel: ${r}`,m),e(m)}};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{properties:n}},h=(l,n)=>{const{properties:e}=C(l),[a,t]=d.useState(),[r,o]=d.useState(),f=s=>{t(s);const i={paramIdx:n,channelType:r,channel:l,value:s};p.sendParameterUpdate(i,null)},m=s=>{if(typeof s=="number")return"number";if(typeof s=="string")return"string"};return d.useEffect(()=>{var i;if((e==null?void 0:e.channel)!==l)return;const s=(i=e==null?void 0:e.range)==null?void 0:i.defaultValue;if(a===void 0&&s!==void 0){console.log(`[Cabbage-React]: Received default value for channel "${e==null?void 0:e.channel}"`,s),t(s);const c=m(s);c&&o(c)}},[e]),d.useEffect(()=>{const s=i=>{const{command:c}=i.data;if(c==="widgetUpdate"){const{channel:u,value:g}=i.data;if(u!==l)return;if(console.log(`[Cabbage-React] ${c}: Received initial value for channel "${u}"`,g),g!==void 0){t(g);const b=m(g);b&&o(b)}}if(c==="parameterChange"){const{paramIdx:u,value:g}=i.data.data||{};u===n&&g!==void 0&&(console.log(`[Cabbage-React] ${c}: Received value change for paramIdx: ${u}`,g),t(g))}};return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},[]),{value:a,setValue:f}};exports.Cabbage=p;exports.useCabbageProperties=C;exports.useCabbageState=h;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useState as
|
|
1
|
+
import { useState as f, useEffect as b } from "react";
|
|
2
2
|
console.log("Cabbage: loading cabbage.js");
|
|
3
|
-
class
|
|
3
|
+
class C {
|
|
4
4
|
static sendParameterUpdate(n, e = null) {
|
|
5
5
|
const a = {
|
|
6
6
|
command: "parameterChange",
|
|
@@ -24,16 +24,16 @@ class h {
|
|
|
24
24
|
e !== null ? e.postMessage(a) : window.sendMessageFromUI(a);
|
|
25
25
|
}
|
|
26
26
|
static sendMidiMessageFromUI(n, e, a, t = null) {
|
|
27
|
-
var
|
|
27
|
+
var d = {
|
|
28
28
|
statusByte: n,
|
|
29
29
|
dataByte1: e,
|
|
30
30
|
dataByte2: a
|
|
31
31
|
};
|
|
32
|
-
const
|
|
32
|
+
const o = {
|
|
33
33
|
command: "midiMessage",
|
|
34
|
-
obj: JSON.stringify(
|
|
34
|
+
obj: JSON.stringify(d)
|
|
35
35
|
};
|
|
36
|
-
console.log("Cabbage: sending midi message from UI",
|
|
36
|
+
console.log("Cabbage: sending midi message from UI", d), t !== null ? t.postMessage(o) : window.sendMessageFromUI(o);
|
|
37
37
|
}
|
|
38
38
|
static MidiMessageFromHost(n, e, a) {
|
|
39
39
|
console.log("Cabbage: Got MIDI Message" + n + ":" + e + ":" + a);
|
|
@@ -49,17 +49,17 @@ class h {
|
|
|
49
49
|
n !== null ? n.postMessage(t) : window.sendMessageFromUI(t);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
const
|
|
53
|
-
const [n, e] =
|
|
54
|
-
return
|
|
52
|
+
const h = (l) => {
|
|
53
|
+
const [n, e] = f();
|
|
54
|
+
return b(() => {
|
|
55
55
|
const a = (t) => {
|
|
56
|
-
const { data: o } = t;
|
|
57
|
-
if (
|
|
58
|
-
const
|
|
56
|
+
const { channel: d, data: o, command: u } = t.data;
|
|
57
|
+
if (d === l && o && u === "widgetUpdate") {
|
|
58
|
+
const c = JSON.parse(o);
|
|
59
59
|
console.log(
|
|
60
|
-
`[Cabbage-React] ${
|
|
61
|
-
|
|
62
|
-
), e(
|
|
60
|
+
`[Cabbage-React] ${u}: Received properties for channel: ${d}`,
|
|
61
|
+
c
|
|
62
|
+
), e(c);
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
return window.addEventListener("message", a), () => {
|
|
@@ -68,53 +68,53 @@ const w = (g) => {
|
|
|
68
68
|
}, []), {
|
|
69
69
|
properties: n
|
|
70
70
|
};
|
|
71
|
-
},
|
|
72
|
-
const { properties: e } =
|
|
71
|
+
}, M = (l, n) => {
|
|
72
|
+
const { properties: e } = h(l), [a, t] = f(), [d, o] = f(), u = (s) => {
|
|
73
73
|
t(s);
|
|
74
|
-
const
|
|
74
|
+
const i = {
|
|
75
75
|
paramIdx: n,
|
|
76
|
-
channelType:
|
|
77
|
-
channel:
|
|
76
|
+
channelType: d,
|
|
77
|
+
channel: l,
|
|
78
78
|
value: s
|
|
79
79
|
};
|
|
80
|
-
|
|
81
|
-
},
|
|
80
|
+
C.sendParameterUpdate(i, null);
|
|
81
|
+
}, c = (s) => {
|
|
82
82
|
if (typeof s == "number") return "number";
|
|
83
83
|
if (typeof s == "string") return "string";
|
|
84
84
|
};
|
|
85
|
-
return
|
|
86
|
-
var
|
|
87
|
-
if ((e == null ? void 0 : e.channel) !==
|
|
88
|
-
const s = (
|
|
85
|
+
return b(() => {
|
|
86
|
+
var i;
|
|
87
|
+
if ((e == null ? void 0 : e.channel) !== l) return;
|
|
88
|
+
const s = (i = e == null ? void 0 : e.range) == null ? void 0 : i.defaultValue;
|
|
89
89
|
if (a === void 0 && s !== void 0) {
|
|
90
90
|
console.log(
|
|
91
91
|
`[Cabbage-React]: Received default value for channel "${e == null ? void 0 : e.channel}"`,
|
|
92
92
|
s
|
|
93
93
|
), t(s);
|
|
94
|
-
const
|
|
95
|
-
|
|
94
|
+
const r = c(s);
|
|
95
|
+
r && o(r);
|
|
96
96
|
}
|
|
97
|
-
}, [e]),
|
|
98
|
-
const s = (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (
|
|
97
|
+
}, [e]), b(() => {
|
|
98
|
+
const s = (i) => {
|
|
99
|
+
const { command: r } = i.data;
|
|
100
|
+
if (r === "widgetUpdate") {
|
|
101
|
+
const { channel: m, value: g } = i.data;
|
|
102
|
+
if (m !== l) return;
|
|
103
103
|
if (console.log(
|
|
104
|
-
`[Cabbage-React] ${
|
|
105
|
-
|
|
106
|
-
),
|
|
107
|
-
t(
|
|
108
|
-
const
|
|
109
|
-
|
|
104
|
+
`[Cabbage-React] ${r}: Received initial value for channel "${m}"`,
|
|
105
|
+
g
|
|
106
|
+
), g !== void 0) {
|
|
107
|
+
t(g);
|
|
108
|
+
const p = c(g);
|
|
109
|
+
p && o(p);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
if (
|
|
113
|
-
const { paramIdx:
|
|
114
|
-
|
|
115
|
-
`[Cabbage-React] ${
|
|
116
|
-
|
|
117
|
-
), t(
|
|
112
|
+
if (r === "parameterChange") {
|
|
113
|
+
const { paramIdx: m, value: g } = i.data.data || {};
|
|
114
|
+
m === n && g !== void 0 && (console.log(
|
|
115
|
+
`[Cabbage-React] ${r}: Received value change for paramIdx: ${m}`,
|
|
116
|
+
g
|
|
117
|
+
), t(g));
|
|
118
118
|
}
|
|
119
119
|
};
|
|
120
120
|
return window.addEventListener("message", s), () => {
|
|
@@ -122,11 +122,11 @@ const w = (g) => {
|
|
|
122
122
|
};
|
|
123
123
|
}, []), {
|
|
124
124
|
value: a,
|
|
125
|
-
setValue:
|
|
125
|
+
setValue: u
|
|
126
126
|
};
|
|
127
127
|
};
|
|
128
128
|
export {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
C as Cabbage,
|
|
130
|
+
h as useCabbageProperties,
|
|
131
|
+
M as useCabbageState
|
|
132
132
|
};
|