@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.
@@ -2,7 +2,7 @@
2
2
  * Copyright (C) 2024 Automated Design Corp. All Rights Reserved.
3
3
  * Created Date: 2024-01-16 14:17:02
4
4
  * -----
5
- * Last Modified: 2024-03-21 15:24:54
5
+ * Last Modified: 2024-03-22 06:42:57
6
6
  * Modified By: ADC
7
7
  * -----
8
8
  *
@@ -17,7 +17,7 @@ import { Tooltip } from "primereact/tooltip";
17
17
  import { ValueDisplay } from './ValueDisplay';
18
18
  import type { NumerableFormatOptions } from '../core/NumerableTypes';
19
19
 
20
-
20
+ import "./ValueIndicator.css";
21
21
 
22
22
 
23
23
  /**
@@ -62,6 +62,12 @@ interface ValueIndicatorProps {
62
62
  * The topic to monitor to display. Optional.
63
63
  */
64
64
  topic?: string;
65
+
66
+
67
+ /**
68
+ * Optional style properties.
69
+ */
70
+ style?: React.CSSProperties | undefined;
65
71
  }
66
72
 
67
73
  /**
@@ -94,56 +100,34 @@ export class ValueIndicator extends Component<ValueIndicatorProps, ValueIndicato
94
100
  * Renders the component into the DOM.
95
101
  * @returns A styled `div` element displaying the indicator.
96
102
  */
97
- render() {
98
103
 
99
104
 
105
+
106
+ render() {
107
+
100
108
  return (
101
- <>
102
- <style>
103
- {`
104
- .value-indicator-container {
105
-
106
- background-color: var(--surface-ground);
107
- border-color: var(--surface-border);
108
- border-radius: var(--border-radius);
109
- border-width: 1px;
110
- border-style: solid;
111
- display: flex;
112
- flex-direction: column;
113
- justify-content: center;
114
- align-items: center;
115
- padding: 2mm;
116
- }
117
-
118
- .value-indicator-label {
119
- padding-bottom: 1mm;
120
- }
121
- `}'
122
- </style>
123
- <Tooltip target=".value-indicator-tooltip" />
124
- <span className="value-indicator-tooltip" >
125
- <div className='value-indicator-container'>
126
-
127
- {this.props.label !== undefined &&
128
- <div className="value-indicator-label">
129
- {this.props.label}
130
- </div>
131
- }
132
-
133
- <ValueDisplay
134
- className={this.props.className}
135
- value={this.props.value}
136
- format={this.props.format}
137
- formatOptions={this.props.formatOptions}
138
- topic={this.props.topic}
139
- data-pr-tooltip={this.props.tooltip}
140
- data-pr-position="down"
141
- data-pr-mousetrack={true}
142
- data-pr-showDelay={2000}
143
- />
144
- </div>
145
- </span>
146
- </>
109
+ <div className='value-indicator-container' style={this.props.style}>
110
+ <Tooltip target=".value-indicator-container" />
111
+
112
+ {this.props.label !== undefined &&
113
+ <div className="value-indicator-label">
114
+ {this.props.label}
115
+ </div>
116
+ }
117
+
118
+ <ValueDisplay
119
+ className={this.props.className}
120
+
121
+ value={this.props.value}
122
+ format={this.props.format}
123
+ formatOptions={this.props.formatOptions}
124
+ topic={this.props.topic}
125
+ data-pr-tooltip={this.props.tooltip}
126
+ data-pr-position="down"
127
+ data-pr-mousetrack={true}
128
+ data-pr-showDelay={2000}
129
+ />
130
+ </div>
147
131
  );
148
132
  }
149
133
  }
@@ -2,18 +2,18 @@
2
2
  * Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
3
3
  * Created Date: 2024-03-20 13:05:42
4
4
  * -----
5
- * Last Modified: 2024-03-21 09:37:17
5
+ * Last Modified: 2024-04-16 19:06:17
6
6
  * -----
7
7
  *
8
8
  */
9
9
 
10
10
 
11
- import React from "react";
11
+ import React, { createRef } from "react";
12
12
 
13
- import { InputNumber} from 'primereact/inputnumber';
13
+ import { InputNumber } from 'primereact/inputnumber';
14
14
  import { Button } from "primereact/button";
15
15
 
16
- import { EventEmitterContext } from "../core/EventEmitterContext.js";
16
+ import { EventEmitterContext } from "../core/EventEmitterContext";
17
17
 
18
18
  /**
19
19
  * Properties of the ValueInput component.
@@ -23,23 +23,23 @@ interface ValueInputProps {
23
23
  /**
24
24
  * The label for the ValueInput field.
25
25
  */
26
- label : React.ReactNode | undefined;
26
+ label: React.ReactNode | undefined;
27
27
 
