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