cabbage-react 1.0.0-beta.1 → 1.0.0-beta.11

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
 
@@ -1,42 +1,9 @@
1
1
  export class Cabbage {
2
- /**
3
- * Sends a parameter update message.
4
- * @param {Object} message - The parameter update data.
5
- * @param {Object|null} [vscode=null] - Optional VSCode API object for messaging.
6
- */
7
- static sendParameterUpdate(message: Object, vscode?: Object | null): void;
8
- /**
9
- * Sends a custom command message.
10
- * @param {string} command - The custom command.
11
- * @param {Object|null} [vscode=null] - Optional VSCode API object for messaging.
12
- */
13
- static sendCustomCommand(command: string, vscode?: Object | null): void;
14
- /**
15
- * Sends a widget update message.
16
- * @param {Object} widget - The widget object containing properties.
17
- * @param {Object|null} [vscode=null] - Optional VSCode API object for messaging.
18
- */
19
- static sendWidgetUpdate(widget: Object, vscode?: Object | null): void;
20
- /**
21
- * Sends a MIDI message from the UI.
22
- * @param {number} statusByte - MIDI status byte.
23
- * @param {number} dataByte1 - First data byte.
24
- * @param {number} dataByte2 - Second data byte.
25
- * @param {Object|null} [vscode=null] - Optional VSCode API object for messaging.
26
- */
27
- static sendMidiMessageFromUI(statusByte: number, dataByte1: number, dataByte2: number, vscode?: Object | null): void;
28
- /**
29
- * Handles incoming MIDI messages from the host.
30
- * @param {number} statusByte - MIDI status byte.
31
- * @param {number} dataByte1 - First data byte.
32
- * @param {number} dataByte2 - Second data byte.
33
- */
34
- static MidiMessageFromHost(statusByte: number, dataByte1: number, dataByte2: number): void;
35
- /**
36
- * Triggers a file open dialog.
37
- * @param {Object} vscode - VSCode API object for messaging.
38
- * @param {string} channel - The channel identifier.
39
- */
40
- static triggerFileOpenDialog(vscode: Object, channel: string): void;
2
+ static sendParameterUpdate(message: any, vscode?: null): void;
3
+ static sendCustomCommand(command: any, vscode?: null): void;
4
+ static sendWidgetUpdate(widget: any, vscode?: null): void;
5
+ static sendMidiMessageFromUI(statusByte: any, dataByte1: any, dataByte2: any, vscode?: null): void;
6
+ static MidiMessageFromHost(statusByte: any, dataByte1: any, dataByte2: any): void;
7
+ static triggerFileOpenDialog(vscode: any, channel: any): void;
41
8
  }
42
9
  //# sourceMappingURL=cabbage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cabbage.d.ts","sourceRoot":"","sources":["../../src/cabbage/cabbage.js"],"names":[],"mappings":"AAMA;IACC;;;;OAIG;IACH,oCAHW,MAAM,WACN,MAAM,GAAC,IAAI,QAerB;IAED;;;;OAIG;IACH,kCAHW,MAAM,WACN,MAAM,GAAC,IAAI,QAerB;IAED;;;;OAIG;IACH,gCAHW,MAAM,WACN,MAAM,GAAC,IAAI,QAerB;IAED;;;;;;OAMG;IACH,yCALW,MAAM,aACN,MAAM,aACN,MAAM,WACN,MAAM,GAAC,IAAI,QAyBrB;IAED;;;;;OAKG;IACH,uCAJW,MAAM,aACN,MAAM,aACN,MAAM,QAWhB;IAED;;;;OAIG;IACH,qCAHW,MAAM,WACN,MAAM,QAiBhB;CACD"}