28
28
 
29
29
  /**
30
30
  * The value for the field.
31
31
  */
32
- value : number | null;
32
+ value: number | null;
33
33
 
34
34
  /**
35
35
  * Minimum value for the field.
36
36
  */
37
- min : number | undefined;
37
+ min: number | undefined;
38
38
 
39
39
  /**
40
40
  * Minimum value for the field.
41
41
  */
42
- max : number | undefined;
42
+ max: number | undefined;
43
43
 
44
44
  /**
45
45
  * Minimum number of decimal points. The user will not
@@ -49,7 +49,7 @@ interface ValueInputProps {
49
49
  * the component will throw an error.
50
50
  * @default 0
51
51
  */
52
- minPrecision : number | undefined;
52
+ minPrecision: number | undefined;
53
53
 
54
54
 
55
55
  /**
@@ -58,7 +58,7 @@ interface ValueInputProps {
58
58
  * the component will throw an error.
59
59
  * @default 3
60
60
  */
61
- maxPrecision : number | undefined;
61
+ maxPrecision: number | undefined;
62
62
 
63
63
 
64
64
  /**
@@ -67,7 +67,7 @@ interface ValueInputProps {
67
67
  * currency type using the currency property.
68
68
  * @default "decimal"
69
69
  */
70
- mode : "currency" | "decimal" | undefined;
70
+ mode: "currency" | "decimal" | undefined;
71
71
 
72
72
 
73
73
  /**
@@ -78,19 +78,19 @@ interface ValueInputProps {
78
78
  *
79
79
  * @default "USD"
80
80
  */
81
- currency : string;
82
-
81
+ currency: string;
82
+
83
83
  /**
84
84
  * An optional prefix before the value of the field.
85
85
  * Unlike the TextInput control, this prefix is internal to the field.
86
86
  */
87
- prefix : string | undefined;
87
+ prefix: string | undefined;
88
88
 
89
89
  /**
90
90
  * An optional suffix after the value of the field.
91
91
  * Unlike the TextInput control, this prefix is internal to the field.
92
92
  */
93
- suffix : string | undefined;
93
+ suffix: string | undefined;
94
94
 
95
95
  /**
96
96
  * Set true to display buttons to increment/decrement the value.
@@ -98,12 +98,12 @@ interface ValueInputProps {
98
98
  *
99
99
  * @default false
100
100
  */
101
- showButtons : boolean;
101
+ showButtons: boolean;
102
102
 
103
103
  /**
104
104
  * The amount clicking an increment/decrement buttion will change the value.
105
105
  */
106
- step : number | undefined;
106
+ step: number | undefined;
107
107
 
108
108
 
109
109
  /**
@@ -112,40 +112,41 @@ interface ValueInputProps {
112
112
  *
113
113
  * @default "en-US"
114
114
  */
115
- locale : string | undefined;
115
+ locale: string | undefined;
116
116
 
117
117
  /**
118
118
  * A small, advisory text below the field.
119
119
  */
120
- description : React.ReactNode | undefined;
120
+ description: React.ReactNode | undefined;
121
121
 
122
122
  /**
123
123
  * If true, all functions of the field will be disabled.
124
124
  */
125
- disabled : boolean | undefined;
126
-
125
+ disabled: boolean | undefined;
126
+
127
127
  /** Topic on which the value will be dispatched through the user interfave on successful data entry. */
128
- dispatchTopic : string | undefined;
128
+ dispatchTopic: string | undefined;
129
129
 
130
130
  /**
131
131
  * Placeholder string to display if the value is empty.
132
132
  */
133
- placeholder : string | undefined;
133
+ placeholder: string | undefined;
134
134
 
135
135
  /**
136
136
  * The user has accepted a new value.
137
137
  * @param newValue New value accepted by the user.
138
- */
139
- onValueChanged?(newValue: number) : void;
138
+ */
139
+ onValueChanged?(newValue: number): void;
140
140
  }
141
141
 
142
142
  /**
143
143
  * State variables of the ValueInput component.
144
144
  */
145
145
  interface ValueInputState {
146
-
147
- entryValue : number | null;
148
- editing : boolean;
146
+
147
+ entryValue: number | null;
148
+ currentValue: number | null;
149
+ editing: boolean;
149
150
  }
150
151
 
151
152
 
@@ -165,67 +166,97 @@ export class ValueInput extends React.Component<ValueInputProps, ValueInputState
165
166
  declare context: React.ContextType<typeof EventEmitterContext>;
166
167
 
167
168
 
168
-
169
+
169
170
 
170
171
  /**
171
172
  * Default properties for the component.
172
173
  */
