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;;CA0BnD,CAAC"}
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;CA2DtC,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 M{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,o=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),o!==null?o.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 o={command:"fileOpen",obj:JSON.stringify(e)};a!==null?a.postMessage(o):window.sendMessageFromUI(o)}}const U=(i,a)=>{const[s,e]=r.useState(),[o,t]=r.useState(),d=l=>{e(l);const g={paramIdx:a,channelType:o,channel:i,value:l};M.sendParameterUpdate(g,null)};return r.useEffect(()=>{const l=g=>{var m,c,u,b,p,f,C,w;const{data:n}=g;if(console.log("Cabbage-React: receiving parameter change",g),console.log("eple",g.data),console.log("banan",(m=g.data)==null?void 0:m.data),console.log("kongle",(u=(c=g.data)==null?void 0:c.data)==null?void 0:u.paramidx),console.log("ananas",(p=(b=g.data)==null?void 0:b.data)==null?void 0:p.value),n.command==="widgetUpdate"){if(n.channel!==i)return;n.value!==void 0&&(e(n.value),typeof n.value=="number"?t("number"):typeof n.value=="string"&&t("string"))}((f=n.data)==null?void 0:f.paramIdx)===a&&n.command==="parameterChange"&&((C=n==null?void 0:n.data)==null?void 0:C.value)!==void 0&&e((w=n==null?void 0:n.data)==null?void 0:w.value)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[]),{value:s,setValue:d}},h=i=>{const[a,s]=r.useState();return r.useEffect(()=>{const e=o=>{const{data:t}=o;t.channel===i&&t.data&&t.command==="widgetUpdate"&&(console.log("Cabbage-React: receiving properties change",t),s(JSON.parse(t.data)))};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}},[]),{properties:a}};exports.Cabbage=M;exports.useCabbageProperties=h;exports.useCabbageState=U;
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 C } from "react";
1
+ import { useState as d, useEffect as f } from "react";
2
2
  console.log("Cabbage: loading cabbage.js");
3
- class U {
4
- static sendParameterUpdate(a, s = null) {
3
+ class v {
4
+ static sendParameterUpdate(s, n = null) {
5
5
  const e = {
6
6
  command: "parameterChange",
7
- obj: JSON.stringify(a)
7
+ obj: JSON.stringify(s)
8
8
  };
9
- s !== null ? s.postMessage(e) : (console.log("Cabbage: sending parameter change from UI", e), window.sendMessageFromUI(e));
9
+ n !== null ? n.postMessage(e) : (console.log("Cabbage: sending parameter change from UI", e), window.sendMessageFromUI(e));
10
10
  }
11
- static sendCustomCommand(a, s = null) {
11
+ static sendCustomCommand(s, n = null) {
12
12
  const e = {
13
- command: a,
13
+ command: s,
14
14
  text: JSON.stringify({})
15
15
  };
16
- console.log("Cabbage: sending custom command from UI", e), s !== null ? s.postMessage(e) : window.sendMessageFromUI(e);
16
+ console.log("Cabbage: sending custom command from UI", e), n !== null ? n.postMessage(e) : window.sendMessageFromUI(e);
17
17
  }
18
- static sendWidgetUpdate(a, s = null) {
19
- console.log("Cabbage: sending widget update from UI", a.props);
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(a.props)
22
+ obj: JSON.stringify(s.props)
23
23
  };
24
- s !== null ? s.postMessage(e) : window.sendMessageFromUI(e);
24
+ n !== null ? n.postMessage(e) : window.sendMessageFromUI(e);
25
25
  }
26
- static sendMidiMessageFromUI(a, s, e, o = null) {
26
+ static sendMidiMessageFromUI(s, n, e, o = null) {
27
27
  var t = {
28
- statusByte: a,
29
- dataByte1: s,
28
+ statusByte: s,
29
+ dataByte1: n,
30
30
  dataByte2: e
31
31
  };
32
- const r = {
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(r) : window.sendMessageFromUI(r);
36
+ console.log("Cabbage: sending midi message from UI", t), o !== null ? o.postMessage(i) : window.sendMessageFromUI(i);
37
37
  }
38
- static MidiMessageFromHost(a, s, e) {
39
- console.log("Cabbage: Got MIDI Message" + a + ":" + s + ":" + e);
38
+ static MidiMessageFromHost(s, n, e) {
39
+ console.log("Cabbage: Got MIDI Message" + s + ":" + n + ":" + e);
40
40
  }
41
- static triggerFileOpenDialog(a, s) {
41
+ static triggerFileOpenDialog(s, n) {
42
42
  var e = {
43
- channel: s
43
+ channel: n
44
44
  };
45
45
  const o = {
46
46
  command: "fileOpen",
47
47
  obj: JSON.stringify(e)
48
48
  };
49
- a !== null ? a.postMessage(o) : window.sendMessageFromUI(o);
49
+ s !== null ? s.postMessage(o) : window.sendMessageFromUI(o);
50
50
  }
51
51
  }
52
- const y = (i, a) => {
53
- const [s, e] = d(), [o, t] = d(), r = (l) => {
54
- e(l);
55
- const g = {
56
- paramIdx: a,
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: i,
59
- value: l
58
+ channel: l,
59
+ value: g
60
60
  };
61
- U.sendParameterUpdate(g, null);
61
+ v.sendParameterUpdate(r, null);
62
62
  };
63
- return C(() => {
64
- const l = (g) => {
65
- var m, c, u, p, b, f, w, M;
66
- const { data: n } = g;
67
- if (console.log("Cabbage-React: receiving parameter change", g), console.log("eple", g.data), console.log("banan", (m = g.data) == null ? void 0 : m.data), console.log("kongle", (u = (c = g.data) == null ? void 0 : c.data) == null ? void 0 : u.paramidx), console.log("ananas", (b = (p = g.data) == null ? void 0 : p.data) == null ? void 0 : b.value), n.command === "widgetUpdate") {
68
- if (n.channel !== i) return;
69
- n.value !== void 0 && (e(n.value), typeof n.value == "number" ? t("number") : typeof n.value == "string" && t("string"));
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
- ((f = n.data) == null ? void 0 : f.paramIdx) === a && n.command === "parameterChange" && ((w = n == null ? void 0 : n.data) == null ? void 0 : w.value) !== void 0 && e((M = n == null ? void 0 : n.data) == null ? void 0 : M.value);
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", l), () => {
74
- window.removeEventListener("message", l);
79
+ return window.addEventListener("message", g), () => {
80
+ window.removeEventListener("message", g);
75
81
  };
76
82
  }, []), {
77
- value: s,
78
- setValue: r
83
+ value: n,
84
+ setValue: i
79
85
  };
80
- }, I = (i) => {
81
- const [a, s] = d();
82
- return C(() => {
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 === i && t.data && t.command === "widgetUpdate" && (console.log("Cabbage-React: receiving properties change", t), s(JSON.parse(t.data)));
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: a
103
+ properties: s
92
104
  };
93
105
  };
94
106
  export {
95
- U as Cabbage,
96
- I as useCabbageProperties,
97
- y as useCabbageState
107
+ v as Cabbage,
108
+ M as useCabbageProperties,
109
+ C as useCabbageState
98
110
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.0-beta.25",
3
+ "version": "1.0.0-beta.26",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",