@adcops/autocore-react 3.0.40 → 3.3.2

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.
Files changed (296) hide show
  1. package/additional-docs/AutoCoreTagContext.md +441 -0
  2. package/additional-docs/react_performance_notes.md +94 -0
  3. package/dist/assets/BlocklyLogo.d.ts +1 -0
  4. package/dist/assets/BlocklyLogo.d.ts.map +1 -0
  5. package/dist/assets/Distance.d.ts +1 -0
  6. package/dist/assets/Distance.d.ts.map +1 -0
  7. package/dist/assets/JogLong.d.ts +1 -0
  8. package/dist/assets/JogLong.d.ts.map +1 -0
  9. package/dist/assets/JogMedium.d.ts +1 -0
  10. package/dist/assets/JogMedium.d.ts.map +1 -0
  11. package/dist/assets/JogShort.d.ts +1 -0
  12. package/dist/assets/JogShort.d.ts.map +1 -0
  13. package/dist/assets/PythonLogo.d.ts +1 -0
  14. package/dist/assets/PythonLogo.d.ts.map +1 -0
  15. package/dist/assets/Rotation3D.d.ts +1 -0
  16. package/dist/assets/Rotation3D.d.ts.map +1 -0
  17. package/dist/assets/RotationCcw.d.ts +1 -0
  18. package/dist/assets/RotationCcw.d.ts.map +1 -0
  19. package/dist/assets/RotationCcwA.d.ts +1 -0
  20. package/dist/assets/RotationCcwA.d.ts.map +1 -0
  21. package/dist/assets/RotationCcwB.d.ts +1 -0
  22. package/dist/assets/RotationCcwB.d.ts.map +1 -0
  23. package/dist/assets/RotationCcwC.d.ts +1 -0
  24. package/dist/assets/RotationCcwC.d.ts.map +1 -0
  25. package/dist/assets/RotationCw.d.ts +1 -0
  26. package/dist/assets/RotationCw.d.ts.map +1 -0
  27. package/dist/assets/RotationCwA.d.ts +1 -0
  28. package/dist/assets/RotationCwA.d.ts.map +1 -0
  29. package/dist/assets/RotationCwB.d.ts +1 -0
  30. package/dist/assets/RotationCwB.d.ts.map +1 -0
  31. package/dist/assets/RotationCwC.d.ts +1 -0
  32. package/dist/assets/RotationCwC.d.ts.map +1 -0
  33. package/dist/assets/Run.d.ts +1 -0
  34. package/dist/assets/Run.d.ts.map +1 -0
  35. package/dist/assets/Speed.d.ts +1 -0
  36. package/dist/assets/Speed.d.ts.map +1 -0
  37. package/dist/assets/SpeedFast.d.ts +1 -0
  38. package/dist/assets/SpeedFast.d.ts.map +1 -0
  39. package/dist/assets/SpeedMedium.d.ts +1 -0
  40. package/dist/assets/SpeedMedium.d.ts.map +1 -0
  41. package/dist/assets/SpeedNone.d.ts +1 -0
  42. package/dist/assets/SpeedNone.d.ts.map +1 -0
  43. package/dist/assets/SpeedSlow.d.ts +1 -0
  44. package/dist/assets/SpeedSlow.d.ts.map +1 -0
  45. package/dist/assets/Walk.d.ts +1 -0
  46. package/dist/assets/Walk.d.ts.map +1 -0
  47. package/dist/assets/index.d.ts +1 -0
  48. package/dist/assets/index.d.ts.map +1 -0
  49. package/dist/components/AutoCoreDevPanel.d.ts +144 -0
  50. package/dist/components/AutoCoreDevPanel.d.ts.map +1 -0
  51. package/dist/components/AutoCoreDevPanel.js +1 -0
  52. package/dist/components/BlocklyEditor.d.ts +1 -0
  53. package/dist/components/BlocklyEditor.d.ts.map +1 -0
  54. package/dist/components/BlocklyEditor.js +1 -1
  55. package/dist/components/CodeEditor.d.ts +2 -1
  56. package/dist/components/CodeEditor.d.ts.map +1 -0
  57. package/dist/components/CodeEditor.js +1 -1
  58. package/dist/components/FileList.d.ts +1 -0
  59. package/dist/components/FileList.d.ts.map +1 -0
  60. package/dist/components/FileList.js +1 -1
  61. package/dist/components/FileSelect.d.ts +1 -0
  62. package/dist/components/FileSelect.d.ts.map +1 -0
  63. package/dist/components/FileSelect.js +1 -1
  64. package/dist/components/FitText.d.ts +1 -0
  65. package/dist/components/FitText.d.ts.map +1 -0
  66. package/dist/components/FitText.js +1 -1
  67. package/dist/components/Indicator.d.ts +2 -1
  68. package/dist/components/Indicator.d.ts.map +1 -0
  69. package/dist/components/Indicator.js +1 -1
  70. package/dist/components/IndicatorButton.d.ts +2 -1
  71. package/dist/components/IndicatorButton.d.ts.map +1 -0
  72. package/dist/components/IndicatorButton.js +1 -1
  73. package/dist/components/IndicatorRect.d.ts +2 -1
  74. package/dist/components/IndicatorRect.d.ts.map +1 -0
  75. package/dist/components/JogPanel.d.ts +1 -0
  76. package/dist/components/JogPanel.d.ts.map +1 -0
  77. package/dist/components/Lamp.d.ts +2 -1
  78. package/dist/components/Lamp.d.ts.map +1 -0
  79. package/dist/components/Lamp.js +1 -1
  80. package/dist/components/Osk.d.ts +1 -0
  81. package/dist/components/Osk.d.ts.map +1 -0
  82. package/dist/components/Osk.js +1 -1
  83. package/dist/components/OskDialog.d.ts +1 -0
  84. package/dist/components/OskDialog.d.ts.map +1 -0
  85. package/dist/components/ProgressBarWithValue.d.ts +1 -0
  86. package/dist/components/ProgressBarWithValue.d.ts.map +1 -0
  87. package/dist/components/ProgressBarWithValue.js +1 -1
  88. package/dist/components/TextInput.d.ts +62 -103
  89. package/dist/components/TextInput.d.ts.map +1 -0
  90. package/dist/components/TextInput.js +1 -1
  91. package/dist/components/ToggleGroup.d.ts +2 -1
  92. package/dist/components/ToggleGroup.d.ts.map +1 -0
  93. package/dist/components/ToggleGroup.js +1 -1
  94. package/dist/components/ValueDisplay.d.ts +3 -2
  95. package/dist/components/ValueDisplay.d.ts.map +1 -0
  96. package/dist/components/ValueDisplay.js +1 -1
  97. package/dist/components/ValueIndicator.d.ts +2 -1
  98. package/dist/components/ValueIndicator.d.ts.map +1 -0
  99. package/dist/components/ValueIndicator.js +1 -1
  100. package/dist/components/ValueInput.d.ts +2 -1
  101. package/dist/components/ValueInput.d.ts.map +1 -0
  102. package/dist/components/ValueInput.js +1 -1
  103. package/dist/core/ActionMode.d.ts +1 -0
  104. package/dist/core/ActionMode.d.ts.map +1 -0
  105. package/dist/core/AutoCoreTagContext.d.ts +98 -0
  106. package/dist/core/AutoCoreTagContext.d.ts.map +1 -0
  107. package/dist/core/AutoCoreTagContext.js +1 -0
  108. package/dist/core/AutoCoreTagTypes.d.ts +283 -0
  109. package/dist/core/AutoCoreTagTypes.d.ts.map +1 -0
  110. package/dist/core/AutoCoreTagTypes.js +1 -0
  111. package/dist/core/CoreStreamTypes.d.ts +345 -0
  112. package/dist/core/CoreStreamTypes.d.ts.map +1 -0
  113. package/dist/core/CoreStreamTypes.js +1 -0
  114. package/dist/core/EventEmitterContext.d.ts +113 -202
  115. package/dist/core/EventEmitterContext.d.ts.map +1 -0
  116. package/dist/core/EventEmitterContext.js +1 -1
  117. package/dist/core/IndicatorButtonState.d.ts +1 -0
  118. package/dist/core/IndicatorButtonState.d.ts.map +1 -0
  119. package/dist/core/IndicatorColor.d.ts +1 -0
  120. package/dist/core/IndicatorColor.d.ts.map +1 -0
  121. package/dist/core/MaskPatterns.d.ts +1 -0
  122. package/dist/core/MaskPatterns.d.ts.map +1 -0
  123. package/dist/core/NumerableTypes.d.ts +1 -0
  124. package/dist/core/NumerableTypes.d.ts.map +1 -0
  125. package/dist/core/NumerableTypes.js +1 -1
  126. package/dist/core/PositionContext.d.ts +1 -1
  127. package/dist/core/PositionContext.d.ts.map +1 -0
  128. package/dist/core/UniqueId.d.ts +1 -0
  129. package/dist/core/UniqueId.d.ts.map +1 -0
  130. package/dist/core/ValueSimulator.d.ts +2 -1
  131. package/dist/core/ValueSimulator.d.ts.map +1 -0
  132. package/dist/core/ValueSimulator.js +1 -1
  133. package/dist/core/hoc.d.ts +1 -0
  134. package/dist/core/hoc.d.ts.map +1 -0
  135. package/dist/core/hoc.js +1 -1
  136. package/dist/hooks/adsHooks.d.ts +1 -0
  137. package/dist/hooks/adsHooks.d.ts.map +1 -0
  138. package/dist/hooks/adsHooks.js +1 -1
  139. package/dist/hooks/commandHooks.d.ts +4 -3
  140. package/dist/hooks/commandHooks.d.ts.map +1 -0
  141. package/dist/hooks/commandHooks.js +1 -1
  142. package/dist/hooks/index.d.ts +1 -0
  143. package/dist/hooks/index.d.ts.map +1 -0
  144. package/dist/hooks/useAutoCoreTag.d.ts +26 -0
  145. package/dist/hooks/useAutoCoreTag.d.ts.map +1 -0
  146. package/dist/hooks/useAutoCoreTag.js +1 -0
  147. package/dist/hooks/useScaledValue.d.ts +1 -0
  148. package/dist/hooks/useScaledValue.d.ts.map +1 -0
  149. package/dist/hooks/useScaledValue.js +1 -1
  150. package/dist/hub/CommandMessage.d.ts +19 -9
  151. package/dist/hub/CommandMessage.d.ts.map +1 -0
  152. package/dist/hub/CommandMessage.js +1 -1
  153. package/dist/hub/DebugPanel.d.ts +31 -0
  154. package/dist/hub/DebugPanel.d.ts.map +1 -0
  155. package/dist/hub/DebugPanel.js +1 -0
  156. package/dist/hub/HubBase.d.ts +85 -130
  157. package/dist/hub/HubBase.d.ts.map +1 -0
  158. package/dist/hub/HubBase.js +1 -1
  159. package/dist/hub/HubSimulate.d.ts +42 -8
  160. package/dist/hub/HubSimulate.d.ts.map +1 -0
  161. package/dist/hub/HubSimulate.js +1 -1
  162. package/dist/hub/HubTauri.d.ts +25 -60
  163. package/dist/hub/HubTauri.d.ts.map +1 -0
  164. package/dist/hub/HubTauri.js +1 -1
  165. package/dist/hub/HubWebSocket.d.ts +34 -17
  166. package/dist/hub/HubWebSocket.d.ts.map +1 -0
  167. package/dist/hub/HubWebSocket.js +1 -1
  168. package/dist/hub/debug.d.ts +23 -0
  169. package/dist/hub/debug.d.ts.map +1 -0
  170. package/dist/hub/debug.js +1 -0
  171. package/dist/hub/index.d.ts +20 -4
  172. package/dist/hub/index.d.ts.map +1 -0
  173. package/dist/hub/index.js +1 -1
  174. package/package.json +32 -27
  175. package/readme.md +193 -22
  176. package/src/components/AutoCoreDevPanel.tsx +414 -0
  177. package/src/components/CodeEditor.tsx +2 -2
  178. package/src/components/FileList.tsx +7 -6
  179. package/src/components/FileSelect.tsx +2 -1
  180. package/src/components/Indicator.tsx +2 -2
  181. package/src/components/IndicatorButton.tsx +2 -2
  182. package/src/components/IndicatorRect.tsx +2 -2
  183. package/src/components/Lamp.tsx +3 -3
  184. package/src/components/TextInput.tsx +159 -240
  185. package/src/components/ToggleGroup.tsx +3 -3
  186. package/src/components/ValueDisplay.tsx +4 -4
  187. package/src/components/ValueIndicator.tsx +2 -2
  188. package/src/components/ValueInput.tsx +2 -2
  189. package/src/core/ActionMode.ts +1 -1
  190. package/src/core/AutoCoreTagContext.tsx +615 -0
  191. package/src/core/AutoCoreTagTypes.ts +334 -0
  192. package/src/core/CoreStreamTypes.ts +512 -0
  193. package/src/core/EventEmitterContext.tsx +257 -281
  194. package/src/core/IndicatorButtonState.ts +1 -1
  195. package/src/core/ValueSimulator.ts +2 -2
  196. package/src/core/hoc.tsx +1 -1
  197. package/src/hooks/adsHooks.tsx +21 -22
  198. package/src/hooks/commandHooks.tsx +23 -19
  199. package/src/hooks/index.ts +1 -1
  200. package/src/hooks/useAutoCoreTag.ts +103 -0
  201. package/src/hooks/useScaledValue.tsx +1 -1
  202. package/src/hub/CommandMessage.ts +71 -19
  203. package/src/hub/DebugPanel.ts +280 -0
  204. package/src/hub/HubBase.ts +147 -223
  205. package/src/hub/HubSimulate.ts +93 -24
  206. package/src/hub/HubTauri.ts +87 -96
  207. package/src/hub/HubWebSocket.ts +133 -158
  208. package/src/hub/debug.ts +211 -0
  209. package/src/hub/index.ts +49 -39
  210. package/tsconfig.json +43 -28
  211. package/docs/classes/components_BlocklyEditor.BlocklyEditor.html +0 -124
  212. package/docs/classes/components_CodeEditor.CodeEditor.html +0 -128
  213. package/docs/classes/components_JogPanel.JogPanel.html +0 -138
  214. package/docs/classes/components_Lamp.Lamp.html +0 -105
  215. package/docs/classes/components_TextInput.TextInput.html +0 -115
  216. package/docs/classes/components_ValueIndicator.ValueIndicator.html +0 -119
  217. package/docs/classes/components_ValueInput.ValueInput.html +0 -113
  218. package/docs/classes/hub_HubWebSocket.HubWebSocket.html +0 -106
  219. package/docs/enums/components_JogPanel.JogDistanceAction.html +0 -5
  220. package/docs/enums/components_JogPanel.JogPanelAction.html +0 -18
  221. package/docs/enums/components_JogPanel.JogSpeedAction.html +0 -5
  222. package/docs/enums/core_ActionMode.ActionMode.html +0 -6
  223. package/docs/enums/core_IndicatorColor.IndicatorColor.html +0 -23
  224. package/docs/functions/assets_BlocklyLogo.default.html +0 -1
  225. package/docs/functions/assets_Distance.default.html +0 -1
  226. package/docs/functions/assets_JogLong.default.html +0 -1
  227. package/docs/functions/assets_JogMedium.default.html +0 -1
  228. package/docs/functions/assets_JogShort.default.html +0 -1
  229. package/docs/functions/assets_PythonLogo.default.html +0 -1
  230. package/docs/functions/assets_Rotation3D.default.html +0 -1
  231. package/docs/functions/assets_RotationCcw.default.html +0 -1
  232. package/docs/functions/assets_RotationCcwA.default.html +0 -1
  233. package/docs/functions/assets_RotationCcwB.default.html +0 -1
  234. package/docs/functions/assets_RotationCcwC.default.html +0 -1
  235. package/docs/functions/assets_RotationCw.default.html +0 -1
  236. package/docs/functions/assets_RotationCwA.default.html +0 -1
  237. package/docs/functions/assets_RotationCwB.default.html +0 -1
  238. package/docs/functions/assets_RotationCwC.default.html +0 -1
  239. package/docs/functions/assets_Run.default.html +0 -1
  240. package/docs/functions/assets_Speed.default.html +0 -1
  241. package/docs/functions/assets_SpeedFast.default.html +0 -1
  242. package/docs/functions/assets_SpeedMedium.default.html +0 -1
  243. package/docs/functions/assets_SpeedNone.default.html +0 -1
  244. package/docs/functions/assets_SpeedSlow.default.html +0 -1
  245. package/docs/functions/assets_Walk.default.html +0 -1
  246. package/docs/functions/components_BlocklyEditor.createCustomToolbox.html +0 -6
  247. package/docs/functions/components_FileList.FileList.html +0 -21
  248. package/docs/functions/components_FitText.FitText.html +0 -8
  249. package/docs/functions/components_ToggleGroup.ToggleGroup.html +0 -5
  250. package/docs/interfaces/components_JogPanel.JogPanelButtonDefinition.html +0 -5
  251. package/docs/interfaces/components_ToggleGroup.ToggleGroupProps.html +0 -618
  252. package/docs/interfaces/core_IndicatorButtonState.IndicatorButtonState.html +0 -10
  253. package/docs/interfaces/hub_CommandMessage.CommandMessage.html +0 -6
  254. package/docs/interfaces/hub_CommandMessage.CommandMessageResult.html +0 -4
  255. package/docs/modules/assets.html +0 -23
  256. package/docs/modules/assets_BlocklyLogo.html +0 -2
  257. package/docs/modules/assets_Distance.html +0 -2
  258. package/docs/modules/assets_JogLong.html +0 -2
  259. package/docs/modules/assets_JogMedium.html +0 -2
  260. package/docs/modules/assets_JogShort.html +0 -2
  261. package/docs/modules/assets_PythonLogo.html +0 -2
  262. package/docs/modules/assets_Rotation3D.html +0 -2
  263. package/docs/modules/assets_RotationCcw.html +0 -2
  264. package/docs/modules/assets_RotationCcwA.html +0 -2
  265. package/docs/modules/assets_RotationCcwB.html +0 -2
  266. package/docs/modules/assets_RotationCcwC.html +0 -2
  267. package/docs/modules/assets_RotationCw.html +0 -2
  268. package/docs/modules/assets_RotationCwA.html +0 -2
  269. package/docs/modules/assets_RotationCwB.html +0 -2
  270. package/docs/modules/assets_RotationCwC.html +0 -2
  271. package/docs/modules/assets_Run.html +0 -2
  272. package/docs/modules/assets_Speed.html +0 -2
  273. package/docs/modules/assets_SpeedFast.html +0 -2
  274. package/docs/modules/assets_SpeedMedium.html +0 -2
  275. package/docs/modules/assets_SpeedNone.html +0 -2
  276. package/docs/modules/assets_SpeedSlow.html +0 -2
  277. package/docs/modules/assets_Walk.html +0 -2
  278. package/docs/modules/components_BlocklyEditor.html +0 -5
  279. package/docs/modules/components_CodeEditor.html +0 -3
  280. package/docs/modules/components_FileList.html +0 -3
  281. package/docs/modules/components_FitText.html +0 -3
  282. package/docs/modules/components_JogPanel.html +0 -9
  283. package/docs/modules/components_Lamp.html +0 -4
  284. package/docs/modules/components_TextInput.html +0 -2
  285. package/docs/modules/components_ToggleGroup.html +0 -6
  286. package/docs/modules/components_ValueIndicator.html +0 -4
  287. package/docs/modules/components_ValueInput.html +0 -2
  288. package/docs/modules/core_ActionMode.html +0 -2
  289. package/docs/modules/core_IndicatorButtonState.html +0 -2
  290. package/docs/modules/core_IndicatorColor.html +0 -2
  291. package/docs/modules/hub_CommandMessage.html +0 -3
  292. package/docs/modules/hub_HubWebSocket.html +0 -2
  293. package/docs/types/components_IndicatorButton.IndicatorButtonOptionsType.html +0 -1
  294. package/docs/variables/components_BlocklyEditor.StandardToolbox.html +0 -1
  295. package/docs/variables/components_JogPanel.DefaultLinearJogButtons.html +0 -2
  296. package/docs/variables/components_JogPanel.DefaultRotationJogButtons.html +0 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAutoCoreTag.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoCoreTag.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEzF,wBAAgB,oBAAoB,CAAC,IAAI,SAAS,SAAS,SAAS,EAAE,EACpE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAC3D,IAAI,EAAE,IAAI;8BAYc,CAAC,2CAA4B,CAAC;;;;;;;+BAyB7B,CAAC,4CAA6B,SAAS,CAAC,EAAE;4BAOrD,CAAC;;kCAY6B,CAAC;;;iCAUlB,CAAC,YAAY,CAAC,GAAG,EAAE,QAAQ,CAAC,OAAO,mBAAM,CAAC,KAAK,CAAC,SAAQ,GAAG,EAAE;;;;;;;uCAW7C,MAAM;;EAKlD"}
