cabbage-react 1.0.55 → 1.0.56

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/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react");class C{static sendControlData({channel:e,value:s,gesture:n="complete"},t=null){const a={command:"controlData",channel:e,value:s,gesture:n};t!==null?t.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):window.parent!==window?window.parent.postMessage(a,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static isReadyToLoad(e=null,s={}){this.sendCustomCommand("isReadyToLoad",e)}static sendMidiMessageFromUI(e,s,n,t=null){var a={statusByte:e,dataByte1:s,dataByte2:n};const r={command:"midiMessage",obj:JSON.stringify(a)};t!==null?t.postMessage(r):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(r):window.parent!==window?window.parent.postMessage(r,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",r)}static MidiMessageFromHost(e,s,n){}static triggerFileOpenDialog(e,s,n={}){var t={channel:s,directory:n.directory||"",filters:n.filters||"*",openAtLastKnownLocation:n.openAtLastKnownLocation!==void 0?n.openAtLastKnownLocation:!0};const a={command:"fileOpen",obj:JSON.stringify(t)};e!==null?e.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):window.parent!==window?window.parent.postMessage(a,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static openUrl(e,s,n){var t={url:s,file:n};const a={command:"openUrl",obj:JSON.stringify(t)};e!==null?e.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):window.parent!==window?window.parent.postMessage(a,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static requestResize(e,s,n=null){const t={command:"requestResize",width:e,height:s};if(n!==null){console.warn("Cabbage: requestResize is not supported in VS Code extension mode");return}else typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(t):window.parent!==window?window.parent.postMessage(t,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",t)}static consumeKeypresses(e){typeof window.consumeKeypresses=="function"&&window.consumeKeypresses(e)}static sendChannelData(e,s,n=null){var t={channel:e};if(typeof s=="string")t.stringData=s;else if(typeof s=="number")t.floatData=s;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof s);return}const a={command:"channelData",obj:JSON.stringify(t)};n!==null?n.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):window.parent!==window?window.parent.postMessage(a,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static sendWidgetUpdate(e,s=null){const n={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};s!==null?s.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static addMessageListener(e){const s=n=>{n.source!==window&&e(n.data)};return window.addEventListener("message",s),window.hostMessageCallback=e,()=>{window.removeEventListener("message",s),window.hostMessageCallback===e&&(window.hostMessageCallback=null)}}static sendCustomCommand(e,s=null,n={}){const t={command:e,text:JSON.stringify(n)};if(s!==null)s.postMessage(t);else if(typeof window.sendMessageFromUI=="function")try{const a=window.sendMessageFromUI(t)}catch(a){console.error("Cabbage: sendMessageFromUI threw error:",a),console.error("Cabbage: Error stack:",a.stack)}else window.parent!==window?window.parent.postMessage(t,"*"):(console.error("Cabbage: window.sendMessageFromUI is not available yet. Message:",t),console.error("Cabbage: typeof window.sendMessageFromUI:",typeof window.sendMessageFromUI),console.error("Cabbage: window.sendMessageFromUI value:",window.sendMessageFromUI))}}const b=(o,e)=>(...s)=>{e&&console.log(`[Cabbage-React][${o}]`,...s)},U=(o,e)=>{if(!o||e?.skip)return{properties:void 0};const s=b(`useCabbageProperties:${o}`,e?.debug),[n,t]=l.useState();return l.useEffect(()=>{const a=r=>{const{id:d,widgetJson:c,command:m}=r.data;if(d===o&&c&&m==="widgetUpdate"){const i=JSON.parse(c);s("Received properties",i),e?.onPropertiesUpdate&&e.onPropertiesUpdate(i),t(i)}};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[o,e?.onPropertiesUpdate]),{properties:n}},y=(o,e)=>{if(!o||e?.skip)return{value:void 0,setValue:()=>{}};const s=b(`useCabbageState:${o}`,e?.debug),{properties:n}=U(o,{debug:e?.debug}),[t,a]=l.useState(),[r,d]=l.useState(),c=(i,g="complete")=>{a(i),C.sendControlData({channel:o,value:i,gesture:g})},m=i=>{e?.onValueUpdate&&e.onValueUpdate(i),a(i)};return l.useEffect(()=>{const i=n?.channels.find(u=>u.id===o);if(!i)return;const g=i.parameterIndex;if(r===void 0&&g!==void 0&&(s("Received parameterIndex",g),d(g)),t!==void 0)return;const w=i.range?.value;w!=null&&(s("Received initial value",w),m(w))},[n]),l.useEffect(()=>{const i=g=>{const{command:w}=g.data;if(w==="parameterChange"){const{value:u,paramIdx:f}=g.data.data;if(f!==r||u===null)return;s("Received parameterChange",u),m(u)}else if(w==="batchWidgetUpdate"){const f=g.data.widgets?.find(p=>p.id===o);if(!f)return;const M=JSON.parse(f.widgetJson).channels.find(p=>p.id===o)?.range?.value;s("Received batchWidgetUpdate",M),m(M)}};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[o,e?.onValueUpdate,r]),{value:t,setValue:c}},v=(o,e)=>{if(!o||e?.skip)return{message:void 0};const s=b(`useCabbageMessage:${o}`,e?.debug),[n,t]=l.useState();return l.useEffect(()=>{const a=r=>{const{data:d,type:c}=r;!d||c!=="message"||d.type===o&&(s("Received data",d),e?.onMessage&&e.onMessage(d),t(d))};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[o,e?.onMessage]),{message:n}};exports.Cabbage=C;exports.useCabbageMessage=v;exports.useCabbageProperties=U;exports.useCabbageState=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react");class C{static sendControlData({channel:e,value:s,gesture:n="complete"},t=null){const a={command:"controlData",channel:e,value:s,gesture:n};t!==null?t.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):window.parent!==window?window.parent.postMessage(a,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static isReadyToLoad(e=null,s={}){this.sendCustomCommand("isReadyToLoad",e)}static sendMidiMessageFromUI(e,s,n,t=null){var a={statusByte:e,dataByte1:s,dataByte2:n};const r={command:"midiMessage",obj:JSON.stringify(a)};t!==null?t.postMessage(r):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(r):window.parent!==window?window.parent.postMessage(r,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",r)}static MidiMessageFromHost(e,s,n){}static triggerFileOpenDialog(e,s,n={}){var t={channel:s,directory:n.directory||"",filters:n.filters||"*",openAtLastKnownLocation:n.openAtLastKnownLocation!==void 0?n.openAtLastKnownLocation:!0};const a={command:"fileOpen",obj:JSON.stringify(t)};e!==null?e.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):window.parent!==window?window.parent.postMessage(a,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static openUrl(e,s,n){var t={url:s,file:n};const a={command:"openUrl",obj:JSON.stringify(t)};e!==null?e.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):window.parent!==window?window.parent.postMessage(a,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static requestResize(e,s,n=null){const t={command:"requestResize",width:e,height:s};if(n!==null){console.warn("Cabbage: requestResize is not supported in VS Code extension mode");return}else typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(t):window.parent!==window?window.parent.postMessage(t,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",t)}static consumeKeypresses(e){typeof window.consumeKeypresses=="function"&&window.consumeKeypresses(e)}static sendChannelData(e,s,n=null){var t={channel:e};if(typeof s=="string")t.stringData=s;else if(typeof s=="number")t.floatData=s;else{console.warn("Cabbage: sendChannelData received unsupported data type:",typeof s);return}const a={command:"channelData",obj:JSON.stringify(t)};n!==null?n.postMessage(a):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(a):window.parent!==window?window.parent.postMessage(a,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",a)}static sendWidgetUpdate(e,s=null){const n={command:"widgetStateUpdate",obj:JSON.stringify(CabbageUtils.sanitizeForEditor(e))};s!==null?s.postMessage(n):typeof window.sendMessageFromUI=="function"?window.sendMessageFromUI(n):window.parent!==window?window.parent.postMessage(n,"*"):console.error("Cabbage: window.sendMessageFromUI is not available. Message:",n)}static addMessageListener(e){const s=n=>{n.source!==window&&e(n.data)};return window.addEventListener("message",s),window.hostMessageCallback=e,()=>{window.removeEventListener("message",s),window.hostMessageCallback===e&&(window.hostMessageCallback=null)}}static sendCustomCommand(e,s=null,n={}){const t={command:e,text:JSON.stringify(n)};if(s!==null)s.postMessage(t);else if(typeof window.sendMessageFromUI=="function")try{const a=window.sendMessageFromUI(t)}catch(a){console.error("Cabbage: sendMessageFromUI threw error:",a),console.error("Cabbage: Error stack:",a.stack)}else window.parent!==window?window.parent.postMessage(t,"*"):(console.error("Cabbage: window.sendMessageFromUI is not available yet. Message:",t),console.error("Cabbage: typeof window.sendMessageFromUI:",typeof window.sendMessageFromUI),console.error("Cabbage: window.sendMessageFromUI value:",window.sendMessageFromUI))}}const b=(o,e)=>(...s)=>{e&&console.log(`[Cabbage-React][${o}]`,...s)},U=(o,e)=>{if(!o||e?.skip)return{properties:void 0};const s=d.useMemo(()=>b(`useCabbageProperties:${o}`,e?.debug),[o,e?.debug]),[n,t]=d.useState();return d.useEffect(()=>{const a=r=>{const{id:g,widgetJson:u,command:m}=r.data;if(g===o&&u&&m==="widgetUpdate"){const i=JSON.parse(u);s("Received properties",i),e?.onPropertiesUpdate&&e.onPropertiesUpdate(i),t(i)}};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[o,e?.onPropertiesUpdate]),{properties:n}},y=(o,e)=>{if(!o||e?.skip)return{value:void 0,setValue:()=>{}};const s=d.useMemo(()=>b(`useCabbageState:${o}`,e?.debug),[o,e?.debug]),{properties:n}=U(o,{debug:e?.debug}),[t,a]=d.useState(),[r,g]=d.useState(),u=(i,w="complete")=>{a(i),C.sendControlData({channel:o,value:i,gesture:w})},m=i=>{e?.onValueUpdate&&e.onValueUpdate(i),a(i)};return d.useEffect(()=>{const i=n?.channels.find(c=>c.id===o);if(!i)return;const w=i.parameterIndex;if(r===void 0&&w!==void 0&&(s("Received parameterIndex",w),g(w)),t!==void 0)return;const l=i.range?.value;l!=null&&(s("Received initial value",l),m(l))},[n]),d.useEffect(()=>{const i=w=>{const{command:l}=w.data;if(l==="parameterChange"){const{value:c,paramIdx:f}=w.data.data;if(f!==r||c===null)return;s("Received parameterChange",c),m(c)}else if(l==="batchWidgetUpdate"){const f=w.data.widgets?.find(p=>p.id===o);if(!f)return;const M=JSON.parse(f.widgetJson).channels.find(p=>p.id===o)?.range?.value;s("Received batchWidgetUpdate",M),m(M)}};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)},[o,e?.onValueUpdate,r]),{value:t,setValue:u}},v=(o,e)=>{if(!o||e?.skip)return{message:void 0};const s=b(`useCabbageMessage:${o}`,e?.debug),[n,t]=d.useState();return d.useEffect(()=>{const a=r=>{const{data:g,type:u}=r;!g||u!=="message"||g.type===o&&(s("Received data",g),e?.onMessage&&e.onMessage(g),t(g))};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[o,e?.onMessage]),{message:n}};exports.Cabbage=C;exports.useCabbageMessage=v;exports.useCabbageProperties=U;exports.useCabbageState=y;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { useState as p, useEffect as f } from "react";
2
- class C {
1
+ import { useMemo as C, useState as f, useEffect as p } from "react";
2
+ class y {
3
3
  /**
4
4
  * Send a widget value change to the Cabbage backend.
5
5
  *
@@ -289,13 +289,13 @@ class C {
289
289
  }
290
290
  const M = (o, e) => (...s) => {
291
291
  e && console.log(`[Cabbage-React][${o}]`, ...s);
292
- }, y = (o, e) => {
292
+ }, v = (o, e) => {
293
293
  if (!o || e?.skip) return { properties: void 0 };
294
- const s = M(
295
- `useCabbageProperties:${o}`,
296
- e?.debug
297
- ), [n, t] = p();
298
- return f(() => {
294
+ const s = C(
295
+ () => M(`useCabbageProperties:${o}`, e?.debug),
296
+ [o, e?.debug]
297
+ ), [n, t] = f();
298
+ return p(() => {
299
299
  const a = (r) => {
300
300
  const { id: d, widgetJson: l, command: u } = r.data;
301
301
  if (d === o && l && u === "widgetUpdate") {
@@ -305,17 +305,17 @@ const M = (o, e) => (...s) => {
305
305
  };
306
306
  return window.addEventListener("message", a), () => window.removeEventListener("message", a);
307
307
  }, [o, e?.onPropertiesUpdate]), { properties: n };
308
- }, h = (o, e) => {
308
+ }, L = (o, e) => {
309
309
  if (!o || e?.skip)
310
310
  return { value: void 0, setValue: () => {
311
311
  } };
312
- const s = M(
313
- `useCabbageState:${o}`,
314
- e?.debug
315
- ), { properties: n } = y(o, {
312
+ const s = C(
313
+ () => M(`useCabbageState:${o}`, e?.debug),
314
+ [o, e?.debug]
315
+ ), { properties: n } = v(o, {
316
316
  debug: e?.debug
317
- }), [t, a] = p(), [r, d] = p(), l = (i, g = "complete") => {
318
- a(i), C.sendControlData({
317
+ }), [t, a] = f(), [r, d] = f(), l = (i, g = "complete") => {
318
+ a(i), y.sendControlData({
319
319
  channel: o,
320
320
  value: i,
321
321
  gesture: g
@@ -323,7 +323,7 @@ const M = (o, e) => (...s) => {
323
323
  }, u = (i) => {
324
324
  e?.onValueUpdate && e.onValueUpdate(i), a(i);
325
325
  };
326
- return f(() => {
326
+ return p(() => {
327
327
  const i = n?.channels.find(
328
328
  (c) => c.id === o
329
329
  );
@@ -332,7 +332,7 @@ const M = (o, e) => (...s) => {
332
332
  if (r === void 0 && g !== void 0 && (s("Received parameterIndex", g), d(g)), t !== void 0) return;
333
333
  const w = i.range?.value;
334
334
  w != null && (s("Received initial value", w), u(w));
335
- }, [n]), f(() => {
335
+ }, [n]), p(() => {
336
336
  const i = (g) => {
337
337
  const { command: w } = g.data;
338
338
  if (w === "parameterChange") {
@@ -350,13 +350,13 @@ const M = (o, e) => (...s) => {
350
350
  };
351
351
  return window.addEventListener("message", i), () => window.removeEventListener("message", i);
352
352
  }, [o, e?.onValueUpdate, r]), { value: t, setValue: l };
353
- }, L = (o, e) => {
353
+ }, S = (o, e) => {
354
354
  if (!o || e?.skip) return { message: void 0 };
355
355
  const s = M(
356
356
  `useCabbageMessage:${o}`,
357
357
  e?.debug
358
- ), [n, t] = p();
359
- return f(() => {
358
+ ), [n, t] = f();
359
+ return p(() => {
360
360
  const a = (r) => {
361
361
  const { data: d, type: l } = r;
362
362
  !d || l !== "message" || d.type === o && (s("Received data", d), e?.onMessage && e.onMessage(d), t(d));
@@ -365,8 +365,8 @@ const M = (o, e) => (...s) => {
365
365
  }, [o, e?.onMessage]), { message: n };
366
366
  };
367
367
  export {
368
- C as Cabbage,
369
- L as useCabbageMessage,
370
- y as useCabbageProperties,
371
- h as useCabbageState
368
+ y as Cabbage,
369
+ S as useCabbageMessage,
370
+ v as useCabbageProperties,
371
+ L as useCabbageState
372
372
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cabbage-react",
3
- "version": "1.0.55",
3
+ "version": "1.0.56",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "cabbage",