@adcops/autocore-react 3.3.5 → 3.3.6

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.
@@ -0,0 +1,7 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(npx tsc:*)"
5
+ ]
6
+ }
7
+ }
@@ -176,5 +176,6 @@ export declare const EventEmitterContext: React.Context<EventEmitterContextType>
176
176
  */
177
177
  export declare const EventEmitterProvider: React.FC<{
178
178
  children: ReactNode;
179
+ debug?: boolean;
179
180
  }>;
180
181
  //# sourceMappingURL=EventEmitterContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EventEmitterContext.d.ts","sourceRoot":"","sources":["../../src/core/EventEmitterContext.tsx"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAON,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AACrC,OAAO,EAAa,GAAG,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,GAAG,EAAE,CAAC;AAEf;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,6DAA6D;IAC7D,EAAE,EAAE,MAAM,CAAC;IACX,yDAAyD;IACzD,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;CAC/B;AAED;;;GAGG;AACH,MAAM,WAAW,KAAK;IACpB;;;OAGG;IACH,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,6CAA6C;IAC7C,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;IAE9C,6DAA6D;IAC7D,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM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AgB,EAAE,CAChB,KAAK,CAAC,EAAE,MAAM,KACX,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,YAAY,EAAE,CAAC;IAErD;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC;CAC5B;AAaD,eAAO,MAAM,mBAAmB,wCAa9B,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,QAAQ,EAAE,SAAS,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CA4LnF,CAAC"}
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import React,{createContext,useState,useMemo,useCallback,useRef,useEffect}from"react";import{createHub,Hub}from"../hub";import{MessageType}from"../hub/CommandMessage";export{Hub};const placeholderResponse={data:{},success:!1,error_message:"Context not initialized",transaction_id:0,timecode:0,topic:"",message_type:MessageType.NoOp};export const EventEmitterContext=createContext({state:{subscriptions:{},nextSubscriptionId:1},dispatch:()=>{},subscribe:()=>0,unsubscribe:()=>{},invoke:async()=>placeholderResponse,read:async()=>placeholderResponse,write:async()=>placeholderResponse,serverSubscribe:async(e,t,s)=>placeholderResponse,serverUnsubscribe:async(e,t)=>placeholderResponse,hub:null,getSubscriptions:()=>[],isConnected:()=>!1});export const EventEmitterProvider=({children:e})=>{const[t,s]=useState({subscriptions:{},nextSubscriptionId:1}),r=useMemo(()=>createHub(),[]),c=useRef(1),n=useRef({});useEffect(()=>{s(e=>({...e,subscriptions:{...n.current},nextSubscriptionId:c.current}))},[]);const o=useCallback(e=>{const{topic:t,payload:s}=e,r=n.current[t]?.slice()??[];for(const e of r)try{e.callback(s)}catch(e){}},[]),u=useCallback((e,t)=>{const r=c.current++,o={id:r,callback:t},u=[...n.current[e]??[],o];return n.current={...n.current,[e]:u},s(e=>({...e,subscriptions:{...n.current},nextSubscriptionId:c.current})),r},[]),i=useCallback(e=>{const t={};for(const[s,r]of Object.entries(n.current)){const c=r.filter(t=>t.id!==e);c.length>0&&(t[s]=c)}n.current=t,s(e=>({...e,subscriptions:{...t}}))},[]);useEffect(()=>()=>{n.current={},c.current=1},[]),import.meta&&import.meta.hot&&import.meta.hot.dispose(()=>{n.current={},c.current=1});const a=useCallback((e,t,s)=>r.invoke(e,t,s),[r]),b=useCallback((e,t)=>r.read(e,t),[r]),l=useCallback((e,t)=>r.write(e,t),[r]),p=useCallback((e,t,s)=>r.subscribe(e,t,s),[r]),d=useCallback((e,t)=>r.unsubscribe(e,t),[r]),m=useCallback(()=>r.isConnected(),[r]),f=useMemo(()=>({state:t,dispatch:o,subscribe:u,unsubscribe:i,invoke:a,read:b,write:l,serverSubscribe:p,serverUnsubscribe:d,hub:r,getSubscriptions:e=>e?n.current[e]??[]:n.current,isConnected:m}),[t,r,o,u,i,a,b,l,p,d,m]);return useEffect(()=>{r.setContext(f)},[r,f]),_jsx(EventEmitterContext.Provider,{value:f,children:e})};
1
+ import{jsx as _jsx}from"react/jsx-runtime";import React,{createContext,useState,useMemo,useCallback,useRef,useEffect}from"react";import{createHub,Hub}from"../hub";import{MessageType}from"../hub/CommandMessage";import{enableDebugPanel}from"../hub/DebugPanel";export{Hub};const placeholderResponse={data:{},success:!1,error_message:"Context not initialized",transaction_id:0,timecode:0,topic:"",message_type:MessageType.NoOp};export const EventEmitterContext=createContext({state:{subscriptions:{},nextSubscriptionId:1},dispatch:()=>{},subscribe:()=>0,unsubscribe:()=>{},invoke:async()=>placeholderResponse,read:async()=>placeholderResponse,write:async()=>placeholderResponse,serverSubscribe:async(e,t,s)=>placeholderResponse,serverUnsubscribe:async(e,t)=>placeholderResponse,hub:null,getSubscriptions:()=>[],isConnected:()=>!1});export const EventEmitterProvider=({children:e,debug:t=!1})=>{t&&enableDebugPanel();const[s,r]=useState({subscriptions:{},nextSubscriptionId:1}),c=useMemo(()=>createHub(),[]),n=useRef(1),o=useRef({});useEffect(()=>{r(e=>({...e,subscriptions:{...o.current},nextSubscriptionId:n.current}))},[]);const u=useCallback(e=>{const{topic:t,payload:s}=e,r=o.current[t]?.slice()??[];for(const e of r)try{e.callback(s)}catch(e){}},[]),a=useCallback((e,t)=>{const s=n.current++,c={id:s,callback:t},u=[...o.current[e]??[],c];return o.current={...o.current,[e]:u},r(e=>({...e,subscriptions:{...o.current},nextSubscriptionId:n.current})),s},[]),i=useCallback(e=>{const t={};for(const[s,r]of Object.entries(o.current)){const c=r.filter(t=>t.id!==e);c.length>0&&(t[s]=c)}o.current=t,r(e=>({...e,subscriptions:{...t}}))},[]);useEffect(()=>()=>{o.current={},n.current=1},[]),import.meta&&import.meta.hot&&import.meta.hot.dispose(()=>{o.current={},n.current=1});const b=useCallback((e,t,s)=>c.invoke(e,t,s),[c]),l=useCallback((e,t)=>c.read(e,t),[c]),p=useCallback((e,t)=>c.write(e,t),[c]),d=useCallback((e,t,s)=>c.subscribe(e,t,s),[c]),m=useCallback((e,t)=>c.unsubscribe(e,t),[c]),f=useCallback(()=>c.isConnected(),[c]),C=useMemo(()=>({state:s,dispatch:u,subscribe:a,unsubscribe:i,invoke:b,read:l,write:p,serverSubscribe:d,serverUnsubscribe:m,hub:c,getSubscriptions:e=>e?o.current[e]??[]:o.current,isConnected:f}),[s,c,u,a,i,b,l,p,d,m,f]);return useEffect(()=>{c.setContext(C)},[c,C]),_jsx(EventEmitterContext.Provider,{value:C,children:e})};
@@ -26,6 +26,17 @@ declare class DebugPanel {
26
26
  messageReceived(type: string, command: string, requestId?: number): void;
27
27
  updateState(state: string): void;
28
28
  }
