@adcops/autocore-react 3.1.1 → 3.3.5

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 (252) hide show
  1. package/additional-docs/react_performance_notes.md +94 -0
  2. package/dist/components/AutoCoreDevPanel.d.ts.map +1 -1
  3. package/dist/components/AutoCoreDevPanel.js +1 -1
  4. package/dist/components/FileList.d.ts.map +1 -1
  5. package/dist/components/FileList.js +1 -1
  6. package/dist/components/FileSelect.d.ts.map +1 -1
  7. package/dist/components/FileSelect.js +1 -1
  8. package/dist/core/AutoCoreTagContext.d.ts +59 -185
  9. package/dist/core/AutoCoreTagContext.d.ts.map +1 -1
  10. package/dist/core/AutoCoreTagContext.js +1 -1
  11. package/dist/core/AutoCoreTagTypes.d.ts +127 -6
  12. package/dist/core/AutoCoreTagTypes.d.ts.map +1 -1
  13. package/dist/core/CoreStreamTypes.d.ts +345 -0
  14. package/dist/core/CoreStreamTypes.d.ts.map +1 -0
  15. package/dist/core/CoreStreamTypes.js +1 -0
  16. package/dist/core/EventEmitterContext.d.ts +91 -473
  17. package/dist/core/EventEmitterContext.d.ts.map +1 -1
  18. package/dist/core/EventEmitterContext.js +1 -1
  19. package/dist/hooks/adsHooks.d.ts.map +1 -1
  20. package/dist/hooks/adsHooks.js +1 -1
  21. package/dist/hooks/commandHooks.d.ts +3 -3
  22. package/dist/hooks/commandHooks.d.ts.map +1 -1
  23. package/dist/hooks/commandHooks.js +1 -1
  24. package/dist/hooks/useAutoCoreTag.js +1 -1
  25. package/dist/hub/CommandMessage.d.ts +18 -9
  26. package/dist/hub/CommandMessage.d.ts.map +1 -1
  27. package/dist/hub/CommandMessage.js +1 -1
  28. package/dist/hub/DebugPanel.d.ts +31 -0
  29. package/dist/hub/DebugPanel.d.ts.map +1 -0
  30. package/dist/hub/DebugPanel.js +1 -0
  31. package/dist/hub/HubBase.d.ts +83 -129
  32. package/dist/hub/HubBase.d.ts.map +1 -1
  33. package/dist/hub/HubBase.js +1 -1
  34. package/dist/hub/HubSimulate.d.ts +41 -8
  35. package/dist/hub/HubSimulate.d.ts.map +1 -1
  36. package/dist/hub/HubSimulate.js +1 -1
  37. package/dist/hub/HubTauri.d.ts +24 -60
  38. package/dist/hub/HubTauri.d.ts.map +1 -1
  39. package/dist/hub/HubTauri.js +1 -1
  40. package/dist/hub/HubWebSocket.d.ts +33 -17
  41. package/dist/hub/HubWebSocket.d.ts.map +1 -1
  42. package/dist/hub/HubWebSocket.js +1 -1
  43. package/dist/hub/debug.d.ts +23 -0
  44. package/dist/hub/debug.d.ts.map +1 -0
  45. package/dist/hub/debug.js +1 -0
  46. package/dist/hub/index.d.ts +19 -4
  47. package/dist/hub/index.d.ts.map +1 -1
  48. package/dist/hub/index.js +1 -1
  49. package/package.json +8 -4
  50. package/src/components/AutoCoreDevPanel.tsx +14 -11
  51. package/src/components/FileList.tsx +5 -4
  52. package/src/components/FileSelect.tsx +2 -1
  53. package/src/core/ActionMode.ts +1 -1
  54. package/src/core/AutoCoreTagContext.tsx +247 -330
  55. package/src/core/AutoCoreTagTypes.ts +236 -104
  56. package/src/core/CoreStreamTypes.ts +512 -0
  57. package/src/core/EventEmitterContext.tsx +182 -520
  58. package/src/core/IndicatorButtonState.ts +1 -1
  59. package/src/core/hoc.tsx +1 -1
  60. package/src/hooks/adsHooks.tsx +21 -22
  61. package/src/hooks/commandHooks.tsx +23 -19
  62. package/src/hooks/index.ts +1 -1
  63. package/src/hooks/useAutoCoreTag.ts +2 -2
  64. package/src/hooks/useScaledValue.tsx +1 -1
  65. package/src/hub/CommandMessage.ts +71 -19
  66. package/src/hub/DebugPanel.ts +280 -0
  67. package/src/hub/HubBase.ts +147 -223
  68. package/src/hub/HubSimulate.ts +93 -24
  69. package/src/hub/HubTauri.ts +87 -96
  70. package/src/hub/HubWebSocket.ts +118 -140
  71. package/src/hub/debug.ts +211 -0
  72. package/src/hub/index.ts +49 -39
  73. package/docs/.nojekyll +0 -1
  74. package/docs/assets/hierarchy.js +0 -1
  75. package/docs/assets/highlight.css +0 -134
  76. package/docs/assets/icons.js +0 -18
  77. package/docs/assets/icons.svg +0 -1
  78. package/docs/assets/main.js +0 -60
  79. package/docs/assets/navigation.js +0 -1
  80. package/docs/assets/search.js +0 -1
  81. package/docs/assets/style.css +0 -1633
  82. package/docs/classes/components_CodeEditor.CodeEditor.html +0 -135
  83. package/docs/classes/components_Indicator.Indicator.html +0 -122
  84. package/docs/classes/components_IndicatorRect.IndicatorRect.html +0 -121
  85. package/docs/classes/components_JogPanel.JogPanel.html +0 -136
  86. package/docs/classes/components_Lamp.Lamp.html +0 -122
  87. package/docs/classes/components_OskDialog.OskDialog.html +0 -125
  88. package/docs/classes/components_TextInput.TextInput.html +0 -125
  89. package/docs/classes/components_ValueDisplay.ValueDisplay.html +0 -148
  90. package/docs/classes/components_ValueIndicator.ValueIndicator.html +0 -126
  91. package/docs/classes/core_ValueSimulator.ValueSimulator.html +0 -51
  92. package/docs/classes/hub_HubBase.HubBase.html +0 -106
  93. package/docs/classes/hub_HubSimulate.HubSimulate.html +0 -75
  94. package/docs/classes/hub_HubTauri.HubTauri.html +0 -93
  95. package/docs/classes/hub_HubWebSocket.HubWebSocket.html +0 -112
  96. package/docs/documents/core_AutoCoreTagContext.AutoCoreTagContext.html +0 -148
  97. package/docs/enums/components_JogPanel.JogDistanceAction.html +0 -5
  98. package/docs/enums/components_JogPanel.JogPanelAction.html +0 -18
  99. package/docs/enums/components_JogPanel.JogSpeedAction.html +0 -5
  100. package/docs/enums/core_ActionMode.ActionMode.html +0 -6
  101. package/docs/enums/core_IndicatorColor.IndicatorColor.html +0 -23
  102. package/docs/functions/assets.BlocklyLogo.html +0 -1
  103. package/docs/functions/assets.Distance.html +0 -1
  104. package/docs/functions/assets.JogLong.html +0 -1
  105. package/docs/functions/assets.JogMedium.html +0 -1
  106. package/docs/functions/assets.JogShort.html +0 -1
  107. package/docs/functions/assets.PythonLogo.html +0 -1
  108. package/docs/functions/assets.Rotation3D.html +0 -1
  109. package/docs/functions/assets.RotationCcw.html +0 -1
  110. package/docs/functions/assets.RotationCcwA.html +0 -1
  111. package/docs/functions/assets.RotationCcwB.html +0 -1
  112. package/docs/functions/assets.RotationCcwC.html +0 -1
  113. package/docs/functions/assets.RotationCw.html +0 -1
  114. package/docs/functions/assets.RotationCwA.html +0 -1
  115. package/docs/functions/assets.RotationCwB.html +0 -1
  116. package/docs/functions/assets.RotationCwC.html +0 -1
  117. package/docs/functions/assets.Run.html +0 -1
  118. package/docs/functions/assets.Speed.html +0 -1
  119. package/docs/functions/assets.SpeedFast.html +0 -1
  120. package/docs/functions/assets.SpeedMedium.html +0 -1
  121. package/docs/functions/assets.SpeedNone.html +0 -1
  122. package/docs/functions/assets.SpeedSlow.html +0 -1
  123. package/docs/functions/assets.Walk.html +0 -1
  124. package/docs/functions/components_BlocklyEditor.createCustomToolbox.html +0 -6
  125. package/docs/functions/core_UniqueId.UniqueId.html +0 -9
  126. package/docs/functions/core_hoc.hocAddSubscription.html +0 -6
  127. package/docs/functions/hooks_adsHooks.useAdsRegisterSymbols.html +0 -16
  128. package/docs/functions/hooks_adsHooks.useAdsTapValue.html +0 -8
  129. package/docs/functions/hooks_adsHooks.useAdsWriteScaledValue.html +0 -18
  130. package/docs/functions/hooks_adsHooks.useAdsWriteValue.html +0 -9
  131. package/docs/functions/hooks_commandHooks.useRegisterSymbols.html +0 -16
  132. package/docs/functions/hooks_commandHooks.useTapValue.html +0 -10
  133. package/docs/functions/hooks_commandHooks.useWriteScaledValue.html +0 -18
  134. package/docs/functions/hooks_commandHooks.useWriteValue.html +0 -11
  135. package/docs/functions/hooks_useAutoCoreTag.ts.makeAutoCoreTagHooks.html +0 -12
  136. package/docs/functions/hooks_useScaledValue.useScaledValue.html +0 -18
  137. package/docs/functions/hub.createHub.html +0 -3
  138. package/docs/hierarchy.html +0 -1
  139. package/docs/index.html +0 -148
  140. package/docs/interfaces/components_IndicatorButton.IndicatorButtonProps.html +0 -654
  141. package/docs/interfaces/components_IndicatorRect.IndicatorRectProps.html +0 -37
  142. package/docs/interfaces/components_JogPanel.JogPanelButtonDefinition.html +0 -5
  143. package/docs/interfaces/components_ToggleGroup.ToggleGroupProps.html +0 -644
  144. package/docs/interfaces/core_AutoCoreTagTypes.BaseContextValue.html +0 -12
  145. package/docs/interfaces/core_AutoCoreTagTypes.ScaleConfig.html +0 -13
  146. package/docs/interfaces/core_EventEmitterContext.Action.html +0 -8
  147. package/docs/interfaces/core_EventEmitterContext.EventEmitterContextType.html +0 -33
  148. package/docs/interfaces/core_EventEmitterContext.State.html +0 -8
  149. package/docs/interfaces/core_EventEmitterContext.Subscription.html +0 -6
  150. package/docs/interfaces/core_IndicatorButtonState.IndicatorButtonState.html +0 -10
  151. package/docs/interfaces/core_PositionContext.IPositionContext.html +0 -17
  152. package/docs/interfaces/hub_CommandMessage.CommandMessage.html +0 -6
  153. package/docs/interfaces/hub_CommandMessage.CommandMessageResult.html +0 -4
  154. package/docs/modules/assets.html +0 -1
  155. package/docs/modules/assets_BlocklyLogo.html +0 -1
  156. package/docs/modules/assets_Distance.html +0 -1
  157. package/docs/modules/assets_JogLong.html +0 -1
  158. package/docs/modules/assets_JogMedium.html +0 -1
  159. package/docs/modules/assets_JogShort.html +0 -1
  160. package/docs/modules/assets_PythonLogo.html +0 -1
  161. package/docs/modules/assets_Rotation3D.html +0 -1
  162. package/docs/modules/assets_RotationCcw.html +0 -1
  163. package/docs/modules/assets_RotationCcwA.html +0 -1
  164. package/docs/modules/assets_RotationCcwB.html +0 -1
  165. package/docs/modules/assets_RotationCcwC.html +0 -1
  166. package/docs/modules/assets_RotationCw.html +0 -1
  167. package/docs/modules/assets_RotationCwA.html +0 -1
  168. package/docs/modules/assets_RotationCwB.html +0 -1
  169. package/docs/modules/assets_RotationCwC.html +0 -1
  170. package/docs/modules/assets_Run.html +0 -1
  171. package/docs/modules/assets_Speed.html +0 -1
  172. package/docs/modules/assets_SpeedFast.html +0 -1
  173. package/docs/modules/assets_SpeedMedium.html +0 -1
  174. package/docs/modules/assets_SpeedNone.html +0 -1
  175. package/docs/modules/assets_SpeedSlow.html +0 -1
  176. package/docs/modules/assets_Walk.html +0 -1
  177. package/docs/modules/components_AutoCoreDevPanel.html +0 -20
  178. package/docs/modules/components_BlocklyEditor.html +0 -1
  179. package/docs/modules/components_CodeEditor.html +0 -1
  180. package/docs/modules/components_FileList.html +0 -1
  181. package/docs/modules/components_FileSelect.html +0 -1
  182. package/docs/modules/components_FitText.html +0 -1
  183. package/docs/modules/components_Indicator.html +0 -1
  184. package/docs/modules/components_IndicatorButton.html +0 -1
  185. package/docs/modules/components_IndicatorRect.html +0 -1
  186. package/docs/modules/components_JogPanel.html +0 -1
  187. package/docs/modules/components_Lamp.html +0 -1
  188. package/docs/modules/components_Osk.html +0 -1
  189. package/docs/modules/components_OskDialog.html +0 -1
  190. package/docs/modules/components_ProgressBarWithValue.html +0 -1
  191. package/docs/modules/components_TextInput.html +0 -1
  192. package/docs/modules/components_ToggleGroup.html +0 -1
  193. package/docs/modules/components_ValueDisplay.html +0 -1
  194. package/docs/modules/components_ValueIndicator.html +0 -1
  195. package/docs/modules/components_ValueInput.html +0 -1
  196. package/docs/modules/core_ActionMode.html +0 -1
  197. package/docs/modules/core_AutoCoreTagContext.html +0 -11
  198. package/docs/modules/core_AutoCoreTagTypes.html +0 -1
  199. package/docs/modules/core_EventEmitterContext.html +0 -53
  200. package/docs/modules/core_IndicatorButtonState.html +0 -1
  201. package/docs/modules/core_IndicatorColor.html +0 -1
  202. package/docs/modules/core_MaskPatterns.html +0 -1
  203. package/docs/modules/core_NumerableTypes.html +0 -1
  204. package/docs/modules/core_PositionContext.html +0 -1
  205. package/docs/modules/core_UniqueId.html +0 -1
  206. package/docs/modules/core_ValueSimulator.html +0 -1
  207. package/docs/modules/core_hoc.html +0 -1
  208. package/docs/modules/hooks.html +0 -1
  209. package/docs/modules/hooks_adsHooks.html +0 -1
  210. package/docs/modules/hooks_commandHooks.html +0 -1
  211. package/docs/modules/hooks_useAutoCoreTag.ts.html +0 -52
  212. package/docs/modules/hooks_useScaledValue.html +0 -1
  213. package/docs/modules/hub.html +0 -1
  214. package/docs/modules/hub_CommandMessage.html +0 -1
  215. package/docs/modules/hub_HubBase.html +0 -1
  216. package/docs/modules/hub_HubSimulate.html +0 -1
  217. package/docs/modules/hub_HubTauri.html +0 -1
  218. package/docs/modules/hub_HubWebSocket.html +0 -1
  219. package/docs/modules.html +0 -23
  220. package/docs/types/components_IndicatorButton.IndicatorButtonOptionsType.html +0 -1
  221. package/docs/types/core_AutoCoreTagTypes.ExtractByTag.html +0 -2
  222. package/docs/types/core_AutoCoreTagTypes.PrimitiveKind.html +0 -1
  223. package/docs/types/core_AutoCoreTagTypes.TagConfig.html +0 -16
  224. package/docs/types/core_AutoCoreTagTypes.TagValueMap.html +0 -1
  225. package/docs/types/core_AutoCoreTagTypes.TagValueOf.html +0 -1
  226. package/docs/types/core_EventEmitterContext.EmitterDispatchFunction.html +0 -3
  227. package/docs/types/core_EventEmitterContext.EmitterSubscribeFunction.html +0 -3
  228. package/docs/types/core_EventEmitterContext.EmitterUnsubscribeFunction.html +0 -3
  229. package/docs/types/core_NumerableTypes.NumerableFormatOptions.html +0 -4
  230. package/docs/types/core_hoc.HocAddSubscriptionProps.html +0 -6
  231. package/docs/variables/components_AutoCoreDevPanel.AutoCoreDevPanel.html +0 -43
  232. package/docs/variables/components_BlocklyEditor.BlocklyEditor.html +0 -13
  233. package/docs/variables/components_BlocklyEditor.StandardToolbox.html +0 -1
  234. package/docs/variables/components_FileList.FileList.html +0 -23
  235. package/docs/variables/components_FileSelect.FileSelect.html +0 -1
  236. package/docs/variables/components_FitText.FitText.html +0 -4
  237. package/docs/variables/components_IndicatorButton.IndicatorButton.html +0 -1
  238. package/docs/variables/components_JogPanel.DefaultLinearJogButtons.html +0 -2
  239. package/docs/variables/components_JogPanel.DefaultRotationJogButtons.html +0 -2
  240. package/docs/variables/components_Osk.Osk.html +0 -1
  241. package/docs/variables/components_ProgressBarWithValue.ProgressBarWithValue.html +0 -1
  242. package/docs/variables/components_ToggleGroup.ToggleGroup.html +0 -1
  243. package/docs/variables/components_ValueInput.ValueInput.html +0 -4
  244. package/docs/variables/core_AutoCoreTagContext.AutoCoreTagContext.html +0 -1
  245. package/docs/variables/core_AutoCoreTagContext.AutoCoreTagProvider.html +0 -7
  246. package/docs/variables/core_EventEmitterContext.EventEmitterContext.html +0 -64
  247. package/docs/variables/core_EventEmitterContext.EventEmitterProvider.html +0 -10
  248. package/docs/variables/core_MaskPatterns.PrimeReactMaskPatterns.html +0 -14
  249. package/docs/variables/core_MaskPatterns.RegExMaskPatterns.html +0 -15
  250. package/docs/variables/core_PositionContext.DimensionsContext.html +0 -6
  251. package/docs/variables/hooks_useScaledValue.kMillimeters2Inches.html +0 -2
  252. package/docs/variables/hooks_useScaledValue.kNewtons2Pounds.html +0 -2