173
174
  static defaultProps = {
174
- label : '',
175
- value : undefined,
176
- keyFilter : undefined,
177
- writeTopic : undefined,
178
- onValueChanged : undefined,
175
+ label: '',
176
+ value: undefined,
177
+ keyFilter: undefined,
178
+ writeTopic: undefined,
179
+ onValueChanged: undefined,
179
180
  description: undefined,
180
181
  prefix: undefined,
181
- suffix : undefined,
182
- disabled : false,
183
- dispatchTopic : undefined,
184
- placeholder : undefined,
185
- validator : undefined,
186
- min : undefined,
187
- max : undefined,
188
- minPrecision : 0,
189
- maxPrecision : 3,
190
- mode : "decimal",
191
- showButtons : false,
192
- step : 1,
193
- locale : "en-US",
194
- currency : "USD"
182
+ suffix: undefined,
183
+ disabled: false,
184
+ dispatchTopic: undefined,
185
+ placeholder: undefined,
186
+ validator: undefined,
187
+ min: undefined,
188
+ max: undefined,
189
+ minPrecision: 0,
190
+ maxPrecision: 3,
191
+ mode: "decimal",
192
+ showButtons: false,
193
+ step: 1,
194
+ locale: "en-US",
195
+ currency: "USD"
195
196
  };
197
+ inputRef: React.RefObject<HTMLInputElement>;
196
198
 
197
199
  /**
198
200
  *
199
201
  * @param {FooterViewProps} props
200
202
  */