29
+ /**
30
+ * Returns the current debug panel instance.
31
+ * If the panel has not been enabled, returns a no-op stub so callers
32
+ * don't need to guard every call.
33
+ */
29
34
  export declare function getDebugPanel(): DebugPanel;
35
+ /**
36
+ * Enables the debug panel, injecting it into the DOM.
37
+ * Subsequent calls to `getDebugPanel()` will return the real panel.
38
+ * Safe to call multiple times — only creates one panel.
39
+ */
40
+ export declare function enableDebugPanel(): void;
30
41
  export default getDebugPanel;
31
42
  //# sour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E,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAIjC;AAsBD;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAE1C;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAMvC;AAED,eAAe,aAAa,CAAC"}
@@ -1 +1 @@
1
- class DebugPanel{constructor(){Object.defineProperty(this,"container",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"logContainer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"statsContainer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"logs",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"maxLogs",{enumerable:!0,configurable:!0,writable:!0,value:100}),Object.defineProperty(this,"stats",{enumerable:!0,configurable:!0,writable:!0,value:{hubInstancesCreated:0,connectCalls:0,wsOpened:0,wsClosed:0,wsErrors:0,messagesSent:0,messagesReceived:0,currentState:"unknown"}}),this.injectPanel(),this.log("info","DebugPanel","Debug panel initialized")}injectPanel(){const e=document.getElementById("autocore-debug-panel");e&&e.remove(),this.container=document.createElement("div"),this.container.id="autocore-debug-panel",this.container.innerHTML='\n <style>\n #autocore-debug-panel {\n position: fixed;\n bottom: 10px;\n right: 10px;\n width: 400px;\n max-height: 300px;\n background: rgba(0, 0, 0, 0.9);\n color: #0f0;\n font-family: monospace;\n font-size: 11px;\n border: 1px solid #0f0;\n border-radius: 4px;\n z-index: 99999;\n overflow: hidden;\n }\n #autocore-debug-panel .header {\n background: #0f0;\n color: #000;\n padding: 4px 8px;\n font-weight: bold;\n cursor: pointer;\n display: flex;\n justify-content: space-between;\n }\n #autocore-debug-panel .stats {\n padding: 4px 8px;\n border-bottom: 1px solid #0f0;\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 2px;\n }\n #autocore-debug-panel .stats span {\n color: #fff;\n }\n #autocore-debug-panel .stats .value {\n color: #ff0;\n }\n #autocore-debug-panel .logs {\n max-height: 180px;\n overflow-y: auto;\n padding: 4px;\n }\n #autocore-debug-panel .log-entry {\n margin: 1px 0;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n #autocore-debug-panel .log-entry.info { color: #888; }\n #autocore-debug-panel .log-entry.warn { color: #fa0; }\n #autocore-debug-panel .log-entry.error { color: #f44; }\n #autocore-debug-panel .log-entry.send { color: #4f4; }\n #autocore-debug-panel .log-entry.recv { color: #44f; }\n #autocore-debug-panel .state-connected { color: #4f4 !important; }\n #autocore-debug-panel .state-disconnected { color: #f44 !important; }\n #autocore-debug-panel .state-connecting { color: #fa0 !important; }\n </style>\n <div class="header">\n <span>AutoCore Debug</span>\n <span id="debug-toggle">[_]</span>\n </div>\n <div id="debug-content">\n <div class="stats" id="debug-stats"></div>\n <div class="logs" id="debug-logs"></div>\n </div>\n ',document.body?(document.body.appendChild(this.container),this.setupElements()):document.addEventListener("DOMContentLoaded",()=>{document.body.appendChild(this.container),this.setupElements()})}setupElements(){this.statsContainer=document.getElementById("debug-stats"),this.logContainer=document.getElementById("debug-logs");const e=document.getElementById("debug-toggle"),t=document.getElementById("debug-content");e?.addEventListener("click",()=>{t&&(t.style.display="none"===t.style.display?"block":"none",e.textContent="none"===t.style.display?"[+]":"[_]")}),this.updateStats()}updateStats(){if(!this.statsContainer)return;const e="OPEN"===this.stats.currentState?"state-connected":"CONNECTING"===this.stats.currentState?"state-connecting":"state-disconnected";this.statsContainer.innerHTML=`\n <div><span>Hub Instances:</span> <span class="value">${this.stats.hubInstancesCreated}</span></div>\n <div><span>connect() calls:</span> <span class="value">${this.stats.connectCalls}</span></div>\n <div><span>WS Opened:</span> <span class="value">${this.stats.wsOpened}</span></div>\n <div><span>WS Closed:</span> <span class="value">${this.stats.wsClosed}</span></div>\n <div><span>WS Errors:</span> <span class="value">${this.stats.wsErrors}</span></div>\n <div><span>Msgs Sent:</span> <span class="value">${this.stats.messagesSent}</span></div>\n <div><span>Msgs Recv:</span> <span class="value">${this.stats.messagesReceived}</span></div>\n <div><span>WS State:</span> <span class="value ${e}">${this.stats.currentState}</span></div>\n `}log(e,t,n){const s=(new Date).toTimeString().slice(0,8),a={time:s,type:e,source:t,message:n};this.logs.push(a),this.logs.length>this.maxLogs&&this.logs.shift();this.renderLogs()}renderLogs(){this.logContainer&&(this.logContainer.innerHTML=this.logs.slice(-50).map(e=>`<div class="log-entry ${e.type}">[${e.time}] ${e.source}: ${e.message}</div>`).join(""),this.logContainer.scrollTop=this.logContainer.scrollHeight)}hubCreated(){this.stats.hubInstancesCreated++,this.log("warn","Hub",`NEW INSTANCE CREATED (total: ${this.stats.hubInstancesCreated})`),this.updateStats()}connectCalled(e){this.stats.connectCalls++,this.stats.currentState=e,this.log("info","Hub",`connect() called (socket state: ${e})`),this.updateStats()}wsOpened(e){this.stats.wsOpened++,this.stats.currentState="OPEN",this.log("info","WS",`OPENED: ${e}`),this.updateStats()}wsClosed(e,t){this.stats.wsClosed++,this.stats.currentState="CLOSED",this.log("warn","WS",`CLOSED: code=${e}, reason=${t}`),this.updateStats()}wsError(e){this.stats.wsErrors++,this.log("error","WS",`ERROR: ${e}`),this.updateStats()}messageSent(e,t,n){this.stats.messagesSent++,this.log("send","WS",`>>> ${e}/${t} (id=${n})`),this.updateStats()}messageReceived(e,t,n){this.stats.messagesReceived++,this.log("recv","WS",`<<< ${e}/${t} (id=${n??"none"})`),this.updateStats()}updateState(e){this.stats.currentState=e,this.updateStats()}}let debugPanel=null;export function getDebugPanel(){return debugPanel||(debugPanel=new DebugPanel,window.__AUTOCORE_DEBUG_PANEL__=debugPanel),debugPanel}getDebugPanel();export default getDebugPanel;
1
+ class DebugPanel{constructor(){Object.defineProperty(this,"container",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"logContainer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"statsContainer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"logs",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"maxLogs",{enumerable:!0,configurable:!0,writable:!0,value:100}),Object.defineProperty(this,"stats",{enumerable:!0,configurable:!0,writable:!0,value:{hubInstancesCreated:0,connectCalls:0,wsOpened:0,wsClosed:0,wsErrors:0,messagesSent:0,messagesReceived:0,currentState:"unknown"}}),this.injectPanel(),this.log("info","DebugPanel","Debug panel initialized")}injectPanel(){const e=document.getElementById("autocore-debug-panel");e&&e.remove(),this.container=document.createElement("div"),this.container.id="autocore-debug-panel",this.container.innerHTML='\n <style>\n #autocore-debug-panel {\n position: fixed;\n bottom: 10px;\n right: 10px;\n width: 400px;\n max-height: 300px;\n background: rgba(0, 0, 0, 0.9);\n color: #0f0;\n font-family: monospace;\n font-size: 11px;\n border: 1px solid #0f0;\n border-radius: 4px;\n z-index: 99999;\n overflow: hidden;\n }\n #autocore-debug-panel .header {\n background: #0f0;\n color: #000;\n padding: 4px 8px;\n font-weight: bold;\n cursor: pointer;\n display: flex;\n justify-content: space-between;\n }\n #autocore-debug-panel .stats {\n padding: 4px 8px;\n border-bottom: 1px solid #0f0;\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 2px;\n }\n #autocore-debug-panel .stats span {\n color: #fff;\n }\n #autocore-debug-panel .stats .value {\n color: #ff0;\n }\n #autocore-debug-panel .logs {\n max-height: 180px;\n overflow-y: auto;\n padding: 4px;\n }\n #autocore-debug-panel .log-entry {\n margin: 1px 0;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n #autocore-debug-panel .log-entry.info { color: #888; }\n #autocore-debug-panel .log-entry.warn { color: #fa0; }\n #autocore-debug-panel .log-entry.error { color: #f44; }\n #autocore-debug-panel .log-entry.send { color: #4f4; }\n #autocore-debug-panel .log-entry.recv { color: #44f; }\n #autocore-debug-panel .state-connected { color: #4f4 !important; }\n #autocore-debug-panel .state-disconnected { color: #f44 !important; }\n #autocore-debug-panel .state-connecting { color: #fa0 !important; }\n </style>\n <div class="header">\n <span>AutoCore Debug</span>\n <span id="debug-toggle">[_]</span>\n </div>\n <div id="debug-content">\n <div class="stats" id="debug-stats"></div>\n <div class="logs" id="debug-logs"></div>\n </div>\n ',document.body?(document.body.appendChild(this.container),this.setupElements()):document.addEventListener("DOMContentLoaded",()=>{document.body.appendChild(this.container),this.setupElements()})}setupElements(){this.statsContainer=document.getElementById("debug-stats"),this.logContainer=document.getElementById("debug-logs");const e=document.getElementById("debug-toggle"),t=document.getElementById("debug-content");e?.addEventListener("click",()=>{t&&(t.style.display="none"===t.style.display?"block":"none",e.textContent="none"===t.style.display?"[+]":"[_]")}),this.updateStats()}updateStats(){if(!this.statsContainer)return;const e="OPEN"===this.stats.currentState?"state-connected":"CONNECTING"===this.stats.currentState?"state-connecting":"state-disconnected";this.statsContainer.innerHTML=`\n <div><span>Hub Instances:</span> <span class="value">${this.stats.hubInstancesCreated}</span></div>\n <div><span>connect() calls:</span> <span class="value">${this.stats.connectCalls}</span></div>\n <div><span>WS Opened:</span> <span class="value">${this.stats.wsOpened}</span></div>\n <div><span>WS Closed:</span> <span class="value">${this.stats.wsClosed}</span></div>\n <div><span>WS Errors:</span> <span class="value">${this.stats.wsErrors}</span></div>\n <div><span>Msgs Sent:</span> <span class="value">${this.stats.messagesSent}</span></div>\n <div><span>Msgs Recv:</span> <span class="value">${this.stats.messagesReceived}</span></div>\n <div><span>WS State:</span> <span class="value ${e}">${this.stats.currentState}</span></div>\n `}log(e,t,n){const s=(new Date).toTimeString().slice(0,8),a={time:s,type:e,source:t,message:n};this.logs.push(a),this.logs.length>this.maxLogs&&this.logs.shift();this.renderLogs()}renderLogs(){this.logContainer&&(this.logContainer.innerHTML=this.logs.slice(-50).map(e=>`<div class="log-entry ${e.type}">[${e.time}] ${e.source}: ${e.message}</div>`).join(""),this.logContainer.scrollTop=this.logContainer.scrollHeight)}hubCreated(){this.stats.hubInstancesCreated++,this.log("warn","Hub",`NEW INSTANCE CREATED (total: ${this.stats.hubInstancesCreated})`),this.updateStats()}connectCalled(e){this.stats.connectCalls++,this.stats.currentState=e,this.log("info","Hub",`connect() called (socket state: ${e})`),this.updateStats()}wsOpened(e){this.stats.wsOpened++,this.stats.currentState="OPEN",this.log("info","WS",`OPENED: ${e}`),this.updateStats()}wsClosed(e,t){this.stats.wsClosed++,this.stats.currentState="CLOSED",this.log("warn","WS",`CLOSED: code=${e}, reason=${t}`),this.updateStats()}wsError(e){this.stats.wsErrors++,this.log("error","WS",`ERROR: ${e}`),this.updateStats()}messageSent(e,t,n){this.stats.messagesSent++,this.log("send","WS",`>>> ${e}/${t} (id=${n})`),this.updateStats()}messageReceived(e,t,n){this.stats.messagesReceived++,this.log("recv","WS",`<<< ${e}/${t} (id=${n??"none"})`),this.updateStats()}updateState(e){this.stats.currentState=e,this.updateStats()}}const noOpPanel={log(){},hubCreated(){},connectCalled(){},wsOpened(){},wsClosed(){},wsError(){},messageSent(){},messageReceived(){},updateState(){}};let debugPanel=noOpPanel,debugEnabled=!1;export function getDebugPanel(){return debugPanel}export function enableDebugPanel(){debugEnabled||(debugEnabled=!0,debugPanel=new DebugPanel,window.__AUTOCORE_DEBUG_PANEL__=debugPanel)}export default getDebugPanel;
@@ -28,4 +28,5 @@ export { HubWebSocket };
28
28
  export { HubSimulate };
