cabbage-react 1.0.0-beta.2 → 1.0.0-beta.22

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
@@ -1,8 +1,8 @@
1
- # Cabbage React
1
+ # Cabbage-React
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/vscabbage-react-example).
5
+ An example of implementation can be found [here](https://github.com/hdale94/cabbage-react-example).
6
6
 
7
7
  ## Install
8
8
 
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Custom hook to get a parameter's properties from Cabbage.
3
+ * This hook listens for updates to parameter properties via Cabbage and updates the local state
4
+ * whenever new data is received.
5
+ */
6
+ export declare const useCabbageProperties: (channel: string) => {
7
+ properties: Record<string, any> | undefined;
8
+ };
9
+ //# sourceMappingURL=useCabbageProperties.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCabbageProperties.d.ts","sourceRoot":"","sources":["../../src/hooks/useCabbageProperties.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,YAAa,MAAM;;CA0BnD,CAAC"}
@@ -6,6 +6,5 @@
6
6
  export declare const useCabbageState: <T>(channel: string, paramIdx: number) => {
7
7
  value: T | undefined;
8
8
  setValue: (newValue: T) => void;
9
- data: any;
10
9
  };
11
10
  //# sourceMappingURL=useCabbageState.d.ts.map
@@ -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;;CAoCtC,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;CAsDtC,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 d={statusByte:s,dataByte1:a,dataByte2:e};const l={command:"midiMessage",obj:JSON.stringify(d)};console.log("Cabbage: sending midi message from UI",d),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,d]=i.useState(),l=g=>{e(g);const r={paramIdx:s,channel:o,value:g};m.sendParameterUpdate(r,null)};return i.useEffect(()=>{const g=r=>{const{data:n}=r;n.channel===o&&n.command==="widgetUpdate"&&(n.value&&e(n.value),n.data&&d(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;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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react");console.log("Cabbage: loading cabbage.js");class C{static sendParameterUpdate(a,s=null){const e={command:"parameterChange",obj:JSON.stringify(a)};s!==null?s.postMessage(e):(console.log("Cabbage: sending parameter change from UI",e),window.sendMessageFromUI(e))}static sendCustomCommand(a,s=null){const e={command:a,text:JSON.stringify({})};console.log("Cabbage: sending custom command from UI",e),s!==null?s.postMessage(e):window.sendMessageFromUI(e)}static sendWidgetUpdate(a,s=null){console.log("Cabbage: sending widget update from UI",a.props);const e={command:"widgetStateUpdate",obj:JSON.stringify(a.props)};s!==null?s.postMessage(e):window.sendMessageFromUI(e)}static sendMidiMessageFromUI(a,s,e,n=null){var t={statusByte:a,dataByte1:s,dataByte2:e};const d={command:"midiMessage",obj:JSON.stringify(t)};console.log("Cabbage: sending midi message from UI",t),n!==null?n.postMessage(d):window.sendMessageFromUI(d)}static MidiMessageFromHost(a,s,e){console.log("Cabbage: Got MIDI Message"+a+":"+s+":"+e)}static triggerFileOpenDialog(a,s){var e={channel:s};const n={command:"fileOpen",obj:JSON.stringify(e)};a!==null?a.postMessage(n):window.sendMessageFromUI(n)}}const w=(r,a)=>{const[s,e]=i.useState(),[n,t]=i.useState(),d=l=>{e(l);const o={paramIdx:a,channelType:n,channel:r,value:l};C.sendParameterUpdate(o,null)};return i.useEffect(()=>{const l=o=>{var m,c,u,b,p,f;const{data:g}=o;console.log("Cabbage-React: receiving message",o),console.log("eple",o.data),console.log("banan",(m=o.data)==null?void 0:m.data),console.log("kongle",(u=(c=o.data)==null?void 0:c.data)==null?void 0:u.paramidx),console.log("ananas",(p=(b=o.data)==null?void 0:b.data)==null?void 0:p.value),g.command==="widgetUpdate"&&g.value!==void 0&&(e(g.value),typeof g.value=="number"?t("number"):typeof g.value=="string"&&t("string")),((f=g.data)==null?void 0:f.paramIdx)===a&&g.command==="parameterChange"&&e(g.value)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[]),{value:s,setValue:d}},M=r=>{const[a,s]=i.useState();return i.useEffect(()=>{const e=n=>{const{data:t}=n;t.channel===r&&t.data&&t.command==="widgetUpdate"&&(console.log("Cabbage-React: receiving data change",t),s(JSON.parse(t.data)))};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}},[]),{properties:a}};exports.Cabbage=C;exports.useCabbageProperties=M;exports.useCabbageState=w;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { useCabbageState } from './hooks/useCabbageState';
2
- export { useGetCabbageFormData } from './hooks/useGetCabbageFormData';
2
+ export { useCabbageProperties } from './hooks/useCabbageProperties';
3
+ export { Cabbage } from './cabbage/cabbage';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.mjs CHANGED
@@ -1,92 +1,94 @@
1
- import { useState as m, useEffect as r } from "react";
1
+ import { useState as r, useEffect as w } from "react";
2
2
  console.log("Cabbage: loading cabbage.js");
3
- class c {
4
- static sendParameterUpdate(s, a = null) {
3
+ class M {
4
+ static sendParameterUpdate(a, s = null) {
5
5
  const e = {
6
6
  command: "parameterChange",
7
- obj: JSON.stringify(s)
7
+ obj: JSON.stringify(a)
8
8
  };
9
- a !== null ? a.postMessage(e) : (console.log("Cabbage: sending parameter change from UI", e), window.sendMessageFromUI(e));
9
+ s !== null ? s.postMessage(e) : (console.log("Cabbage: sending parameter change from UI", e), window.sendMessageFromUI(e));
10
10
  }
11
- static sendCustomCommand(s, a = null) {
11
+ static sendCustomCommand(a, s = null) {
12
12
  const e = {
13
- command: s,
13
+ command: a,
14
14
  text: JSON.stringify({})
15
15
  };
16
- console.log("Cabbage: sending custom command from UI", e), a !== null ? a.postMessage(e) : window.sendMessageFromUI(e);
16
+ console.log("Cabbage: sending custom command from UI", e), s !== null ? s.postMessage(e) : window.sendMessageFromUI(e);
17
17
  }
18
- static sendWidgetUpdate(s, a = null) {
19
- console.log("Cabbage: sending widget update from UI", s.props);
18
+ static sendWidgetUpdate(a, s = null) {
19
+ console.log("Cabbage: sending widget update from UI", a.props);
20
20
  const e = {
21
21
  command: "widgetStateUpdate",
22
- obj: JSON.stringify(s.props)
22
+ obj: JSON.stringify(a.props)
23
23
  };
24
- a !== null ? a.postMessage(e) : window.sendMessageFromUI(e);
24
+ s !== null ? s.postMessage(e) : window.sendMessageFromUI(e);
25
25
  }
26
- static sendMidiMessageFromUI(s, a, e, n = null) {
27
- var i = {
28
- statusByte: s,
29
- dataByte1: a,
26
+ static sendMidiMessageFromUI(a, s, e, t = null) {
27
+ var n = {
28
+ statusByte: a,
29
+ dataByte1: s,
30
30
  dataByte2: e
31
31
  };
32
32
  const d = {
33
33
  command: "midiMessage",
34
- obj: JSON.stringify(i)
34
+ obj: JSON.stringify(n)
35
35
  };
36
- console.log("Cabbage: sending midi message from UI", i), n !== null ? n.postMessage(d) : window.sendMessageFromUI(d);
36
+ console.log("Cabbage: sending midi message from UI", n), t !== null ? t.postMessage(d) : window.sendMessageFromUI(d);
37
37
  }
38
- static MidiMessageFromHost(s, a, e) {
39
- console.log("Cabbage: Got MIDI Message" + s + ":" + a + ":" + e);
38
+ static MidiMessageFromHost(a, s, e) {
39
+ console.log("Cabbage: Got MIDI Message" + a + ":" + s + ":" + e);
40
40
  }
41
- static triggerFileOpenDialog(s, a) {
41
+ static triggerFileOpenDialog(a, s) {
42
42
  var e = {
43
- channel: a
43
+ channel: s
44
44
  };
45
- const n = {
45
+ const t = {
46
46
  command: "fileOpen",
47
47
  obj: JSON.stringify(e)
48
48
  };
49
- s !== null ? s.postMessage(n) : window.sendMessageFromUI(n);
49
+ a !== null ? a.postMessage(t) : window.sendMessageFromUI(t);
50
50
  }
51
51
  }
52
- const b = (o, s) => {
53
- const [a, e] = m(), [n, i] = m(), d = (g) => {
54
- e(g);
55
- const l = {
56
- paramIdx: s,
57
- channel: o,
58
- value: g
52
+ const U = (i, a) => {
53
+ const [s, e] = r(), [t, n] = r(), d = (l) => {
54
+ e(l);
55
+ const o = {
56
+ paramIdx: a,
57
+ channelType: t,
58
+ channel: i,
59
+ value: l
59
60
  };
60
- c.sendParameterUpdate(l, null);
61
+ M.sendParameterUpdate(o, null);
61
62
  };
62
- return r(() => {
63
- const g = (l) => {
64
- const { data: t } = l;
65
- t.channel === o && t.command === "widgetUpdate" && (t.value && e(t.value), t.data && i(JSON.parse(t.data)));
63
+ return w(() => {
64
+ const l = (o) => {
65
+ var m, c, u, p, b, f;
66
+ const { data: g } = o;
67
+ console.log("Cabbage-React: receiving message", o), console.log("eple", o.data), console.log("banan", (m = o.data) == null ? void 0 : m.data), console.log("kongle", (u = (c = o.data) == null ? void 0 : c.data) == null ? void 0 : u.paramidx), console.log("ananas", (b = (p = o.data) == null ? void 0 : p.data) == null ? void 0 : b.value), g.command === "widgetUpdate" && g.value !== void 0 && (e(g.value), typeof g.value == "number" ? n("number") : typeof g.value == "string" && n("string")), ((f = g.data) == null ? void 0 : f.paramIdx) === a && g.command === "parameterChange" && e(g.value);
66
68
  };
67
- return window.addEventListener("message", g), () => {
68
- window.removeEventListener("message", g);
69
+ return window.addEventListener("message", l), () => {
70
+ window.removeEventListener("message", l);
69
71
  };
70
72
  }, []), {
71
- value: a,
72
- setValue: d,
73
- data: n
73
+ value: s,
74
+ setValue: d
74
75
  };
75
- }, f = () => {
76
- const [o, s] = m();
77
- return r(() => {
78
- const a = (e) => {
79
- const { data: n } = e;
80
- n.data && n.channel === "MainForm" && n.command === "widgetUpdate" && s(JSON.parse(n.data));
76
+ }, h = (i) => {
77
+ const [a, s] = r();
78
+ return w(() => {
79
+ const e = (t) => {
80
+ const { data: n } = t;
81
+ n.channel === i && n.data && n.command === "widgetUpdate" && (console.log("Cabbage-React: receiving data change", n), s(JSON.parse(n.data)));
81
82
  };
82
- return window.addEventListener("message", a), () => {
83
- window.removeEventListener("message", a);
83
+ return window.addEventListener("message", e), () => {
84
+ window.removeEventListener("message", e);
84
85
  };
85
86
  }, []), {
86
- data: o
87
+ properties: a
87
88
  };
88
89
  };
89
90
  export {
90
- b as useCabbageState,
91
- f as useGetCabbageFormData
91
+ M as Cabbage,
92
+ h as useCabbageProperties,
93
+ U as useCabbageState
92
94
  };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.22",
4
4
  "type": "module",
5
5
  "keywords": [
6
- "vscabbage",
6
+ "cabbage",
7
7
  "react"
8
8
  ],
9
9
  "author": "Håkon Dale",
@@ -13,13 +13,14 @@
13
13
  "url": "git+https://github.com/hdale94/cabbage-react.git"
14
14
  },
15
15
  "main": "./dist/index.cjs",
16
+ "types": "./dist/index.d.ts",
16
17
  "exports": {
17
18
  ".": {
19
+ "types": "./dist/index.d.ts",
18
20
  "import": "./dist/index.mjs",
19
21
  "require": "./dist/index.cjs"
20
22
  }
21
23
  },
22
- "types": "./dist/index.d.ts",
23
24
  "scripts": {
24
25
  "prepublish": "rm -rf ./dist && npm run build",
25
26
  "build": "vite build"
@@ -1,9 +0,0 @@
1
- /**
2
- * Custom hook to get form data from Cabbage.
3
- * This hook listens for updates to form data via Cabbage and updates the local state
4
- * whenever new data is received.
5
- */
6
- export declare const useGetCabbageFormData: () => {
7
- data: any;
8
- };
9
- //# sourceMappingURL=useGetCabbageFormData.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useGetCabbageFormData.d.ts","sourceRoot":"","sources":["../../src/hooks/useGetCabbageFormData.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;;CA2BjC,CAAC"}