@adcops/autocore-react 3.0.8 → 3.0.12

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.
@@ -1,103 +1,21 @@
1
- import { Component } from 'react';
1
+ import React from 'react';
2
2
  import { SelectButtonProps } from 'primereact/selectbutton';
3
- import { EventEmitterContextType } from '../core/EventEmitterContext';
4
3
  import { IndicatorColor } from "../core/IndicatorColor";
5
4
  export { IndicatorColor };
6
5
  import { ActionMode } from '../core/ActionMode';
7
6
  export { ActionMode };
8
- import { IndicatorButtonState } from '../core/IndicatorButtonState';
9
7
  export interface ToggleGroupProps extends SelectButtonProps {
10
- /**
11
- * Label of the group/row. Can be any element.
12
- *
13
- * ## Examples
14
- * ```
15
- * <ToggleGroup label="Simple Text" />
16
- * <ToggleGroup label={<span><i className="pi pi-check"></i> Icon and Text</span>} />
17
- * <ToggleGroup label={<YourCustomIconComponent />} />
18
- * ```
19
- */
20
8
  label?: React.ReactNode;
21
- /**
22
- * Topic name to monitor for state indication.
23
- * If `value` field is not undefined, then that value is used instead.
24
- */
25
9
  topic?: string;
26
- /**
27
- * Color for the button when the state is TRUE.
28
- */
29
10
  onColor?: IndicatorColor | IndicatorColor[];
30
- /**
31
- * Color for the button when the state is FALSE.
32
- */
33
11
  offColor?: IndicatorColor;
34
- /**
35
- * Name of the command to invoke on button events.
36
- * If command is "*", then the commandTopic will be dispatched
37
- * internally.
38
- */
39
12
  command?: string;
40
- /**
41
- * Optional topic parameter to send along with the command.
42
- * If set, will automatically be included with commandArgs as
43
- * the value of field 'topic.'
44
- */
45
13
  commandTopic?: string;
46
- /**
47
- * Optional arguments sent with the command.
48
- */
49
14
  commandArgs?: any;
50
- /**
51
- * Topic to disable button interaction.
52
- */
53
15
  disableTopic?: string;
54
- /**
55
- * Topic to control the visibility of the button.
56
- */
57
16
  invisibleTopic?: string;
58
- /**
59
- * Mode of input for the button (e.g., TAP, TOGGLE).
60
- */
61
17
  actionMode?: ActionMode;
62
- /**
63
- * Inverts the signal values for TAP, PRESSED, and RELEASED modes.
64
- */
65
18
  invert?: boolean;
66
19
  }
