@adcops/autocore-react 3.0.34 → 3.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/BlocklyLogo.js +1 -9
- package/dist/assets/Distance.js +1 -5
- package/dist/assets/JogLong.js +1 -3
- package/dist/assets/JogMedium.js +1 -3
- package/dist/assets/JogShort.js +1 -3
- package/dist/assets/PythonLogo.js +1 -21
- package/dist/assets/Rotation3D.js +1 -3
- package/dist/assets/RotationCcw.js +1 -10
- package/dist/assets/RotationCcwA.js +1 -16
- package/dist/assets/RotationCcwB.js +1 -16
- package/dist/assets/RotationCcwC.js +1 -16
- package/dist/assets/RotationCw.js +1 -10
- package/dist/assets/RotationCwA.js +1 -16
- package/dist/assets/RotationCwB.js +1 -16
- package/dist/assets/RotationCwC.js +1 -16
- package/dist/assets/Run.js +1 -3
- package/dist/assets/Speed.js +1 -5
- package/dist/assets/SpeedFast.js +1 -3
- package/dist/assets/SpeedMedium.js +1 -3
- package/dist/assets/SpeedNone.js +1 -3
- package/dist/assets/SpeedSlow.js +1 -3
- package/dist/assets/Walk.js +1 -3
- package/dist/assets/index.js +1 -22
- package/dist/components/BlocklyEditor.css +71 -2
- package/dist/components/BlocklyEditor.js +1 -508
- package/dist/components/CodeEditor.js +1 -108
- package/dist/components/FileList.js +1 -218
- package/dist/components/FileSelect.js +1 -63
- package/dist/components/FitText.js +1 -13
- package/dist/components/Indicator.js +1 -113
- package/dist/components/IndicatorButton.js +1 -187
- package/dist/components/IndicatorRect.js +1 -93
- package/dist/components/JogPanel.js +1 -295
- package/dist/components/Lamp.js +1 -161
- package/dist/components/Osk.js +1 -125
- package/dist/components/OskDialog.js +1 -128
- package/dist/components/ProgressBarWithValue.js +1 -18
- package/dist/components/TextInput.js +1 -139
- package/dist/components/ToggleGroup.js +1 -204
- package/dist/components/ValueDisplay.js +1 -160
- package/dist/components/ValueIndicator.js +1 -38
- package/dist/components/ValueInput.js +1 -158
- package/dist/core/ActionMode.js +1 -18
- package/dist/core/EventEmitterContext.js +1 -252
- package/dist/core/IndicatorButtonState.js +1 -9
- package/dist/core/IndicatorColor.js +1 -36
- package/dist/core/MaskPatterns.js +1 -80
- package/dist/core/NumerableTypes.js +1 -10
- package/dist/core/PositionContext.js +1 -24
- package/dist/core/UniqueId.js +1 -32
- package/dist/core/ValueSimulator.js +1 -233
- package/dist/core/hoc.js +1 -44
- package/dist/hooks/adsHooks.js +1 -253
- package/dist/hooks/commandHooks.js +1 -252
- package/dist/hooks/index.js +1 -10
- package/dist/hooks/useScaledValue.js +1 -86
- package/dist/hub/CommandMessage.js +1 -9
- package/dist/hub/HubBase.js +1 -310
- package/dist/hub/HubSimulate.js +1 -46
- package/dist/hub/HubTauri.js +1 -130
- package/dist/hub/HubWebSocket.js +1 -240
- package/dist/hub/index.js +1 -57
- package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleMono-Italic-VariableFont_wght.ttf +0 -0
- package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleMono-VariableFont_wght.ttf +0 -0
- package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-Italic-VariableFont_wght.ttf +0 -0
- package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-Regular.woff2 +0 -0
- package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-RegularItalic.woff2 +0 -0
- package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-VariableFont_wght.ttf +0 -0
- package/dist/themes/adc-dark/blue/theme.css +7097 -0
- package/dist/themes/adc-dark/blue/theme.css.map +1 -0
- package/package.json +8 -2
- package/src/components/BlocklyEditor.css +71 -2
- package/src/themes/adc-dark/_extensions.scss +166 -0
- package/src/themes/adc-dark/_variables.scss +913 -0
- package/src/themes/adc-dark/blue/_fonts.scss +24 -0
- package/src/themes/adc-dark/blue/adc_theme.scss +31 -0
- package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleMono-Italic-VariableFont_wght.ttf +0 -0
- package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleMono-VariableFont_wght.ttf +0 -0
- package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-Italic-VariableFont_wght.ttf +0 -0
- package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-Regular.woff2 +0 -0
- package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-RegularItalic.woff2 +0 -0
- package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-VariableFont_wght.ttf +0 -0
- package/src/themes/adc-dark/blue/theme.scss +14 -0
- package/src/themes/theme-base/_colors.scss +18 -0
- package/src/themes/theme-base/_common.scss +75 -0
- package/src/themes/theme-base/_components.scss +111 -0
- package/src/themes/theme-base/_mixins.scss +243 -0
- package/src/themes/theme-base/components/button/_button.scss +644 -0
- package/src/themes/theme-base/components/button/_speeddial.scss +91 -0
- package/src/themes/theme-base/components/button/_splitbutton.scss +359 -0
- package/src/themes/theme-base/components/data/_carousel.scss +39 -0
- package/src/themes/theme-base/components/data/_datascroller.scss +47 -0
- package/src/themes/theme-base/components/data/_datatable.scss +389 -0
- package/src/themes/theme-base/components/data/_dataview.scss +47 -0
- package/src/themes/theme-base/components/data/_filter.scss +138 -0
- package/src/themes/theme-base/components/data/_orderlist.scss +86 -0
- package/src/themes/theme-base/components/data/_organizationchart.scss +50 -0
- package/src/themes/theme-base/components/data/_paginator.scss +91 -0
- package/src/themes/theme-base/components/data/_picklist.scss +74 -0
- package/src/themes/theme-base/components/data/_timeline.scss +38 -0
- package/src/themes/theme-base/components/data/_tree.scss +184 -0
- package/src/themes/theme-base/components/data/_treetable.scss +431 -0
- package/src/themes/theme-base/components/file/_fileupload.scss +41 -0
- package/src/themes/theme-base/components/input/_autocomplete.scss +95 -0
- package/src/themes/theme-base/components/input/_calendar.scss +251 -0
- package/src/themes/theme-base/components/input/_cascadeselect.scss +107 -0
- package/src/themes/theme-base/components/input/_checkbox.scss +181 -0
- package/src/themes/theme-base/components/input/_chips.scss +102 -0
- package/src/themes/theme-base/components/input/_colorpicker.scss +18 -0
- package/src/themes/theme-base/components/input/_dropdown.scss +252 -0
- package/src/themes/theme-base/components/input/_editor.scss +122 -0
- package/src/themes/theme-base/components/input/_iconfield.scss +10 -0
- package/src/themes/theme-base/components/input/_inputgroup.scss +74 -0
- package/src/themes/theme-base/components/input/_inputicon.scss +15 -0
- package/src/themes/theme-base/components/input/_inputnumber.scss +5 -0
- package/src/themes/theme-base/components/input/_inputotp.scss +10 -0
- package/src/themes/theme-base/components/input/_inputswitch.scss +100 -0
- package/src/themes/theme-base/components/input/_inputtext.scss +101 -0
- package/src/themes/theme-base/components/input/_listbox.scss +139 -0
- package/src/themes/theme-base/components/input/_mention.scss +31 -0
- package/src/themes/theme-base/components/input/_multiselect.scss +278 -0
- package/src/themes/theme-base/components/input/_password.scss +33 -0
- package/src/themes/theme-base/components/input/_radiobutton.scss +170 -0
- package/src/themes/theme-base/components/input/_rating.scss +81 -0
- package/src/themes/theme-base/components/input/_selectbutton.scss +50 -0
- package/src/themes/theme-base/components/input/_slider.scss +49 -0
- package/src/themes/theme-base/components/input/_togglebutton.scss +99 -0
- package/src/themes/theme-base/components/input/_treeselect.scss +151 -0
- package/src/themes/theme-base/components/input/_tristatecheckbox.scss +46 -0
- package/src/themes/theme-base/components/menu/_breadcrumb.scss +42 -0
- package/src/themes/theme-base/components/menu/_contextmenu.scss +39 -0
- package/src/themes/theme-base/components/menu/_dock.scss +109 -0
- package/src/themes/theme-base/components/menu/_megamenu.scss +141 -0
- package/src/themes/theme-base/components/menu/_menu.scss +33 -0
- package/src/themes/theme-base/components/menu/_menubar.scss +216 -0
- package/src/themes/theme-base/components/menu/_panelmenu.scss +153 -0
- package/src/themes/theme-base/components/menu/_slidemenu.scss +60 -0
- package/src/themes/theme-base/components/menu/_steps.scss +57 -0
- package/src/themes/theme-base/components/menu/_tabmenu.scss +50 -0
- package/src/themes/theme-base/components/menu/_tieredmenu.scss +43 -0
- package/src/themes/theme-base/components/messages/_inlinemessage.scss +69 -0
- package/src/themes/theme-base/components/messages/_message.scss +107 -0
- package/src/themes/theme-base/components/messages/_toast.scss +100 -0
- package/src/themes/theme-base/components/misc/_avatar.scss +34 -0
- package/src/themes/theme-base/components/misc/_badge.scss +77 -0
- package/src/themes/theme-base/components/misc/_blockui.scss +0 -0
- package/src/themes/theme-base/components/misc/_chip.scss +39 -0
- package/src/themes/theme-base/components/misc/_inplace.scss +17 -0
- package/src/themes/theme-base/components/misc/_metergroup.scss +81 -0
- package/src/themes/theme-base/components/misc/_progressbar.scss +17 -0
- package/src/themes/theme-base/components/misc/_scrolltop.scss +25 -0
- package/src/themes/theme-base/components/misc/_skeleton.scss +8 -0
- package/src/themes/theme-base/components/misc/_tag.scss +40 -0
- package/src/themes/theme-base/components/misc/_terminal.scss +12 -0
- package/src/themes/theme-base/components/multimedia/_galleria.scss +153 -0
- package/src/themes/theme-base/components/multimedia/_image.scss +54 -0
- package/src/themes/theme-base/components/overlay/_confirmpopup.scss +72 -0
- package/src/themes/theme-base/components/overlay/_dialog.scss +78 -0
- package/src/themes/theme-base/components/overlay/_overlaypanel.scss +64 -0
- package/src/themes/theme-base/components/overlay/_sidebar.scss +23 -0
- package/src/themes/theme-base/components/overlay/_tooltip.scss +33 -0
- package/src/themes/theme-base/components/panel/_accordion.scss +118 -0
- package/src/themes/theme-base/components/panel/_card.scss +30 -0
- package/src/themes/theme-base/components/panel/_divider.scss +31 -0
- package/src/themes/theme-base/components/panel/_fieldset.scss +47 -0
- package/src/themes/theme-base/components/panel/_panel.scss +47 -0
- package/src/themes/theme-base/components/panel/_scrollpanel.scss +10 -0
- package/src/themes/theme-base/components/panel/_splitter.scss +23 -0
- package/src/themes/theme-base/components/panel/_stepper.scss +136 -0
- package/src/themes/theme-base/components/panel/_tabview.scss +147 -0
- package/src/themes/theme-base/components/panel/_toolbar.scss +11 -0
- package/tools/build-themes.cjs +66 -0
- package/tools/copy-distribution-files.cjs +20 -16
package/dist/hub/HubBase.js
CHANGED
|
@@ -1,310 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Copyright (C) 2023 Automated Design Corp. All Rights Reserved.
|
|
3
|
-
* Created Date: 2023-12-15 14:21:33
|
|
4
|
-
* Author: Thomas C. Bitsky Jr.
|
|
5
|
-
* -----
|
|
6
|
-
* Last Modified: 2025-03-31 08:35:09
|
|
7
|
-
* Modified By: ADC
|
|
8
|
-
* -----
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Base class for the interface for the IPC to the backend,
|
|
13
|
-
* which may be websockets, MQTT, the Tauri API,
|
|
14
|
-
* or something else.
|
|
15
|
-
*
|
|
16
|
-
* The EventEmitterContext should generate the hub automatically.
|
|
17
|
-
*
|
|
18
|
-
* # Usage
|
|
19
|
-
* The hub can be used to publish and subscribe to
|
|
20
|
-
* topics in the front-end, regardless of being connected to any backend.
|
|
21
|
-
*
|
|
22
|
-
* ```
|
|
23
|
-
* const {dispatch, subscribe, unsubscribe} = useContext(EventEmitterContext);
|
|
24
|
-
* const [controlPower, setControlPower] = useState(false);
|
|
25
|
-
* useEffect(() => {
|
|
26
|
-
* const unsubscribeControlPower = subscribe('value-simulator-bBit1', (value) => {
|
|
27
|
-
* setControlPower(value);
|
|
28
|
-
* });
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* return () => {
|
|
32
|
-
* unsubscribe(unsubscribeControlPower);
|
|
33
|
-
* }
|
|
34
|
-
* }, [] );
|
|
35
|
-
*
|
|
36
|
-
* const onPbPressed = () => {
|
|
37
|
-
* let count = 1;
|
|
38
|
-
* dispatch({
|
|
39
|
-
* topic: "my-awesome-topic",
|
|
40
|
-
* payload: count
|
|
41
|
-
* });
|
|
42
|
-
* }
|
|
43
|
-
*
|
|
44
|
-
* ```
|
|
45
|
-
* The hub should also be used for invoking events in the backend.
|
|
46
|
-
* This example will call the function "update_count" in the backend, passing
|
|
47
|
-
* the expected argument "count". Details of the interaction between the Hub and
|
|
48
|
-
* the backend will be handled by the appropriate HubBase sub-class, and should
|
|
49
|
-
* be transparent to the front end.
|
|
50
|
-
*
|
|
51
|
-
* ```
|
|
52
|
-
* const {invoke} = useContext(EventEmitterContext);
|
|
53
|
-
* const incrementCount = () => {
|
|
54
|
-
* count += 1;
|
|
55
|
-
* invoke('update_count', {"count": count});
|
|
56
|
-
* };
|
|
57
|
-
*
|
|
58
|
-
* Subscribing to a topic is simple. The type of value received is specific
|
|
59
|
-
* to the topic.
|
|
60
|
-
*
|
|
61
|
-
* Example: Listen to an event 'xarm-position':
|
|
62
|
-
* ```
|
|
63
|
-
* const {subscribe, unsubscribe} = useContext(EventEmitterContext);
|
|
64
|
-
* useEffect(() => {
|
|
65
|
-
* const unsubscripeMp = subscribe('xarm-position', (value) => {
|
|
66
|
-
* // The publisher sent a JSON object of 3D position values.
|
|
67
|
-
* setX(value.x);
|
|
68
|
-
* setY(value.y);
|
|
69
|
-
* setZ(value.z);
|
|
70
|
-
* setA(value.roll);
|
|
71
|
-
* setB(value.yaw);
|
|
72
|
-
* setC(value.pitch);
|
|
73
|
-
* });
|
|
74
|
-
*
|
|
75
|
-
* return () => {
|
|
76
|
-
* unsubscribe(unsubscripeMp);
|
|
77
|
-
* }
|
|
78
|
-
*
|
|
79
|
-
* }, [] );
|
|
80
|
-
*
|
|
81
|
-
* ```
|
|
82
|
-
*
|
|
83
|
-
*/
|
|
84
|
-
export class HubBase {
|
|
85
|
-
/**
|
|
86
|
-
* Constructor
|
|
87
|
-
*/
|
|
88
|
-
constructor() {
|
|
89
|
-
Object.defineProperty(this, "localTopicToBackendTopicMap", {
|
|
90
|
-
enumerable: true,
|
|
91
|
-
configurable: true,
|
|
92
|
-
writable: true,
|
|
93
|
-
value: new Map()
|
|
94
|
-
});
|
|
95
|
-
Object.defineProperty(this, "backendTopicToLocalMap", {
|
|
96
|
-
enumerable: true,
|
|
97
|
-
configurable: true,
|
|
98
|
-
writable: true,
|
|
99
|
-
value: new Map()
|
|
100
|
-
});
|
|
101
|
-
Object.defineProperty(this, "localFNameToBackendFNameMap", {
|
|
102
|
-
enumerable: true,
|
|
103
|
-
configurable: true,
|
|
104
|
-
writable: true,
|
|
105
|
-
value: new Map()
|
|
106
|
-
});
|
|
107
|
-
Object.defineProperty(this, "backendFNameToLocalFNameMap", {
|
|
108
|
-
enumerable: true,
|
|
109
|
-
configurable: true,
|
|
110
|
-
writable: true,
|
|
111
|
-
value: new Map()
|
|
112
|
-
});
|
|
113
|
-
Object.defineProperty(this, "context", {
|
|
114
|
-
enumerable: true,
|
|
115
|
-
configurable: true,
|
|
116
|
-
writable: true,
|
|
117
|
-
value: null
|
|
118
|
-
});
|
|
119
|
-
Object.defineProperty(this, "isConnected_", {
|
|
120
|
-
enumerable: true,
|
|
121
|
-
configurable: true,
|
|
122
|
-
writable: true,
|
|
123
|
-
value: false
|
|
124
|
-
});
|
|
125
|
-
/**
|
|
126
|
-
* Allos the derived class to set whether the hub is connected to its source.
|
|
127
|
-
* @param s boolean
|
|
128
|
-
*/
|
|
129
|
-
Object.defineProperty(this, "setIsConnected", {
|
|
130
|
-
enumerable: true,
|
|
131
|
-
configurable: true,
|
|
132
|
-
writable: true,
|
|
133
|
-
value: (s) => {
|
|
134
|
-
this.isConnected_ = s;
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
/**
|
|
138
|
-
* Returns true if the Hub is connected to its source.
|
|
139
|
-
*/
|
|
140
|
-
Object.defineProperty(this, "isConnected", {
|
|
141
|
-
enumerable: true,
|
|
142
|
-
configurable: true,
|
|
143
|
-
writable: true,
|
|
144
|
-
value: () => {
|
|
145
|
-
return this.isConnected_;
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Set the EventEmitterContext for this instance of the Hub. The EventEmitterContext
|
|
151
|
-
* should handle this as part of the initialization sequence. Because React can
|
|
152
|
-
* sometimes make (and destroy) multiple copies of the EventEmitterContext, it's important
|
|
153
|
-
* that the context be stored in the instance this way so that the HubBase can properly target
|
|
154
|
-
* right context.
|
|
155
|
-
*
|
|
156
|
-
* If this context is not sent, no events will be emitted from the backend to the front end,
|
|
157
|
-
* and global events in the interface may not work.
|
|
158
|
-
*
|
|
159
|
-
*/
|
|
160
|
-
setContext(context) {
|
|
161
|
-
this.context = context;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Convenience function to invoke a command with an optional topic and optional value.
|
|
165
|
-
* This will invoke the specified command in the backend. It does not broadcast the
|
|
166
|
-
* value within the local frontend.
|
|
167
|
-
* @param domain string The domain of the command that will be invoked.
|
|
168
|
-
* @param fname string Function name
|
|
169
|
-
* @param topic string Topic
|
|
170
|
-
* @param value any data payload
|
|
171
|
-
*/
|
|
172
|
-
invokeTopic(domain, fname, topic, value) {
|
|
173
|
-
const msg = {
|
|
174
|
-
topic: topic,
|
|
175
|
-
data: value
|
|
176
|
-
};
|
|
177
|
-
return this.invoke(domain, fname, msg);
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Pubish a topic throughout the web app using the
|
|
181
|
-
* Global EventEmitterContext. This will broadcast within the local frontend.
|
|
182
|
-
* This does NOT get relayed to the backend.
|
|
183
|
-
*/
|
|
184
|
-
publish(topic, data) {
|
|
185
|
-
const convertedTopic = this.toLocalTopic(topic);
|
|
186
|
-
console.log(`HUB Dispatch topic ${convertedTopic} payload ${JSON.stringify(data)}`);
|
|
187
|
-
this.context?.dispatch({
|
|
188
|
-
topic: convertedTopic,
|
|
189
|
-
payload: data
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Map a local topic to a topic in the backend.
|
|
194
|
-
* @param localTopic string
|
|
195
|
-
* @param backendTopic string
|
|
196
|
-
*/
|
|
197
|
-
mapTopic(localTopic, backendTopic) {
|
|
198
|
-
this.localTopicToBackendTopicMap.set(localTopic, backendTopic);
|
|
199
|
-
this.backendTopicToLocalMap.set(backendTopic, localTopic);
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Unmap a local topic.
|
|
203
|
-
* @param localTopic string
|
|
204
|
-
*/
|
|
205
|
-
unmapTopic(localTopic) {
|
|
206
|
-
if (this.localTopicToBackendTopicMap.has(localTopic)) {
|
|
207
|
-
const be = this.localTopicToBackendTopicMap.get(localTopic);
|
|
208
|
-
this.localTopicToBackendTopicMap.delete(localTopic);
|
|
209
|
-
if (be !== null && be !== undefined && this.backendTopicToLocalMap.has(be)) {
|
|
210
|
-
this.backendTopicToLocalMap.delete(be);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Map a local function name, as would be sent to the invoke method, to a
|
|
216
|
-
* function name in the backend.
|
|
217
|
-
* @param localFName string
|
|
218
|
-
* @param backendFName string
|
|
219
|
-
*/
|
|
220
|
-
mapFName(localFName, backendFName) {
|
|
221
|
-
this.localFNameToBackendFNameMap.set(localFName, backendFName);
|
|
222
|
-
this.backendFNameToLocalFNameMap.set(backendFName, localFName);
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Unmap a local function name.
|
|
226
|
-
* @param localFName string
|
|
227
|
-
*/
|
|
228
|
-
unmapFName(localFName) {
|
|
229
|
-
if (this.localFNameToBackendFNameMap.has(localFName)) {
|
|
230
|
-
const be = this.localFNameToBackendFNameMap.get(localFName);
|
|
231
|
-
this.localFNameToBackendFNameMap.delete(localFName);
|
|
232
|
-
if (be !== null && be !== undefined && this.backendFNameToLocalFNameMap.has(be)) {
|
|
233
|
-
this.backendFNameToLocalFNameMap.delete(be);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Convert a local topic to a backend topic. If a mapping isn't
|
|
239
|
-
* registered, the local topic is returned.
|
|
240
|
-
* @param localTopic local topic name
|
|
241
|
-
* @returns string
|
|
242
|
-
*/
|
|
243
|
-
toBackendTopic(localTopic) {
|
|
244
|
-
if (this.localTopicToBackendTopicMap.has(localTopic)) {
|
|
245
|
-
const ret = this.localTopicToBackendTopicMap.get(localTopic);
|
|
246
|
-
if (ret !== null && ret !== undefined)
|
|
247
|
-
return ret;
|
|
248
|
-
else
|
|
249
|
-
return localTopic;
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
return localTopic;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Convert a local function name to a backend function name. If a mapping isn't
|
|
257
|
-
* registered, the local FName is returned.
|
|
258
|
-
* @param localTopic local function name
|
|
259
|
-
* @returns string
|
|
260
|
-
*/
|
|
261
|
-
toBackendFName(localFName) {
|
|
262
|
-
if (this.localFNameToBackendFNameMap.has(localFName)) {
|
|
263
|
-
const ret = this.localFNameToBackendFNameMap.get(localFName);
|
|
264
|
-
if (ret !== null && ret !== undefined)
|
|
265
|
-
return ret;
|
|
266
|
-
else
|
|
267
|
-
return localFName;
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
return localFName;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Convert a backend topic to a local topic. If a mapping isn't
|
|
275
|
-
* registered, the backend topic is returned.
|
|
276
|
-
* @param backendTopic backend topic name
|
|
277
|
-
* @returns string
|
|
278
|
-
*/
|
|
279
|
-
toLocalTopic(backendTopic) {
|
|
280
|
-
if (this.backendTopicToLocalMap.has(backendTopic)) {
|
|
281
|
-
const ret = this.backendTopicToLocalMap.get(backendTopic);
|
|
282
|
-
if (ret !== null && ret !== undefined)
|
|
283
|
-
return ret;
|
|
284
|
-
else
|
|
285
|
-
return backendTopic;
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
return backendTopic;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Convert a backend function name to a local function name. If a mapping isn't
|
|
293
|
-
* registered, the backend function name is returned.
|
|
294
|
-
* @param backendTopic backend function name
|
|
295
|
-
* @returns string
|
|
296
|
-
*/
|
|
297
|
-
toLocalFName(backendTopic) {
|
|
298
|
-
if (this.backendFNameToLocalFNameMap.has(backendTopic)) {
|
|
299
|
-
const ret = this.backendFNameToLocalFNameMap.get(backendTopic);
|
|
300
|
-
if (ret !== null && ret !== undefined)
|
|
301
|
-
return ret;
|
|
302
|
-
else
|
|
303
|
-
return backendTopic;
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
return backendTopic;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
export default HubBase;
|
|
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;
|
package/dist/hub/HubSimulate.js
CHANGED
|
@@ -1,46 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Copyright (C) 2023 Automated Design Corp. All Rights Reserved.
|
|
3
|
-
* Created Date: 2023-12-17 10:38:21
|
|
4
|
-
* -----
|
|
5
|
-
* Last Modified: 2024-04-24 11:56:26
|
|
6
|
-
* Modified By: ADC
|
|
7
|
-
* -----
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
import { HubBase } from './HubBase';
|
|
11
|
-
/**
|
|
12
|
-
* Hub for simulating functionality when no backend is present.
|
|
13
|
-
*/
|
|
14
|
-
export class HubSimulate extends HubBase {
|
|
15
|
-
/**
|
|
16
|
-
* Constructor
|
|
17
|
-
*/
|
|
18
|
-
constructor() {
|
|
19
|
-
super();
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Invoke a method in the Socket.IO backend and wait for acknowledgment.
|
|
23
|
-
*
|
|
24
|
-
* @param fname method name
|
|
25
|
-
* @param payload Optional data payload
|
|
26
|
-
* @param timeout Timeout in milliseconds after which the promise is rejected if no response is received.
|
|
27
|
-
* @returns A Promise that resolves to the response from the backend or rejects if a timeout occurs.
|
|
28
|
-
*/
|
|
29
|
-
invoke(domain, fname, payload, timeout = 20) {
|
|
30
|
-
domain; // Not using for simulator
|
|
31
|
-
fname; // Not using for simulator
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
reject; // not using for simulator
|
|
34
|
-
// Set a timeout to echo a response
|
|
35
|
-
setTimeout(() => {
|
|
36
|
-
let ret = {
|
|
37
|
-
data: payload,
|
|
38
|
-
error_message: "",
|
|
39
|
-
success: true
|
|
40
|
-
};
|
|
41
|
-
resolve(ret);
|
|
42
|
-
}, timeout);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
export default HubSimulate;
|
|
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;
|
package/dist/hub/HubTauri.js
CHANGED
|
@@ -1,130 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Copyright (C) 2023 Automated Design Corp. All Rights Reserved.
|
|
3
|
-
* Created Date: 2023-12-17 09:50:23
|
|
4
|
-
* Author: Thomas C. Bitsky Jr.
|
|
5
|
-
* -----
|
|
6
|
-
* Last Modified: 2024-04-24 11:56:32
|
|
7
|
-
* Modified By: ADC
|
|
8
|
-
* -----
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
import { HubBase } from './HubBase';
|
|
12
|
-
import { event, invoke } from '@tauri-apps/api';
|
|
13
|
-
/**
|
|
14
|
-
* Hub for integrating with the Tauri backend.
|
|
15
|
-
*
|
|
16
|
-
* The tauri backend is expected to broadcast messages on the event
|
|
17
|
-
* name: 'autocore://broadcast_event'
|
|
18
|
-
*
|
|
19
|
-
* This hub will capture those messages and dispatch them globally to any
|
|
20
|
-
* listeners in the web app.
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* Example: Listen to an event 'xarm-position':
|
|
24
|
-
* ```
|
|
25
|
-
* const {subscribe, unsubscribe} = useContext(EventEmitterContext);
|
|
26
|
-
* useEffect(() => {
|
|
27
|
-
* const unsubscripeMp = subscribe('xarm-position', (value) => {
|
|
28
|
-
* // The rust backend sent a JSON object of 3D position values.
|
|
29
|
-
* setX(value.x);
|
|
30
|
-
* setY(value.y);
|
|
31
|
-
* setZ(value.z);
|
|
32
|
-
* setA(value.roll);
|
|
33
|
-
* setB(value.yaw);
|
|
34
|
-
* setC(value.pitch);
|
|
35
|
-
* });
|
|
36
|
-
*
|
|
37
|
-
* return () => {
|
|
38
|
-
* unsubscribe(unsubscripeMp);
|
|
39
|
-
* }
|
|
40
|
-
*
|
|
41
|
-
* }, [] );
|
|
42
|
-
*
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* The hub should also be used for invoking events in the Tauri backend.
|
|
46
|
-
* This example will call the function "update_count" in the rust backend, passing
|
|
47
|
-
* the expected argument "count".
|
|
48
|
-
* ```
|
|
49
|
-
* const {invoke} = useContext(EventEmitterContext);
|
|
50
|
-
* const incrementCount = () => {
|
|
51
|
-
* count += 1;
|
|
52
|
-
* invoke('update_count', {"count": count});
|
|
53
|
-
* };
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* Of course, like any class derived from HubBase, the hub can be used to publish and subscribe to
|
|
57
|
-
* topics in the front-end, without need of interacting with the Tauri backed.
|
|
58
|
-
*
|
|
59
|
-
* ```
|
|
60
|
-
* const {dispatch, subscribe, unsubscribe} = useContext(EventEmitterContext);
|
|
61
|
-
* const [controlPower, setControlPower] = useState(false);
|
|
62
|
-
* useEffect(() => {
|
|
63
|
-
* const unsubscribeControlPower = subscribe('value-simulator-bBit1', (value) => {
|
|
64
|
-
* setControlPower(value);
|
|
65
|
-
* });
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* return () => {
|
|
69
|
-
* unsubscribe(unsubscribeControlPower);
|
|
70
|
-
* }
|
|
71
|
-
* }, [] );
|
|
72
|
-
*
|
|
73
|
-
* const onPbPressed = () => {
|
|
74
|
-
* let count = 1;
|
|
75
|
-
* dispatch({
|
|
76
|
-
* topic: "my-awesome-topic",
|
|
77
|
-
* payload: count
|
|
78
|
-
* });
|
|
79
|
-
* }
|
|
80
|
-
*
|
|
81
|
-
* ```
|
|
82
|
-
*
|
|
83
|
-
*/
|
|
84
|
-
export class HubTauri extends HubBase {
|
|
85
|
-
/**
|
|
86
|
-
* Constructor
|
|
87
|
-
*/
|
|
88
|
-
constructor() {
|
|
89
|
-
super();
|
|
90
|
-
/**
|
|
91
|
-
* Receive broadcasts from the Tauri backend. Data is received as a payload object,
|
|
92
|
-
* {topic: string, payload: any | null}
|
|
93
|
-
* From here, we extract into a form HubBase can use, then pass on to the
|
|
94
|
-
* dispatcher.
|
|
95
|
-
*
|
|
96
|
-
* Events without a topic are ignored.
|
|
97
|
-
*/
|
|
98
|
-
event.listen('autocore://broadcast_event', (ev) => {
|
|
99
|
-
let objPayload = JSON.parse(ev.payload);
|
|
100
|
-
if (objPayload.topic !== undefined && objPayload.topic !== null) {
|
|
101
|
-
if (objPayload.payload !== undefined && objPayload.payload !== null) {
|
|
102
|
-
this.publish(objPayload.topic, objPayload.payload);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
this.publish(objPayload.topic, undefined);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Invoke a method in the rust backend.
|
|
112
|
-
*
|
|
113
|
-
* @param fname method name
|
|
114
|
-
* @param payload Optional data payload
|
|
115
|
-
* @returns The return value of the backend method.
|
|
116
|
-
*/
|
|
117
|
-
invoke(domain, fname, payload) {
|
|
118
|
-
console.log(JSON.stringify(event));
|
|
119
|
-
if (payload !== undefined && payload !== null) {
|
|
120
|
-
console.log(`Payload: ${JSON.stringify(payload)}`);
|
|
121
|
-
// todo! This should probably always been the same function, and then that function
|
|
122
|
-
// in the backend routes the command.
|
|
123
|
-
let topic = `${domain}_${fname}`;
|
|
124
|
-
return invoke(topic, payload);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
return invoke(fname);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
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)}}
|