@adcops/autocore-react 3.3.84 → 3.3.87
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/ValueInput.css +9 -12
- package/dist/components/ValueInput.d.ts +45 -154
- package/dist/components/ValueInput.d.ts.map +1 -1
- package/dist/components/ValueInput.js +1 -1
- package/dist/components/ams/AssetEditDialog.d.ts.map +1 -1
- package/dist/components/ams/AssetEditDialog.js +1 -1
- package/dist/components/forms/FormRow.d.ts +20 -0
- package/dist/components/forms/FormRow.d.ts.map +1 -0
- package/dist/components/forms/FormRow.js +1 -0
- package/dist/components/forms/FormSection.d.ts +19 -0
- package/dist/components/forms/FormSection.d.ts.map +1 -0
- package/dist/components/forms/FormSection.js +1 -0
- package/dist/components/forms/forms.css +89 -0
- package/dist/components/forms/index.d.ts +3 -0
- package/dist/components/forms/index.d.ts.map +1 -0
- package/dist/components/forms/index.js +1 -0
- package/dist/components/tis-editor/TisConfigEditor.css +121 -0
- package/dist/components/tis-editor/TisConfigEditor.d.ts +28 -0
- package/dist/components/tis-editor/TisConfigEditor.d.ts.map +1 -0
- package/dist/components/tis-editor/TisConfigEditor.js +1 -0
- package/dist/components/tis-editor/editor/AnalysisEditor.d.ts +7 -0
- package/dist/components/tis-editor/editor/AnalysisEditor.d.ts.map +1 -0
- package/dist/components/tis-editor/editor/AnalysisEditor.js +1 -0
- package/dist/components/tis-editor/editor/AssetRefsEditor.d.ts +10 -0
- package/dist/components/tis-editor/editor/AssetRefsEditor.d.ts.map +1 -0
- package/dist/components/tis-editor/editor/AssetRefsEditor.js +1 -0
- package/dist/components/tis-editor/editor/ChartViewDialog.d.ts +16 -0
- package/dist/components/tis-editor/editor/ChartViewDialog.d.ts.map +1 -0
- package/dist/components/tis-editor/editor/ChartViewDialog.js +1 -0
- package/dist/components/tis-editor/editor/FieldArrayEditor.d.ts +8 -0
- package/dist/components/tis-editor/editor/FieldArrayEditor.d.ts.map +1 -0
- package/dist/components/tis-editor/editor/FieldArrayEditor.js +1 -0
- package/dist/components/tis-editor/editor/IdentitySection.d.ts +7 -0
- package/dist/components/tis-editor/editor/IdentitySection.d.ts.map +1 -0
- package/dist/components/tis-editor/editor/IdentitySection.js +1 -0
- package/dist/components/tis-editor/editor/MethodFormEditor.d.ts +20 -0
- package/dist/components/tis-editor/editor/MethodFormEditor.d.ts.map +1 -0
- package/dist/components/tis-editor/editor/MethodFormEditor.js +1 -0
- package/dist/components/tis-editor/editor/RawDataEditor.d.ts +7 -0
- package/dist/components/tis-editor/editor/RawDataEditor.d.ts.map +1 -0
- package/dist/components/tis-editor/editor/RawDataEditor.js +1 -0
- package/dist/components/tis-editor/editor/SaveDiffDialog.d.ts +22 -0
- package/dist/components/tis-editor/editor/SaveDiffDialog.d.ts.map +1 -0
- package/dist/components/tis-editor/editor/SaveDiffDialog.js +1 -0
- package/dist/components/tis-editor/editor/TestFieldDialog.d.ts +11 -0
- package/dist/components/tis-editor/editor/TestFieldDialog.d.ts.map +1 -0
- package/dist/components/tis-editor/editor/TestFieldDialog.js +1 -0
- package/dist/components/tis-editor/editor/ViewsEditor.d.ts +7 -0
- package/dist/components/tis-editor/editor/ViewsEditor.d.ts.map +1 -0
- package/dist/components/tis-editor/editor/ViewsEditor.js +1 -0
- package/dist/components/tis-editor/types.d.ts +78 -0
- package/dist/components/tis-editor/types.d.ts.map +1 -0
- package/dist/components/tis-editor/types.js +1 -0
- package/dist/components/tis-editor/validation.d.ts +20 -0
- package/dist/components/tis-editor/validation.d.ts.map +1 -0
- package/dist/components/tis-editor/validation.js +1 -0
- package/dist/hooks/useAmsAssetTypes.d.ts +23 -0
- package/dist/hooks/useAmsAssetTypes.d.ts.map +1 -0
- package/dist/hooks/useAmsAssetTypes.js +1 -0
- package/dist/hooks/useTisConfig.d.ts +51 -0
- package/dist/hooks/useTisConfig.d.ts.map +1 -0
- package/dist/hooks/useTisConfig.js +1 -0
- package/package.json +9 -3
- package/src/components/ValueInput.css +9 -12
- package/src/components/ValueInput.tsx +132 -317
- package/src/components/ams/AssetEditDialog.tsx +357 -20
- package/src/components/forms/FormRow.tsx +37 -0
- package/src/components/forms/FormSection.tsx +39 -0
- package/src/components/forms/forms.css +89 -0
- package/src/components/forms/index.ts +2 -0
- package/src/components/tis-editor/TisConfigEditor.css +121 -0
- package/src/components/tis-editor/TisConfigEditor.tsx +321 -0
- package/src/components/tis-editor/editor/AnalysisEditor.tsx +54 -0
- package/src/components/tis-editor/editor/AssetRefsEditor.tsx +187 -0
- package/src/components/tis-editor/editor/ChartViewDialog.tsx +170 -0
- package/src/components/tis-editor/editor/FieldArrayEditor.tsx +131 -0
- package/src/components/tis-editor/editor/IdentitySection.tsx +36 -0
- package/src/components/tis-editor/editor/MethodFormEditor.tsx +176 -0
- package/src/components/tis-editor/editor/RawDataEditor.tsx +117 -0
- package/src/components/tis-editor/editor/SaveDiffDialog.tsx +160 -0
- package/src/components/tis-editor/editor/TestFieldDialog.tsx +134 -0
- package/src/components/tis-editor/editor/ViewsEditor.tsx +101 -0
- package/src/components/tis-editor/types.ts +95 -0
- package/src/components/tis-editor/validation.ts +104 -0
- package/src/hooks/useAmsAssetTypes.ts +70 -0
- package/src/hooks/useTisConfig.ts +164 -0
|
@@ -2,387 +2,202 @@
|
|
|
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: 2025-09-05 14:50:52
|
|
6
|
-
* -----
|
|
7
|
-
*
|
|
8
5
|
*/
|
|
9
6
|
|
|
10
7
|
/** @file
|
|
11
|
-
* `ValueInput` is a React component for
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* with configurable precision and optional prefix/suffix text.
|
|
16
|
-
*
|
|
17
|
-
* Properties:
|
|
18
|
-
* - `label`: Label text displayed on the input field.
|
|
19
|
-
* - `value`: Current numeric value of the input field.
|
|
20
|
-
* - `min`: Minimum allowable value.
|
|
21
|
-
* - `max`: Maximum allowable value.
|
|
22
|
-
* - `minPrecision`: Minimum number of decimal places to display.
|
|
23
|
-
* - `maxPrecision`: Maximum number of decimal places allowed.
|
|
24
|
-
* - `mode`: Determines whether the input is treated as a plain decimal or currency. Defaults to "decimal".
|
|
25
|
-
* - `currency`: ISO 4217 currency code for formatting the value as currency.
|
|
26
|
-
* - `prefix`: String to display before the value.
|
|
27
|
-
* - `suffix`: String to display after the value.
|
|
28
|
-
* - `showButtons`: Whether to display increment and decrement buttons.
|
|
29
|
-
* - `step`: The amount by which the value should be incremented or decremented.
|
|
30
|
-
* - `locale`: Locale code for formatting the value.
|
|
31
|
-
* - `description`: Additional descriptive text to display below the input.
|
|
32
|
-
* - `disabled`: Whether the input is disabled.
|
|
33
|
-
* - `dispatchTopic`: Event topic to dispatch on value change.
|
|
34
|
-
* - `placeholder`: Placeholder text when the input is empty.
|
|
35
|
-
* - `onValueChanged`: Callback function that is called when the user accepts a new value.
|
|
8
|
+
* `ValueInput` is a React component for numeric entry built on top of
|
|
9
|
+
* `react-number-format`. It wraps a PrimeReact `InputText` so the field
|
|
10
|
+
* inherits the standard inputgroup styling and integrates with the
|
|
11
|
+
* accept/cancel button row below.
|
|
36
12
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* minPrecision={0}
|
|
45
|
-
* maxPrecision={2}
|
|
46
|
-
* mode="decimal"
|
|
47
|
-
* showButtons={true}
|
|
48
|
-
* step={1}
|
|
49
|
-
* locale="en-US"
|
|
50
|
-
* onValueChanged={(newValue) => console.log("New Value:", newValue)}
|
|
51
|
-
* />
|
|
52
|
-
* ```
|
|
13
|
+
* Why react-number-format and not PrimeReact's `InputNumber`:
|
|
14
|
+
* - `InputNumber` handles the `-` key via `onKeyDown` (sign-toggle action).
|
|
15
|
+
* On Wayland on-screen keyboards (Ubuntu 24 virtual keyboard) keydown is
|
|
16
|
+
* not always delivered, so negative entry was broken on touch HMIs.
|
|
17
|
+
* - `NumericFormat` treats the input as text and validates it against a
|
|
18
|
+
* numeric format. The user can simply type `-`, `2`, `0`, `0` to get
|
|
19
|
+
* `-200` on every input device.
|
|
53
20
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
21
|
+
* Properties:
|
|
22
|
+
* - `label`: Optional label addon shown before the field.
|
|
23
|
+
* - `value`: Externally controlled value.
|
|
24
|
+
* - `min` / `max`: Range validation, applied on accept.
|
|
25
|
+
* - `minPrecision` / `maxPrecision`: Decimal precision. (Aliases
|
|
26
|
+
* `minFractionDigits` / `maxFractionDigits` are also accepted for
|
|
27
|
+
* compatibility with older call sites.)
|
|
28
|
+
* - `prefix` / `suffix`: Inline string before/after the number.
|
|
29
|
+
* - `description`: Small advisory text below the field.
|
|
30
|
+
* - `disabled`: Disable all interaction.
|
|
31
|
+
* - `dispatchTopic`: Topic dispatched on accept via the EventEmitter context.
|
|
32
|
+
* - `placeholder`: Placeholder when empty.
|
|
33
|
+
* - `onValueChanged`: Called with the new numeric value when the user accepts.
|
|
34
|
+
* - `size`: Field width — small (30mm), normal (55mm), large (70mm).
|
|
57
35
|
*/
|
|
58
36
|
|
|
59
|
-
|
|
60
|
-
import React, { useState, useRef, useEffect, useContext } from 'react';
|
|
37
|
+
import React, { useState, useEffect, useContext } from 'react';
|
|
61
38
|
import clsx from 'clsx';
|
|
62
|
-
import {
|
|
63
|
-
import {
|
|
39
|
+
import { NumericFormat, type NumberFormatValues, type SourceInfo } from 'react-number-format';
|
|
40
|
+
import { InputText } from 'primereact/inputtext';
|
|
64
41
|
import { Button } from 'primereact/button';
|
|
42
|
+
import { EventEmitterContext } from '../core/EventEmitterContext';
|
|
65
43
|
|
|
66
|
-
import
|
|
44
|
+
import './ValueInput.css';
|
|
67
45
|
|
|
68
46
|
export type ValueInputSize = 'small' | 'normal' | 'large';
|
|
69
47
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*/
|
|
73
|
-
interface ValueInputProps extends Omit<InputNumberProps, 'value' | 'size'> {
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* The label for the ValueInput field.
|
|
77
|
-
*/
|
|
78
|
-
label: React.ReactNode | undefined | null;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* The value for the field.
|
|
83
|
-
*/
|
|
48
|
+
export interface ValueInputProps {
|
|
49
|
+
label?: React.ReactNode | null;
|
|
84
50
|
value: number | null;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
minPrecision?: number | undefined;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Maximum number of decimal points.
|
|
109
|
-
* Set to 0 for integer-only. Must be greater or equal to than minPrecision, or
|
|
110
|
-
* the component will throw an error.
|
|
111
|
-
* @default 3
|
|
112
|
-
*/
|
|
113
|
-
maxPrecision?: number | undefined;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Defines the behavior of the component.
|
|
118
|
-
* If set to "currency", then you need to specify the
|
|
119
|
-
* currency type using the currency property.
|
|
120
|
-
* @default "decimal"
|
|
121
|
-
*/
|
|
122
|
-
mode?: "currency" | "decimal" | undefined;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* The currency to use in currency formatting. Possible values are the
|
|
127
|
-
* [ISO 4217 currency codes](https://www.six-group.com/en/products-services/financial-information/data-standards.html#scrollTo=maintenance-agency),
|
|
128
|
-
* such as "USD" for the US dollar, "EUR" for the euro, or "CNY" for the Chinese RMB.
|
|
129
|
-
* If the mode is "currency", the currency property must be provided.
|
|
130
|
-
*
|
|
131
|
-
* @default "USD"
|
|
132
|
-
*/
|
|
133
|
-
currency?: string;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* An optional prefix before the value of the field.
|
|
137
|
-
* Unlike the TextInput control, this prefix is internal to the field.
|
|
138
|
-
*/
|
|
139
|
-
prefix?: string | undefined;
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* An optional suffix after the value of the field.
|
|
143
|
-
* Unlike the TextInput control, this prefix is internal to the field.
|
|
144
|
-
*/
|
|
145
|
-
suffix?: string | undefined;
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Set true to display buttons to increment/decrement the value.
|
|
149
|
-
* Use the step property to adjust the amount that the value will change.
|
|
150
|
-
*
|
|
151
|
-
* @default false
|
|
152
|
-
*/
|
|
153
|
-
showButtons?: boolean;
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* The amount clicking an increment/decrement buttion will change the value.
|
|
157
|
-
*/
|
|
158
|
-
step?: number | undefined;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Locale to be used in formatting. Changes how the numbers/separators are displayed
|
|
163
|
-
* for international users. The typical locale codes are used.
|
|
164
|
-
*
|
|
165
|
-
* @default "en-US"
|
|
166
|
-
*/
|
|
167
|
-
locale?: string | undefined;
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* A small, advisory text below the field.
|
|
171
|
-
*/
|
|
172
|
-
description?: React.ReactNode | undefined;
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* If true, all functions of the field will be disabled.
|
|
176
|
-
*/
|
|
177
|
-
disabled?: boolean | undefined;
|
|
178
|
-
|
|
179
|
-
/** Topic on which the value will be dispatched through the user interfave on successful data entry. */
|
|
180
|
-
dispatchTopic?: string | undefined;
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Placeholder string to display if the value is empty.
|
|
184
|
-
*/
|
|
185
|
-
placeholder?: string | undefined;
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* The user has accepted a new value.
|
|
189
|
-
* @param newValue New value accepted by the user.
|
|
190
|
-
*/
|
|
51
|
+
min?: number;
|
|
52
|
+
max?: number;
|
|
53
|
+
|
|
54
|
+
/** Minimum decimal places displayed. @default 0 */
|
|
55
|
+
minPrecision?: number;
|
|
56
|
+
/** Maximum decimal places allowed. @default 3 */
|
|
57
|
+
maxPrecision?: number;
|
|
58
|
+
|
|
59
|
+
/** Alias for `minPrecision` (compat with older call sites). */
|
|
60
|
+
minFractionDigits?: number;
|
|
61
|
+
/** Alias for `maxPrecision` (compat with older call sites). */
|
|
62
|
+
maxFractionDigits?: number;
|
|
63
|
+
|
|
64
|
+
prefix?: string;
|
|
65
|
+
suffix?: string;
|
|
66
|
+
description?: React.ReactNode;
|
|
67
|
+
disabled?: boolean;
|
|
68
|
+
dispatchTopic?: string;
|
|
69
|
+
placeholder?: string;
|
|
191
70
|
onValueChanged?(newValue: number): void;
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Width of the InputNumber field. The label addon and accept/cancel buttons
|
|
195
|
-
* keep their natural size; only the numeric input is constrained.
|
|
196
|
-
* Widths: small=30mm, normal=55mm, large=70mm.
|
|
197
|
-
* @default 'normal'
|
|
198
|
-
*/
|
|
199
71
|
size?: ValueInputSize;
|
|
72
|
+
className?: string;
|
|
200
73
|
}
|
|
201
74
|
|
|
202
|
-
/**
|
|
203
|
-
* A convenient field with all the usual features of inputing numbers.
|
|
204
|
-
* Wraps the common features of use of a InputNumber, p-inputgroup, some icon buttons,
|
|
205
|
-
* accepting and rejecting values and keyboard management.
|
|
206
|
-
*/
|
|
207
75
|
export const ValueInput: React.FC<ValueInputProps> = ({
|
|
208
|
-
label
|
|
76
|
+
label,
|
|
209
77
|
value = null,
|
|
210
|
-
min
|
|
211
|
-
max
|
|
212
|
-
minPrecision
|
|
213
|
-
maxPrecision
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
prefix
|
|
217
|
-
suffix
|
|
218
|
-
|
|
219
|
-
step = 1,
|
|
220
|
-
locale = "en-US",
|
|
221
|
-
description = undefined,
|
|
78
|
+
min,
|
|
79
|
+
max,
|
|
80
|
+
minPrecision,
|
|
81
|
+
maxPrecision,
|
|
82
|
+
minFractionDigits,
|
|
83
|
+
maxFractionDigits,
|
|
84
|
+
prefix,
|
|
85
|
+
suffix,
|
|
86
|
+
description,
|
|
222
87
|
disabled = false,
|
|
223
|
-
dispatchTopic
|
|
224
|
-
placeholder
|
|
225
|
-
onValueChanged
|
|
88
|
+
dispatchTopic,
|
|
89
|
+
placeholder,
|
|
90
|
+
onValueChanged,
|
|
226
91
|
size = 'normal',
|
|
227
|
-
|
|
92
|
+
className,
|
|
228
93
|
}) => {
|
|
94
|
+
const minDecimals = minPrecision ?? minFractionDigits ?? 0;
|
|
95
|
+
const maxDecimals = maxPrecision ?? maxFractionDigits ?? 3;
|
|
96
|
+
|
|
229
97
|
const [entryValue, setEntryValue] = useState<number | null>(value);
|
|
230
|
-
const [
|
|
231
|
-
const [
|
|
232
|
-
const [editing, setEditing] = useState<boolean>(false);
|
|
233
|
-
const [invalidValue, setInvalidValue] = useState<boolean>(false);
|
|
234
|
-
const inputRef = useRef<InputNumber>(null);
|
|
98
|
+
const [editing, setEditing] = useState(false);
|
|
99
|
+
const [invalid, setInvalid] = useState(false);
|
|
235
100
|
const eventEmitter = useContext(EventEmitterContext);
|
|
236
101
|
|
|
102
|
+
// Sync external value into entryValue when not editing. While editing,
|
|
103
|
+
// ignore prop updates so we don't yank the rug out from under the user.
|
|
237
104
|
useEffect(() => {
|
|
238
|
-
|
|
239
|
-
if (bufferedValue !== null) {
|
|
240
|
-
setCurrentValue(bufferedValue);
|
|
241
|
-
setBufferedValue(null);
|
|
242
|
-
setInvalidValue(false);
|
|
243
|
-
}
|
|
244
|
-
else if (value !== currentValue) {
|
|
245
|
-
setCurrentValue(value);
|
|
246
|
-
setEntryValue(value);
|
|
247
|
-
setEditing(false);
|
|
248
|
-
setInvalidValue(false);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}, [value, currentValue]);
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Buffers the original value, if editing just starting,
|
|
256
|
-
* and updates the entry value.
|
|
257
|
-
*
|
|
258
|
-
* @param val New value being entered.
|
|
259
|
-
*/
|
|
260
|
-
const handleBufferValue = (val: number | null) => {
|
|
261
105
|
if (!editing) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
setEntryValue(val);
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Returns true if the new value falls within specified parameters.
|
|
270
|
-
* @param val The new value.
|
|
271
|
-
* @returns
|
|
272
|
-
*/
|
|
273
|
-
const validateValue = (val : number) : boolean => {
|
|
274
|
-
|
|
275
|
-
if (max !== undefined) {
|
|
276
|
-
if (val > max) {
|
|
277
|
-
return false;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
if (min !== undefined) {
|
|
281
|
-
if (val < min) {
|
|
282
|
-
return false;
|
|
283
|
-
}
|
|
106
|
+
setEntryValue(value);
|
|
107
|
+
setInvalid(false);
|
|
284
108
|
}
|
|
109
|
+
}, [value, editing]);
|
|
285
110
|
|
|
111
|
+
const validate = (val: number | null): boolean => {
|
|
112
|
+
if (val === null || Number.isNaN(val)) return false;
|
|
113
|
+
if (min !== undefined && val < min) return false;
|
|
114
|
+
if (max !== undefined && val > max) return false;
|
|
286
115
|
return true;
|
|
287
|
-
}
|
|
116
|
+
};
|
|
288
117
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (
|
|
118
|
+
const handleChange = (values: NumberFormatValues, sourceInfo: SourceInfo) => {
|
|
119
|
+
// NumericFormat fires onValueChange both from user interaction and from
|
|
120
|
+
// prop-driven re-renders. Only treat user interaction as editing —
|
|
121
|
+
// otherwise external value changes would falsely flip editing=true.
|
|
122
|
+
if (sourceInfo.source !== 'event') return;
|
|
294
123
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
setInvalidValue(false);
|
|
300
|
-
|
|
301
|
-
if (dispatchTopic) {
|
|
302
|
-
eventEmitter.dispatch({ topic: dispatchTopic, payload: entryValue });
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
setInvalidValue(true);
|
|
307
|
-
}
|
|
124
|
+
setEntryValue(values.floatValue ?? null);
|
|
125
|
+
setEditing(true);
|
|
126
|
+
setInvalid(false);
|
|
127
|
+
};
|
|
308
128
|
|
|
129
|
+
const handleAccept = () => {
|
|
130
|
+
if (!editing) return;
|
|
131
|
+
if (!validate(entryValue)) {
|
|
132
|
+
setInvalid(true);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const v = entryValue as number;
|
|
136
|
+
onValueChanged?.(v);
|
|
137
|
+
if (dispatchTopic) {
|
|
138
|
+
eventEmitter.dispatch({ topic: dispatchTopic, payload: v });
|
|
309
139
|
}
|
|
140
|
+
setEditing(false);
|
|
141
|
+
setInvalid(false);
|
|
310
142
|
};
|
|
311
143
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
if (editing) {
|
|
317
|
-
setEntryValue(null);
|
|
318
|
-
setCurrentValue(null);
|
|
319
|
-
setEditing(false);
|
|
320
|
-
setInvalidValue(false);
|
|
321
|
-
}
|
|
144
|
+
const handleCancel = () => {
|
|
145
|
+
setEntryValue(value);
|
|
146
|
+
setEditing(false);
|
|
147
|
+
setInvalid(false);
|
|
322
148
|
};
|
|
323
149
|
|
|
324
|
-
const isLabelDefined =
|
|
325
|
-
|
|
326
|
-
}
|
|
150
|
+
const isLabelDefined = label !== undefined && label !== null && label !== '';
|
|
151
|
+
const allowNegative = min === undefined || min < 0;
|
|
327
152
|
|
|
328
153
|
return (
|
|
329
154
|
<div>
|
|
330
155
|
<div className="p-inputgroup">
|
|
331
|
-
{
|
|
156
|
+
{isLabelDefined && (
|
|
332
157
|
<span className="p-inputgroup-addon">{label}</span>
|
|
333
|
-
}
|
|
334
|
-
<
|
|
335
|
-
{
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
maxFractionDigits={maxPrecision}
|
|
343
|
-
mode={mode}
|
|
158
|
+
)}
|
|
159
|
+
<NumericFormat
|
|
160
|
+
value={entryValue ?? ''}
|
|
161
|
+
onValueChange={handleChange}
|
|
162
|
+
decimalScale={maxDecimals}
|
|
163
|
+
fixedDecimalScale={minDecimals > 0 && !editing}
|
|
164
|
+
allowNegative={allowNegative}
|
|
165
|
+
decimalSeparator="."
|
|
166
|
+
thousandSeparator={false}
|
|
344
167
|
prefix={prefix}
|
|
345
168
|
suffix={suffix}
|
|
346
|
-
showButtons={showButtons}
|
|
347
|
-
step={step}
|
|
348
169
|
placeholder={placeholder}
|
|
349
|
-
value={currentValue}
|
|
350
|
-
onChange={(e) => handleBufferValue(e.value)}
|
|
351
|
-
locale={locale}
|
|
352
|
-
currency={currency}
|
|
353
|
-
onKeyDown={(e) => {
|
|
354
|
-
if (e.key === 'Enter') {
|
|
355
|
-
handleAcceptValue();
|
|
356
|
-
} else if (e.key === 'Escape') {
|
|
357
|
-
handleResetValue();
|
|
358
|
-
}
|
|
359
|
-
}}
|
|
360
170
|
disabled={disabled}
|
|
171
|
+
customInput={InputText}
|
|
172
|
+
className={clsx(
|
|
173
|
+
'value-input-field',
|
|
174
|
+
`size-${size}`,
|
|
175
|
+
className,
|
|
176
|
+
)}
|
|
177
|
+
invalid={invalid || undefined}
|
|
178
|
+
onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
179
|
+
if (e.key === 'Enter') handleAccept();
|
|
180
|
+
else if (e.key === 'Escape') handleCancel();
|
|
181
|
+
}}
|
|
361
182
|
/>
|
|
362
|
-
|
|
363
183
|
<Button
|
|
364
184
|
icon="pi pi-check"
|
|
365
185
|
disabled={disabled || !editing}
|
|
366
186
|
className="p-button-success"
|
|
367
|
-
onClick={
|
|
368
|
-
visible={true}
|
|
187
|
+
onClick={handleAccept}
|
|
369
188
|
autoFocus={false}
|
|
370
189
|
/>
|
|
371
|
-
|
|
372
190
|
<Button
|
|
373
191
|
icon="pi pi-times"
|
|
374
192
|
disabled={disabled || !editing}
|
|
375
193
|
className="p-button-danger"
|
|
376
|
-
|
|
377
|
-
visible={true}
|
|
194
|
+
onClick={handleCancel}
|
|
378
195
|
autoFocus={false}
|
|
379
196
|
/>
|
|
380
|
-
|
|
381
|
-
|
|
382
197
|
</div>
|
|
383
198
|
{description && <small>{description}</small>}
|
|
384
199
|
</div>
|
|
385
200
|
);
|
|
386
201
|
};
|
|
387
202
|
|
|
388
|
-
export default ValueInput;
|
|
203
|
+
export default ValueInput;
|