@@ -0,0 +1 @@
1
+ import{useCallback,useContext,useMemo}from"react";export function makeAutoCoreTagHooks(e,a){return{useAutoCoreTag:s=>{const{values:t,rawValues:u,isLoading:o,write:r,tap:n}=useContext(e),l=(e=>a.find(a=>a.fqdn===e))(s);if(!l)throw new Error(`useAutoCoreTag: unknown tagName '${String(s)}'`);const i=useCallback(e=>r(s,e),[r,s]),c=useCallback(()=>n?.(s),[n,s]);return{value:t[s],rawValue:u[s],write:i,tap:c,isLoading:o}},useAutoCoreTags:a=>{const{values:s,rawValues:t,isLoading:u,write:o}=useContext(e);return{values:useMemo(()=>Object.fromEntries(a.map(e=>[e,s[e]])),[s,a]),rawValues:useMemo(()=>Object.fromEntries(a.map(e=>[e,t[e]])),[t,a]),write:useCallback(async(e,a)=>{await o(e,a)},[o]),isLoading:u}},useAutoCoreSelect:(a,s=[])=>{const{values:t,isLoading:u}=useContext(e);return{selected:useMemo(()=>a(t),[t,...s]),isLoading:u}},useScales:()=>{const{scales:a,updateScale:s}=useContext(e),t=useCallback(e=>a[e],[a]);return{scales:a,updateScale:s,getScale:t}}}}
@@ -62,3 +62,4 @@ type UseScaledValueReturn = [number, (newValue: number) => void];
62
62
  */