@@ -7,521 +7,164 @@
7
7
  *
8
8
  * ## Core Features
9
9
  *
10
- * - **Global Event Bus**: Publish and subscribe to events across all components
11
- * - **Backend Integration**: Direct communication with AutoCore server via Hub abstraction
12
- * - **Type-Safe Subscriptions**: Strongly-typed event handling with automatic cleanup
13
- * - **Connection Management**: Automatic reconnection and state synchronization
14
- * - **Development Tools**: Built-in debugging and subscription introspection
10
+ * - **Global Event Bus**: Publish and subscribe to events across all components.
11
+ * - **Backend Integration**: Direct communication with AutoCore server via Hub abstraction.
12
+ * - **Type-Safe Subscriptions**: Strongly-typed event handling with automatic cleanup.
13
+ * - **Performance Optimized**: Uses stable context values and direct callbacks to avoid global re-renders.
14
+ * - **Connection Management**: Automatic reconnection and state synchronization.
15
15
  *
16
16
  * ## Architecture
17
17
  *
18
18
  * The system consists of three main components:
19
- * 1. **EventEmitterProvider**: React context provider that manages global state
20
- * 2. **Hub**: Abstraction layer for backend communication (WebSocket, HTTP, etc.)
21
- * 3. **Subscription Manager**: Handles event routing and lifecycle management
19
+ * 1. **EventEmitterProvider**: React context provider that manages global state and event routing.
20
+ * 2. **Hub**: Abstraction layer for backend communication (WebSocket, HTTP, etc.).
21
+ * 3. **Subscription Manager**: Handles event routing and lifecycle management.
22
22
  *
