cabbage-react 1.0.0-beta.6 → 1.0.0-beta.8
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
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
This project provides hooks that allow you to synchronize [Cabbage](https://cabbageaudio.com) with [React](https://github.com/facebook/react).
|
|
4
4
|
|
|
5
|
-
An example of implementation can be found [here](https://github.com/hdale94/
|
|
5
|
+
An example of implementation can be found [here](https://github.com/hdale94/cabbage-react-example).
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -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;;CAqCtC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetCabbageFormData.d.ts","sourceRoot":"","sources":["../../src/hooks/useGetCabbageFormData.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;;
|
|
1
|
+
{"version":3,"file":"useGetCabbageFormData.d.ts","sourceRoot":"","sources":["../../src/hooks/useGetCabbageFormData.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;;CA4BjC,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react");console.log("Cabbage: loading cabbage.js");class m{static sendParameterUpdate(s,a=null){const e={command:"parameterChange",obj:JSON.stringify(s)};a!==null?a.postMessage(e):(console.log("Cabbage: sending parameter change from UI",e),window.sendMessageFromUI(e))}static sendCustomCommand(s,a=null){const e={command:s,text:JSON.stringify({})};console.log("Cabbage: sending custom command from UI",e),a!==null?a.postMessage(e):window.sendMessageFromUI(e)}static sendWidgetUpdate(s,a=null){console.log("Cabbage: sending widget update from UI",s.props);const e={command:"widgetStateUpdate",obj:JSON.stringify(s.props)};a!==null?a.postMessage(e):window.sendMessageFromUI(e)}static sendMidiMessageFromUI(s,a,e,t=null){var
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react");console.log("Cabbage: loading cabbage.js");class m{static sendParameterUpdate(s,a=null){const e={command:"parameterChange",obj:JSON.stringify(s)};a!==null?a.postMessage(e):(console.log("Cabbage: sending parameter change from UI",e),window.sendMessageFromUI(e))}static sendCustomCommand(s,a=null){const e={command:s,text:JSON.stringify({})};console.log("Cabbage: sending custom command from UI",e),a!==null?a.postMessage(e):window.sendMessageFromUI(e)}static sendWidgetUpdate(s,a=null){console.log("Cabbage: sending widget update from UI",s.props);const e={command:"widgetStateUpdate",obj:JSON.stringify(s.props)};a!==null?a.postMessage(e):window.sendMessageFromUI(e)}static sendMidiMessageFromUI(s,a,e,t=null){var r={statusByte:s,dataByte1:a,dataByte2:e};const l={command:"midiMessage",obj:JSON.stringify(r)};console.log("Cabbage: sending midi message from UI",r),t!==null?t.postMessage(l):window.sendMessageFromUI(l)}static MidiMessageFromHost(s,a,e){console.log("Cabbage: Got MIDI Message"+s+":"+a+":"+e)}static triggerFileOpenDialog(s,a){var e={channel:a};const t={command:"fileOpen",obj:JSON.stringify(e)};s!==null?s.postMessage(t):window.sendMessageFromUI(t)}}const c=(o,s)=>{const[a,e]=i.useState(),[t,r]=i.useState(),l=g=>{e(g);const d={paramIdx:s,channel:o,value:g};m.sendParameterUpdate(d,null)};return i.useEffect(()=>{const g=d=>{const{data:n}=d;console.log("Cabbage-react: receiving parameter change",n),n.channel===o&&n.command==="widgetUpdate"&&(n.value&&e(n.value),n.data&&r(JSON.parse(n.data)))};return window.addEventListener("message",g),()=>{window.removeEventListener("message",g)}},[]),{value:a,setValue:l,data:t}},u=()=>{const[o,s]=i.useState();return i.useEffect(()=>{const a=e=>{const{data:t}=e;console.log("Cabbage-react: receiving form data change",t),t.data&&t.channel==="MainForm"&&t.command==="widgetUpdate"&&s(JSON.parse(t.data))};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{data:o}};exports.useCabbageState=c;exports.useGetCabbageFormData=u;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState as
|
|
1
|
+
import { useState as d, useEffect as m } from "react";
|
|
2
2
|
console.log("Cabbage: loading cabbage.js");
|
|
3
3
|
class c {
|
|
4
4
|
static sendParameterUpdate(s, a = null) {
|
|
@@ -29,11 +29,11 @@ class c {
|
|
|
29
29
|
dataByte1: a,
|
|
30
30
|
dataByte2: e
|
|
31
31
|
};
|
|
32
|
-
const
|
|
32
|
+
const l = {
|
|
33
33
|
command: "midiMessage",
|
|
34
34
|
obj: JSON.stringify(i)
|
|
35
35
|
};
|
|
36
|
-
console.log("Cabbage: sending midi message from UI", i), n !== null ? n.postMessage(
|
|
36
|
+
console.log("Cabbage: sending midi message from UI", i), n !== null ? n.postMessage(l) : window.sendMessageFromUI(l);
|
|
37
37
|
}
|
|
38
38
|
static MidiMessageFromHost(s, a, e) {
|
|
39
39
|
console.log("Cabbage: Got MIDI Message" + s + ":" + a + ":" + e);
|
|
@@ -50,34 +50,34 @@ class c {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
const b = (o, s) => {
|
|
53
|
-
const [a, e] =
|
|
53
|
+
const [a, e] = d(), [n, i] = d(), l = (g) => {
|
|
54
54
|
e(g);
|
|
55
|
-
const
|
|
55
|
+
const r = {
|
|
56
56
|
paramIdx: s,
|
|
57
57
|
channel: o,
|
|
58
58
|
value: g
|
|
59
59
|
};
|
|
60
|
-
c.sendParameterUpdate(
|
|
60
|
+
c.sendParameterUpdate(r, null);
|
|
61
61
|
};
|
|
62
|
-
return
|
|
63
|
-
const g = (
|
|
64
|
-
const { data: t } =
|
|
65
|
-
t.channel === o && t.command === "widgetUpdate" && (t.value && e(t.value), t.data && i(JSON.parse(t.data)));
|
|
62
|
+
return m(() => {
|
|
63
|
+
const g = (r) => {
|
|
64
|
+
const { data: t } = r;
|
|
65
|
+
console.log("Cabbage-react: receiving parameter change", t), t.channel === o && t.command === "widgetUpdate" && (t.value && e(t.value), t.data && i(JSON.parse(t.data)));
|
|
66
66
|
};
|
|
67
67
|
return window.addEventListener("message", g), () => {
|
|
68
68
|
window.removeEventListener("message", g);
|
|
69
69
|
};
|
|
70
70
|
}, []), {
|
|
71
71
|
value: a,
|
|
72
|
-
setValue:
|
|
72
|
+
setValue: l,
|
|
73
73
|
data: n
|
|
74
74
|
};
|
|
75
75
|
}, f = () => {
|
|
76
|
-
const [o, s] =
|
|
77
|
-
return
|
|
76
|
+
const [o, s] = d();
|
|
77
|
+
return m(() => {
|
|
78
78
|
const a = (e) => {
|
|
79
79
|
const { data: n } = e;
|
|
80
|
-
n.data && n.channel === "MainForm" && n.command === "widgetUpdate" && s(JSON.parse(n.data));
|
|
80
|
+
console.log("Cabbage-react: receiving form data change", n), n.data && n.channel === "MainForm" && n.command === "widgetUpdate" && s(JSON.parse(n.data));
|
|
81
81
|
};
|
|
82
82
|
return window.addEventListener("message", a), () => {
|
|
83
83
|
window.removeEventListener("message", a);
|