29
29
  export type { CommandMessage } from './CommandMessage';
30
30
  export { MessageType } from './CommandMessage';
31
+ export { enableDebugPanel } from './DebugPanel';
31
32
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hub/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAW5C;;;;;;;;GAQG;AACH,wBAAgB,SAAS,IAAI,GAAG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ase as Hub}from"./HubBase";import{HubTauri}from"./HubTauri";import{HubWebSocket}from"./HubWebSocket";import{HubSimulate}from"./HubSimulate";import{getDebugPanel}from"./DebugPanel";let hubInstance=null;export function createHub(){const e=getDebugPanel();return e.log("info","createHub",`called (hasInstance: ${!!hubInstance})`),hubInstance?e.log("info","createHub","Returning existing hub instance"):"undefined"!=typeof window&&void 0!==window.__TAURI__&&null!==window.__TAURI__?(e.log("info","createHub","Creating HubTauri instance"),hubInstance=new HubTauri):(e.log("info","createHub","Creating HubWebSocket instance"),hubInstance=new HubWebSocket),hubInstance}export function getHubInstance(){return hubInstance}export function resetHub(){hubInstance=null}export{HubBase as Hub}from"./HubBase";export{HubTauri};export{HubWebSocket};export{HubSimulate};export{MessageType}from"./CommandMessage";
1
+ import{HubBase as Hub}from"./HubBase";import{HubTauri}from"./HubTauri";import{HubWebSocket}from"./HubWebSocket";import{HubSimulate}from"./HubSimulate";import{getDebugPanel}from"./DebugPanel";let hubInstance=null;export function createHub(){const e=getDebugPanel();return e.log("info","createHub",`called (hasInstance: ${!!hubInstance})`),hubInstance?e.log("info","createHub","Returning existing hub instance"):"undefined"!=typeof window&&void 0!==window.__TAURI__&&null!==window.__TAURI__?(e.log("info","createHub","Creating HubTauri instance"),hubInstance=new HubTauri):(e.log("info","createHub","Creating HubWebSocket instance"),hubInstance=new HubWebSocket),hubInstance}export function getHubInstance(){return hubInstance}export function resetHub(){hubInstance=null}export{HubBase as Hub}from"./HubBase";export{HubTauri};export{HubWebSocket};export{HubSimulate};export{MessageType}from"./CommandMessage";export{enableDebugPanel}from"./DebugPanel";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adcops/autocore-react",
3
- "version": "3.3.5",
3
+ "version": "3.3.6",
4
4
  "description": "A React component library for industrial user interfaces.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -56,6 +56,7 @@ import type {ReactNode} from "react";