23
- * ## Basic Usage
23
+ * ## Performance Notes
24
24
  *
25
- * ### 1. Application Setup
26
- *
27
- * Wrap your entire application with the EventEmitterProvider:
28
- *
29
- * ```tsx
30
- * // App.tsx
31
- * import React from 'react';
32
- * import { EventEmitterProvider } from '@adcops/autocore-react/core/EventEmitterContext';
33
- * import { PrimeReactProvider } from 'primereact/api';
34
- * import { MainView } from './MainView';
35
- *
36
- * export default function App() {
37
- * return (
38
- * <EventEmitterProvider>
39
- * <PrimeReactProvider>
40
- * <MainView />
41
- * </PrimeReactProvider>
42
- * </EventEmitterProvider>
43
- * );
44
- * }
45
- * ```
46
- *
47
- * ### 2. Component Communication
48
- *
49
- * Use the context for inter-component communication:
50
- *
51
- * ```tsx
52
- * // PublisherComponent.tsx
53
- * import React, { useContext } from 'react';
54
- * import { EventEmitterContext } from '@adcops/autocore-react/core/EventEmitterContext';
55
- * import { Button } from 'primereact/button';
56
- *
57
- * export const PublisherComponent: React.FC = () => {
58
- * const { dispatch } = useContext(EventEmitterContext);
59
- *
60
- * const handleButtonClick = () => {
61
- * dispatch({
62
- * topic: 'user-action/button-clicked',
63
- * payload: { timestamp: Date.now(), buttonId: 'main-action' }
64
- * });
65
- * };
66
- *
67
- * return <Button label="Trigger Event" onClick={handleButtonClick} />;
68
- * };
69
- *
70
- * // SubscriberComponent.tsx
71
- * import React, { useContext, useEffect, useState } from 'react';
72
- * import { EventEmitterContext } from '@adcops/autocore-react/core/EventEmitterContext';
73
- *
74
- * export const SubscriberComponent: React.FC = () => {
75
- * const { subscribe, unsubscribe } = useContext(EventEmitterContext);
76
- * const [lastAction, setLastAction] = useState<any>(null);
77
- *
78
- * useEffect(() => {
79
- * const subscriptionId = subscribe('user-action/button-clicked', (payload) => {
80
- * setLastAction(payload);
81
- * console.log('Button clicked at:', payload.timestamp);
82
- * });
83
- *
84
- * return () => unsubscribe(subscriptionId);
85
- * }, [subscribe, unsubscribe]);
86
- *
87
- * return (
88
- * <div>
89
- * {lastAction && (
90
- * <p>Last action: {new Date(lastAction.timestamp).toLocaleTimeString()}</p>
91
- * )}
92
- * </div>
93
- * );
94
- * };
95
- * ```
96
- *
97
- * ### 3. Backend Integration
98
- *
99
- * Communicate with AutoCore server through the integrated Hub:
100
- *
101
- * ```tsx
102
- * // ControlPanel.tsx
103
- * import React, { useContext, useEffect, useState } from 'react';
104
- * import { EventEmitterContext } from '@adcops/autocore-react/core/EventEmitterContext';
105
- * import { Button } from 'primereact/button';
106
- * import { InputNumber } from 'primereact/inputnumber';
107
- *
108
- * export const ControlPanel: React.FC = () => {
109
- * const { invoke, subscribe, unsubscribe, isConnected } = useContext(EventEmitterContext);
110
- * const [motorSpeed, setMotorSpeed] = useState<number>(0);
111
- * const [targetSpeed, setTargetSpeed] = useState<number>(100);
112
- * const [connected, setConnected] = useState<boolean>(false);
113
- *
114
- * // Monitor connection status
115
- * useEffect(() => {
116
- * setConnected(isConnected());
117
- *
118
- * const connectionSub = subscribe('HUB/connected', () => setConnected(true));
119
- * const disconnectionSub = subscribe('HUB/disconnected', () => setConnected(false));
120
- *
121
- * return () => {
122
- * unsubscribe(connectionSub);
123
- * unsubscribe(disconnectionSub);
124
- * };
125
- * }, [subscribe, unsubscribe, isConnected]);
126
- *
127
- * // Subscribe to real-time motor speed updates
128
- * useEffect(() => {
129
- * const speedSub = subscribe('ADS/MAIN.motor.speed', (data) => {
130
- * setMotorSpeed(data.value);
131
- * });
132
- *
133
- * return () => unsubscribe(speedSub);
134
- * }, [subscribe, unsubscribe]);
135
- *
136
- * // Send commands to backend
137
- * const handleSpeedChange = async () => {
138
- * try {
139
- * const result = await invoke('ADS', 'write_value', {
140
- * symbol_name: 'MAIN.motor.setpoint',
141
- * value: targetSpeed
142
- * });
143
- *
144
- * if (!result.success) {
145
- * console.error('Failed to set motor speed:', result.error_message);
146
- * }
147
- * } catch (error) {
148
- * console.error('Communication error:', error);
149
- * }
150
- * };
151
- *
152
- * const handleEmergencyStop = async () => {
153
- * try {
154
- * await invoke('ADS', 'emergency_stop', {});
155
- * } catch (error) {
156
- * console.error('Emergency stop failed:', error);
157
- * }
158
- * };
159
- *
160
- * return (
161
- * <div className="control-panel">
162
- * <div className="status">
163
- * Connection: {connected ? '🟢 Connected' : '🔴 Disconnected'}
164
- * </div>
165
- *
166
- * <div className="motor-control">
167
- * <p>Current Speed: {motorSpeed} RPM</p>
168
- *
169
- * <InputNumber
170
- * value={targetSpeed}
171
- * onValueChange={(e) => setTargetSpeed(e.value || 0)}
172
- * min={0}
173
- * max={1000}
174
- * suffix=" RPM"
175
- * />
176
- *
177
- * <Button
178
- * label="Set Speed"
179
- * onClick={handleSpeedChange}
180
- * disabled={!connected}
181
- * />
182
- *
183
- * <Button
184
- * label="Emergency Stop"
185
- * onClick={handleEmergencyStop}
186
- * severity="danger"
187
- * disabled={!connected}
188
- * />
189
- * </div>
190
- * </div>
191
- * );
192
- * };
193
- * ```
194
- *
195
- * ### 4. Advanced Pattern: State Management Hook
196
- *
197
- * Create reusable hooks for common patterns:
198
- *
199
- * ```tsx
200
- * // hooks/useRealtimeValue.ts
201
- * import { useContext, useEffect, useState } from 'react';
202
- * import { EventEmitterContext } from '@adcops/autocore-react/core/EventEmitterContext';
203
- *
204
- * export function useRealtimeValue<T>(topic: string, initialValue?: T) {
205
- * const { subscribe, unsubscribe } = useContext(EventEmitterContext);
206
- * const [value, setValue] = useState<T | undefined>(initialValue);
207
- * const [lastUpdate, setLastUpdate] = useState<Date | null>(null);
208
- *
209
- * useEffect(() => {
210
- * const subscriptionId = subscribe(topic, (data) => {
211
- * setValue(data.value);
212
- * setLastUpdate(new Date());
213
- * });
214
- *
215
- * return () => unsubscribe(subscriptionId);
216
- * }, [topic, subscribe, unsubscribe]);
217
- *
218
- * return { value, lastUpdate };
219
- * }
220
- *
221
- * // Usage in component
222
- * export const SensorDisplay: React.FC = () => {
223
- * const { value: temperature } = useRealtimeValue<number>('ADS/sensors.temperature');
224
- * const { value: pressure } = useRealtimeValue<number>('ADS/sensors.pressure');
225
- *
226
- * return (
227
- * <div>
228
- * <p>Temperature: {temperature?.toFixed(1)}°C</p>
229
- * <p>Pressure: {pressure?.toFixed(2)} bar</p>
230
- * </div>
231
- * );
232
- * };
233
- * ```
234
- *
235
- * ## Integration with AutoCore Systems
236
- *
237
- * The EventEmitterContext is designed to work seamlessly with other AutoCore React components:
238
- *
239
- * ```tsx
240
- * // Complete AutoCore application setup
241
- * import React from 'react';
242
- * import { EventEmitterProvider } from '@adcops/autocore-react/core/EventEmitterContext';
243
- * import { AutoCoreTagProvider } from '@adcops/autocore-react/core/AutoCoreTagContext';
244
- * import { PrimeReactProvider } from 'primereact/api';
245
- * import { tagSpec } from './config/tags';
246
- * import { MainInterface } from './components/MainInterface';
247
- *
248
- * export default function App() {
249
- * return (
250
- * <EventEmitterProvider>
251
- * <AutoCoreTagProvider tags={tagSpec} eagerRead>
252
- * <PrimeReactProvider>
253
- * <MainInterface />
254
- * </PrimeReactProvider>
255
- * </AutoCoreTagProvider>
256
- * </EventEmitterProvider>
257
- * );
258
- * }
259
- * ```
260
- *
261
- * ## Best Practices
262
- *
263
- * 1. **Always Cleanup Subscriptions**: Use the cleanup function returned by useEffect
264
- * 2. **Use Meaningful Topic Names**: Follow a hierarchical naming convention (e.g., 'domain/category/specific')
265
- * 3. **Handle Connection States**: Always check connection status before invoking backend functions
266
- * 4. **Error Handling**: Wrap invoke calls in try-catch blocks
267
- * 5. **Type Safety**: Use TypeScript interfaces for payload structures
268
- * 6. **Performance**: Avoid subscribing to high-frequency events in render-heavy components
269
- *
270
- * ## Debugging
271
- *
272
- * Use the built-in debugging features:
273
- *
274
- * ```tsx
275
- * const { getSubscriptions, state } = useContext(EventEmitterContext);
276
- *
277
- * // View all subscriptions
278
- * console.log('All subscriptions:', getSubscriptions());
279
- *
280
- * // View subscriptions for specific topic
281
- * console.log('Motor subscriptions:', getSubscriptions('ADS/MAIN.motor.speed'));
282
- *
283
- * // View current state
284
- * console.log('EventEmitter state:', state);
285
- * ```
25
+ * To ensure high performance with high-frequency data (e.g., 50Hz sensor updates):
26
+ * 1. **No State Updates on Dispatch**: The `dispatch` function does NOT update React state. It calls listeners directly.
27
+ * This prevents the entire component tree from re-rendering on every message.
28
+ * 2. **Stable Context Value**: The `contextValue` object is memoized and rarely changes.
29
+ * 3. **Direct Subscriptions**: Components subscribe via `useEffect` and receive updates via callbacks, not props.
286
30
  *
