cabbage-react 1.0.0-beta.1 → 1.0.0-beta.10
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 +2 -2
- package/dist/cabbage/cabbage.d.ts +6 -39
- package/dist/cabbage/cabbage.d.ts.map +1 -1
- package/dist/hooks/useCabbageState.d.ts.map +1 -1
- package/dist/hooks/useGetCabbageFormData.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +27 -61
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# Cabbage
|
|
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/
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
static
|
|
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;
|
|
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;;
|
|
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;;CAsCtC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetCabbageFormData.d.ts","sourceRoot":"","sources":["../../src/hooks/useGetCabbageFormData.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;;
|
|
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
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react");console.log("Cabbage: loading cabbage.js");class m{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 r={statusByte:s,dataByte1:a,dataByte2:e};const l={command:"midiMessage",obj:JSON.stringify(r)};console.log("Cabbage: sending midi message from UI",r),t!==null?t.postMessage(l):window.sendMessageFromUI(l)}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 c=(o,s)=>{const[a,e]=i.useState(),[t,r]=i.useState(),l=g=>{e(g);const d={paramIdx:s,channel:o,value:g,gesture:"value"};m.sendParameterUpdate(d,null)};return i.useEffect(()=>{const g=d=>{const{data:n}=d;console.log("Cabbage-React: receiving parameter change",n),n.channel===o&&n.command==="widgetUpdate"&&(n.value&&e(n.value),n.data&&r(JSON.parse(n.data)))};return window.addEventListener("message",g),()=>{window.removeEventListener("message",g)}},[]),{value:a,setValue:l,data:t}},u=()=>{const[o,s]=i.useState();return i.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:o}};exports.useCabbageState=c;exports.useGetCabbageFormData=u;
|
package/dist/index.mjs
CHANGED
|
@@ -1,78 +1,43 @@
|
|
|
1
|
-
import { useState as
|
|
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
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),
|
|
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) :
|
|
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) :
|
|
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
|
|
27
|
+
var i = {
|
|
50
28
|
statusByte: s,
|
|
51
29
|
dataByte1: a,
|
|
52
30
|
dataByte2: e
|
|
53
31
|
};
|
|
54
|
-
const
|
|
32
|
+
const l = {
|
|
55
33
|
command: "midiMessage",
|
|
56
|
-
obj: JSON.stringify(
|
|
34
|
+
obj: JSON.stringify(i)
|
|
57
35
|
};
|
|
58
|
-
console.log("Cabbage: sending midi message from UI",
|
|
36
|
+
console.log("Cabbage: sending midi message from UI", i), 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,39 @@ class c {
|
|
|
81
46
|
command: "fileOpen",
|
|
82
47
|
obj: JSON.stringify(e)
|
|
83
48
|
};
|
|
84
|
-
s !== null ? s.postMessage(n) :
|
|
49
|
+
s !== null ? s.postMessage(n) : window.sendMessageFromUI(n);
|
|
85
50
|
}
|
|
86
51
|
}
|
|
87
|
-
const
|
|
88
|
-
const [a, e] =
|
|
52
|
+
const b = (o, s) => {
|
|
53
|
+
const [a, e] = d(), [n, i] = d(), l = (g) => {
|
|
89
54
|
e(g);
|
|
90
|
-
const
|
|
55
|
+
const r = {
|
|
91
56
|
paramIdx: s,
|
|
92
57
|
channel: o,
|
|
93
|
-
value: g
|
|
58
|
+
value: g,
|
|
59
|
+
gesture: "value"
|
|
94
60
|
};
|
|
95
|
-
c.sendParameterUpdate(
|
|
61
|
+
c.sendParameterUpdate(r, null);
|
|
96
62
|
};
|
|
97
|
-
return
|
|
98
|
-
const g = (
|
|
99
|
-
const { data: t } =
|
|
100
|
-
t.channel === o && t.command === "widgetUpdate" && (t.value && e(t.value), t.data &&
|
|
63
|
+
return m(() => {
|
|
64
|
+
const g = (r) => {
|
|
65
|
+
const { data: t } = r;
|
|
66
|
+
console.log("Cabbage-React: receiving parameter change", t), t.channel === o && t.command === "widgetUpdate" && (t.value && e(t.value), t.data && i(JSON.parse(t.data)));
|
|
101
67
|
};
|
|
102
68
|
return window.addEventListener("message", g), () => {
|
|
103
69
|
window.removeEventListener("message", g);
|
|
104
70
|
};
|
|
105
71
|
}, []), {
|
|
106
72
|
value: a,
|
|
107
|
-
setValue:
|
|
73
|
+
setValue: l,
|
|
108
74
|
data: n
|
|
109
75
|
};
|
|
110
|
-
},
|
|
111
|
-
const [o, s] =
|
|
112
|
-
return
|
|
76
|
+
}, f = () => {
|
|
77
|
+
const [o, s] = d();
|
|
78
|
+
return m(() => {
|
|
113
79
|
const a = (e) => {
|
|
114
80
|
const { data: n } = e;
|
|
115
|
-
n.data && n.channel === "MainForm" && n.command === "widgetUpdate" && s(JSON.parse(n.data));
|
|
81
|
+
console.log("Cabbage-react: receiving form data change", n), n.data && n.channel === "MainForm" && n.command === "widgetUpdate" && s(JSON.parse(n.data));
|
|
116
82
|
};
|
|
117
83
|
return window.addEventListener("message", a), () => {
|
|
118
84
|
window.removeEventListener("message", a);
|
|
@@ -122,6 +88,6 @@ const f = (o, s) => {
|
|
|
122
88
|
};
|
|
123
89
|
};
|
|
124
90
|
export {
|
|
125
|
-
|
|
126
|
-
|
|
91
|
+
b as useCabbageState,
|
|
92
|
+
f as useGetCabbageFormData
|
|
127
93
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cabbage-react",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
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"
|