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

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"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Custom hook to get a parameter's properties from Cabbage.
3
+ * This hook listens for updates to parameter properties via Cabbage and updates the local state
4
+ * whenever new data is received.
5
+ */
6
+ export declare const useCabbageProperties: (channel: string) => {
7
+ properties: Record<string, any> | undefined;
8
+ };
9
+ //# sourceMappingURL=useCabbageProperties.d.ts.map
@@ -0,0 +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"}
@@ -6,6 +6,5 @@
6
6
  export declare const useCabbageState: <T>(channel: string, paramIdx: number) => {
7
7
  value: T | undefined;
8
8
  setValue: (newValue: T) => void;
9
- data: any;
10
9
  };
11
10
  //# sourceMappingURL=useCabbageState.d.ts.map
@@ -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;;yBAI9B,CAAC;CAkDtC,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 i=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 l={command:"midiMessage",obj:JSON.stringify(t)};console.log("Cabbage: sending midi message from UI",t),o!==null?o.postMessage(l):window.sendMessageFromUI(l)}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 c=(r,a)=>{const[s,e]=i.useState(),[o,t]=i.useState(),l=g=>{e(g);const d={paramIdx:a,channelType:o,channel:r,value:g};m.sendParameterUpdate(d,null)};return i.useEffect(()=>{const g=d=>{const{data:n}=d;console.log("Cabbage-React: receiving parameter change",n),console.log("data.data",n.data),n.data.paramIdx===a&&(n.command==="widgetUpdate"?n.value!==void 0&&(e(n.value),typeof n.value=="number"?t("number"):typeof n.value=="string"&&t("string")):n.command==="parameterChange"&&e(n.value))};return window.addEventListener("message",g),()=>{window.removeEventListener("message",g)}},[]),{value:s,setValue:l}},u=r=>{const[a,s]=i.useState();return i.useEffect(()=>{const e=o=>{const{data:t}=o;t.channel===r&&t.data&&t.command==="widgetUpdate"&&(console.log("Cabbage-React: receiving data change",t),s(JSON.parse(t.data)))};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}},[]),{properties:a}};exports.Cabbage=m;exports.useCabbageProperties=u;exports.useCabbageState=c;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { useCabbageState } from './hooks/useCabbageState';
2
- export { useGetCabbageFormData } from './hooks/useGetCabbageFormData';
2
+ export { useCabbageProperties } from './hooks/useCabbageProperties';
3
+ export { Cabbage } from './cabbage/cabbage';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.mjs CHANGED
@@ -1,127 +1,93 @@
1
- import { useState as m, useEffect as r } from "react";
1
+ import { useState as d, useEffect as m } from "react";
2
2
  console.log("Cabbage: loading cabbage.js");