287
31
  * @module core/EventEmitterContext
288
- * @version 3.0.41
32
+ * @version 3.0.42
289
33
  * @author Automated Design Corp.
290
- * @since 1.0.0
291
34
  */
292
35
  import React from "react";
293
36
  import type { ReactNode } from "react";
294
37
  import { Hub } from "../hub";
295
- import type { CommandMessageResult } from "../hub/CommandMessage";
38
+ import type { CommandMessage } from "../hub";
39
+ import { MessageType } from "../hub/CommandMessage";
296
40
  export { Hub };
297
41
  /**
298
- * Represents an event subsription.
42
+ * Represents an active event subscription.
299
43
  */
300
44
  export interface Subscription {
301
- /** ID of the subscription used for unsubscription. */
45
+ /** Unique ID of the subscription used for unsubscription. */
302
46
  id: number;
303
- /** Callback function. */
47
+ /** Callback function to execute when the event fires. */
304
48
  callback: React.Dispatch<any>;
305
49
  }
306
50
  /**
307
- * Represents the payload data associated with an event.
51
+ * Represents the internal state of the EventEmitter.
52
+ * Mostly used for debugging and dev tools inspection.
308
53
  */
309
54
  export interface State {
310
55
  /**
311
- * The optional data payload of the event.
56
+ * The optional data payload of the last event (DEBUGGING ONLY).
57
+ * Note: This is no longer updated in production for performance reasons.
312
58
  */
313
59
  eventData?: any;
314
- /** Callback subscription. A list of callback subscriptions matched to a topic. */
60
+ /** Active subscriptions grouped by topic. */
315
61
  subscriptions: Record<string, Subscription[]>;
316
62
  /** Tracks the next subscription ID that will be assigned. */
317
63
  nextSubscriptionId: number;
318
64
  }