63
63
  export declare function useScaledValue(initialValue: number, scale: number, offset?: number): UseScaledValueReturn;
64
64
  export {};
65
+ //# sourceMappingURL=useScaledValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useScaledValue.d.ts","sourceRoot":"","sources":["../../src/hooks/useScaledValue.tsx"],"names":[],"mappings":"AAaA;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAiB,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,eAAe,EAAG,MAAyB,CAAC;AAGzD,KAAK,oBAAoB,GAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,MAAU,GAAG,oBAAoB,CAoB5G"}
@@ -1 +1 @@
1
- import{useCallback,useState,useEffect}from"react";export const kMillimeters2Inches=1/25.4;export const kNewtons2Pounds=1/4.4482216153;export function useScaledValue(e,t,s=0){const[u,c]=useState(e),[o,a]=useState((()=>e*t+s));useEffect((()=>{a(u*t+s)}),[u,t,s]);return[o,useCallback((e=>{c(e)}),[t,s])]}
1
+ import{useCallback,useState,useEffect}from"react";export const kMillimeters2Inches=1/25.4;export const kNewtons2Pounds=1/4.4482216153;export function useScaledValue(e,t,s=0){const[u,c]=useState(e),[o,a]=useState(()=>e*t+s);useEffect(()=>{a(u*t+s)},[u,t,s]);return[o,useCallback(e=>{c(e)},[t,s])]}
@@ -1,12 +1,22 @@
1
- export interface CommandMessageResult {
2
- data: any;
3
- success: boolean;
4
- error_message: string;
1
+ export declare enum MessageType {
2
+ NoOp = 0,
3
+ Response = 1,
4
+ Read = 2,
5
+ Write = 3,
6
+ Subscribe = 4,
7
+ Unsubscribe = 5,
8
+ Broadcast = 6,
9
+ Heartbeat = 7,
10
+ Control = 8,
11
+ Request = 10
5
12
  }
6
13
  export interface CommandMessage {
7
- request_id: number;
8
- domain: string;
9
- fname: string;
10
- args?: any;
11
- result?: CommandMessageResult;
14
+ transaction_id: number;
15
+ timecode: number;
16
+ topic: string;
17
+ message_type: MessageType;
18
+ data?: any;
19
+ success: boolean;
20
+ error_message: string;
12
21
  }
22
+ //# sourceMappingURL=CommandMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommandMessage.d.ts","sourceRoot":"","sources":["../../src/hub/CommandMessage.ts"],"names":[],"mappings":"AAuBA,oBAAY,WAAW;IAEnB,IAAI,IAAI;IAGR,QAAQ,IAAI;IAGZ,IAAI,IAAI;IAGR,KAAK,IAAI;IAGT,SAAS,IAAI;IAGb,WAAW,IAAI;IAGf,SAAS,IAAI;IAGb,SAAS,IAAI;IAGb,OAAO,IAAI;IAGX,OAAO,KAAK;CACf;AAMD,MAAM,WAAW,cAAc;IAG3B,cAAc,EAAE,MAAM,CAAC;IAIvB,QAAQ,EAAE,MAAM,CAAC;IAKjB,KAAK,EAAE,MAAM,CAAC;IAGd,YAAY,EAAE,WAAW,CAAC;IAK1B,IAAI,CAAC,EAAE,GAAG,CAAC;IAIX,OAAO,EAAE,OAAO,CAAC;IAGjB,aAAa,EAAE,MAAM,CAAC;CAEzB"}
@@ -1 +1 @@
1
- export{};
1
+ export var MessageType;!function(e){e[e.NoOp=0]="NoOp",e[e.Response=1]="Response",e[e.Read=2]="Read",e[e.Write=3]="Write",e[e.Subscribe=4]="Subscribe",e[e.Unsubscribe=5]="Unsubscribe",e[e.Broadcast=6]="Broadcast",e[e.Heartbeat=7]="Heartbeat",e[e.Control=8]="Control",e[e.Request=10]="Request"}(MessageType||(MessageType={}));
@@ -0,0 +1,31 @@
1
+ interface DebugLog {
2
+ time: string;
3
+ type: "info" | "warn" | "error" | "send" | "recv";
4
+ source: string;
5
+ message: string;
6
+ }
7
+ declare class DebugPanel {
8
+ private container;
9
+ private logContainer;
10
+ private statsContainer;
11
+ private logs;
12
+ private maxLogs;
13
+ private stats;
14
+ constructor();
15
+ private injectPanel;
16
+ private setupElements;
17
+ private updateStats;
18
+ log(type: DebugLog["type"], source: string, message: string): void;
19
+ private renderLogs;
20
+ hubCreated(): void;
21
+ connectCalled(socketState: string): void;
22
+ wsOpened(url: string): void;
23
+ wsClosed(code: number, reason: string): void;
24
+ wsError(error: string): void;
25
+ messageSent(type: string, command: string, requestId: number): void;
26
+ messageReceived(type: string, command: string, requestId?: number): void;
27
+ updateState(state: string): void;
28
+ }
29
+ export declare function getDebugPanel(): DebugPanel;
30
+ export default getDebugPanel;
31
+ //# sourceMappingURL=DebugPanel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DebugPanel.d.ts","sourceRoot":"","sources":["../../src/hub/DebugPanel.ts"],"names":[],"mappings":"AAWA,UAAU,QAAQ;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,cAAM,UAAU;IACd,OAAO,CAAC,SAAS,CAA+B;IAChD,OAAO,CAAC,YAAY,CAA+B;IACnD,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,IAAI,CAAkB;IAC9B,OAAO,CAAC,OAAO,CAAO;IAGtB,OAAO,CAAC,KAAK,CASX;;IAOF,OAAO,CAAC,WAAW;IA2FnB,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,WAAW;IAsBnB,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAyBlE,OAAO,CAAC,UAAU;IAgBlB,UAAU,IAAI,IAAI;IAMlB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAOxC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAO3B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAO5C,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAM5B,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAMnE,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI;IAMxE,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAIjC;AAKD,wBAAgB,aAAa,IAAI,UAAU,CAO1C;AAKD,eAAe,aAAa,CAAC"}
@@ -0,0 +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,181 +1,136 @@
1
- import { EventEmitterContextType } from '../core/EventEmitterContext';
2
- import { CommandMessageResult } from "./CommandMessage";
1
+ import type { EventEmitterContextType } from '../core/EventEmitterContext';
2
+ import type { CommandMessage } from "./CommandMessage";
3
+ import { MessageType } from "./CommandMessage";
3
4
  /**
4
- * Base class for the interface for the IPC to the backend,
5
- * which may be websockets, MQTT, the Tauri API,
6
- * or something else.
5
+ * @class HubBase
6
+ * @abstract
7
7
  *
8
- * The EventEmitterContext should generate the hub automatically.
8
+ * Abstract base class that defines the interface for communicating with the AutoCore backend.
9
+ * Implementations (like `HubWebSocket` or `HubTauri`) handle the specific transport mechanics.
9
10
  *
10
- * # Usage
11
- * The hub can be used to publish and subscribe to
12
- * topics in the front-end, regardless of being connected to any backend.
11
+ * ## Core Responsibilities
13
12
  *
14
- * ```
15
- * const {dispatch, subscribe, unsubscribe} = useContext(EventEmitterContext);
16
- * const [controlPower, setControlPower] = useState(false);
17
- * useEffect(() => {
18
- * const unsubscribeControlPower = subscribe('value-simulator-bBit1', (value) => {
19
- * setControlPower(value);
20
- * });
21
- *
22
- *
23
- * return () => {
24
- * unsubscribe(unsubscribeControlPower);
25
- * }
26
- * }, [] );
27
- *
28
- * const onPbPressed = () => {
29
- * let count = 1;
30
- * dispatch({
31
- * topic: "my-awesome-topic",
32
- * payload: count
33
- * });
34
- * }
35
- *
36
- * ```
37
- * The hub should also be used for invoking events in the backend.
38
- * This example will call the function "update_count" in the backend, passing
39
- * the expected argument "count". Details of the interaction between the Hub and
40
- * the backend will be handled by the appropriate HubBase sub-class, and should
41
- * be transparent to the front end.
42
- *
43
- * ```
44
- * const {invoke} = useContext(EventEmitterContext);
45
- * const incrementCount = () => {
46
- * count += 1;
47
- * invoke('update_count', {"count": count});
48
- * };
49
- *
50
- * Subscribing to a topic is simple. The type of value received is specific
51
- * to the topic.
13
+ * 1. **Transport Abstraction**: Provides a unified API (`read`, `write`, `subscribe`) regardless of
14
+ * underlying transport (WS, IPC, etc.).
15
+ * 2. **Topic Mapping**: Maintains a bidirectional mapping between local `tagName` (UI friendly)
16
+ * and backend `FQDN` (Fully Qualified Domain Name).
17
+ * - `tagName`: "motorsEnable"
18
+ * - `FQDN`: "ADS.Main.bMotorsEnable"
19
+ * 3. **Event Dispatching**: Routes incoming messages from the backend to the `EventEmitterContext`.
52
20
  *
53
- * Example: Listen to an event 'xarm-position':
54
- * ```
55
- * const {subscribe, unsubscribe} = useContext(EventEmitterContext);
56
- * useEffect(() => {
57
- * const unsubscripeMp = subscribe('xarm-position', (value) => {
58
- * // The publisher sent a JSON object of 3D position values.
59
- * setX(value.x);
60
- * setY(value.y);
61
- * setZ(value.z);
62
- * setA(value.roll);
63
- * setB(value.yaw);
64
- * setC(value.pitch);
65
- * });
66
- *
67
- * return () => {
68
- * unsubscribe(unsubscripeMp);
69
- * }
21
+ * ## Usage
70
22
  *
71
- * }, [] );
23
+ * The `Hub` is typically accessed via the `EventEmitterContext`:
72
24
  *
25
+ * ```typescript
26
+ * const { hub } = useContext(EventEmitterContext);
27
+ * await hub.write("ADS.Main.nSpeed", 500);
73
28
  * ```
74
- *
75
29
  */
76
30
  export declare abstract class HubBase {
31
+ /** Maps local tag names to backend FQDNs. */
77
32
  protected localTopicToBackendTopicMap: Map<string, string>;
33
+ /** Maps backend FQDNs to local tag names. */
78
34
  protected backendTopicToLocalMap: Map<string, string>;
79
- protected localFNameToBackendFNameMap: Map<string, string>;
80
- protected backendFNameToLocalFNameMap: Map<string, string>;
35
+ /** Reference to the global event emitter for dispatching incoming messages. */
81
36
  protected context: EventEmitterContextType | null;
37
+ /** Connection state tracker. */
82
38
  protected isConnected_: boolean;
83
39
  /**
84
40
  * Constructor
85
41
  */
86
42
  constructor();
87
43
  /**
88
- * Set the EventEmitterContext for this instance of the Hub. The EventEmitterContext
89
- * should handle this as part of the initialization sequence. Because React can
90
- * sometimes make (and destroy) multiple copies of the EventEmitterContext, it's important
91
- * that the context be stored in the instance this way so that the HubBase can properly target
92
- * right context.
44
+ * Links this Hub instance with the React application's Event Context.
93
45
  *
94
- * If this context is not sent, no events will be emitted from the backend to the front end,
95
- * and global events in the interface may not work.
46
+ * This connection allows the Hub to "push" messages into the React app by calling `context.dispatch()`.
47
+ * This is called automatically by `EventEmitterProvider` on initialization.
96
48
  *
49
+ * @param context The React context instance.
97
50
  */
98
51
  setContext(context: EventEmitterContextType | null): void;
99
52
  /**
100
- * Invoke/send a message to the back end.
101
- * This does NOT get published to the front end.
53
+ * Sends a raw command message to the backend.
54
+ *
55
+ * @param topic The resource identifier (FQDN).
56
+ * @param messageType The operation to perform (Read, Write, etc.).
57
+ * @param payload The data payload.
58
+ * @returns A Promise that resolves with the server's response.
102
59
  */
103
- abstract invoke(domain: string, fname: string, payload?: object): Promise<CommandMessageResult>;
60
+ abstract invoke(topic: string, messageType: MessageType, payload?: object): Promise<CommandMessage>;
104
61
  /**
105
- * Allos the derived class to set whether the hub is connected to its source.
106
- * @param s boolean
62
+ * Request the current value of a resource.
63
+ *
64
+ * @param topic FQDN of the resource.
107
65
  */
108
- protected setIsConnected: (s: boolean) => void;
66
+ read(topic: string, payload?: object): Promise<CommandMessage>;
109
67
  /**
110
- * Returns true if the Hub is connected to its source.
68
+ * Write a new value to a resource.
69
+ *
70
+ * @param topic FQDN of the resource.
71
+ * @param value The value to write.
111
72
  */
112
- isConnected: () => boolean;
73
+ write(topic: string, value: any): Promise<CommandMessage>;
113
74
  /**
114
- * Convenience function to invoke a command with an optional topic and optional value.
115
- * This will invoke the specified command in the backend. It does not broadcast the
116
- * value within the local frontend.
117
- * @param domain string The domain of the command that will be invoked.
118
- * @param fname string Function name
119
- * @param topic string Topic
120
- * @param value any data payload
75
+ * Subscribe to updates for a specific resource.
76
+ *
77
+ * Registers a mapping so that when the server sends updates for `topic` (FQDN),
78
+ * the Hub will translate it to `tagName` before dispatching to the UI.
79
+ *
80
+ * @param tagName The local alias for this resource (e.g., "position").
81
+ * @param topic The backend FQDN (e.g., "ADS.Main.fPos").
82
+ * @param payload Optional subscription parameters (rate, deadband).
121
83
  */
122
- invokeTopic(domain: string, fname: string, topic: string | null, value?: any): Promise<CommandMessageResult>;
84
+ subscribe(tagName: string, topic: string, payload?: object): Promise<CommandMessage>;
123
85
  /**
124
- * Pubish a topic throughout the web app using the
125
- * Global EventEmitterContext. This will broadcast within the local frontend.
126
- * This does NOT get relayed to the backend.
86
+ * Unsubscribe from updates.
87
+ *
88
+ * Uses the `tagName` to look up the FQDN and send the unsubscribe command.
89
+ * Also removes the local mapping.
90
+ *
91
+ * @param tagName The local alias to unsubscribe.
127
92
  */
128
- publish(topic: string, data: any | undefined): void;
93
+ unsubscribe(/* topic: string,*/ tagName: string, payload?: object): Promise<CommandMessage>;
129
94
  /**
130
- * Map a local topic to a topic in the backend.
131
- * @param localTopic string
132
- * @param backendTopic string
95
+ * Send a generic request (custom command).
133
96
  */
134
- mapTopic(localTopic: string, backendTopic: string): void;
97
+ request(topic: string, payload?: object): Promise<CommandMessage>;
135
98
  /**
136
- * Unmap a local topic.
137
- * @param localTopic string
99
+ * Update internal connection state.
138
100
  */
139
- unmapTopic(localTopic: string): void;
101
+ protected setIsConnected: (s: boolean) => void;
140
102
  /**
141
- * Map a local function name, as would be sent to the invoke method, to a
142
- * function name in the backend.
143
- * @param localFName string
144
- * @param backendFName string
103
+ * Check if currently connected to backend.
145
104
  */
146
- mapFName(localFName: string, backendFName: string): void;
105
+ isConnected: () => boolean;
147
106
  /**
148
- * Unmap a local function name.
149
- * @param localFName string
107
+ * Dispatches an event to the React application.
108
+ *
109
+ * 1. Translates the `topic` (potentially an FQDN) to a local `tagName` if a mapping exists.
110
+ * 2. Calls `context.dispatch()` to notify local subscribers.
111
+ *
112
+ * This is the bridge between the backend transport and the frontend UI components.
113
+ *
114
+ * @param topic The topic from the message (usually FQDN).
115
+ * @param data The data payload.
150
116
  */
151
- unmapFName(localFName: string): void;
117
+ publish(topic: string, data: any | undefined): void;
152
118
  /**
153
- * Convert a local topic to a backend topic. If a mapping isn't
154
- * registered, the local topic is returned.
155
- * @param localTopic local topic name
156
- * @returns string
119
+ * Registers a mapping between a local name and a backend FQDN.
157
120
  */
158
- toBackendTopic(localTopic: string): string;
121
+ mapTopic(localTopic: string, backendTopic: string): void;
159
122
  /**
160
- * Convert a local function name to a backend function name. If a mapping isn't
161
- * registered, the local FName is returned.
162
- * @param localTopic local function name
163
- * @returns string
123
+ * Removes a mapping.
164
124
  */
165
- toBackendFName(localFName: string): string;
125
+ unmapTopic(localTopic: string): void;
166
126
  /**
167
- * Convert a backend topic to a local topic. If a mapping isn't
168
- * registered, the backend topic is returned.
169
- * @param backendTopic backend topic name
170
- * @returns string
127
+ * Translates Local Name -> Backend FQDN.
171
128
  */
172
- toLocalTopic(backendTopic: string): string;
129
+ toBackendTopic(localTopic: string): string;
173
130
  /**
174
- * Convert a backend function name to a local function name. If a mapping isn't
175
- * registered, the backend function name is returned.
176
- * @param backendTopic backend function name
177
- * @returns string
131
+ * Translates Backend FQDN -> Local Name.
178
132
  */
179
- toLocalFName(backendTopic: string): string;
133
+ toLocalTopic(backendTopic: string): string;
180
134
  }
181
135
  export default HubBase;
136
+ //# sourceMappingURL=HubBase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HubBase.d.ts","sourceRoot":"","sources":["../../src/hub/HubBase.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,8BAAsB,OAAO;IAEzB,6CAA6C;IAC7C,SAAS,CAAC,2BAA2B,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAA6B;IAEvF,6CAA6C;IAC7C,SAAS,CAAC,sBAAsB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAA6B;IAElF,+EAA+E;IAC/E,SAAS,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAAQ;IAEzD,gCAAgC;IAChC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAS;IAGxC;;OAEG;;IAKH;;;;;;;OAOG;IACH,UAAU,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI;IAQlD;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAMnG;;;;OAIG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAI9D;;;;;OAKG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,cAAc,CAAC;IAIzD;;;;;;;;;OASG;IACH,SAAS,CAAC,OAAO,EAAG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAKrF;;;;;;;OAOG;IACH,WAAW,CAAE,mBAAmB,CAAC,OAAO,EAAG,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAM7F;;OAEG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAQjE;;OAEG;IACH,SAAS,CAAC,cAAc,GAAI,GAAG,OAAO,UAErC;IAED;;OAEG;IACH,WAAW,QAAO,OAAO,CAExB;IAMD;;;;;;;;;;OAUG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,SAAS,GAAG,IAAI;IAcnD;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IAKxD;;OAEG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAWpC;;OAEG;IACH,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAK1C;;OAEG;IACH,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;CAI7C;AAGD,eAAe,OAAO,CAAC"}
@@ -1 +1 @@
1
- export class HubBase{constructor(){Object.defineProperty(this,"localTopicToBackendTopicMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"backendTopicToLocalMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"localFNameToBackendFNameMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"backendFNameToLocalFNameMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"isConnected_",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"setIsConnected",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.isConnected_=e}}),Object.defineProperty(this,"isConnected",{enumerable:!0,configurable:!0,writable:!0,value:()=>this.isConnected_})}setContext(e){this.context=e}invokeTopic(e,a,o,c){const t={topic:o,data:c};return this.invoke(e,a,t)}publish(e,a){const o=this.toLocalTopic(e);this.context?.dispatch({topic:o,payload:a})}mapTopic(e,a){this.localTopicToBackendTopicMap.set(e,a),this.backendTopicToLocalMap.set(a,e)}unmapTopic(e){if(this.localTopicToBackendTopicMap.has(e)){const a=this.localTopicToBackendTopicMap.get(e);this.localTopicToBackendTopicMap.delete(e),null!=a&&this.backendTopicToLocalMap.has(a)&&this.backendTopicToLocalMap.delete(a)}}mapFName(e,a){this.localFNameToBackendFNameMap.set(e,a),this.backendFNameToLocalFNameMap.set(a,e)}unmapFName(e){if(this.localFNameToBackendFNameMap.has(e)){const a=this.localFNameToBackendFNameMap.get(e);this.localFNameToBackendFNameMap.delete(e),null!=a&&this.backendFNameToLocalFNameMap.has(a)&&this.backendFNameToLocalFNameMap.delete(a)}}toBackendTopic(e){if(this.localTopicToBackendTopicMap.has(e)){const a=this.localTopicToBackendTopicMap.get(e);return null!=a?a:e}return e}toBackendFName(e){if(this.localFNameToBackendFNameMap.has(e)){const a=this.localFNameToBackendFNameMap.get(e);return null!=a?a:e}return e}toLocalTopic(e){if(this.backendTopicToLocalMap.has(e)){const a=this.backendTopicToLocalMap.get(e);return null!=a?a:e}return e}toLocalFName(e){if(this.backendFNameToLocalFNameMap.has(e)){const a=this.backendFNameToLocalFNameMap.get(e);return null!=a?a:e}return e}}export default HubBase;
1
+ import{MessageType}from"./CommandMessage";export class HubBase{constructor(){Object.defineProperty(this,"localTopicToBackendTopicMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"backendTopicToLocalMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"isConnected_",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"setIsConnected",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.isConnected_=e}}),Object.defineProperty(this,"isConnected",{enumerable:!0,configurable:!0,writable:!0,value:()=>this.isConnected_})}setContext(e){this.context=e}read(e,t){return this.invoke(e,MessageType.Read,t)}write(e,t){return this.invoke(e,MessageType.Write,{value:t})}subscribe(e,t,i){return this.mapTopic(e,t),this.invoke(t,MessageType.Subscribe,i)}unsubscribe(e,t){const i=this.toBackendTopic(e);return this.unmapTopic(e),this.invoke(i,MessageType.Unsubscribe,t)}request(e,t){return this.invoke(e,MessageType.Request,t)}publish(e,t){const i=this.toLocalTopic(e);this.context?.dispatch({topic:i,payload:t})}mapTopic(e,t){this.localTopicToBackendTopicMap.set(e,t),this.backendTopicToLocalMap.set(t,e)}unmapTopic(e){if(this.localTopicToBackendTopicMap.has(e)){const t=this.localTopicToBackendTopicMap.get(e);this.localTopicToBackendTopicMap.delete(e),null!=t&&this.backendTopicToLocalMap.has(t)&&this.backendTopicToLocalMap.delete(t)}}toBackendTopic(e){return this.localTopicToBackendTopicMap.get(e)??e}toLocalTopic(e){return this.backendTopicToLocalMap.get(e)??e}}export default HubBase;
@@ -1,21 +1,55 @@
1
1
  import { HubBase } from './HubBase';
