cabbage-react 1.0.0-beta.31 → 1.0.0-beta.33

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