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 +2 -2
- package/dist/cabbage/cabbage.d.ts +6 -39
- package/dist/cabbage/cabbage.d.ts.map +1 -1
- package/dist/hooks/useCabbageProperties.d.ts +9 -0
- package/dist/hooks/useCabbageProperties.d.ts.map +1 -0
- package/dist/hooks/useCabbageState.d.ts +0 -1
- package/dist/hooks/useCabbageState.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +49 -83
- package/package.json +4 -3
- package/dist/hooks/useGetCabbageFormData.d.ts +0 -9
- package/dist/hooks/useGetCabbageFormData.d.ts.map +0 -1
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"}
|
|
@@ -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"}
|
|
@@ -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;CAkDtC,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(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 {
|
|
2
|
+
export { useCabbageProperties } from './hooks/useCabbageProperties';
|
|
3
|
+
export { Cabbage } from './cabbage/cabbage';
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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
|
|
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(
|
|
7
|
+
obj: JSON.stringify(a)
|
|
13
8
|
};
|
|
14
|
-
|
|
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:
|
|
13
|
+
command: a,
|
|
24
14
|
text: JSON.stringify({})
|
|
25
15
|
};
|
|
26
|
-
console.log("Cabbage: sending custom command from UI", e),
|
|
16
|
+
console.log("Cabbage: sending custom command from UI", e), s !== null ? s.postMessage(e) : window.sendMessageFromUI(e);
|
|
27
17
|
}
|
|
28
|
-
|
|
29
|
-
|
|
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(
|
|
22
|
+
obj: JSON.stringify(a.props)
|
|
38
23
|
};
|
|
39
|
-
|
|
24
|
+
s !== null ? s.postMessage(e) : window.sendMessageFromUI(e);
|
|
40
25
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
|
32
|
+
const l = {
|
|
55
33
|
command: "midiMessage",
|
|
56
|
-
obj: JSON.stringify(
|
|
34
|
+
obj: JSON.stringify(n)
|
|
57
35
|
};
|
|
58
|
-
console.log("Cabbage: sending midi message from UI",
|
|
36
|
+
console.log("Cabbage: sending midi message from UI", n), o !== null ? o.postMessage(l) : window.sendMessageFromUI(l);
|
|
59
37
|
}
|
|
60
|
-
|
|
61
|
-
|
|
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:
|
|
43
|
+
channel: s
|
|
79
44
|
};
|
|
80
|
-
const
|
|
45
|
+
const o = {
|
|
81
46
|
command: "fileOpen",
|
|
82
47
|
obj: JSON.stringify(e)
|
|
83
48
|
};
|
|
84
|
-
|
|
49
|
+
a !== null ? a.postMessage(o) : window.sendMessageFromUI(o);
|
|
85
50
|
}
|
|
86
51
|
}
|
|
87
|
-
const
|
|
88
|
-
const [
|
|
52
|
+
const p = (i, a) => {
|
|
53
|
+
const [s, e] = d(), [o, n] = d(), l = (g) => {
|
|
89
54
|
e(g);
|
|
90
|
-
const
|
|
91
|
-
paramIdx:
|
|
92
|
-
|
|
55
|
+
const r = {
|
|
56
|
+
paramIdx: a,
|
|
57
|
+
channelType: o,
|
|
58
|
+
channel: i,
|
|
93
59
|
value: g
|
|
94
60
|
};
|
|
95
|
-
c.sendParameterUpdate(
|
|
61
|
+
c.sendParameterUpdate(r, null);
|
|
96
62
|
};
|
|
97
|
-
return
|
|
98
|
-
const g = (
|
|
99
|
-
const { data: t } =
|
|
100
|
-
t.
|
|
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:
|
|
107
|
-
setValue:
|
|
108
|
-
data: n
|
|
72
|
+
value: s,
|
|
73
|
+
setValue: l
|
|
109
74
|
};
|
|
110
|
-
},
|
|
111
|
-
const [
|
|
112
|
-
return
|
|
113
|
-
const
|
|
114
|
-
const { data: n } =
|
|
115
|
-
n.
|
|
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",
|
|
118
|
-
window.removeEventListener("message",
|
|
82
|
+
return window.addEventListener("message", e), () => {
|
|
83
|
+
window.removeEventListener("message", e);
|
|
119
84
|
};
|
|
120
85
|
}, []), {
|
|
121
|
-
|
|
86
|
+
properties: a
|
|
122
87
|
};
|
|
123
88
|
};
|
|
124
89
|
export {
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
"
|
|
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"}
|