201
- constructor(props : ValueInputProps) {
203
+ constructor(props: ValueInputProps) {
202
204
  super(props);
203
205
  this.state = {
204
- entryValue : props.value,
205
- editing : false
206
+ entryValue: props.value,
207
+ currentValue: props.value,
208
+ editing: false
206
209
  };
210
+
211
+ this.inputRef = createRef();
207
212
  }
208
213
 
209
214
  /**
210
215
  * The component has been loaded into the DOM.
211
216
  */
212
- componentDidMount() {
213
- }
217
+ componentDidMount() {
218
+ }
219
+
220
+
221
+ private onBufferValue(val: number | null) {
222
+ if (val === null)
223
+ return;
214
224
 
215
-
225
+ if (!this.state.editing) {
226
+ this.setState({
227
+ entryValue: this.state.currentValue,
228
+ editing: true
229
+ }, () => {
230
+
231
+ setTimeout(() => {
232
+ if (this.inputRef.current) {
233
+ this.inputRef.current.focus();
234
+ }
235
+
236
+ }, 0);
237
+
238
+ }
239
+ );
240
+ }
241
+ else {
242
+ this.setState({
243
+ entryValue: val
244
+ });
245
+ }
246
+ }
216
247
 
217
248
  /**
218
249
  * The user has elected to accept the input value. Validate and store, if valid.
219
250
  */
220
251
  private onAcceptValue() {
221
- if (this.state.entryValue !== null ) {
222
- this.setState({editing : false});
223
-
252
+ if (this.state.entryValue !== null) {
253
+ this.setState({ editing: false, currentValue: this.state.entryValue });
254
+
224
255
  if (this.props.onValueChanged)
225
256
  this.props.onValueChanged(this.state.entryValue);
226
257
 
227
258
  if (this.props.dispatchTopic !== undefined) {
228
- this.context.dispatch({topic: this.props.dispatchTopic, payload:this.state.entryValue});
259
+ this.context.dispatch({ topic: this.props.dispatchTopic, payload: this.state.entryValue });
229
260
  }
230
261
 
231
262
  }
@@ -235,22 +266,29 @@ export class ValueInput extends React.Component<ValueInputProps, ValueInputState
235
266
  * The user wishes to reset/cancel the previous value.
236
267
  */
237
268
  private onResetValue() {
238
- this.setState({
239
- entryValue: this.props.value,
240
- editing : false
241
- });
269
+
270
+ if (this.state.editing) {
271
+
272
+ this.setState({
273
+ currentValue: this.state.currentValue,
274
+ entryValue: this.state.currentValue,
275
+ editing: false
276
+ });
277
+ }
242
278
  }
243
279
 
244
280
 
245
281
  render() {
246
282
 
247
- return(
283
+ return (
248
284
  <div>
249
285
  <div className="p-inputgroup flex-1" >
250
286
  <span className="p-inputgroup-addon">
251
287
  {this.props.label}
252
- </span>
253
- <InputNumber
288
+ </span>
289
+ <InputNumber
290
+ inputRef={this.inputRef}
291
+ key={this.state.editing ? "editing" : "not-editing"}
254
292
  min={this.props.min}
255
293
  max={this.props.max}
256
294
  minFractionDigits={this.props.minPrecision}
@@ -260,14 +298,14 @@ export class ValueInput extends React.Component<ValueInputProps, ValueInputState
260
298
  suffix={this.props.suffix}
261
299
  showButtons={this.props.showButtons}
262
300
  step={this.props.step}
263
- placeholder={this.props.placeholder}
264
- value={this.state.entryValue}
265
- onChange={(e) => {this.setState({entryValue: e.value, editing : true})} }
301
+ placeholder={this.props.placeholder}
302
+ value={this.state.currentValue}
303
+ onChange={(e) => { this.onBufferValue(e.value) }}
266
304
 
267
305
  buttonLayout="horizontal"
268
- decrementButtonClassName="p-button-danger"
269
- incrementButtonClassName="p-button-success"
270
- incrementButtonIcon="pi pi-plus"
306
+ decrementButtonClassName="p-button-danger"
307
+ incrementButtonClassName="p-button-success"
308
+ incrementButtonIcon="pi pi-plus"
271
309
  decrementButtonIcon="pi pi-minus"
272
310
 
273
311
  locale="en-US"
@@ -280,32 +318,35 @@ export class ValueInput extends React.Component<ValueInputProps, ValueInputState
280
318
  else if (e.key === 'Escape') {
281
319
  this.onResetValue();
282
320
  }
283
- }}
284
- disabled={this.props.disabled}
285
- />
286
- <Button
287
- icon="pi pi-check"
321
+ }}
322
+ disabled={this.props.disabled}
323
+ autoFocus={false}
324
+ />
325
+ <Button
326
+ icon="pi pi-check"
288
327
  disabled={this.props.disabled || !this.state.editing}
289
- className="p-button-success"
290
- onClick={() => this.onAcceptValue()}
328
+ className="p-button-success"
329
+ onClick={() => this.onAcceptValue()}
291
330
  visible={this.state.editing}
292
331
  size="small"
332
+ autoFocus={false}
293
333
  />
294
334
 
295
- <Button
296
- icon="pi pi-times"
335
+ <Button
336
+ icon="pi pi-times"
297
337
  disabled={this.props.disabled || !this.state.editing}
298
- className="p-button-danger"
299
- onClickCapture={()=>this.onResetValue()}
338
+ className="p-button-danger"
339
+ onClickCapture={() => this.onResetValue()}
300
340
  visible={this.state.editing}
301
341
  size="small"
342
+ autoFocus={false}
302
343
  />
303
344
  </div>
304
-
345
+
305
346
  {this.props.description !== undefined &&
306
347
  <small>{this.props.description}</small>
307
348
  }
308
-
349
+
309
350
 
310
351
  </div>
311
352
 
@@ -2,7 +2,7 @@
2
2
  * Copyright (C) 2024 Automated Design Corp. All Rights Reserved.
3
3
  * Created Date: 2024-01-17 11:45:10
4
4
  * -----
5
- * Last Modified: 2024-03-08 10:20:46
5
+ * Last Modified: 2024-03-22 14:25:08
6
6
  * Modified By: ADC
7
7
  * -----
8
8
  *
@@ -135,6 +135,9 @@ export interface EventEmitterContextType {
135
135
  getSubscriptions: (topic?: string) => Record<string, Subscription[]> | Subscription[];
136
136
  }
137
137
 
138
+
139
+ let globalSubscriptionId = 1;
140
+
138
141
  /**
139
142
  * A global context for managing event emission and subscription.
140
143
  *
@@ -324,7 +327,8 @@ export const EventEmitterProvider: React.FC<{ children: ReactNode }> = ({ childr
324
327
 
325
328
  const subscribe = (topic: string, callback: React.Dispatch<any>) : number => {
326
329
 
327
- const subscriptionId = state.nextSubscriptionId;
330
+ globalSubscriptionId += 1;
331
+ const subscriptionId = globalSubscriptionId; // state.nextSubscriptionId;
328
332
 
329
333
  setState(prevState => ({
330
334
  ...prevState,
@@ -332,7 +336,7 @@ export const EventEmitterProvider: React.FC<{ children: ReactNode }> = ({ childr
332
336
  ...prevState.subscriptions,
333
337
  [topic]: [...(prevState.subscriptions[topic] || []), { id: subscriptionId, callback }]
334
338
  },
335
- nextSubscriptionId: prevState.nextSubscriptionId + 1
339
+ nextSubscriptionId: globalSubscriptionId + 1 // prevState.nextSubscriptionId + 1
336
340
  }));
337
341
 
338
342
  return subscriptionId;
@@ -357,7 +361,7 @@ export const EventEmitterProvider: React.FC<{ children: ReactNode }> = ({ childr
357
361
  }
358
362
 
359
363
  return { ...prevState, subscriptions: newSubscriptions };
360
- });
364
+ });
361
365
  };
362
366
 
363
367