2
- import { CommandMessageResult } from "./CommandMessage";
2
+ import type { CommandMessage } from "./CommandMessage";
3
+ import { MessageType } from "./CommandMessage";
3
4
  /**
4
- * Hub for simulating functionality when no backend is present.
5
+ * Hub for simulating backend functionality when no actual backend is present.
6
+ *
7
+ * Useful for development, testing, and demos without a running autocore-server.
8
+ * The simulator echoes back requests as successful responses after a configurable delay.
9
+ *
10
+ * ## Usage Examples
11
+ *
12
+ * ```typescript
13
+ * const { hub } = useContext(EventEmitterContext);
14
+ *
15
+ * // Read returns the topic as the "value"
16
+ * const result = await hub.read("ads.plc1.gio.bControlPowerOk");
17
+ * console.log(result.data); // { value: "ads.plc1.gio.bControlPowerOk" }
18
+ *
19
+ * // Write echoes back the written value
20
+ * await hub.write("ads.plc1.gio.nSetpoint", 100);
21
+ * ```
5
22
  */
6
23
  export declare class HubSimulate extends HubBase {
24
+ private responseDelay;
7
25
  /**
8
26
  * Constructor
27
+ * @param responseDelay Simulated response delay in milliseconds (default: 20ms)
9
28
  */
10
- constructor();
29
+ constructor(responseDelay?: number);
11
30
  /**
12
- * Invoke a method in the Socket.IO backend and wait for acknowledgment.
31
+ * Simulate sending a message to a backend.
13
32
  *
14
- * @param fname method name
33
+ * For Read operations, returns the topic as the value.
34
+ * For Write operations, echoes back the payload.
35
+ * For all operations, returns a successful response after the configured delay.
36
+ *
37
+ * @param topic The FQDN of the resource
38
+ * @param messageType The action to perform
15
39
  * @param payload Optional data payload
16
- * @param timeout Timeout in milliseconds after which the promise is rejected if no response is received.
17
- * @returns A Promise that resolves to the response from the backend or rejects if a timeout occurs.
40
+ * @returns Promise<CommandMessage> A simulated successful response
41
+ */
42
+ invoke(topic: string, messageType: MessageType, payload?: object): Promise<CommandMessage>;
43
+ /**
44
+ * Simulate a broadcast from the "backend".
45
+ *
46
+ * This is useful for testing subscription handlers.
47
+ *
48
+ * @param topic The topic to broadcast on
49
+ * @param data The data to broadcast
50
+ * @param delay Optional delay before broadcasting (default: 0ms)
18
51
  */
19
- invoke(domain: string, fname: string, payload?: object, timeout?: number): Promise<CommandMessageResult>;
52
+ simulateBroadcast(topic: string, data: any, delay?: number): void;
20
53
  }