319
65
  /**
320
- * An action event published by the EventEmitterContext. Contains
321
- * the topic identifying the event and the optional payload, which is
322
- * a value of any type.
66
+ * An action event published by the EventEmitterContext.
323
67
  */
324
68
  export interface Action {
325
- /**
326
- * The topic or identifier of the event.
327
- */
69
+ /** The topic or identifier of the event. */
328
70
  topic: string;
329
- /**
330
- * The optional data payload associated with the event.
331
- */
71
+ /** The optional data payload associated with the event. */
332
72
  payload?: any;
333
73
  }
334
- /**
335
- * Type declaration for the EventEmitter dispatch function, which
336
- * publishes an Action globally throughout the EventEmitterContext.
337
- */
338
74
  export type EmitterDispatchFunction = (action: Action) => void;
339
75
  /**
340
- * Type declaration for the EventEmitter dispatch function, which
341
- * receives an Action on a specific topic broadcast through the EventEmitterContext.
342
- */
343
- export type EmitterSubscribeFunction = (action: Action) => void;
344
- /**
345
- * Type declaration for the EventEmitter unsubscribe function, which
346
- * receives an Action on a specific topic broadcast through the EventEmitterContext.
347
- */
348
- export type EmitterUnsubscribeFunction = (action: Action) => void;
349
- /**
350
- * Defines the context for an event emitter used throughout a front-end application to manage and dispatch events.
351
- * This interface includes methods for managing the application's state, handling global actions, communicating with the back end,
352
- * subscribing to and unsubscribing from events, and accessing a global hub for event publishing and subscription management.
353
- * It serves as a central point for event-driven interactions within the application, facilitating communication between
354
- * components and the back end, as well as among components themselves.
76
+ * Defines the context for the global event emitter.
77
+ * Provides methods for dispatching events, subscribing to topics, and communicating with the backend.
355
78
  */