56
56
  import { createHub, Hub } from "../hub";
57
57
  import type { CommandMessage } from "../hub";
58
58
  import { MessageType } from "../hub/CommandMessage";
59
+ import { enableDebugPanel } from "../hub/DebugPanel";
59
60
 
60
61
  export { Hub };
61
62
 
@@ -243,11 +244,17 @@ export const EventEmitterContext = createContext<EventEmitterContextType>({
243
244
  *
244
245
  * @param children The child components to be wrapped in the context.
245
246
  */
246
- export const EventEmitterProvider: React.FC<{ children: ReactNode }> = ({
247
+ export const EventEmitterProvider: React.FC<{ children: ReactNode; debug?: boolean }> = ({
247
248
  children,
249
+ debug = false,
248
250
  }) => {
249
251
  console.log("[EventEmitterProvider] Rendering...");
250
252
 
253
+ // Enable the debug panel if requested (must run before Hub creation)
254
+ if (debug) {
255
+ enableDebugPanel();
256
+ }
257
+
251
258
  const [state, setState] = useState<State>({
252
259
  subscriptions: {},
253
260
  nextSubscriptionId: 1,
@@ -262,19 +262,46 @@ class DebugPanel {
262
262
  }
263
263
  }
264
264
 
265
- // Create singleton and expose globally
266
- let debugPanel: DebugPanel | null = null;
267
-
265
+ /**
266
+ * No-op stub that satisfies the DebugPanel interface without injecting any DOM elements.
267
+ * Used when the debug panel is not enabled.
268
+ */
269
+ const noOpPanel: DebugPanel = {
270
+ log() {},
271
+ hubCreated() {},
272
+ connectCalled() {},
273
+ wsOpened() {},
274
+ wsClosed() {},
275
+ wsError() {},
276
+ messageSent() {},
277
+ messageReceived() {},
278
+ updateState() {},
279
+ } as unknown as DebugPanel;
280
+
281
+ // Singleton instance — starts as the no-op stub
282
+ let debugPanel: DebugPanel = noOpPanel;
283
+ let debugEnabled = false;
284
+
285
+ /**
286
+ * Returns the current debug panel instance.
287
+ * If the panel has not been enabled, returns a no-op stub so callers
288
+ * don't need to guard every call.
289
+ */
268
290
  export function getDebugPanel(): DebugPanel {
269
- if (!debugPanel) {
291
+ return debugPanel;
292
+ }
293
+
294
+ /**
295
+ * Enables the debug panel, injecting it into the DOM.
296
+ * Subsequent calls to `getDebugPanel()` will return the real panel.
297
+ * Safe to call multiple times — only creates one panel.
298
+ */
299
+ export function enableDebugPanel(): void {
300
+ if (!debugEnabled) {
301
+ debugEnabled = true;
270
302
  debugPanel = new DebugPanel();
271
- // Expose globally for console access
272
303
  (window as any).__AUTOCORE_DEBUG_PANEL__ = debugPanel;
273
304
  }
274
- return debugPanel;
275
305
  }
276
306
 
277
- // Auto-initialize on import
278
- getDebugPanel();
279
-
280
307
  export default getDebugPanel;
package/src/hub/index.ts CHANGED
@@ -76,4 +76,7 @@ export { HubSimulate };
76
76
 
77
77
  // Export CommandMessage types
78
78
  export type { CommandMessage } from './CommandMessage';
79
- export { MessageType } from './CommandMessage';
79
+ export { MessageType } from './CommandMessage';
80
+
81
+ // Export DebugPanel utilities
82
+ export { enableDebugPanel } from './DebugPanel';