cabbage-react 1.0.0-beta.30 → 1.0.0-beta.32

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