356
79
  export interface EventEmitterContextType {
357
80
  /**
358
- * The current state of the event emitter, containing the latest event data.
81
+ * The current state of the event emitter (mostly for debugging).
359
82
  */
360
83
  state: State;
361
84
  /**
362
- * A function to dispatch actions globally throughout the front-end,
363
- * triggering state updates and events.
85
+ * Dispatch an action globally throughout the front-end.
86
+ * Triggers callbacks for all subscribers of the topic.
87
+ *
88
+ * @param action The action to dispatch.
89
+ */
90
+ dispatch: EmitterDispatchFunction;
91
+ /**
92
+ * Send a message to the backend (Low-level).
93
+ *
94
+ * @param topic The FQDN of the resource (e.g., "ads.plc1.gio.bControlPowerOk")
95
+ * @param messageType The action to perform (Read, Write, Subscribe, etc.)
96
+ * @param payload Optional data payload
97
+ * @returns Promise resolving to the CommandMessage response
98
+ */
99
+ invoke(topic: string, messageType: MessageType, payload?: object): Promise<CommandMessage>;
100
+ /**
101
+ * Read a value from the backend.
102
+ *
103
+ * @param topic The FQDN of the resource to read
104
+ * @param payload Optional additional parameters
105
+ * @returns Promise resolving to the CommandMessage response with the value in `data`
106
+ */
107
+ read(topic: string, payload?: object): Promise<CommandMessage>;
108
+ /**
109
+ * Write a value to the backend.
364
110
  *
365
- * @param action The action to dispatch, containing topic and optional payload.
111
+ * @param topic The FQDN of the resource to write
112
+ * @param value The value to write
113
+ * @returns Promise resolving to the CommandMessage response
366
114
  */
367
- dispatch: (action: Action) => void;
115
+ write(topic: string, value: any): Promise<CommandMessage>;
368
116
  /**
369
- * Invoke/send a message to the back end.
370
- * This does NOT get published to the front end.
117
+ * Subscribe to value changes on the backend.
118
+ *
119
+ * Tells the server to start broadcasting updates for a specific topic.
120
+ * Also registers a mapping between the local `tagName` and the remote `topic` (FQDN)
121
+ * in the Hub, so that incoming broadcasts are routed correctly.
122
+ *
123
+ * @param tagName The local tag name to map the topic to
124
+ * @param topic The FQDN of the resource to watch
125
+ * @param payload Optional subscription parameters (e.g., update rate)
126
+ * @returns Promise resolving to the CommandMessage response
371
127
  */
372
- invoke(domain: string, fname: string, payload?: object): Promise<CommandMessageResult>;
128
+ serverSubscribe(tagName: string, topic: string, payload?: object): Promise<CommandMessage>;
373
129
  /**
374
- * Subscribe to events identified by the topic.
375
- * @param topic The subscription topic.
130
+ * Unsubscribe from value changes on the backend.
131
+ *
132
+ * @param tagName The local tag name to stop watching
133
+ * @param payload Optional parameters
134
+ * @returns Promise resolving to the CommandMessage response
135
+ */
136
+ serverUnsubscribe(tagName: string, payload?: object): Promise<CommandMessage>;
137
+ /**
138
+ * Subscribe to **local** frontend events.
139
+ *
140
+ * This registers a callback to listen for events dispatched on the local event bus.
141
+ * This includes both locally dispatched events AND broadcast messages received
142
+ * from the server (which the Hub dispatches to the local bus).
143
+ *
144
+ * @param topic The subscription topic (or tagName).
376
145
  * @param callback The callback to signal.
377
146
  * @returns number Subscription ID used to unsubscribe later.
378
147
  */
379
148
  subscribe: (topic: string, callback: React.Dispatch<any>) => number;
380
149
  /**
381
- * Unsubscribe to events.
382
- * @param subscriptionId The id of the subscription returned by the subscribe method.
383
- * @returns
150
+ * Unsubscribe from **local** frontend events.
151
+ *
152
+ * @param subscriptionId The id returned by the subscribe method.
384
153
  */
385
154
  unsubscribe: (subscriptionId: number) => void;
386
155
  /**
387
- * Global hub for publishing and receiving events throughout the interface, and for exchanging
388
- * data with the backend.
156
+ * Global hub instance for backend communication.
389
157
  */
390
158
  hub: Hub | null;
391
159
  /**
392
160
  * Retrieves the current subscriptions. Used for debugging purposes.
393
- * @param topic Optional. The topic to retrieve subscriptions for. If omitted, returns all subscriptions.
394
- * @returns An object containing the current subscriptions, optionally filtered by topic.
395
161
  */
396
162
  getSubscriptions: (topic?: string) => Record<string, Subscription[]> | Subscription[];
397
163
  /**
398
- * Returns true if the Hub in use is connected to its source.
399
- * @returns boolean
164
+ * Returns true if the Hub is connected to the backend.
400
165
  */
401
166
  isConnected: () => boolean;
402
167
  }