1
+ {"version":3,"file":"cabbage.d.ts","sourceRoot":"","sources":["../../src/cabbage/cabbage.js"],"names":[],"mappings":"AAMA;IAEE,8DAYC;IAED,4DAYC;IAED,0DAYC;IAED,mGAmBC;IAED,kFAEC;IAED,8DAeC;CAGF"}
@@ -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;;yBAK9B,CAAC;;CA4CtC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useGetCabbageFormData.d.ts","sourceRoot":"","sources":["../../src/hooks/useGetCabbageFormData.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;;CA2BjC,CAAC"}
1
+ {"version":3,"file":"useGetCabbageFormData.d.ts","sourceRoot":"","sources":["../../src/hooks/useGetCabbageFormData.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;;CA4BjC,CAAC"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react");console.log("Cabbage: loading cabbage.js");class u{static sendParameterUpdate(t,a=null){const e={command:"parameterChange",obj:JSON.stringify(t)};a!==null?a.postMessage(e):(console.log("Cabbage: sending parameter change from UI",e),typeof IPlugSendMsg=="function"&&IPlugSendMsg(e))}static sendCustomCommand(t,a=null){const e={command:t,text:JSON.stringify({})};console.log("Cabbage: sending custom command from UI",e),a!==null?a.postMessage(e):typeof IPlugSendMsg=="function"&&IPlugSendMsg(e)}static sendWidgetUpdate(t,a=null){console.log("Cabbage: sending widget update from UI",t.props);const e={command:"widgetStateUpdate",obj:JSON.stringify(t.props)};a!==null?a.postMessage(e):typeof IPlugSendMsg=="function"&&IPlugSendMsg(e)}static sendMidiMessageFromUI(t,a,e,s=null){var i={statusByte:t,dataByte1:a,dataByte2:e};const d={command:"midiMessage",obj:JSON.stringify(i)};console.log("Cabbage: sending midi message from UI",i),s!==null?s.postMessage(d):typeof IPlugSendMsg=="function"&&IPlugSendMsg(d)}static MidiMessageFromHost(t,a,e){console.log("Cabbage: Got MIDI Message"+t+":"+a+":"+e)}static triggerFileOpenDialog(t,a){var e={channel:a};const s={command:"fileOpen",obj:JSON.stringify(e)};t!==null?t.postMessage(s):typeof IPlugSendMsg=="function"&&IPlugSendMsg(s)}}const m=(o,t)=>{const[a,e]=l.useState(),[s,i]=l.useState(),d=g=>{e(g);const r={paramIdx:t,channel:o,value:g};u.sendParameterUpdate(r,null)};return l.useEffect(()=>{const g=r=>{const{data:n}=r;n.channel===o&&n.command==="widgetUpdate"&&(n.value&&e(n.value),n.data&&i(JSON.parse(n.data)))};return window.addEventListener("message",g),()=>{window.removeEventListener("message",g)}},[]),{value:a,setValue:d,data:s}},c=()=>{const[o,t]=l.useState();return l.useEffect(()=>{const a=e=>{const{data:s}=e;s.data&&s.channel==="MainForm"&&s.command==="widgetUpdate"&&t(JSON.parse(s.data))};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{data:o}};exports.useCabbageState=m;exports.useGetCabbageFormData=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react");console.log("Cabbage: loading cabbage.js");class u{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 i={statusByte:s,dataByte1:a,dataByte2:e};const r={command:"midiMessage",obj:JSON.stringify(i)};console.log("Cabbage: sending midi message from UI",i),t!==null?t.postMessage(r):window.sendMessageFromUI(r)}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 b=(g,s)=>{const[a,e]=o.useState(),[t,i]=o.useState(),[r,m]=o.useState(),c=l=>{e(l);const d={paramIdx:s,channelType:t,channel:g,value:l,gesture:"value"};u.sendParameterUpdate(d,null)};return o.useEffect(()=>{const l=d=>{const{data:n}=d;console.log("Cabbage-React: receiving parameter change",n),n.channel===g&&n.command==="widgetUpdate"&&(n.value&&e(n.value),n.data&&m(JSON.parse(n.data)),typeof n.value=="number"?i("number"):typeof n.value=="string"&&i("string"))};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[]),{value:a,setValue:c,data:r}},f=()=>{const[g,s]=o.useState();return o.useEffect(()=>{const a=e=>{const{data:t}=e;console.log("Cabbage-react: receiving form data change",t),t.data&&t.channel==="MainForm"&&t.command==="widgetUpdate"&&s(JSON.parse(t.data))};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[]),{data:g}};exports.useCabbageState=b;exports.useGetCabbageFormData=f;
package/dist/index.mjs CHANGED
@@ -1,78 +1,43 @@
1
- import { useState as m, useEffect as r } from "react";
1
+ import { useState as r, useEffect as d } from "react";
2
2
  console.log("Cabbage: loading cabbage.js");
3
- class c {
4
- /**
5
- * Sends a parameter update message.
6
- * @param {Object} message - The parameter update data.
7
- * @param {Object|null} [vscode=null] - Optional VSCode API object for messaging.
8
- */
3
+ class b {
9
4
  static sendParameterUpdate(s, a = null) {
10
5
  const e = {
11
6
  command: "parameterChange",
12
7
  obj: JSON.stringify(s)
13
8
  };
14
- a !== null ? a.postMessage(e) : (console.log("Cabbage: sending parameter change from UI", e), typeof IPlugSendMsg == "function" && IPlugSendMsg(e));
9
+ a !== null ? a.postMessage(e) : (console.log("Cabbage: sending parameter change from UI", e), window.sendMessageFromUI(e));
15
10
  }
16
- /**
17
- * Sends a custom command message.
18
- * @param {string} command - The custom command.
19
- * @param {Object|null} [vscode=null] - Optional VSCode API object for messaging.
20
- */
21
11
  static sendCustomCommand(s, a = null) {
22
12
  const e = {
23
13
  command: s,
24
14
  text: JSON.stringify({})
25
15
  };
26
- console.log("Cabbage: sending custom command from UI", e), a !== null ? a.postMessage(e) : typeof IPlugSendMsg == "function" && IPlugSendMsg(e);
16
+ console.log("Cabbage: sending custom command from UI", e), a !== null ? a.postMessage(e) : window.sendMessageFromUI(e);
27
17
  }
28
- /**
29
- * Sends a widget update message.
30
- * @param {Object} widget - The widget object containing properties.
31
- * @param {Object|null} [vscode=null] - Optional VSCode API object for messaging.
32
- */
33
18
  static sendWidgetUpdate(s, a = null) {
34
19
  console.log("Cabbage: sending widget update from UI", s.props);
35
20
  const e = {
36
21
  command: "widgetStateUpdate",
37
22
  obj: JSON.stringify(s.props)
38
23
  };
39
- a !== null ? a.postMessage(e) : typeof IPlugSendMsg == "function" && IPlugSendMsg(e);
24
+ a !== null ? a.postMessage(e) : window.sendMessageFromUI(e);
40
25
  }
41
- /**
42
- * Sends a MIDI message from the UI.
43
- * @param {number} statusByte - MIDI status byte.
44
- * @param {number} dataByte1 - First data byte.
45
- * @param {number} dataByte2 - Second data byte.
46
- * @param {Object|null} [vscode=null] - Optional VSCode API object for messaging.
47
- */
48
26
  static sendMidiMessageFromUI(s, a, e, n = null) {
49
- var l = {
27
+ var g = {
50
28
  statusByte: s,
51
29
  dataByte1: a,
52
30
  dataByte2: e
53
31
  };
54
- const i = {
32
+ const l = {
55
33
  command: "midiMessage",
56
- obj: JSON.stringify(l)
34
+ obj: JSON.stringify(g)
57
35
  };
58
- console.log("Cabbage: sending midi message from UI", l), n !== null ? n.postMessage(i) : typeof IPlugSendMsg == "function" && IPlugSendMsg(i);
36
+ console.log("Cabbage: sending midi message from UI", g), n !== null ? n.postMessage(l) : window.sendMessageFromUI(l);
59
37
  }
60
- /**
61
- * Handles incoming MIDI messages from the host.
62
- * @param {number} statusByte - MIDI status byte.
63
- * @param {number} dataByte1 - First data byte.
64
- * @param {number} dataByte2 - Second data byte.
65
- */
66
38
  static MidiMessageFromHost(s, a, e) {
67
- console.log(
68
- "Cabbage: Got MIDI Message" + s + ":" + a + ":" + e
69
- );
39
+ console.log("Cabbage: Got MIDI Message" + s + ":" + a + ":" + e);
70
40
  }
71
- /**
72
- * Triggers a file open dialog.
73
- * @param {Object} vscode - VSCode API object for messaging.
74
- * @param {string} channel - The channel identifier.
75
- */
76
41
  static triggerFileOpenDialog(s, a) {
77
42
  var e = {
78
43
  channel: a
@@ -81,38 +46,40 @@ class c {
81
46
  command: "fileOpen",
82
47
  obj: JSON.stringify(e)
83
48
  };
84
- s !== null ? s.postMessage(n) : typeof IPlugSendMsg == "function" && IPlugSendMsg(n);
49
+ s !== null ? s.postMessage(n) : window.sendMessageFromUI(n);
85
50
  }
86
51
  }
87
- const f = (o, s) => {
88
- const [a, e] = m(), [n, l] = m(), i = (g) => {
89
- e(g);
90
- const d = {
52
+ const p = (o, s) => {
53
+ const [a, e] = r(), [n, g] = r(), [l, c] = r(), u = (i) => {
54
+ e(i);
55
+ const m = {
91
56
  paramIdx: s,
57
+ channelType: n,
92
58
  channel: o,
93
- value: g
59
+ value: i,
60
+ gesture: "value"
94
61
  };
95
- c.sendParameterUpdate(d, null);
62
+ b.sendParameterUpdate(m, null);
96
63
  };
97
- return r(() => {
98
- const g = (d) => {
99
- const { data: t } = d;
100
- t.channel === o && t.command === "widgetUpdate" && (t.value && e(t.value), t.data && l(JSON.parse(t.data)));
64
+ return d(() => {
65
+ const i = (m) => {
66
+ const { data: t } = m;
67
+ console.log("Cabbage-React: receiving parameter change", t), t.channel === o && t.command === "widgetUpdate" && (t.value && e(t.value), t.data && c(JSON.parse(t.data)), typeof t.value == "number" ? g("number") : typeof t.value == "string" && g("string"));
101
68
  };
102
- return window.addEventListener("message", g), () => {
103
- window.removeEventListener("message", g);
69
+ return window.addEventListener("message", i), () => {
70
+ window.removeEventListener("message", i);
104
71
  };
105
72
  }, []), {
106
73
  value: a,
107
- setValue: i,
108
- data: n
74
+ setValue: u,
75
+ data: l
109
76
  };
110
- }, p = () => {
111
- const [o, s] = m();
112
- return r(() => {
77
+ }, w = () => {
78
+ const [o, s] = r();
79
+ return d(() => {
113
80
  const a = (e) => {
114
81
  const { data: n } = e;
115
- n.data && n.channel === "MainForm" && n.command === "widgetUpdate" && s(JSON.parse(n.data));
82
+ console.log("Cabbage-react: receiving form data change", n), n.data && n.channel === "MainForm" && n.command === "widgetUpdate" && s(JSON.parse(n.data));
116
83
  };
117
84
  return window.addEventListener("message", a), () => {
118
85
  window.removeEventListener("message", a);
@@ -122,6 +89,6 @@ const f = (o, s) => {
122
89
  };
123
90
  };
124
91
  export {
125
- f as useCabbageState,
126
- p as useGetCabbageFormData
92
+ p as useCabbageState,
93
+ w as useGetCabbageFormData
127
94
  };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.11",
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"