21
54
  export default HubSimulate;
55
+ //# sourceMappingURL=HubSimulate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HubSimulate.d.ts","sourceRoot":"","sources":["../../src/hub/HubSimulate.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,WAAY,SAAQ,OAAO;IAEpC,OAAO,CAAC,aAAa,CAAS;IAE9B;;;OAGG;gBACS,aAAa,GAAE,MAAW;IAMtC;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAgD1F;;;;;;;;OAQG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,GAAE,MAAU,GAAG,IAAI;CAKvE;AAED,eAAe,WAAW,CAAC"}
@@ -1 +1 @@
1
- import{HubBase}from"./HubBase";export class HubSimulate extends HubBase{constructor(){super()}invoke(e,s,r,t=20){return new Promise(((e,s)=>{setTimeout((()=>{e({data:r,error_message:"",success:!0})}),t)}))}}export default HubSimulate;
1
+ import{HubBase}from"./HubBase";import{MessageType}from"./CommandMessage";export class HubSimulate extends HubBase{constructor(e=20){super(),Object.defineProperty(this,"responseDelay",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.responseDelay=e,this.setIsConnected(!0)}invoke(e,s,a){return new Promise(t=>{setTimeout(()=>{let r;switch(s){case MessageType.Read:r={value:e,simulated:!0};break;case MessageType.Write:r={written:!0,...a};break;case MessageType.Subscribe:r={subscribed:!0,topic:e};break;case MessageType.Unsubscribe:r={unsubscribed:!0,topic:e};break;default:r=a??{}}const i={transaction_id:0,timecode:Date.now(),topic:e,message_type:MessageType.Response,data:r,success:!0,error_message:""};t(i)},this.responseDelay)})}simulateBroadcast(e,s,a=0){setTimeout(()=>{this.publish(e,s)},a)}}export default HubSimulate;
@@ -1,75 +1,35 @@
1
1
  import { HubBase } from './HubBase';
2
- import { CommandMessageResult } from "./CommandMessage";
2
+ import type { CommandMessage } from "./CommandMessage";
3
+ import { MessageType } from "./CommandMessage";
3
4
  /**
4
5
  * Hub for integrating with the Tauri backend.
5
6
  *
6
- * The tauri backend is expected to broadcast messages on the event
7
+ * The Tauri backend is expected to broadcast messages on the event
7
8
  * name: 'autocore://broadcast_event'
8
9
  *
9
10
  * This hub will capture those messages and dispatch them globally to any
10
11
  * listeners in the web app.
11
12
  *
13
+ * ## Usage Examples
12
14
  *
13
- * Example: Listen to an event 'xarm-position':
14
- * ```
15
- * const {subscribe, unsubscribe} = useContext(EventEmitterContext);
16
- * useEffect(() => {
17
- * const unsubscripeMp = subscribe('xarm-position', (value) => {
18
- * // The rust backend sent a JSON object of 3D position values.
19
- * setX(value.x);
20
- * setY(value.y);
21
- * setZ(value.z);
22
- * setA(value.roll);
23
- * setB(value.yaw);
24
- * setC(value.pitch);
25
- * });
26
- *
27
- * return () => {
28
- * unsubscribe(unsubscripeMp);
29
- * }
15
+ * ```typescript
16
+ * const { hub } = useContext(EventEmitterContext);
30
17
  *
31
- * }, [] );
18
+ * // Read a value
19
+ * const result = await hub.read("ads.plc1.gio.bControlPowerOk");
32
20
  *
33
- * ```
21
+ * // Write a value
22
+ * await hub.write("ads.plc1.gio.nSetpoint", 100);
34
23
  *
35
- * The hub should also be used for invoking events in the Tauri backend.
36
- * This example will call the function "update_count" in the rust backend, passing
37
- * the expected argument "count".
38
- * ```
39
- * const {invoke} = useContext(EventEmitterContext);
40
- * const incrementCount = () => {
41
- * count += 1;
42
- * invoke('update_count', {"count": count});
43
- * };
24
+ * // Subscribe to changes
25
+ * await hub.subscribe("modbus.holding_registers.5");
44
26
  * ```
45
27
  *
46
- * Of course, like any class derived from HubBase, the hub can be used to publish and subscribe to
47
- * topics in the front-end, without need of interacting with the Tauri backed.
28
+ * The hub can also publish/subscribe to frontend-only events:
48
29
  *
30
+ * ```typescript
31
+ * hub.publish("ui/panel-opened", { panelId: "settings" });
49
32
  * ```
50
- * const {dispatch, subscribe, unsubscribe} = useContext(EventEmitterContext);
51
- * const [controlPower, setControlPower] = useState(false);
52
- * useEffect(() => {
53
- * const unsubscribeControlPower = subscribe('value-simulator-bBit1', (value) => {
54
- * setControlPower(value);
55
- * });
56
- *
57
- *
58
- * return () => {
59
- * unsubscribe(unsubscribeControlPower);
60
- * }
61
- * }, [] );
62
- *
63
- * const onPbPressed = () => {
64
- * let count = 1;
65
- * dispatch({
66
- * topic: "my-awesome-topic",
67
- * payload: count
68
- * });
69
- * }
70
- *
71
- * ```
72
- *
73
33
  */
74
34
  export declare class HubTauri extends HubBase {
75
35
  /**
@@ -77,11 +37,16 @@ export declare class HubTauri extends HubBase {
77
37
  */
78
38
  constructor();
79
39
  /**
80
- * Invoke a method in the rust backend.
40
+ * Send a message to the Tauri backend.
41
+ *
42
+ * The topic and messageType are passed to a generic Tauri command handler
43
+ * that routes the request appropriately.
81
44
  *
82
- * @param fname method name
83
- * @param payload Optional data payload
84
- * @returns The return value of the backend method.
45
+ * @param topic The FQDN of the resource (e.g., "ads.plc1.gio.bControlPowerOk")
46
+ * @param messageType The action to perform (Read, Write, Subscribe, etc.)
47
+ * @param payload Optional data payload (e.g., value to write)
48
+ * @returns Promise<CommandMessage> The response from the backend
85
49
  */
86
- invoke(domain: string, fname: string, payload?: object | undefined): Promise<CommandMessageResult>;
50
+ invoke(topic: string, messageType: MessageType, payload?: object): Promise<CommandMessage>;
87
51
  }
52
+ //# sourceMappingURL=HubTauri.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HubTauri.d.ts","sourceRoot":"","sources":["../../src/hub/HubTauri.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,QAAS,SAAQ,OAAO;IAEjC;;OAEG;;IA6BH;;;;;;;;;;OAUG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;CA8C7F"}
@@ -1 +1 @@
1
- import{HubBase}from"./HubBase";import{event,invoke}from"@tauri-apps/api";export class HubTauri extends HubBase{constructor(){super(),event.listen("autocore://broadcast_event",(o=>{let e=JSON.parse(o.payload);void 0!==e.topic&&null!==e.topic&&(void 0!==e.payload&&null!==e.payload?this.publish(e.topic,e.payload):this.publish(e.topic,void 0))}))}invoke(o,e,i){if(null!=i){return invoke(`${o}_${e}`,i)}return invoke(e)}}
1
+ import{HubBase}from"./HubBase";import{invoke as tauriInvoke}from"@tauri-apps/api/core";import{listen}from"@tauri-apps/api/event";import{MessageType}from"./CommandMessage";export class HubTauri extends HubBase{constructor(){super(),this.setIsConnected(!0),listen("autocore://broadcast_event",e=>{let o=JSON.parse(e.payload);void 0!==o.topic&&null!==o.topic&&(void 0!==o.payload&&null!==o.payload?this.publish(o.topic,o.payload):this.publish(o.topic,void 0))})}invoke(e,o,s){const t={topic:e,message_type:o,...s??{}};return new Promise((o,s)=>{tauriInvoke("autocore_invoke",t).then(s=>{if(s&&"object"==typeof s&&"topic"in s)o(s);else{const t={transaction_id:0,timecode:Date.now(),topic:e,message_type:MessageType.Response,data:s,success:!0,error_message:""};o(t)}}).catch(o=>{const t={transaction_id:0,timecode:Date.now(),topic:e,message_type:MessageType.Response,data:null,success:!1,error_message:o?.toString()||"Unknown error"};s(t)})})}}