403
- /**
404
- * A global context for managing event emission and subscription.
405
- *
406
- * Creates a React context for the EventEmitter system, providing a structured way to manage events and data flow
407
- * in a React application. It serves as a global event bus that components can subscribe to or emit events, allowing for
408
- * a loosely coupled architecture. Additionally, it provides a mechanism for invoking backend functions and managing
409
- * subscriptions, making it easier to integrate React components with backend services.
410
- *
411
- * The context includes several key functionalities:
412
- * - `state`: Maintains the current state of subscriptions and their identifiers.
413
- * - `dispatch`: Allows components to emit events with specific topics and payloads, which can be listened to by other components.
414
- * - `subscribe`: Enables components to listen to specific topics and react to those events by providing a callback function.
415
- * - `unsubscribe`: Provides a way for components to stop listening to events, helping prevent memory leaks and unnecessary updates.
416
- * - `invoke`: Facilitates calling backend functions with specific arguments and handling their responses asynchronously.
417
- * - `getSubscriptions`: Offers insight into current active subscriptions, useful for debugging purposes.
418
- *
419
- * This context is essential for applications that require a high degree of inter-component communication or need to
420
- * interact with a backend efficiently.
421
- *
422
- * For more information, see [Additional Documentation](../additional-docs/GlobalEventEmitter.md).
423
- *
424
- * ## Usage
425
- *
426
- * The entire application should be wrapped in the EventEmitterProvider.
427
- *
428
- * App.tsx
429
- * ```
430
- * import { EventEmitterProvider } from "@adcops/autocore-react/core/EventEmitterContext.js";
431
- * function App() {
432
- *
433
- * return(
434
- * <EventEmitterProvider>
435
- * <PrimeReactProvider>
436
- * <main>
437
- * <section>
438
- * <ContentView />
439
- * </section>
440
- * </main>
441
- * </PrimeReactProvider>
442
- * </EventEmitterProvider>
443
- * );
444
- *
445
- * }
446
- *
447
- * ```
448
- *
449
- * ### Catching and receiving events
450
- * The EventEmitterContext creates an appropriate instance of the hub, which is derived from HubBase.
451
- * That hub can be used to publish and subscribe to
452
- * topics globally in the front-end, regardless of being connected to any backend.
453
- * Usage within a component is simple.
454
- *
455
- * ```
456
- * const {dispatch, subscribe, unsubscribe} = useContext(EventEmitterContext);
457
- * const [controlPower, setControlPower] = useState(false);
458
- * useEffect(() => {
459
- * const unsubscribeControlPower = subscribe('value-simulator-bBit1', (value) => {
460
- * setControlPower(value);
461
- * });
462
- *
463
- *
464
- * return () => {
465
- * unsubscribe(unsubscribeControlPower);
466
- * }
467
- * }, [] );
468
- *
469
- * const onPbPressed = () => {
470
- * let count = 1;
471
- * dispatch({
472
- * topic: "my-awesome-topic",
473
- * payload: count
474
- * });
475
- * }
476
- *
477
- * ```
478
- * The hub should also be used for invoking events in the backend.
479
- * This example will call the function "update_count" in the backend, passing
480
- * the expected argument "count". Details of the interaction between the Hub and
481
- * the backend will be handled by the appropriate HubBase sub-class, and should
482
- * be transparent to the front end.
483
- *
484
- * ```
485
- * const {invoke} = useContext(EventEmitterContext);
486
- * const incrementCount = () => {
487
- * count += 1;
488
- * invoke('update_count', {"count": count});
489
- * };
490
- *
491
- * Subscribing to a topic is simple. The type of value received is specific
492
- * to the topic.
493
- *
494
- * Example: Listen to an event 'xarm-position':
495
- * ```
496
- * const {subscribe, unsubscribe} = useContext(EventEmitterContext);
497
- * useEffect(() => {
498
- * const unsubscripeMp = subscribe('xarm-position', (value) => {
499
- * // The publisher sent a JSON object of 3D position values.
500
- * setX(value.x);
501
- * setY(value.y);
502
- * setZ(value.z);
503
- * setA(value.roll);
504
- * setB(value.yaw);
505
- * setC(value.pitch);
506
- * });
507
- *
508
- * return () => {
509
- * unsubscribe(unsubscripeMp);
510
- * }
511
- *
512
- * }, [] );
513
- *
514
- * ```
515
- *
516
- * For applications that need to access the instance of the hub, get the current instance
517
- * from the EventEmitterContext:
518
- *
519
- * ```
520
- * const {hub} = useContext(EventEmitterContext);
521
- * * ```
522
- *
523
- *
524
- */
525
168
  export declare const EventEmitterContext: React.Context<EventEmitterContextType>;