67
- export declare class ToggleGroup extends Component<ToggleGroupProps, IndicatorButtonState> {
68
- static contextType: import("react").Context<EventEmitterContextType>;
69
- constructor(props: ToggleGroupProps);
70
- componentDidMount(): void;
71
- componentDidUpdate(prevProps: ToggleGroupProps): void;
72
- componentWillUnmount(): void;
73
- /**
74
- * Sets up subscriptions based on provided topics.
75
- */
76
- private setupSubscriptions;
77
- /**
78
- * Handles updates for the main topic.
79
- */
80
- private handleTopicUpdate;
81
- /**
82
- * Handles updates for the disable topic.
83
- */
84
- private handleDisableTopicUpdate;
85
- /**
86
- * Handles updates for the invisible topic.
87
- */
88
- private handleInvisibleTopicUpdate;
89
- /**
90
- * Handle the button being pressed down. Used for TAP and PRESSED action modes.
91
- */
92
- protected handleOnPressed(): void;
93
- /**
94
- * Handle the button being released. Used for TAP and RELEASED action modes.
95
- */
96
- protected handleOnReleased(): void;
97
- /**
98
- * Dispatch a value to any listeners.
99
- * @param value The value to dispatch as part of the payload.
100
- */
101
- protected dispatchCommand(value: any): void;
102
- render(): import("react/jsx-runtime").JSX.Element;
103
- }
20
+ export declare const ToggleGroup: React.FC<ToggleGroupProps>;
21
+ export default ToggleGroup;
@@ -1 +1 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Component}from"react";import{SelectButton}from"primereact/selectbutton";import{EventEmitterContext}from"../core/EventEmitterContext";import{IndicatorColor}from"../core/IndicatorColor";export{IndicatorColor};import{ActionMode}from"../core/ActionMode";export{ActionMode};function matchCurrentValue(e,t){if(null==t||0===t.length)return;let o=typeof e;if("boolean"==o){return e&&t.length>1?t[1]:t[0]}if("number"==o){let o=e;if(void 0!==o&&o<t.length)return t[o]}else if("string"==o)return e}function selectOnColor(e,t,o){if(!t||0===t.length)return IndicatorColor.IndicatorInvalid;let n=Array.isArray(o)?o:void 0!==o?[o]:[IndicatorColor.IndicatorInvalid],i=typeof e;if("boolean"===i)return e?n[0]:n.length>1?n[1]:n[0];if("number"===i&&t.length>e){if(n.length>e){return n[e]}return n[0]}if("string"===i){let o=t.indexOf(e);return-1!==o&&o<n.length?n[o]:n[0]}return null!=o?Array.isArray(o)?o[0]:o:IndicatorColor.IndicatorInvalid}export class ToggleGroup extends Component{constructor(e){super(e),Object.defineProperty(this,"handleTopicUpdate",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.setState({currentValue:e})}}),Object.defineProperty(this,"handleDisableTopicUpdate",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.setState({isDisabled:e})}}),Object.defineProperty(this,"handleInvisibleTopicUpdate",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.setState({isInvisible:e})}}),this.state={currentValue:void 0,isDisabled:!1,isInvisible:!1,isPressed:!1}}componentDidMount(){this.setupSubscriptions()}componentDidUpdate(e){}componentWillUnmount(){}setupSubscriptions(){const{topic:e,disableTopic:t,invisibleTopic:o}=this.props,{subscribe:n}=this.context;e&&n(e,this.handleTopicUpdate),t&&n(t,this.handleDisableTopicUpdate),o&&n(o,this.handleInvisibleTopicUpdate)}handleOnPressed(){const{isPressed:e}=this.state,{actionMode:t}=this.props;e||(this.setState({isPressed:!0}),t!==ActionMode.Tap&&t!==ActionMode.Pressed||this.dispatchCommand(!0))}handleOnReleased(){const{isPressed:e}=this.state,{actionMode:t}=this.props;e&&(this.setState({isPressed:!1}),t===ActionMode.Tap?this.dispatchCommand(!1):t===ActionMode.Released&&this.dispatchCommand(!0))}dispatchCommand(e){const{command:t,commandTopic:o,commandArgs:n}=this.props,{dispatch:i}=this.context;if(null!=t&&t.length>0){i({topic:t,payload:{topic:o,value:e,...n}})}}render(){const{currentValue:e,isDisabled:t,isInvisible:o}=this.state,{label:n,value:i,disabled:r,className:s,onColor:l,offColor:a,options:c,...d}=this.props;let p=e;void 0!==i&&(p=i);let u=selectOnColor(p,c,l);void 0===p&&(u=IndicatorColor.IndicatorInvalid);const h=null!=c&&c.length>2;return _jsxs("div",{className:"flex",children:[_jsx("style",{children:` \n ${void 0!==a?`\n .togglegroup-selectbutton-container .p-selectbutton .p-button {\n background-color: ${a};\n }\n `:""}\n .togglegroup-selectbutton-container .p-selectbutton .p-button.p-highlight {\n background-color: ${u} !important;\n border-color: ${u} !important;\n }\n .togglegroup-selectbutton-container .p-selectbutton .p-highlight {\n background-color: ${u} !important;\n border-color: ${u} !important;\n }\n `}),_jsxs("div",{className:"p-inputgroup togglegroup-selectbutton-container",children:[_jsx("span",{className:"p-inputgroup-addon",style:{flexGrow:1},children:n}),_jsx(SelectButton,{...d,options:c,disabled:t||r,multiple:h,className:`${s||""} ${void 0===p?"p-invalid":""}`.trim(),...o&&{style:{display:"none"}},value:matchCurrentValue(p,c),allowEmpty:!1,onMouseDown:()=>this.handleOnPressed(),onTouchStart:()=>this.handleOnPressed(),onMouseUp:()=>this.handleOnReleased(),onTouchEnd:()=>this.handleOnReleased()})]})]})}}Object.defineProperty(ToggleGroup,"contextType",{enumerable:!0,configurable:!0,writable:!0,value:EventEmitterContext});
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useState,useEffect,useContext}from"react";import{SelectButton}from"primereact/selectbutton";import{EventEmitterContext}from"../core/EventEmitterContext";import{IndicatorColor}from"../core/IndicatorColor";export{IndicatorColor};import{ActionMode}from"../core/ActionMode";export{ActionMode};import clsx from"clsx";export const ToggleGroup=({label:o,topic:t,onColor:e,offColor:n,command:r,commandTopic:i,commandArgs:l,disableTopic:s,invisibleTopic:a,actionMode:c,invert:d,...u})=>{const[p]=useState((()=>`toggleGroup-${Math.random().toString(36).substr(2,9)}`)),[m,f]=useState(void 0),[g,v]=useState(!1),[x,b]=useState(!1),[h,I]=useState(!1),C=useContext(EventEmitterContext);useEffect((()=>(t&&C.subscribe(t,y),s&&C.subscribe(s,A),a&&C.subscribe(a,j),()=>{})),[t,s,a]);const y=o=>{f(o)},A=o=>{v(o)},j=o=>{b(o)},M=()=>{h||(I(!0),c!==ActionMode.Tap&&c!==ActionMode.Pressed||S(!0))},E=()=>{h&&(I(!1),c===ActionMode.Tap?S(!1):c===ActionMode.Released&&S(!0))},S=o=>{if(r&&r.length>0){const t={topic:i,value:o,...l};C.dispatch({topic:r,payload:t})}};let T=m;void 0!==u.value&&(T=u.value);let $=((o,t,e)=>{if(!t||0===t.length)return IndicatorColor.IndicatorInvalid;let n=Array.isArray(e)?e:void 0!==e?[e]:[IndicatorColor.IndicatorInvalid],r=typeof o;if("boolean"===r)return o?n[0]:n.length>1?n[1]:n[0];if("number"===r&&t.length>o){if(n.length>o){return n[o]}return n[0]}if("string"===r){let e=t.indexOf(o);return-1!==e&&e<n.length?n[e]:n[0]}return null!=e?Array.isArray(e)?e[0]:e:IndicatorColor.IndicatorInvalid})(T,u.options,e);void 0===T&&($=IndicatorColor.IndicatorInvalid);const _=void 0!==u.options&&null!==u.options&&void 0!==u.options.length&&u.options.length>2,N=`${p}-togglegroup-selectbutton-container`;return _jsxs("div",{className:"flex",children:[_jsx("style",{children:`\n ${void 0!==n?`\n .${N} .p-selectbutton .p-button {\n background-color: ${n};\n }\n `:""}\n .${N} .p-selectbutton .p-button.p-highlight {\n background-color: ${$} !important;\n border-color: ${$} !important;\n }\n `}),_jsx("div",{className:N,children:_jsxs("div",{className:"p-inputgroup",children:[_jsx("span",{className:"p-inputgroup-addon",style:{flexGrow:1},children:o}),_jsx(SelectButton,{...u,options:u.options,disabled:g||u.disabled,multiple:_,className:clsx(p,u.className,{"p-invalid":void 0===u.value}),style:x?{display:"none"}:{},value:((o,t)=>{if(null==t||0===t.length)return;let e=typeof o;if("boolean"==e){return o&&t.length>1?t[1]:t[0]}if("number"==e){let e=o;if(void 0!==e&&e<t.length)return t[e]}else if("string"==e)return o})(T,u.options),allowEmpty:!1,onMouseDown:M,onTouchStart:M,onMouseUp:E,onTouchEnd:E})]})})]})};export default ToggleGroup;
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { EventEmitterContext } from "../core/EventEmitterContext.js";
2
+ import { EventEmitterContext } from "../core/EventEmitterContext";
3
3
  /**
4
4
  * Properties of the ValueInput component.
5
5
  */
