@adcops/autocore-react 3.0.6 → 3.0.10

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;
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
3
+ * Created Date: 2024-03-22 06:26:45
4
+ * -----
5
+ * Last Modified: 2024-03-22 07:07:50
6
+ * -----
7
+ *
8
+ */
9
+
10
+
11
+
12
+ .value-indicator-container {
13
+
14
+ display: flex;
15
+ flex-direction: column;
16
+ background-color: var(--surface-ground);
17
+ border-color: var(--surface-border);
18
+ border-radius: var(--border-radius);
19
+ border-width: 1px;
20
+ border-style: solid;
21
+ justify-content: center;
22
+ align-items: center;
23
+ padding: 2mm;
24
+ flex-grow: 1; /* Allow the item to grow to fill available space */
25
+ flex-shrink: 0; /* Allow the item to shrink if necessary */
26
+ flex-basis: 0; /* Start with 0 width and then grow as needed, equal distribution */
27
+ min-width: 0; /* Prevents flex items from overflowing their container */
28
+ }
29
+
30
+ .value-indicator-label {
31
+ padding-bottom: 1mm;
32
+ }
@@ -1,5 +1,6 @@
1
1
  import React, { Component } from 'react';
2
2
  import type { NumerableFormatOptions } from '../core/NumerableTypes';
3
+ import "./ValueIndicator.css";
3
4
  /**
4
5
  * Properties of the ValueDisplay component.
5
6
  */
@@ -34,6 +35,10 @@ interface ValueIndicatorProps {
34
35
  * The topic to monitor to display. Optional.
35
36
  */
36
37
  topic?: string;
38
+ /**
39
+ * Optional style properties.
40
+ */
41
+ style?: React.CSSProperties | undefined;
37
42
  }
38
43
  /**
39
44
  * State of the ValueDisplay component.
@@ -1 +1 @@
1
- import{jsxs as _jsxs,jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{Component}from"react";import{Tooltip}from"primereact/tooltip";import{ValueDisplay}from"./ValueDisplay";export class ValueIndicator extends Component{constructor(r){super(r),this.state={}}render(){return _jsxs(_Fragment,{children:[_jsxs("style",{children:["\n .value-indicator-container {\n\n background-color: var(--surface-ground);\n border-color: var(--surface-border);\n border-radius: var(--border-radius);\n border-width: 1px;\n border-style: solid;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n padding: 2mm;\n }\n\n .value-indicator-label {\n padding-bottom: 1mm;\n } \n ","'"]}),_jsx(Tooltip,{target:".value-indicator-tooltip"}),_jsx("span",{className:"value-indicator-tooltip",children:_jsxs("div",{className:"value-indicator-container",children:[void 0!==this.props.label&&_jsx("div",{className:"value-indicator-label",children:this.props.label}),_jsx(ValueDisplay,{className:this.props.className,value:this.props.value,format:this.props.format,formatOptions:this.props.formatOptions,topic:this.props.topic,"data-pr-tooltip":this.props.tooltip,"data-pr-position":"down","data-pr-mousetrack":!0,"data-pr-showDelay":2e3})]})})]})}}export default ValueIndicator;
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Component}from"react";import{Tooltip}from"primereact/tooltip";import{ValueDisplay}from"./ValueDisplay";import"./ValueIndicator.css";export class ValueIndicator extends Component{constructor(t){super(t),this.state={}}render(){return _jsxs("div",{className:"value-indicator-container",style:this.props.style,children:[_jsx(Tooltip,{target:".value-indicator-container"}),void 0!==this.props.label&&_jsx("div",{className:"value-indicator-label",children:this.props.label}),_jsx(ValueDisplay,{className:this.props.className,value:this.props.value,format:this.props.format,formatOptions:this.props.formatOptions,topic:this.props.topic,"data-pr-tooltip":this.props.tooltip,"data-pr-position":"down","data-pr-mousetrack":!0,"data-pr-showDelay":2e3})]})}}export default ValueIndicator;
@@ -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"}});
@@ -1 +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})};
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})};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adcops/autocore-react",
3
- "version": "3.0.6",
3
+ "version": "3.0.10",
4
4
  "description": "A React component library for industrial user interfaces.",
5
5
  "private": false,
6
6
  "type": "module",