3
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
- */
9
- static sendParameterUpdate(s, a = null) {
4
+ static sendParameterUpdate(a, s = null) {
10
5
  const e = {
11
6
  command: "parameterChange",
12
- obj: JSON.stringify(s)
7
+ obj: JSON.stringify(a)
13
8
  };
14
- a !== null ? a.postMessage(e) : (console.log("Cabbage: sending parameter change from UI", e), typeof IPlugSendMsg == "function" && IPlugSendMsg(e));
9
+ s !== null ? s.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
- static sendCustomCommand(s, a = null) {
11
+ static sendCustomCommand(a, s = null) {
22
12
  const e = {
23
- command: s,
13
+ command: a,
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), s !== null ? s.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
- static sendWidgetUpdate(s, a = null) {
34
- console.log("Cabbage: sending widget update from UI", s.props);
18
+ static sendWidgetUpdate(a, s = null) {
19
+ console.log("Cabbage: sending widget update from UI", a.props);
35
20
  const e = {
36
21
  command: "widgetStateUpdate",
37
- obj: JSON.stringify(s.props)
22
+ obj: JSON.stringify(a.props)
38
23
  };
39
- a !== null ? a.postMessage(e) : typeof IPlugSendMsg == "function" && IPlugSendMsg(e);
24
+ s !== null ? s.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
- static sendMidiMessageFromUI(s, a, e, n = null) {
49
- var l = {
50
- statusByte: s,
51
- dataByte1: a,
26
+ static sendMidiMessageFromUI(a, s, e, o = null) {
27
+ var n = {
28
+ statusByte: a,
29
+ dataByte1: s,
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(n)
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", n), o !== null ? o.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
- static MidiMessageFromHost(s, a, e) {
67
- console.log(
68
- "Cabbage: Got MIDI Message" + s + ":" + a + ":" + e
69
- );
38
+ static MidiMessageFromHost(a, s, e) {
39
+ console.log("Cabbage: Got MIDI Message" + a + ":" + s + ":" + 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
- static triggerFileOpenDialog(s, a) {
41
+ static triggerFileOpenDialog(a, s) {
77
42
  var e = {
78
- channel: a
43
+ channel: s
79
44
  };
80
- const n = {
45
+ const o = {
81
46
  command: "fileOpen",
82
47
  obj: JSON.stringify(e)
83
48
  };
84
- s !== null ? s.postMessage(n) : typeof IPlugSendMsg == "function" && IPlugSendMsg(n);
49
+ a !== null ? a.postMessage(o) : window.sendMessageFromUI(o);
85
50
  }
86
51
  }
87
- const f = (o, s) => {
88
- const [a, e] = m(), [n, l] = m(), i = (g) => {
52
+ const p = (i, a) => {
53
+ const [s, e] = d(), [o, n] = d(), l = (g) => {
89
54
  e(g);
90
- const d = {
91
- paramIdx: s,
92
- channel: o,
55
+ const r = {
56
+ paramIdx: a,
57
+ channelType: o,
58
+ channel: i,
93
59
  value: g
94
60
  };
95
- c.sendParameterUpdate(d, null);
61
+ c.sendParameterUpdate(r, null);
96
62
  };
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)));
63
+ return m(() => {
64
+ const g = (r) => {
65
+ const { data: t } = r;
66
+ console.log("Cabbage-React: receiving parameter change", t), console.log("data.data", t.data), t.data.paramIdx === a && (t.command === "widgetUpdate" ? t.value !== void 0 && (e(t.value), typeof t.value == "number" ? n("number") : typeof t.value == "string" && n("string")) : t.command === "parameterChange" && e(t.value));
101
67
  };
102
68
  return window.addEventListener("message", g), () => {
103
69
  window.removeEventListener("message", g);
104
70
  };
105
71
  }, []), {
106
- value: a,
107
- setValue: i,
108
- data: n
72
+ value: s,
73
+ setValue: l
109
74
  };
110
- }, p = () => {
111
- const [o, s] = m();
112
- return r(() => {
113
- const a = (e) => {
114
- const { data: n } = e;
115
- n.data && n.channel === "MainForm" && n.command === "widgetUpdate" && s(JSON.parse(n.data));
75
+ }, b = (i) => {
76
+ const [a, s] = d();
77
+ return m(() => {
78
+ const e = (o) => {
79
+ const { data: n } = o;
80
+ n.channel === i && n.data && n.command === "widgetUpdate" && (console.log("Cabbage-React: receiving data change", n), s(JSON.parse(n.data)));
116
81
  };
117
- return window.addEventListener("message", a), () => {
118
- window.removeEventListener("message", a);
82
+ return window.addEventListener("message", e), () => {
83
+ window.removeEventListener("message", e);
119
84
  };
120
85
  }, []), {
121
- data: o
86
+ properties: a
122
87
  };
123
88
  };
124
89
  export {
125
- f as useCabbageState,
126
- p as useGetCabbageFormData
90
+ c as Cabbage,
91
+ b as useCabbageProperties,
92
+ p as useCabbageState
127
93
  };
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.1.1",
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"
@@ -1,9 +0,0 @@
1
- /**
2
- * Custom hook to get form data from Cabbage.
3
- * This hook listens for updates to form data via Cabbage and updates the local state
4
- * whenever new data is received.
5
- */
6
- export declare const useGetCabbageFormData: () => {
7
- data: any;
8
- };
9
- //# sourceMappingURL=useGetCabbageFormData.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useGetCabbageFormData.d.ts","sourceRoot":"","sources":["../../src/hooks/useGetCabbageFormData.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;;CA2BjC,CAAC"}