@adcops/autocore-react 3.0.39 → 3.0.40
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/components/IndicatorButton.d.ts +22 -137
- package/dist/components/IndicatorButton.js +1 -1
- package/dist/core/EventEmitterContext.d.ts +1 -1
- package/dist/core/EventEmitterContext.js +1 -1
- package/package.json +1 -1
- package/src/components/IndicatorButton.tsx +187 -333
- package/src/core/EventEmitterContext.tsx +266 -223
|
@@ -1,156 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ButtonProps } from
|
|
3
|
-
import { EventEmitterContextType } from '../core/EventEmitterContext';
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ButtonProps } from "primereact/button";
|
|
4
3
|
import { IndicatorColor } from "../core/IndicatorColor";
|
|
5
4
|
export { IndicatorColor };
|
|
6
|
-
import { ActionMode } from
|
|
5
|
+
import { ActionMode } from "../core/ActionMode";
|
|
7
6
|
export { ActionMode };
|
|
8
|
-
import { IndicatorButtonState } from '../core/IndicatorButtonState';
|
|
9
7
|
export declare type IndicatorButtonOptionsType = string[] | undefined[] | undefined;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* These types of components both indicate a state and execute commands/signals.
|
|
13
|
-
* This type of component is very common in industrial HMIs.
|
|
14
|
-
*
|
|
15
|
-
* These properties support displaying values of boolean, number and string states.
|
|
16
|
-
*
|
|
17
|
-
* Available boolean states: **on**, **off** and **not available**:
|
|
18
|
-
*
|
|
19
|
-
* * `true` is treated as **on**
|
|
20
|
-
* * `false` is treated as **off**
|
|
21
|
-
* * `undefined` is treated as **not available**
|
|
22
|
-
*
|
|
23
|
-
* Numeric values can be used. When there is only 2 or less possible states,
|
|
24
|
-
* 0 will be considered false (OFF), anything else will be considered true (ON).
|
|
25
|
-
* Undefined will be treated as "not available.""
|
|
26
|
-
*
|
|
27
|
-
* When the indicator contains more than 2 states, then the number will be matched
|
|
28
|
-
* to the available state, in order. More than two states requires usage of the
|
|
29
|
-
* options field, and declaring more than two states there.
|
|
30
|
-
*
|
|
31
|
-
* If a string state is used, it will be matched exactly to the matching
|
|
32
|
-
* label in the `options` field.
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* For more information on the AutoCore Button API Specification, see
|
|
36
|
-
* [Additional Documentation](../additional-docs/ButtonApiSpecs.md).
|
|
37
|
-
*/
|
|
38
|
-
export interface IndicatorButtonProps extends Omit<ButtonProps, 'value'> {
|
|
39
|
-
/**
|
|
40
|
-
* Topic name to monitor for state indication.
|
|
41
|
-
* If `value` field is not undefined, then that value is used instead.
|
|
42
|
-
*/
|
|
8
|
+
export interface IndicatorButtonProps extends Omit<ButtonProps, "value"> {
|
|
9
|
+
/** Topic name to monitor for state indication. If `value` is not undefined, that value is used instead. */
|
|
43
10
|
topic?: string;
|
|
44
|
-
/**
|
|
45
|
-
* State to be displayed.
|
|
46
|
-
*
|
|
47
|
-
*/
|
|
11
|
+
/** State to be displayed. */
|
|
48
12
|
value?: boolean | number | string;
|
|
49
|
-
/**
|
|
50
|
-
* Color for the button when the state is TRUE.
|
|
51
|
-
*/
|
|
13
|
+
/** Color for the button when the state is TRUE. */
|
|
52
14
|
onColor?: IndicatorColor;
|
|
53
|
-
/**
|
|
54
|
-
* Color for the button when the state is FALSE.
|
|
55
|
-
*/
|
|
15
|
+
/** Color for the button when the state is FALSE. */
|
|
56
16
|
offColor?: IndicatorColor;
|
|
57
|
-
/**
|
|
58
|
-
* An array of string labels to display as the available options.
|
|
59
|
-
*
|
|
60
|
-
* For items with 2 states or less:
|
|
61
|
-
* Index 0 is the label when value is OFF.
|
|
62
|
-
* Index 1 is the label when value is ON.
|
|
63
|
-
*
|
|
64
|
-
* If only only value is given (Index 0), then that value is used for all states.
|
|
65
|
-
* For many controls, this is the same as setting the `label` field and leaving this
|
|
66
|
-
* field undefined.
|
|
67
|
-
*/
|
|
17
|
+
/** Labels for available options (see docs). */
|
|
68
18
|
options?: IndicatorButtonOptionsType;
|
|
69
|
-
/**
|
|
70
|
-
* Icon to be displayed on the button. Overrideen by onIcon or offIcon if those
|
|
71
|
-
* are not undefined.
|
|
72
|
-
*/
|
|
19
|
+
/** Base icon class (overridden by onIcon/offIcon). */
|
|
73
20
|
icon?: string;
|
|
74
|
-
/**
|
|
75
|
-
* Icon displayed when the state is TRUE. Falls back to `icon` if undefined.
|
|
76
|
-
*/
|
|
21
|
+
/** Icon when TRUE. */
|
|
77
22
|
onIcon?: string;
|
|
78
|
-
/**
|
|
79
|
-
* Icon displayed when the state is FALSE. Falls back to `icon` if undefined.
|
|
80
|
-
*/
|
|
23
|
+
/** Icon when FALSE. */
|
|
81
24
|
offIcon?: string;
|
|
82
|
-
/**
|
|
83
|
-
* Name of the command to invoke on button events.
|
|
84
|
-
* If command is "*", then the commandTopic will be dispatched
|
|
85
|
-
* internally.
|
|
86
|
-
*/
|
|
25
|
+
/** Name of the command to invoke on button events. */
|
|
87
26
|
command?: string;
|
|
88
|
-
/**
|
|
89
|
-
* Optional topic parameter to send along with the command.
|
|
90
|
-
* If set, will automatically be included with commandArgs as
|
|
91
|
-
* the value of field 'topic.'
|
|
92
|
-
*/
|
|
27
|
+
/** Optional topic sent with the command payload. */
|
|
93
28
|
commandTopic?: string;
|
|
94
|
-
/**
|
|
95
|
-
* Optional arguments sent with the command.
|
|
96
|
-
*/
|
|
29
|
+
/** Optional args sent with the command payload. */
|
|
97
30
|
commandArgs?: any;
|
|
98
|
-
/**
|
|
99
|
-
* Topic to disable button interaction.
|
|
100
|
-
*/
|
|
101
|
-
disableTopic?: string;
|
|
102
|
-
/**
|
|
103
|
-
* Topic to control the visibility of the button.
|
|
104
|
-
*/
|
|
105
|
-
invisibleTopic?: string;
|
|
106
|
-
/**
|
|
107
|
-
* Mode of input for the button (e.g., TAP, TOGGLE).
|
|
108
|
-
*/
|
|
31
|
+
/** Input mode (Tap, Pressed, Released). */
|
|
109
32
|
actionMode?: ActionMode;
|
|
110
|
-
/**
|
|
111
|
-
* Inverts the signal values for TAP, PRESSED, and RELEASED modes.
|
|
112
|
-
*/
|
|
33
|
+
/** Inverts values for Tap/Pressed/Released dispatches. */
|
|
113
34
|
invert?: boolean;
|
|
35
|
+
/** Directly disables the button (replaces old disableTopic). */
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
/** Hides the button (replaces old invisibleTopic/hiddenTopic). */
|
|
38
|
+
hidden?: boolean;
|
|
114
39
|
}
|
|
115
|
-
export declare
|
|
116
|
-
static contextType: import("react").Context<EventEmitterContextType>;
|
|
117
|
-
static defaultProps: {
|
|
118
|
-
onColor: IndicatorColor;
|
|
119
|
-
offColor: string;
|
|
120
|
-
};
|
|
121
|
-
constructor(props: IndicatorButtonProps);
|
|
122
|
-
componentDidMount(): void;
|
|
123
|
-
componentDidUpdate(prevProps: IndicatorButtonProps): void;
|
|
124
|
-
componentWillUnmount(): void;
|
|
125
|
-
/**
|
|
126
|
-
* Sets up subscriptions based on provided topics.
|
|
127
|
-
*/
|
|
128
|
-
private setupSubscriptions;
|
|
129
|
-
/**
|
|
130
|
-
* Handles updates for the main topic.
|
|
131
|
-
*/
|
|
132
|
-
private handleTopicUpdate;
|
|
133
|
-
/**
|
|
134
|
-
* Handles updates for the disable topic.
|
|
135
|
-
*/
|
|
136
|
-
private handleDisableTopicUpdate;
|
|
137
|
-
/**
|
|
138
|
-
* Handles updates for the invisible topic.
|
|
139
|
-
*/
|
|
140
|
-
private handleInvisibleTopicUpdate;
|
|
141
|
-
/**
|
|
142
|
-
* Handle the button being pressed down. Used for TAP and PRESSED action modes.
|
|
143
|
-
*/
|
|
144
|
-
protected handleOnPressed(): void;
|
|
145
|
-
/**
|
|
146
|
-
* Handle the button being released. Used for TAP and RELEASED action modes.
|
|
147
|
-
*/
|
|
148
|
-
protected handleOnReleased(): void;
|
|
149
|
-
/**
|
|
150
|
-
* Dispatch a value to any listeners.
|
|
151
|
-
* @param value The value to dispatch as part of the payload.
|
|
152
|
-
*/
|
|
153
|
-
protected dispatchCommand(value: any): void;
|
|
154
|
-
render(): import("react/jsx-runtime").JSX.Element;
|
|
155
|
-
}
|
|
40
|
+
export declare const IndicatorButton: React.FC<IndicatorButtonProps>;
|
|
156
41
|
export default IndicatorButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useCallback,useContext,useEffect,useState}from"react";import{Button}from"primereact/button";import{EventEmitterContext}from"../core/EventEmitterContext";import{IndicatorColor}from"../core/IndicatorColor";export{IndicatorColor};import{ActionMode}from"../core/ActionMode";export{ActionMode};const toPrimeIcon=o=>o?o.includes("pi ")?o:`pi ${o}`:void 0;export const IndicatorButton=({topic:o,value:t,onColor:e=IndicatorColor.IndicatorGreen,offColor:n="gray",options:r,icon:i,onIcon:c,offIcon:a,command:s,commandTopic:l,commandArgs:d,actionMode:u,invert:m,className:f,label:p,style:C,disabled:b,hidden:I,...x})=>{const{subscribe:g,unsubscribe:v,dispatch:h}=useContext(EventEmitterContext),[M,E]=useState(void 0),[y,A]=useState(!1);useEffect((()=>{if(!o||!g)return;const t=g(o,(o=>E(o)));return()=>{try{v&&void 0!==t&&v(t)}catch{}}}),[o,g,v]);const S=void 0!==t?t:M,k=(()=>{if(!r||0===r.length)return p;if(r.length>2){if("number"==typeof S){const o=Math.trunc(S);if(o>=0&&o<r.length&&null!=r[o])return String(r[o])}else if("string"==typeof S){const o=r.findIndex((o=>o===S));if(o>=0)return String(r[o])}return p}const o=S?r[1]:r[0];return null!=o&&String(o).length>0?String(o):p})(),T=toPrimeIcon((S?c:a)??i);let j=S?e:n;void 0===S&&(j=IndicatorColor.IndicatorInvalid);const B=useCallback((o=>{if(!s||!h)return;const t={topic:l,value:m?!o:o,...d??{}};h({topic:s,payload:t})}),[s,h,m,d,l]),P=useCallback((()=>{y||(A(!0),u!==ActionMode.Tap&&u!==ActionMode.Pressed||B(!0))}),[y,u,B]),w=useCallback((()=>{y&&(A(!1),u===ActionMode.Tap?B(!1):u===ActionMode.Released&&B(!0))}),[y,u,B]),N={color:"white",backgroundColor:j,display:I?"none":"block",...C??{}};return _jsx(Button,{...x,label:k,icon:T,className:f,style:N,disabled:!!b,onMouseDown:P,onTouchStart:P,onMouseUp:w,onTouchEnd:w})};export default IndicatorButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{createContext,useState,useMemo,useCallback}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
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{createContext,useState,useMemo,useCallback,useRef,useEffect}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,e,s)=>Promise.resolve({data:{},success:!1,error_message:""}),unsubscribe:t=>{},hub:null,getSubscriptions:()=>[],isConnected:()=>!1});export const EventEmitterProvider=({children:t})=>{const[e,s]=useState({subscriptions:{},nextSubscriptionId:1}),r=useMemo((()=>createHub()),[]),c=useRef({});useEffect((()=>{c.current=e.subscriptions}),[e.subscriptions]);const o=useCallback((t=>{const{topic:e,payload:r}=t,o=c.current[e]?.slice()??[];for(const t of o)try{t.callback(r)}catch(t){}s((t=>({...t,eventData:r})))}),[]),n=useCallback(((t,e)=>{const r=++globalSubscriptionId,o=[...c.current[t]??[],{id:r,callback:e}];return c.current[t]=o,s((e=>({...e,subscriptions:{...e.subscriptions,[t]:o},nextSubscriptionId:globalSubscriptionId+1}))),r}),[]),i=useCallback((t=>{const e=c.current;for(const s of Object.keys(e)){const r=e[s].filter((e=>e.id!==t));r.length?e[s]=r:delete e[s]}s((t=>({...t,subscriptions:{...e}})))}),[]);import.meta&&import.meta.hot&&import.meta.hot.dispose((()=>{c.current={}}));const u=useMemo((()=>({state:e,dispatch:o,subscribe:n,unsubscribe:i,invoke:r.invoke,hub:r,getSubscriptions:t=>t?c.current[t]??[]:c.current,isConnected:r.isConnected})),[e,r,o,n,i]);return r.setContext(u),_jsx(EventEmitterContext.Provider,{value:u,children:t})};
|