@@ -105,6 +105,7 @@ interface ValueInputProps {
105
105
  */
106
106
  interface ValueInputState {
107
107
  entryValue: number | null;
108
+ currentValue: number | null;
108
109
  editing: boolean;
109
110
  }
110
111
  /**
@@ -113,7 +114,7 @@ interface ValueInputState {
113
114
  * accepting and rejecting values and keyboard management.
114
115
  */
115
116
  export declare class ValueInput extends React.Component<ValueInputProps, ValueInputState> {
116
- static contextType: React.Context<import("../core/EventEmitterContext.js").EventEmitterContextType>;
117
+ static contextType: React.Context<import("../core/EventEmitterContext").EventEmitterContextType>;
117
118
  context: React.ContextType<typeof EventEmitterContext>;
118
119
  /**
119
120
  * Default properties for the component.
@@ -141,6 +142,7 @@ export declare class ValueInput extends React.Component<ValueInputProps, ValueIn
141
142
  locale: string;
142
143
  currency: string;
143
144
  };
145
+ inputRef: React.RefObject<HTMLInputElement>;
144
146
  /**
145
147
  *
146
148
  * @param {FooterViewProps} props
@@ -150,6 +152,7 @@ export declare class ValueInput extends React.Component<ValueInputProps, ValueIn
150
152
  * The component has been loaded into the DOM.
151
153
  */
152
154
  componentDidMount(): void;
155
+ private onBufferValue;
153
156
  /**
154
157
  * The user has elected to accept the input value. Validate and store, if valid.
155
158
  */
@@ -1 +1 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import React from"react";import{InputNumber}from"primereact/inputnumber";import{Button}from"primereact/button";import{EventEmitterContext}from"../core/EventEmitterContext.js";export class ValueInput extends React.Component{constructor(e){super(e),this.state={entryValue:e.value,editing:!1}}componentDidMount(){}onAcceptValue(){null!==this.state.entryValue&&(this.setState({editing:!1}),this.props.onValueChanged&&this.props.onValueChanged(this.state.entryValue),void 0!==this.props.dispatchTopic&&this.context.dispatch({topic:this.props.dispatchTopic,payload:this.state.entryValue}))}onResetValue(){this.setState({entryValue:this.props.value,editing:!1})}render(){return _jsxs("div",{children:[_jsxs("div",{className:"p-inputgroup flex-1",children:[_jsx("span",{className:"p-inputgroup-addon",children:this.props.label}),_jsx(InputNumber,{min:this.props.min,max:this.props.max,minFractionDigits:this.props.minPrecision,maxFractionDigits:this.props.maxPrecision,mode:this.props.mode,prefix:this.props.prefix,suffix:this.props.suffix,showButtons:this.props.showButtons,step:this.props.step,placeholder:this.props.placeholder,value:this.state.entryValue,onChange:e=>{this.setState({entryValue:e.value,editing:!0})},buttonLayout:"horizontal",decrementButtonClassName:"p-button-danger",incrementButtonClassName:"p-button-success",incrementButtonIcon:"pi pi-plus",decrementButtonIcon:"pi pi-minus",locale:"en-US",currency:this.props.currency,onKeyDown:e=>{"Enter"===e.key?this.onAcceptValue():"Escape"===e.key&&this.onResetValue()},disabled:this.props.disabled}),_jsx(Button,{icon:"pi pi-check",disabled:this.props.disabled||!this.state.editing,className:"p-button-success",onClick:()=>this.onAcceptValue(),visible:this.state.editing,size:"small"}),_jsx(Button,{icon:"pi pi-times",disabled:this.props.disabled||!this.state.editing,className:"p-button-danger",onClickCapture:()=>this.onResetValue(),visible:this.state.editing,size:"small"})]}),void 0!==this.props.description&&_jsx("small",{children:this.props.description})]})}}Object.defineProperty(ValueInput,"contextType",{enumerable:!0,configurable:!0,writable:!0,value:EventEmitterContext}),Object.defineProperty(ValueInput,"defaultProps",{enumerable:!0,configurable:!0,writable:!0,value:{label:"",value:void 0,keyFilter:void 0,writeTopic:void 0,onValueChanged:void 0,description:void 0,prefix:void 0,suffix:void 0,disabled:!1,dispatchTopic:void 0,placeholder:void 0,validator:void 0,min:void 0,max:void 0,minPrecision:0,maxPrecision:3,mode:"decimal",showButtons:!1,step:1,locale:"en-US",currency:"USD"}});
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import React,{createRef}from"react";import{InputNumber}from"primereact/inputnumber";import{Button}from"primereact/button";import{EventEmitterContext}from"../core/EventEmitterContext";export class ValueInput extends React.Component{constructor(t){super(t),Object.defineProperty(this,"inputRef",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.state={entryValue:t.value,currentValue:t.value,editing:!1},this.inputRef=createRef()}componentDidMount(){}onBufferValue(t){null!==t&&(this.state.editing?this.setState({entryValue:t}):this.setState({entryValue:this.state.currentValue,editing:!0},(()=>{setTimeout((()=>{this.inputRef.current&&this.inputRef.current.focus()}),0)})))}onAcceptValue(){null!==this.state.entryValue&&(this.setState({editing:!1,currentValue:this.state.entryValue}),this.props.onValueChanged&&this.props.onValueChanged(this.state.entryValue),void 0!==this.props.dispatchTopic&&this.context.dispatch({topic:this.props.dispatchTopic,payload:this.state.entryValue}))}onResetValue(){this.state.editing&&this.setState({currentValue:this.state.currentValue,entryValue:this.state.currentValue,editing:!1})}render(){return _jsxs("div",{children:[_jsxs("div",{className:"p-inputgroup flex-1",children:[_jsx("span",{className:"p-inputgroup-addon",children:this.props.label}),_jsx(InputNumber,{inputRef:this.inputRef,min:this.props.min,max:this.props.max,minFractionDigits:this.props.minPrecision,maxFractionDigits:this.props.maxPrecision,mode:this.props.mode,prefix:this.props.prefix,suffix:this.props.suffix,showButtons:this.props.showButtons,step:this.props.step,placeholder:this.props.placeholder,value:this.state.currentValue,onChange:t=>{this.onBufferValue(t.value)},buttonLayout:"horizontal",decrementButtonClassName:"p-button-danger",incrementButtonClassName:"p-button-success",incrementButtonIcon:"pi pi-plus",decrementButtonIcon:"pi pi-minus",locale:"en-US",currency:this.props.currency,onKeyDown:t=>{"Enter"===t.key?this.onAcceptValue():"Escape"===t.key&&this.onResetValue()},disabled:this.props.disabled,autoFocus:!1},this.state.editing?"editing":"not-editing"),_jsx(Button,{icon:"pi pi-check",disabled:this.props.disabled||!this.state.editing,className:"p-button-success",onClick:()=>this.onAcceptValue(),visible:this.state.editing,size:"small",autoFocus:!1}),_jsx(Button,{icon:"pi pi-times",disabled:this.props.disabled||!this.state.editing,className:"p-button-danger",onClickCapture:()=>this.onResetValue(),visible:this.state.editing,size:"small",autoFocus:!1})]}),void 0!==this.props.description&&_jsx("small",{children:this.props.description})]})}}Object.defineProperty(ValueInput,"contextType",{enumerable:!0,configurable:!0,writable:!0,value:EventEmitterContext}),Object.defineProperty(ValueInput,"defaultProps",{enumerable:!0,configurable:!0,writable:!0,value:{label:"",value:void 0,keyFilter:void 0,writeTopic:void 0,onValueChanged:void 0,description:void 0,prefix:void 0,suffix:void 0,disabled:!1,dispatchTopic:void 0,placeholder:void 0,validator:void 0,min:void 0,max:void 0,minPrecision:0,maxPrecision:3,mode:"decimal",showButtons:!1,step:1,locale:"en-US",currency:"USD"}});
@@ -76,7 +76,7 @@ export interface EventEmitterContextType {
76
76
  * Invoke/send a message to the back end.
77
77
  * This does NOT get published to the front end.
78
78
  */
79
- invoke(fname: string, payload?: object): Promise<object>;
79
+ invoke(domain: string, fname: string, payload?: object): Promise<object>;
80
80
  /**
81
81
  * Subscribe to events identified by the topic.
82
82
  * @param topic The subscription topic.
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{createContext,useState,useMemo}from"react";import{createHub,Hub}from"../hub";export{Hub};let globalSubscriptionId=1;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})))},o=(t,s)=>{globalSubscriptionId+=1;const i=globalSubscriptionId;return e((e=>({...e,subscriptions:{...e.subscriptions,[t]:[...e.subscriptions[t]||[],{id:i,callback:s}]},nextSubscriptionId:globalSubscriptionId+1}))),i},n=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:o,unsubscribe:n,invoke:i.invoke,hub:i,getSubscriptions:c})),[s,i]);return i.setContext(u),_jsx(EventEmitterContext.Provider,{value:u,children:t})};
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{createContext,useState,useMemo}from"react";import{createHub,Hub}from"../hub";export{Hub};let globalSubscriptionId=1;export const EventEmitterContext=createContext({state:{subscriptions:{},nextSubscriptionId:1},dispatch:()=>{},subscribe:()=>0,invoke:async(t,s,e)=>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})))},o=(t,s)=>{globalSubscriptionId+=1;const i=globalSubscriptionId;return e((e=>({...e,subscriptions:{...e.subscriptions,[t]:[...e.subscriptions[t]||[],{id:i,callback:s}]},nextSubscriptionId:globalSubscriptionId+1}))),i},n=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:o,unsubscribe:n,invoke:i.invoke,hub:i,getSubscriptions:c})),[s,i]);return i.setContext(u),_jsx(EventEmitterContext.Provider,{value:u,children:t})};
@@ -98,16 +98,17 @@ export declare abstract class HubBase {
98
98
  * Invoke/send a message to the back end.
99
99
  * This does NOT get published to the front end.
100
100
  */
101
- abstract invoke(fname: string, payload?: object): Promise<object>;
101
+ abstract invoke(domain: string, fname: string, payload?: object): Promise<object>;
102
102
  /**
103
103
  * Convenience function to invoke a command with an optional topic and optional value.
104
104
  * This will invoke the specified command in the backend. It does not broadcast the
105
105
  * value within the local frontend.
106
+ * @param domain string The domain of the command that will be invoked.
106
107
  * @param fname string Function name
107
108
  * @param topic string Topic
108
109
  * @param value any data payload
109
110
  */
110
- invokeTopic(fname: string, topic: string | null, value?: any): Promise<object>;
111
+ invokeTopic(domain: string, fname: string, topic: string | null, value?: any): Promise<object>;
111
112
  /**
112
113
  * Pubish a topic throughout the web app using the
113
114
  * Global EventEmitterContext. This will broadcast within the local frontend.
@@ -1 +1 @@
1
- export class HubBase{constructor(){Object.defineProperty(this,"localTopicToBackendTopicMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"backendTopicToLocalMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"localFNameToBackendFNameMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"backendFNameToLocalFNameMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:null})}setContext(a){this.context=a}invokeTopic(a,e,o){const c={topic:e,data:o};return this.invoke(a,c)}publish(a,e){const o=this.toLocalTopic(a);this.context?.dispatch({topic:o,payload:e})}mapTopic(a,e){this.localTopicToBackendTopicMap.set(a,e),this.backendTopicToLocalMap.set(e,a)}unmapTopic(a){if(this.localTopicToBackendTopicMap.has(a)){const e=this.localTopicToBackendTopicMap.get(a);this.localTopicToBackendTopicMap.delete(a),null!=e&&this.backendTopicToLocalMap.has(e)&&this.backendTopicToLocalMap.delete(e)}}mapFName(a,e){this.localFNameToBackendFNameMap.set(a,e),this.backendFNameToLocalFNameMap.set(e,a)}unmapFName(a){if(this.localFNameToBackendFNameMap.has(a)){const e=this.localFNameToBackendFNameMap.get(a);this.localFNameToBackendFNameMap.delete(a),null!=e&&this.backendFNameToLocalFNameMap.has(e)&&this.backendFNameToLocalFNameMap.delete(e)}}toBackendTopic(a){if(this.localTopicToBackendTopicMap.has(a)){const e=this.localTopicToBackendTopicMap.get(a);return null!=e?e:a}return a}toBackendFName(a){if(this.localFNameToBackendFNameMap.has(a)){const e=this.localFNameToBackendFNameMap.get(a);return null!=e?e:a}return a}toLocalTopic(a){if(this.backendTopicToLocalMap.has(a)){const e=this.backendTopicToLocalMap.get(a);return null!=e?e:a}return a}toLocalFName(a){if(this.backendFNameToLocalFNameMap.has(a)){const e=this.backendFNameToLocalFNameMap.get(a);return null!=e?e:a}return a}}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})}setContext(a){this.context=a}invokeTopic(a,e,o,c){const t={topic:o,data:c};return this.invoke(a,e,t)}publish(a,e){const o=this.toLocalTopic(a);this.context?.dispatch({topic:o,payload:e})}mapTopic(a,e){this.localTopicToBackendTopicMap.set(a,e),this.backendTopicToLocalMap.set(e,a)}unmapTopic(a){if(this.localTopicToBackendTopicMap.has(a)){const e=this.localTopicToBackendTopicMap.get(a);this.localTopicToBackendTopicMap.delete(a),null!=e&&this.backendTopicToLocalMap.has(e)&&this.backendTopicToLocalMap.delete(e)}}mapFName(a,e){this.localFNameToBackendFNameMap.set(a,e),this.backendFNameToLocalFNameMap.set(e,a)}unmapFName(a){if(this.localFNameToBackendFNameMap.has(a)){const e=this.localFNameToBackendFNameMap.get(a);this.localFNameToBackendFNameMap.delete(a),null!=e&&this.backendFNameToLocalFNameMap.has(e)&&this.backendFNameToLocalFNameMap.delete(e)}}toBackendTopic(a){if(this.localTopicToBackendTopicMap.has(a)){const e=this.localTopicToBackendTopicMap.get(a);return null!=e?e:a}return a}toBackendFName(a){if(this.localFNameToBackendFNameMap.has(a)){const e=this.localFNameToBackendFNameMap.get(a);return null!=e?e:a}return a}toLocalTopic(a){if(this.backendTopicToLocalMap.has(a)){const e=this.backendTopicToLocalMap.get(a);return null!=e?e:a}return a}toLocalFName(a){if(this.backendFNameToLocalFNameMap.has(a)){const e=this.backendFNameToLocalFNameMap.get(a);return null!=e?e:a}return a}}export default HubBase;
@@ -15,6 +15,6 @@ export declare class HubSimulate extends HubBase {
15
15
  * @param timeout Timeout in milliseconds after which the promise is rejected if no response is received.
16
16
  * @returns A Promise that resolves to the response from the backend or rejects if a timeout occurs.
17
17
  */
18
- invoke(fname: string, payload?: object, timeout?: number): Promise<object>;
18
+ invoke(domain: string, fname: string, payload?: object, timeout?: number): Promise<object>;
19
19
  }
20
20
  export default HubSimulate;
@@ -1 +1 @@
1
- import{HubBase}from"./HubBase";export class HubSimulate extends HubBase{constructor(){super()}invoke(e,t,u=20){return new Promise(((e,r)=>{setTimeout((()=>{e({data:t})}),u)}))}}export default HubSimulate;
1
+ import{HubBase}from"./HubBase";export class HubSimulate extends HubBase{constructor(){super()}invoke(e,t,u,r=20){return new Promise(((e,t)=>{setTimeout((()=>{e({data:u})}),r)}))}}export default HubSimulate;
@@ -82,5 +82,5 @@ export declare class HubTauri extends HubBase {
82
82
  * @param payload Optional data payload
83
83
  * @returns The return value of the backend method.
84
84
  */
85
- invoke(fname: string, payload?: object | undefined): Promise<object>;
85
+ invoke(domain: string, fname: string, payload?: object | undefined): Promise<object>;
86
86
  }
@@ -1 +1 @@
1
- import{HubBase}from"./HubBase";import{event,invoke}from"@tauri-apps/api";export class HubTauri extends HubBase{constructor(){super(),event.listen("autocore://broadcast_event",(o=>{let e=JSON.parse(o.payload);void 0!==e.topic&&null!==e.topic&&(void 0!==e.payload&&null!==e.payload?this.publish(e.topic,e.payload):this.publish(e.topic,void 0))}))}invoke(o,e){return null!=e?invoke(o,e):invoke(o)}}
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)}}
@@ -0,0 +1,37 @@
1
+ /** @file
2
+ *
3
+ * ## broadcast messages
4
+ * The result field of CommandMessages used for broadcast must have
5
+ * success set to true, and must contain the field "topic." The topic field, along
6
+ * with the domain field of the CommandMessage will be combined for the topic used
7
+ * by the websocket client.
8
+ *
9
+ * broadcast topic = `${CommandMessage.domain}/${CommandMessage.result["topic"]}
10
+ *
11
+ * So, to subscribe to a broadcast topic for GM.fReal that is served by the ADS client, the
12
+ * topic will be: "ADS/GM.fReal"
13
+ */
14
+ import { HubBase } from './HubBase';
15
+ interface CommandMessageResult {
16
+ data: any;
17
+ success: boolean;
18
+ error_message: string;
19
+ }
20
+ interface CommandMessage {
21
+ request_id: number;
22
+ domain: string;
23
+ fname: string;
24
+ args?: any;
25
+ result?: CommandMessageResult;
26
+ }
27
+ export declare class HubWebSocket extends HubBase {
28
+ private socket;
29
+ private requestId;
30
+ private pendingRequests;
31
+ constructor();
32
+ invoke: (domain: string, fname: string, payload?: object) => Promise<object>;
33
+ handleUnsolicitedMessage: (msg: CommandMessage) => void;
34
+ disconnect: () => void;
35
+ protected emit: (eventName: string, payload?: object) => void;
36
+ }
37
+ export {};
@@ -0,0 +1 @@
1
+ import{HubBase}from"./HubBase";export class HubWebSocket extends HubBase{constructor(){super(),Object.defineProperty(this,"socket",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"requestId",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"pendingRequests",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"invoke",{enumerable:!0,configurable:!0,writable:!0,value:(e,t,s)=>new Promise(((i,n)=>{const r=++this.requestId;this.pendingRequests.set(r,{resolve:i,reject:n});let o={request_id:r,domain:e,fname:t,args:s,result:void 0};this.socket.send(JSON.stringify(o))}))}),Object.defineProperty(this,"handleUnsolicitedMessage",{enumerable:!0,configurable:!0,writable:!0,value:e=>{if("BROADCAST"===e.fname&&e.domain.length>=1&&void 0!==e.result&&null!==e.result&&void 0!==e.result.data&&null!==e.result.data){let t=`${e.domain}/${e.result.data.topic}`;this.publish(t,e.result.data)}}}),Object.defineProperty(this,"disconnect",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.socket.close()}}),Object.defineProperty(this,"emit",{enumerable:!0,configurable:!0,writable:!0,value:(e,t)=>{this.socket.send(JSON.stringify({eventName:e,payload:t}))}});const e=window.location.hostname,t=window.location.port,s=`${"https:"===window.location.protocol?"wss://":"ws://"}${e}${t?":"+t:""}/ws/`;this.socket=new WebSocket(s);let i=this;this.socket.onopen=function(){i.publish("HUB/connected",!0)},this.socket.onmessage=e=>{const t=JSON.parse(e.data);if(t.request_id&&this.pendingRequests.has(t.request_id)){const{resolve:e,reject:s}=this.pendingRequests.get(t.request_id);t.result?.success?e(t):s(new Error(t.result?.error_message)),this.pendingRequests.delete(t.request_id)}else this.handleUnsolicitedMessage(t)},this.socket.onerror=e=>{},this.socket.onclose=()=>{}}}
@@ -1,6 +1,6 @@
1
1
  import { HubBase as Hub } from './HubBase';
