@adcops/autocore-react 3.0.0
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/LICENSE +59 -0
- package/additional-docs/ButtonApiSpecs.md +48 -0
- package/additional-docs/GlobalEventEmitter.md +244 -0
- package/additional-docs/general_recommendations.md +22 -0
- package/dist/components/DPad.css +522 -0
- package/dist/components/DPad.d.ts +34 -0
- package/dist/components/DPad.js +1 -0
- package/dist/components/Indicator.d.ts +81 -0
- package/dist/components/Indicator.js +1 -0
- package/dist/components/IndicatorButton.d.ts +137 -0
- package/dist/components/IndicatorButton.js +1 -0
- package/dist/components/IndicatorColor.d.ts +26 -0
- package/dist/components/IndicatorColor.js +1 -0
- package/dist/components/Osk.d.ts +14 -0
- package/dist/components/Osk.js +1 -0
- package/dist/components/OskDialog.d.ts +33 -0
- package/dist/components/OskDialog.js +1 -0
- package/dist/components/ValueDisplay.d.ts +99 -0
- package/dist/components/ValueDisplay.js +1 -0
- package/dist/components/osk.css +123 -0
- package/dist/core/EventEmitterContext.d.ts +223 -0
- package/dist/core/EventEmitterContext.js +1 -0
- package/dist/core/MaskPatterns.d.ts +71 -0
- package/dist/core/MaskPatterns.js +1 -0
- package/dist/core/NumerableTypes.d.ts +58 -0
- package/dist/core/NumerableTypes.js +1 -0
- package/dist/core/PositionContext.d.ts +38 -0
- package/dist/core/PositionContext.js +1 -0
- package/dist/core/UniqueId.d.ts +16 -0
- package/dist/core/UniqueId.js +1 -0
- package/dist/core/ValueSimulator.d.ts +71 -0
- package/dist/core/ValueSimulator.js +1 -0
- package/dist/core/hoc.d.ts +31 -0
- package/dist/core/hoc.js +1 -0
- package/dist/hub/HubBase.d.ts +169 -0
- package/dist/hub/HubBase.js +1 -0
- package/dist/hub/HubSimulate.d.ts +20 -0
- package/dist/hub/HubSimulate.js +1 -0
- package/dist/hub/HubSocketIo.d.ts +101 -0
- package/dist/hub/HubSocketIo.js +1 -0
- package/dist/hub/HubTauri.d.ts +86 -0
- package/dist/hub/HubTauri.js +1 -0
- package/dist/hub/index.d.ts +13 -0
- package/dist/hub/index.js +1 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +106 -0
- package/docs/assets/icons.js +15 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +59 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1414 -0
- package/docs/classes/components_Indicator.Indicator.html +105 -0
- package/docs/classes/components_IndicatorButton.IndicatorButton.html +119 -0
- package/docs/classes/components_OskDialog.OskDialog.html +117 -0
- package/docs/classes/components_ValueDisplay.ValueDisplay.html +104 -0
- package/docs/classes/core_ValueSimulator.ValueSimulator.html +41 -0
- package/docs/classes/hub_HubBase.HubBase.html +67 -0
- package/docs/classes/hub_HubSimulate.HubSimulate.html +72 -0
- package/docs/classes/hub_HubSocketIo.HubSocketIo.html +80 -0
- package/docs/classes/hub_HubTauri.HubTauri.html +80 -0
- package/docs/enums/components_DPad.VcJoyPadAction.html +10 -0
- package/docs/enums/components_DPad.VcJoyPadButtonId.html +7 -0
- package/docs/enums/components_IndicatorButton.ActionMode.html +6 -0
- package/docs/enums/components_IndicatorColor.IndicatorColor.html +13 -0
- package/docs/functions/components_DPad.VcDPad.html +5 -0
- package/docs/functions/components_Osk.Osk.html +5 -0
- package/docs/functions/core_EventEmitterContext.EventEmitterProvider.html +8 -0
- package/docs/functions/core_UniqueId.UniqueId.html +4 -0
- package/docs/functions/core_hoc.hocAddSubscription.html +6 -0
- package/docs/functions/hub.createHub.html +3 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +69 -0
- package/docs/interfaces/components_IndicatorButton.IndicatorButtonProps.html +635 -0
- package/docs/interfaces/components_IndicatorButton.IndicatorButtonState.html +10 -0
- package/docs/interfaces/core_DimensionsContext.IDimensionsContext.html +4 -0
- package/docs/interfaces/core_EventEmitterContext.Action.html +5 -0
- package/docs/interfaces/core_EventEmitterContext.EventEmitterContextType.html +18 -0
- package/docs/interfaces/core_EventEmitterContext.State.html +8 -0
- package/docs/interfaces/core_EventEmitterContext.Subscription.html +6 -0
- package/docs/modules/components_DPad.html +5 -0
- package/docs/modules/components_Indicator.html +4 -0
- package/docs/modules/components_IndicatorButton.html +7 -0
- package/docs/modules/components_IndicatorColor.html +2 -0
- package/docs/modules/components_Osk.html +3 -0
- package/docs/modules/components_OskDialog.html +3 -0
- package/docs/modules/components_ValueDisplay.html +3 -0
- package/docs/modules/core_DimensionsContext.html +4 -0
- package/docs/modules/core_EventEmitterContext.html +11 -0
- package/docs/modules/core_InputPatterns.html +2 -0
- package/docs/modules/core_NumerableTypes.html +2 -0
- package/docs/modules/core_UniqueId.html +2 -0
- package/docs/modules/core_ValueSimulator.html +3 -0
- package/docs/modules/core_hoc.html +3 -0
- package/docs/modules/hub.html +6 -0
- package/docs/modules/hub_HubBase.html +3 -0
- package/docs/modules/hub_HubSimulate.html +3 -0
- package/docs/modules/hub_HubSocketIo.html +3 -0
- package/docs/modules/hub_HubTauri.html +2 -0
- package/docs/types/core_EventEmitterContext.EmitterDispatchFunction.html +1 -0
- package/docs/types/core_EventEmitterContext.EmitterSubscribeFunction.html +1 -0
- package/docs/types/core_EventEmitterContext.EmitterUnsubscribeFunction.html +1 -0
- package/docs/types/core_NumerableTypes.NumerableFormatOptions.html +1 -0
- package/docs/types/core_hoc.HocAddSubscriptionProps.html +4 -0
- package/docs/variables/core_DimensionsContext.DimensionsContext.html +1 -0
- package/docs/variables/core_EventEmitterContext.EventEmitterContext.html +5 -0
- package/docs/variables/core_InputPatterns.InputPatterns.html +2 -0
- package/package.json +79 -0
- package/readme.md +140 -0
- package/src/components/DPad.css +522 -0
- package/src/components/DPad.tsx +94 -0
- package/src/components/Indicator.tsx +243 -0
- package/src/components/IndicatorButton.tsx +306 -0
- package/src/components/IndicatorColor.ts +36 -0
- package/src/components/Osk.tsx +193 -0
- package/src/components/OskDialog.tsx +165 -0
- package/src/components/ValueDisplay.tsx +181 -0
- package/src/components/osk.css +123 -0
- package/src/core/EventEmitterContext.tsx +394 -0
- package/src/core/MaskPatterns.ts +82 -0
- package/src/core/NumerableTypes.ts +81 -0
- package/src/core/PositionContext.ts +60 -0
- package/src/core/UniqueId.ts +41 -0
- package/src/core/ValueSimulator.ts +167 -0
- package/src/core/hoc.tsx +65 -0
- package/src/hub/HubBase.ts +293 -0
- package/src/hub/HubSimulate.ts +47 -0
- package/src/hub/HubSocketIo.ts +166 -0
- package/src/hub/HubTauri.ts +145 -0
- package/src/hub/index.ts +41 -0
- package/terser.config.cjs +25 -0
- package/todo.md +18 -0
- package/tools/copy-distribution-files.cjs +73 -0
- package/tools/minify.cjs +56 -0
- package/tsconfig.json +34 -0
- package/typedoc.json +13 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { Hub } from "../hub";
|
|
3
|
+
export { Hub };
|
|
4
|
+
/**
|
|
5
|
+
* Represents an event subsription.
|
|
6
|
+
*/
|
|
7
|
+
export interface Subscription {
|
|
8
|
+
/** ID of the subscription used for unsubscription. */
|
|
9
|
+
id: number;
|
|
10
|
+
/** Callback function. */
|
|
11
|
+
callback: React.Dispatch<any>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Represents the payload data associated with an event.
|
|
15
|
+
*/
|
|
16
|
+
export interface State {
|
|
17
|
+
/**
|
|
18
|
+
* The optional data payload of the event.
|
|
19
|
+
*/
|
|
20
|
+
eventData?: any;
|
|
21
|
+
/** Callback subscription. A list of callback subscriptions matched to a topic. */
|
|
22
|
+
subscriptions: Record<string, Subscription[]>;
|
|
23
|
+
/** Tracks the next subscription ID that will be assigned. */
|
|
24
|
+
nextSubscriptionId: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* An action event published by the EventEmitterContext. Contains
|
|
28
|
+
* the topic identifying the event and the optional payload, which is
|
|
29
|
+
* a value of any type.
|
|
30
|
+
*/
|
|
31
|
+
export interface Action {
|
|
32
|
+
/**
|
|
33
|
+
* The topic or identifier of the event.
|
|
34
|
+
*/
|
|
35
|
+
topic: string;
|
|
36
|
+
/**
|
|
37
|
+
* The optional data payload associated with the event.
|
|
38
|
+
*/
|
|
39
|
+
payload?: any;
|
|
40
|
+
}
|
|
41
|
+
export type EmitterDispatchFunction = (action: Action) => void;
|
|
42
|
+
export type EmitterSubscribeFunction = (action: Action) => void;
|
|
43
|
+
export type EmitterUnsubscribeFunction = (action: Action) => void;
|
|
44
|
+
export interface EventEmitterContextType {
|
|
45
|
+
/**
|
|
46
|
+
* The current state of the event emitter, containing the latest event data.
|
|
47
|
+
*/
|
|
48
|
+
state: State;
|
|
49
|
+
/**
|
|
50
|
+
* A function to dispatch actions globally throughout the front-end,
|
|
51
|
+
* triggering state updates and events.
|
|
52
|
+
*
|
|
53
|
+
* @param action The action to dispatch, containing topic and optional payload.
|
|
54
|
+
*/
|
|
55
|
+
dispatch: (action: Action) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Invoke/send a message to the back end.
|
|
58
|
+
* This does NOT get published to the front end.
|
|
59
|
+
*/
|
|
60
|
+
invoke(fname: string, payload?: object): Promise<object>;
|
|
61
|
+
/**
|
|
62
|
+
* Subscribe to events identified by the topic.
|
|
63
|
+
* @param topic The subscription topic.
|
|
64
|
+
* @param callback The callback to signal.
|
|
65
|
+
* @returns number Subscription ID used to unsubscribe later.
|
|
66
|
+
*/
|
|
67
|
+
subscribe: (topic: string, callback: React.Dispatch<any>) => number;
|
|
68
|
+
/**
|
|
69
|
+
* Unsubscribe to events.
|
|
70
|
+
* @param subscriptionId The id of the subscription returned by the subscribe method.
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
unsubscribe: (subscriptionId: number) => void;
|
|
74
|
+
/**
|
|
75
|
+
* Global hub for publishing and receiving events throughout the interface, and for exchanging
|
|
76
|
+
* data with the backend.
|
|
77
|
+
*/
|
|
78
|
+
hub: Hub | null;
|
|
79
|
+
/**
|
|
80
|
+
* Retrieves the current subscriptions. Used for debugging purposes.
|
|
81
|
+
* @param topic Optional. The topic to retrieve subscriptions for. If omitted, returns all subscriptions.
|
|
82
|
+
* @returns An object containing the current subscriptions, optionally filtered by topic.
|
|
83
|
+
*/
|
|
84
|
+
getSubscriptions: (topic?: string) => Record<string, Subscription[]> | Subscription[];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A global context for managing event emission and subscription.
|
|
88
|
+
*
|
|
89
|
+
* Provides a mechanism for decoupled data sharing between components
|
|
90
|
+
* using a publish-subscribe pattern.
|
|
91
|
+
* For more information, see [Additional Documentation](../additional-docs/GlobalEventEmitter.md).
|
|
92
|
+
*
|
|
93
|
+
* ## Usage
|
|
94
|
+
*
|
|
95
|
+
* The entire application should be wrapped in the EventEmitterProvider.
|
|
96
|
+
*
|
|
97
|
+
* App.tsx
|
|
98
|
+
* ```
|
|
99
|
+
* import { EventEmitterProvider } from "@adcops/autocore-react/core/EventEmitterContext.js";
|
|
100
|
+
* function App() {
|
|
101
|
+
*
|
|
102
|
+
* return(
|
|
103
|
+
* <EventEmitterProvider>
|
|
104
|
+
* <PrimeReactProvider>
|
|
105
|
+
* <main>
|
|
106
|
+
* <section>
|
|
107
|
+
* <ContentView />
|
|
108
|
+
* </section>
|
|
109
|
+
* </main>
|
|
110
|
+
* </PrimeReactProvider>
|
|
111
|
+
* </EventEmitterProvider>
|
|
112
|
+
* );
|
|
113
|
+
*
|
|
114
|
+
* }
|
|
115
|
+
*
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* ### Catching and receiving events
|
|
119
|
+
* The EventEmitterContext creates an appropriate instance of the hub, which is derived from HubBase.
|
|
120
|
+
* That hub can be used to publish and subscribe to
|
|
121
|
+
* topics globally in the front-end, regardless of being connected to any backend.
|
|
122
|
+
* Usage within a component is simple.
|
|
123
|
+
*
|
|
124
|
+
* ```
|
|
125
|
+
* const {dispatch, subscribe, unsubscribe} = useContext(EventEmitterContext);
|
|
126
|
+
* const [controlPower, setControlPower] = useState(false);
|
|
127
|
+
* useEffect(() => {
|
|
128
|
+
* const unsubscribeControlPower = subscribe('value-simulator-bBit1', (value) => {
|
|
129
|
+
* setControlPower(value);
|
|
130
|
+
* });
|
|
131
|
+
*
|
|
132
|
+
*
|
|
133
|
+
* return () => {
|
|
134
|
+
* unsubscribe(unsubscribeControlPower);
|
|
135
|
+
* }
|
|
136
|
+
* }, [] );
|
|
137
|
+
*
|
|
138
|
+
* const onPbPressed = () => {
|
|
139
|
+
* let count = 1;
|
|
140
|
+
* dispatch({
|
|
141
|
+
* topic: "my-awesome-topic",
|
|
142
|
+
* payload: count
|
|
143
|
+
* });
|
|
144
|
+
* }
|
|
145
|
+
*
|
|
146
|
+
* ```
|
|
147
|
+
* The hub should also be used for invoking events in the backend.
|
|
148
|
+
* This example will call the function "update_count" in the backend, passing
|
|
149
|
+
* the expected argument "count". Details of the interaction between the Hub and
|
|
150
|
+
* the backend will be handled by the appropriate HubBase sub-class, and should
|
|
151
|
+
* be transparent to the front end.
|
|
152
|
+
*
|
|
153
|
+
* ```
|
|
154
|
+
* const {invoke} = useContext(EventEmitterContext);
|
|
155
|
+
* const incrementCount = () => {
|
|
156
|
+
* count += 1;
|
|
157
|
+
* invoke('update_count', {"count": count});
|
|
158
|
+
* };
|
|
159
|
+
*
|
|
160
|
+
* Subscribing to a topic is simple. The type of value received is specific
|
|
161
|
+
* to the topic.
|
|
162
|
+
*
|
|
163
|
+
* Example: Listen to an event 'xarm-position':
|
|
164
|
+
* ```
|
|
165
|
+
* const {subscribe, unsubscribe} = useContext(EventEmitterContext);
|
|
166
|
+
* useEffect(() => {
|
|
167
|
+
* const unsubscripeMp = subscribe('xarm-position', (value) => {
|
|
168
|
+
* // The publisher sent a JSON object of 3D position values.
|
|
169
|
+
* setX(value.x);
|
|
170
|
+
* setY(value.y);
|
|
171
|
+
* setZ(value.z);
|
|
172
|
+
* setA(value.roll);
|
|
173
|
+
* setB(value.yaw);
|
|
174
|
+
* setC(value.pitch);
|
|
175
|
+
* });
|
|
176
|
+
*
|
|
177
|
+
* return () => {
|
|
178
|
+
* unsubscribe(unsubscripeMp);
|
|
179
|
+
* }
|
|
180
|
+
*
|
|
181
|
+
* }, [] );
|
|
182
|
+
*
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
*
|
|
186
|
+
*/
|
|
187
|
+
export declare const EventEmitterContext: React.Context<EventEmitterContextType>;
|
|
188
|
+
/**
|
|
189
|
+
* A React component that provides the EventEmitterContext to its children.
|
|
190
|
+
*
|
|
191
|
+
* Wraps child components with the context, enabling them to access and interact
|
|
192
|
+
* with the event emitter.
|
|
193
|
+
*
|
|
194
|
+
* @param children The child components to be wrapped in the context.
|
|
195
|
+
*
|
|
196
|
+
* ## Usage
|
|
197
|
+
*
|
|
198
|
+
* The entire application should be wrapped in the EventEmitterProvider.
|
|
199
|
+
*
|
|
200
|
+
* App.tsx
|
|
201
|
+
* ```
|
|
202
|
+
* import { EventEmitterProvider } from "@adcops/autocore-react/core/EventEmitterContext.js";
|
|
203
|
+
* function App() {
|
|
204
|
+
*
|
|
205
|
+
* return(
|
|
206
|
+
* <EventEmitterProvider>
|
|
207
|
+
* <PrimeReactProvider>
|
|
208
|
+
* <main>
|
|
209
|
+
* <section>
|
|
210
|
+
* <ContentView />
|
|
211
|
+
* </section>
|
|
212
|
+
* </main>
|
|
213
|
+
* </PrimeReactProvider>
|
|
214
|
+
* </EventEmitterProvider>
|
|
215
|
+
* );
|
|
216
|
+
*
|
|
217
|
+
* }
|
|
218
|
+
*
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
export declare const EventEmitterProvider: React.FC<{
|
|
222
|
+
children: ReactNode;
|
|
223
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{createContext,useState,useMemo}from"react";import{createHub,Hub}from"../hub";export{Hub};export const EventEmitterContext=createContext({state:{subscriptions:{},nextSubscriptionId:1},dispatch:()=>{},subscribe:()=>0,invoke:async(t,s)=>Promise.resolve({}),unsubscribe:t=>{},hub:null,getSubscriptions:()=>[]});export const EventEmitterProvider=({children:t})=>{const[s,e]=useState({subscriptions:{},nextSubscriptionId:1}),i=useMemo((()=>createHub()),[]),r=t=>{const{topic:s,payload:i}=t;e((t=>(t.subscriptions[s]?.forEach((t=>t.callback(i))),{...t,eventData:i})))},n=(t,i)=>{const r=s.nextSubscriptionId;return e((s=>({...s,subscriptions:{...s.subscriptions,[t]:[...s.subscriptions[t]||[],{id:r,callback:i}]},nextSubscriptionId:s.nextSubscriptionId+1}))),r},o=t=>{e((s=>{const e={...s.subscriptions};for(const s in e)e.hasOwnProperty(s)&&(e[s]=e[s].filter((s=>s.id!==t)),0===e[s].length&&delete e[s]);return{...s,subscriptions:e}}))},c=t=>t?s.subscriptions[t]||[]:s.subscriptions,u=useMemo((()=>({state:s,dispatch:r,subscribe:n,unsubscribe:o,invoke:i.invoke,hub:i,getSubscriptions:c})),[s,i]);return i.setContext(u),_jsx(EventEmitterContext.Provider,{value:u,children:t})};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview
|
|
3
|
+
* Provides a collection of pre-defined patterns for masking/validating different types of user input or data string.
|
|
4
|
+
* These patterns come up so regularly in our work that it seemed best to standardize and centralize their definition.
|
|
5
|
+
*
|
|
6
|
+
* These patterns can be used to ensure that user inputs conform to expected formats, such as real numbers (with or without
|
|
7
|
+
* decimal points), positive real numbers, integers, and positive integers. Utilizing these patterns simplifies the process
|
|
8
|
+
* of validating and filtering input in forms or any other user input scenarios.
|
|
9
|
+
*
|
|
10
|
+
* The patterns are defined as regular expressions and are encapsulated within the `InputPatterns` constant for easy access.
|
|
11
|
+
* They can be used directly with input validation functions or in conjunction with form validation libraries to enforce
|
|
12
|
+
* input constraints.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Regular expressions Common input patterns for matching different input or expected data types.
|
|
16
|
+
*/
|
|
17
|
+
export declare const RegExMaskPatterns: {
|
|
18
|
+
/**
|
|
19
|
+
* Regular expression pattern for matching real numbers.
|
|
20
|
+
* This pattern matches any real number, including negative and positive numbers with or without a decimal point.
|
|
21
|
+
* Examples of valid inputs: "123", "-123", "123.456", "-123.456", ".456", "-.456"
|
|
22
|
+
*/
|
|
23
|
+
readonly RealNumber: RegExp;
|
|
24
|
+
/**
|
|
25
|
+
* Regular expression pattern for matching positive real numbers.
|
|
26
|
+
* This pattern matches any positive real number with or without a decimal point, excluding negative numbers.
|
|
27
|
+
* Examples of valid inputs: "123", "123.456", ".456"
|
|
28
|
+
*/
|
|
29
|
+
readonly RealNumberPositive: RegExp;
|
|
30
|
+
/**
|
|
31
|
+
* Regular expression pattern for matching integers.
|
|
32
|
+
* This pattern matches any integer, including negative and positive integers without a decimal point.
|
|
33
|
+
* Examples of valid inputs: "123", "-123"
|
|
34
|
+
*/
|
|
35
|
+
readonly Integer: RegExp;
|
|
36
|
+
/**
|
|
37
|
+
* Regular expression pattern for matching positive integers.
|
|
38
|
+
* This pattern matches any positive integer without a decimal point, excluding negative numbers.
|
|
39
|
+
* Examples of valid inputs: "123"
|
|
40
|
+
*/
|
|
41
|
+
readonly IntegerPositive: RegExp;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Patterns for use with PrimeReact.InputMask components
|
|
45
|
+
*/
|
|
46
|
+
export declare const PrimeReactMaskPatterns: {
|
|
47
|
+
/** USA Social Security Number */
|
|
48
|
+
readonly SocialSecurityNumber: "999-99-9999";
|
|
49
|
+
/** USA phone number with optional extension */
|
|
50
|
+
readonly PhoneNumberUS: "(999) 999-9999? x99999";
|
|
51
|
+
/** International phone number with optional extension */
|
|
52
|
+
readonly PhoneNumberInternational: "+999 999 999 9999? x99999";
|
|
53
|
+
/** International phone number with optional extension */
|
|
54
|
+
readonly PhoneNumberJapan: "+81 9999 999 9999? x99999";
|
|
55
|
+
/** International phone number with optional extension */
|
|
56
|
+
readonly PhoneNumberChina: "+86 999 999 9999? x99999";
|
|
57
|
+
/** International phone number with optional extension */
|
|
58
|
+
readonly PhoneNumberVietnam: "+84 999 999 9999? x99999";
|
|
59
|
+
/** International phone number with optional extension */
|
|
60
|
+
readonly PhoneNumberSouthKorea: "+82 99 9999 9999 x99999";
|
|
61
|
+
/** International phone number with optional extension */
|
|
62
|
+
readonly PhoneNumberCanada: "+1 (999) 999-9999 x99999";
|
|
63
|
+
/** International phone number with optional extension */
|
|
64
|
+
readonly PhoneNumberMexico: "+52 999 999 9999 x99999";
|
|
65
|
+
/** International phone number with optional extension */
|
|
66
|
+
readonly PhoneNumberScotland: "+44 9999 999999 x99999";
|
|
67
|
+
/** International phone number with optional extension */
|
|
68
|
+
readonly PhoneNumberEngland: "+44 9999 999999 x99999";
|
|
69
|
+
/** International phone number with optional extension */
|
|
70
|
+
readonly PhoneNumberIreland: "+353 99 999 9999 x99999";
|
|
71
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const RegExMaskPatterns={RealNumber:/^-?\d*(\.)?(\d+)?$/,RealNumberPositive:/^\d*(\.)?(\d+)?$/,Integer:/^-?\d*$/,IntegerPositive:/^\d+$/};export const PrimeReactMaskPatterns={SocialSecurityNumber:"999-99-9999",PhoneNumberUS:"(999) 999-9999? x99999",PhoneNumberInternational:"+999 999 999 9999? x99999",PhoneNumberJapan:"+81 9999 999 9999? x99999",PhoneNumberChina:"+86 999 999 9999? x99999",PhoneNumberVietnam:"+84 999 999 9999? x99999",PhoneNumberSouthKorea:"+82 99 9999 9999 x99999",PhoneNumberCanada:"+1 (999) 999-9999 x99999",PhoneNumberMexico:"+52 999 999 9999 x99999",PhoneNumberScotland:"+44 9999 999999 x99999",PhoneNumberEngland:"+44 9999 999999 x99999",PhoneNumberIreland:"+353 99 999 9999 x99999"};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview
|
|
3
|
+
*
|
|
4
|
+
* These types enhance TypeScript support for the `numerable` library, which does not directly
|
|
5
|
+
* export the `NumerableFormatNumberOptions` type. By extracting and refining the type definitions
|
|
6
|
+
* for the `format` function's parameters, including handling its overloaded signatures, this file
|
|
7
|
+
* makes it easier to use `numerable` in TypeScript and React projects.
|
|
8
|
+
*
|
|
9
|
+
* The process involves creating a type that captures the overloads of the `format` function and
|
|
10
|
+
* then mapping over these overloads to extract their parameters. This technique enables the
|
|
11
|
+
* extraction of the specific options type `NumerableFormatNumberOptions` used by the `format`
|
|
12
|
+
* function, thereby providing type safety and IntelliSense support in TypeScript environments.
|
|
13
|
+
*
|
|
14
|
+
* The approach used here is based on a solution for handling function overloads in TypeScript,
|
|
15
|
+
* as discussed in a StackOverflow answer: https://stackoverflow.com/a/59538756/10049787.
|
|
16
|
+
*/
|
|
17
|
+
import { format } from 'numerable';
|
|
18
|
+
/**
|
|
19
|
+
* Type helper to capture the overload signatures of a function.
|
|
20
|
+
* This utility type takes a function with multiple overloads and maps them to a tuple of
|
|
21
|
+
* functions, each representing one of the overloads.
|
|
22
|
+
*/
|
|
23
|
+
type NumerableFormatOverloads<T> = T extends {
|
|
24
|
+
(...args: infer A1): infer R1;
|
|
25
|
+
(...args: infer A2): infer R2;
|
|
26
|
+
(...args: infer A3): infer R3;
|
|
27
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3] : T extends {
|
|
28
|
+
(...args: infer A1): infer R1;
|
|
29
|
+
(...args: infer A2): infer R2;
|
|
30
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2] : T extends {
|
|
31
|
+
(...args: infer A1): infer R1;
|
|
32
|
+
} ? [(...args: A1) => R1] : any;
|
|
33
|
+
/**
|
|
34
|
+
* Extracts parameters from a tuple of function types.
|
|
35
|
+
* This utility type maps over a tuple of functions (representing overloads) to produce a tuple
|
|
36
|
+
* of their respective parameter types.
|
|
37
|
+
*/
|
|
38
|
+
type OverloadedParameters<T> = NumerableFormatOverloads<T> extends infer O ? {
|
|
39
|
+
[K in keyof O]: Parameters<Extract<O[K], (...args: any) => any>>;
|
|
40
|
+
} : never;
|
|
41
|
+
/**
|
|
42
|
+
* Type representing the parameters of the `numerable.format` function, taking into account its
|
|
43
|
+
* overloaded signatures.
|
|
44
|
+
*/
|
|
45
|
+
type NumerableFormatParams = OverloadedParameters<typeof format>;
|
|
46
|
+
/**
|
|
47
|
+
* Type specifically for the options parameter of the `numerable.format` function.
|
|
48
|
+
* This extracts the type of the third parameter (options) from the first overload of `format`,
|
|
49
|
+
* as this is where the formatting options are specified.
|
|
50
|
+
*/
|
|
51
|
+
type NumerableFormatNumberOptions = NumerableFormatParams[0][2];
|
|
52
|
+
/**
|
|
53
|
+
* Exported type for external use, providing a non-nullable version of the formatting options.
|
|
54
|
+
* This type is intended for use wherever `numerable.format` options are needed, enhancing
|
|
55
|
+
* code readability and type safety.
|
|
56
|
+
*/
|
|
57
|
+
export type NumerableFormatOptions = NonNullable<NumerableFormatNumberOptions>;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* Interface representing the position and scale context of a component within its parent container.
|
|
4
|
+
*
|
|
5
|
+
* This context is designed to provide components with necessary scaling and positioning
|
|
6
|
+
* information, such as for rendering elements correctly in absolute positioning or for
|
|
7
|
+
* adjusting layout based on dynamic offsets.
|
|
8
|
+
*/
|
|
9
|
+
export interface IPositionContext {
|
|
10
|
+
/**
|
|
11
|
+
* Represents the scale factor applied to the dimensions of elements.
|
|
12
|
+
* A scale of 1 indicates no scaling, while values greater or less than 1
|
|
13
|
+
* indicate zoomed-in or zoomed-out states respectively.
|
|
14
|
+
*/
|
|
15
|
+
scale: number;
|
|
16
|
+
/**
|
|
17
|
+
* Represents the horizontal offset that should be applied to the position
|
|
18
|
+
* of elements. This can be used to adjust element positioning in response to
|
|
19
|
+
* dynamic layout changes or to align elements within a scaled environment.
|
|
20
|
+
*/
|
|
21
|
+
xOffset: number;
|
|
22
|
+
/**
|
|
23
|
+
* Represents the vertical offset that should be applied to the position
|
|
24
|
+
* of elements. Similar to `xOffset`, this is used for vertical alignment and
|
|
25
|
+
* positioning adjustments in a dynamic or scaled layout.
|
|
26
|
+
*/
|
|
27
|
+
yOffset: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates a React context for position and scaling information of a component using absolute positioning.
|
|
31
|
+
* This context provides a standardized way to access and react to changes in scale and positioning offsets,
|
|
32
|
+
* enabling components to adjust their layout and rendering behavior dynamically.
|
|
33
|
+
*
|
|
34
|
+
* The default context values are set to assume no scaling (`scale: 1`) and no offsets (`xOffset: 0, yOffset: 0`),
|
|
35
|
+
* which corresponds to the initial state in many applications before any dynamic adjustments are made.
|
|
36
|
+
*/
|
|
37
|
+
export declare const DimensionsContext: import("react").Context<IPositionContext>;
|
|
38
|
+
export default DimensionsContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createContext}from"react";export const DimensionsContext=createContext({scale:1,xOffset:0,yOffset:0});export default DimensionsContext;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a unique UUID per RFC4122.
|
|
3
|
+
* 8 chars, followed by 3 groups of 4 chars, followed by 12 chars.
|
|
4
|
+
*
|
|
5
|
+
* @returns string UUID
|
|
6
|
+
*
|
|
7
|
+
* ## Remarks
|
|
8
|
+
* NOTE: This format of 8 chars, followed by 3 groups of 4 chars, followed by 12 chars
|
|
9
|
+
* is known as a UUID and is defined in RFC4122 and is a standard for generating unique IDs.
|
|
10
|
+
* This function DOES NOT implement this standard. It simply outputs a string
|
|
11
|
+
* that looks similar. The standard is found here: https://www.ietf.org/rfc/rfc4122.txt
|
|
12
|
+
*
|
|
13
|
+
* Should avoid duplicates over 10-millions subsequent calls.
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export declare function UniqueId(): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const PrivateUniqueId=function(){function n(){return Math.random().toString(16).slice(-4)}return n()+n()+"-"+n()+"-"+n()+"-"+n()+"-"+n()+n()+n()};export function UniqueId(){return PrivateUniqueId()}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { EmitterDispatchFunction } from "./EventEmitterContext";
|
|
2
|
+
/**
|
|
3
|
+
* Generates values for simulating data into an HMI.
|
|
4
|
+
* Used for demonstration and development testing.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ValueSimulator {
|
|
7
|
+
protected bBit1: boolean;
|
|
8
|
+
protected bBit2: boolean;
|
|
9
|
+
protected iRamp1: number;
|
|
10
|
+
protected iRamp2: number;
|
|
11
|
+
protected fRamp1: number;
|
|
12
|
+
protected fRamp2: number;
|
|
13
|
+
protected iSin1: number;
|
|
14
|
+
protected iSin2: number;
|
|
15
|
+
protected fSin1: number;
|
|
16
|
+
protected fSin2: number;
|
|
17
|
+
protected iRamp1DirectionUp: boolean;
|
|
18
|
+
protected iRamp2DirectionUp: boolean;
|
|
19
|
+
protected fRamp1DirectionUp: boolean;
|
|
20
|
+
protected fRamp2DirectionUp: boolean;
|
|
21
|
+
protected iSin1Angle: number;
|
|
22
|
+
protected iSin2Angle: number;
|
|
23
|
+
protected fSin1Angle: number;
|
|
24
|
+
protected fSin2Angle: number;
|
|
25
|
+
protected intervalId: number;
|
|
26
|
+
protected dispatch: EmitterDispatchFunction;
|
|
27
|
+
/**
|
|
28
|
+
* Constructor
|
|
29
|
+
* @param dispatch EmitterDispatchFunction Dispatch function from the application's EventEmiterContext.
|
|
30
|
+
*/
|
|
31
|
+
constructor(dispatch: EmitterDispatchFunction);
|
|
32
|
+
/**
|
|
33
|
+
* Start simulating values on a tick
|
|
34
|
+
*/
|
|
35
|
+
start(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Stop simulating values.
|
|
38
|
+
*/
|
|
39
|
+
stop(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Update and dispatch the values.
|
|
42
|
+
*/
|
|
43
|
+
protected update(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Updates the value of a ramp variable, changing its direction when limits are reached.
|
|
46
|
+
* @param {number} value The current value of the ramp variable.
|
|
47
|
+
* @param {boolean} directionUp Indicates if the ramp variable is currently increasing.
|
|
48
|
+
* @param {number} max The maximum value for the ramp.
|
|
49
|
+
* @returns {[number, boolean]} The updated value and direction.
|
|
50
|
+
*/
|
|
51
|
+
protected updateRamp(value: number, directionUp: boolean, max: number): [number, boolean];
|
|
52
|
+
/**
|
|
53
|
+
* Updates a sine wave value based on the given angle and increments, then calculates the new value and angle.
|
|
54
|
+
* This method is useful for scenarios where a sine wave value needs to be progressively updated, such as in animations
|
|
55
|
+
* or simulations. The sine of the updated angle is calculated, multiplied by the maximum value to scale it, and both
|
|
56
|
+
* the new value and the updated angle are returned.
|
|
57
|
+
*
|
|
58
|
+
* @param {number} value The current value of the sine wave. This parameter is not directly used in the calculation of the new value,
|
|
59
|
+
* but it can be utilized if the method is extended or modified.
|
|
60
|
+
* @param {number} angle The current angle in radians. This is the phase of the sine wave.
|
|
61
|
+
* @param {number} increment The value by which the angle is to be incremented, in radians. This controls the progression of the wave.
|
|
62
|
+
* @param {number} max The maximum value (amplitude) of the sine wave. The calculated sine value will be scaled by this factor.
|
|
63
|
+
* @returns {[number,number]} A tuple where the first element is the new sine wave value and the second element is the updated angle.
|
|
64
|
+
*/
|
|
65
|
+
protected updateSin(value: number, angle: number, increment: number, max: number): [number, number];
|
|
66
|
+
/**
|
|
67
|
+
* Dispatch the update for a particular topic.
|
|
68
|
+
*/
|
|
69
|
+
protected updateTopic(topic: string, value: any): void;
|
|
70
|
+
}
|
|
71
|
+
export default ValueSimulator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class ValueSimulator{constructor(i){Object.defineProperty(this,"bBit1",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"bBit2",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"iRamp1",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"iRamp2",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"fRamp1",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"fRamp2",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"iSin1",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"iSin2",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"fSin1",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"fSin2",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"iRamp1DirectionUp",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"iRamp2DirectionUp",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"fRamp1DirectionUp",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"fRamp2DirectionUp",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"iSin1Angle",{enumerable:!0,configurable:!0,writable:!0,value:Math.random()*Math.PI*2}),Object.defineProperty(this,"iSin2Angle",{enumerable:!0,configurable:!0,writable:!0,value:Math.random()*Math.PI*2}),Object.defineProperty(this,"fSin1Angle",{enumerable:!0,configurable:!0,writable:!0,value:Math.random()*Math.PI*2/10}),Object.defineProperty(this,"fSin2Angle",{enumerable:!0,configurable:!0,writable:!0,value:Math.random()*Math.PI*2/10}),Object.defineProperty(this,"intervalId",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"dispatch",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.dispatch=i}start(){0===this.intervalId&&(this.intervalId=setInterval((()=>this.update()),1e3))}stop(){0!==this.intervalId&&(clearInterval(this.intervalId),this.intervalId=0)}update(){this.bBit1=!this.bBit1,this.bBit2=!this.bBit2,[this.iRamp1,this.iRamp1DirectionUp]=this.updateRamp(this.iRamp1,this.iRamp1DirectionUp,32767),[this.iRamp2,this.iRamp2DirectionUp]=this.updateRamp(this.iRamp2,this.iRamp2DirectionUp,32767),[this.fRamp1,this.fRamp1DirectionUp]=this.updateRamp(this.fRamp1,this.fRamp1DirectionUp,3276.7),[this.fRamp2,this.fRamp2DirectionUp]=this.updateRamp(this.fRamp2,this.fRamp2DirectionUp,3276.7),[this.iSin1,this.iSin1Angle]=this.updateSin(this.iSin1,this.iSin1Angle,Math.PI/180,32767),[this.iSin2,this.iSin2Angle]=this.updateSin(this.iSin2,this.iSin2Angle,Math.PI/180,32767),[this.fSin1,this.fSin1Angle]=this.updateSin(this.fSin1,this.fSin1Angle,Math.PI/180,3276.7),[this.fSin2,this.fSin2Angle]=this.updateSin(this.fSin2,this.fSin2Angle,Math.PI/180,3276.7),this.updateTopic("value-simulator-bBit1",this.bBit1),this.updateTopic("value-simulator-bBit2",this.bBit2),this.updateTopic("value-simulator-iRamp1",this.iRamp1),this.updateTopic("value-simulator-iRamp2",this.iRamp2),this.updateTopic("value-simulator-fRamp1",this.fRamp1),this.updateTopic("value-simulator-fRamp2",this.fRamp2),this.updateTopic("value-simulator-iSin1",this.iSin1),this.updateTopic("value-simulator-iSin2",this.iSin2),this.updateTopic("value-simulator-fSin1",this.fSin1),this.updateTopic("value-simulator-fSin2",this.fSin2)}updateRamp(i,e,t){if(e){if(++i>=t)return[i,!1]}else if(--i<=0)return[i,!0];return[i,e]}updateSin(i,e,t,a){return e+=t,[Math.sin(e)*a,e]}updateTopic(i,e){this.dispatch({topic:i,payload:e})}}export default ValueSimulator;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileinfo
|
|
3
|
+
* Explanation:
|
|
4
|
+
* React.ComponentType<P>: This is a generic type that can accept any React component (functional or class) with props of type P.
|
|
5
|
+
* P extends WithSubscriptionProps: Here, P is a generic type parameter that extends WithSubscriptionProps,
|
|
6
|
+
* meaning it can be any type that includes the properties of WithSubscriptionProps.
|
|
7
|
+
* Omit<P, keyof WithSubscriptionProps>: This utility type creates a new type by omitting properties from
|
|
8
|
+
* P that are also in WithSubscriptionProps. This is useful to prevent type clashes.
|
|
9
|
+
* useState<any>(): The state is typed as any since the value received from the subscription
|
|
10
|
+
* can be of any type. You may choose to make this more specific based on your application's needs.
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
import React from 'react';
|
|
14
|
+
/**
|
|
15
|
+
* High Order Component Subscription properties.
|
|
16
|
+
*/
|
|
17
|
+
export type HocAddSubscriptionProps = {
|
|
18
|
+
/** The topic to subscribe to. */
|
|
19
|
+
topic: string;
|
|
20
|
+
/** The name of the prop through which the subscription data is passed to the WrappedComponent. */
|
|
21
|
+
propName?: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Creates a higher-order component that subscribes to a specified topic and passes the data to the wrapped component.
|
|
25
|
+
*
|
|
26
|
+
* @param WrappedComponent The component to be wrapped and enhanced with subscription data.
|
|
27
|
+
* @param topic The topic to subscribe to.
|
|
28
|
+
* @param propName The name of the prop through which the subscription data is passed to the WrappedComponent.
|
|
29
|
+
* @returns A component that subscribes to the given topic and updates its specified prop with the received data.
|
|
30
|
+
*/
|
|
31
|
+
export declare function hocAddSubscription<P extends HocAddSubscriptionProps>(WrappedComponent: React.ComponentType<P>, topic: string, propName: keyof P): (props: Omit<P, keyof HocAddSubscriptionProps>) => import("react/jsx-runtime").JSX.Element;
|
package/dist/core/hoc.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useState,useEffect,useContext}from"react";import{EventEmitterContext}from"./EventEmitterContext";export function hocAddSubscription(t,e,r){return function(n){const[o,s]=useState(),{subscribe:u,unsubscribe:i}=useContext(EventEmitterContext);useEffect((()=>{const t=u(e,s);return()=>i(t)}),[e,u,i]);return _jsx(t,{...n,...{[r]:o}})}}
|