526
169
  /**
527
170
  * A React component that provides the EventEmitterContext to its children.
@@ -530,31 +173,6 @@ export declare const EventEmitterContext: React.Context<EventEmitterContextType>
530
173
  * with the event emitter.
531
174
  *
532
175
  * @param children The child components to be wrapped in the context.
533
- *
534
- * ## Usage
535
- *
536
- * The entire application should be wrapped in the EventEmitterProvider.
537
- *
538
- * App.tsx
539
- * ```
540
- * import { EventEmitterProvider } from "@adcops/autocore-react/core/EventEmitterContext.js";
541
- * function App() {
542
- *
543
- * return(
544
- * <EventEmitterProvider>
545
- * <PrimeReactProvider>
546
- * <main>
547
- * <section>
548
- * <ContentView />
549
- * </section>
550
- * </main>
551
- * </PrimeReactProvider>
552
- * </EventEmitterProvider>
553
- * );
554
- *
555
- * }
556
- *
557
- * ```
558
176
  */
559
177
  export declare const EventEmitterProvider: React.FC<{
560
178
  children: ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"EventEmitterContext.d.ts","sourceRoot":"","sources":["../../src/core/EventEmitterContext.tsx"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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State,useMemo,useCallback,useRef,useEffect}from"react";import{createHub,Hub}from"../hub";export{Hub};export const EventEmitterContext=createContext({state:{subscriptions:{},nextSubscriptionId:1},dispatch:()=>{},subscribe:()=>0,invoke:async(e,t,r)=>Promise.resolve({data:{},success:!1,error_message:""}),unsubscribe:e=>{},hub:null,getSubscriptions:()=>[],isConnected:()=>!1});export const EventEmitterProvider=({children:e})=>{const[t,r]=useState({subscriptions:{},nextSubscriptionId:1}),s=useMemo(()=>createHub(),[]),c=useRef(1),n=useRef({});useEffect(()=>{r(e=>({...e,subscriptions:{...n.current},nextSubscriptionId:c.current}))},[]);const o=useCallback(e=>{const{topic:t,payload:s}=e,c=n.current[t]?.slice()??[];for(const e of c)try{e.callback(s)}catch(e){}r(e=>({...e,eventData:s}))},[]),u=useCallback((e,t)=>{const s=c.current++,o={id:s,callback:t},u=[...n.current[e]??[],o];return n.current={...n.current,[e]:u},r(e=>({...e,subscriptions:{...n.current},nextSubscriptionId:c.current})),s},[]),i=useCallback(e=>{const t={};for(const[r,s]of Object.entries(n.current)){const c=s.filter(t=>t.id!==e);c.length>0&&(t[r]=c)}n.current=t,r(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=useMemo(()=>({state:t,dispatch:o,subscribe:u,unsubscribe:i,invoke:s.invoke,hub:s,getSubscriptions:e=>e?n.current[e]??[]:n.current,isConnected:s.isConnected}),[t,s,o,u,i]);return s.setContext(a),_jsx(EventEmitterContext.Provider,{value:a,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";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 +1 @@
1
- {"version":3,"file":"adsHooks.d.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