2
2
  import { HubTauri } from './HubTauri';
3
- import { HubSocketIo } from "./HubSocketIo";
3
+ import { HubWebSocket } from "./HubWebSocket";
4
4
  import { HubSimulate } from "./HubSimulate";
5
5
  /**
6
6
  * Creates a connection to the backend.
@@ -9,5 +9,5 @@ import { HubSimulate } from "./HubSimulate";
9
9
  export declare function createHub(): Hub;
10
10
  export { HubBase as Hub } from './HubBase';
11
11
  export { HubTauri };
12
- export { HubSocketIo };
12
+ export { HubWebSocket };
13
13
  export { HubSimulate };
package/dist/hub/index.js CHANGED
@@ -1 +1 @@
1
- import{HubTauri}from"./HubTauri";import{HubSocketIo}from"./HubSocketIo";import{HubSimulate}from"./HubSimulate";export function createHub(){return window.__TAURI__?new HubTauri:"80"!==window.location.port&&"443"!==window.location.port?new HubSimulate:new HubSocketIo}export{HubBase as Hub}from"./HubBase";export{HubTauri};export{HubSocketIo};export{HubSimulate};
1
+ import{HubTauri}from"./HubTauri";import{HubWebSocket}from"./HubWebSocket";import{HubSimulate}from"./HubSimulate";export function createHub(){return void 0!==window.__TAURI__&&null!==window.__TAURI__?new HubTauri:void 0!==window.location.port&&window.location.port.length>0&&"80"!==window.location.port&&"8080"!==window.location.port&&"443"!==window.location.port?new HubSimulate:new HubWebSocket}export{HubBase as Hub}from"./HubBase";export{HubTauri};export{HubWebSocket};export{HubSimulate};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adcops/autocore-react",
3
- "version": "3.0.8",
3
+ "version": "3.0.12",
4
4
  "description": "A React component library for industrial user interfaces.",
5
5
  "private": false,
6
6
  "type": "module",