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

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;CAkEtC,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(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;
package/dist/index.mjs CHANGED
@@ -1,110 +1,111 @@
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 C {
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
- const i = {
32
+ const g = {
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(g) : window.sendMessageFromUI(g);
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 M = (i) => {
53
+ const [s, e] = r();
54
+ return m(() => {
55
+ const a = (t) => {
56
+ const { data: o } = t;
57
+ if (o.channel === i && o.data && o.command === "widgetUpdate") {
58
+ const g = 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
+ g
62
+ ), e(g);
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);
93
- console.log(
94
- `[Cabbage-React] ${t.command}: Received properties for channel: ${t.channel}`,
95
- i
96
- ), n(i);
97
- }
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,
76
+ channelType: o,
77
+ channel: i,
78
+ value: l
98
79
  };
99
- return window.addEventListener("message", e), () => {
100
- window.removeEventListener("message", e);
80
+ C.sendParameterUpdate(d, null);
81
+ };
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));
98
+ };
99
+ return window.addEventListener("message", l), () => {
100
+ window.removeEventListener("message", l);
101
101
  };
102
102
  }, []), {
103
- properties: s
103
+ value: a,
104
+ setValue: w
104
105
  };
105
106
  };
106
107
  export {
107
- v as Cabbage,
108
+ C as Cabbage,
108
109
  M as useCabbageProperties,
109
- C as useCabbageState
110
+ v as useCabbageState
110
111
  };
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.31",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",