@adcops/autocore-react 3.3.85 → 3.3.89

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.
Files changed (99) hide show
  1. package/dist/assets/AxisC.d.ts +4 -0
  2. package/dist/assets/AxisC.d.ts.map +1 -0
  3. package/dist/assets/AxisC.js +1 -0
  4. package/dist/assets/AxisX.js +1 -1
  5. package/dist/assets/AxisY.js +1 -1
  6. package/dist/assets/AxisZ.js +1 -1
  7. package/dist/components/ValueInput.css +9 -12
  8. package/dist/components/ValueInput.d.ts +45 -154
  9. package/dist/components/ValueInput.d.ts.map +1 -1
  10. package/dist/components/ValueInput.js +1 -1
  11. package/dist/components/ams/AmsProvider.d.ts +10 -0
  12. package/dist/components/ams/AmsProvider.d.ts.map +1 -1
  13. package/dist/components/ams/AssetRegistryTable.d.ts.map +1 -1
  14. package/dist/components/ams/AssetRegistryTable.js +1 -1
  15. package/dist/components/forms/FormRow.d.ts +20 -0
  16. package/dist/components/forms/FormRow.d.ts.map +1 -0
  17. package/dist/components/forms/FormRow.js +1 -0
  18. package/dist/components/forms/FormSection.d.ts +19 -0
  19. package/dist/components/forms/FormSection.d.ts.map +1 -0
  20. package/dist/components/forms/FormSection.js +1 -0
  21. package/dist/components/forms/forms.css +89 -0
  22. package/dist/components/forms/index.d.ts +3 -0
  23. package/dist/components/forms/index.d.ts.map +1 -0
  24. package/dist/components/forms/index.js +1 -0
  25. package/dist/components/tis-editor/TisConfigEditor.css +121 -0
  26. package/dist/components/tis-editor/TisConfigEditor.d.ts +28 -0
  27. package/dist/components/tis-editor/TisConfigEditor.d.ts.map +1 -0
  28. package/dist/components/tis-editor/TisConfigEditor.js +1 -0
  29. package/dist/components/tis-editor/editor/AnalysisEditor.d.ts +7 -0
  30. package/dist/components/tis-editor/editor/AnalysisEditor.d.ts.map +1 -0
  31. package/dist/components/tis-editor/editor/AnalysisEditor.js +1 -0
  32. package/dist/components/tis-editor/editor/AssetRefsEditor.d.ts +10 -0
  33. package/dist/components/tis-editor/editor/AssetRefsEditor.d.ts.map +1 -0
  34. package/dist/components/tis-editor/editor/AssetRefsEditor.js +1 -0
  35. package/dist/components/tis-editor/editor/ChartViewDialog.d.ts +16 -0
  36. package/dist/components/tis-editor/editor/ChartViewDialog.d.ts.map +1 -0
  37. package/dist/components/tis-editor/editor/ChartViewDialog.js +1 -0
  38. package/dist/components/tis-editor/editor/FieldArrayEditor.d.ts +8 -0
  39. package/dist/components/tis-editor/editor/FieldArrayEditor.d.ts.map +1 -0
  40. package/dist/components/tis-editor/editor/FieldArrayEditor.js +1 -0
  41. package/dist/components/tis-editor/editor/IdentitySection.d.ts +7 -0
  42. package/dist/components/tis-editor/editor/IdentitySection.d.ts.map +1 -0
  43. package/dist/components/tis-editor/editor/IdentitySection.js +1 -0
  44. package/dist/components/tis-editor/editor/MethodFormEditor.d.ts +20 -0
  45. package/dist/components/tis-editor/editor/MethodFormEditor.d.ts.map +1 -0
  46. package/dist/components/tis-editor/editor/MethodFormEditor.js +1 -0
  47. package/dist/components/tis-editor/editor/RawDataEditor.d.ts +7 -0
  48. package/dist/components/tis-editor/editor/RawDataEditor.d.ts.map +1 -0
  49. package/dist/components/tis-editor/editor/RawDataEditor.js +1 -0
  50. package/dist/components/tis-editor/editor/SaveDiffDialog.d.ts +22 -0
  51. package/dist/components/tis-editor/editor/SaveDiffDialog.d.ts.map +1 -0
  52. package/dist/components/tis-editor/editor/SaveDiffDialog.js +1 -0
  53. package/dist/components/tis-editor/editor/TestFieldDialog.d.ts +11 -0
  54. package/dist/components/tis-editor/editor/TestFieldDialog.d.ts.map +1 -0
  55. package/dist/components/tis-editor/editor/TestFieldDialog.js +1 -0
  56. package/dist/components/tis-editor/editor/ViewsEditor.d.ts +7 -0
  57. package/dist/components/tis-editor/editor/ViewsEditor.d.ts.map +1 -0
  58. package/dist/components/tis-editor/editor/ViewsEditor.js +1 -0
  59. package/dist/components/tis-editor/types.d.ts +78 -0
  60. package/dist/components/tis-editor/types.d.ts.map +1 -0
  61. package/dist/components/tis-editor/types.js +1 -0
  62. package/dist/components/tis-editor/validation.d.ts +20 -0
  63. package/dist/components/tis-editor/validation.d.ts.map +1 -0
  64. package/dist/components/tis-editor/validation.js +1 -0
  65. package/dist/hooks/useAmsAssetTypes.d.ts +23 -0
  66. package/dist/hooks/useAmsAssetTypes.d.ts.map +1 -0
  67. package/dist/hooks/useAmsAssetTypes.js +1 -0
  68. package/dist/hooks/useTisConfig.d.ts +51 -0
  69. package/dist/hooks/useTisConfig.d.ts.map +1 -0
  70. package/dist/hooks/useTisConfig.js +1 -0
  71. package/package.json +9 -3
  72. package/src/assets/AxisC.tsx +38 -0
  73. package/src/assets/AxisX.tsx +32 -32
  74. package/src/assets/AxisY.tsx +34 -34
  75. package/src/assets/AxisZ.tsx +31 -31
  76. package/src/components/ValueInput.css +9 -12
  77. package/src/components/ValueInput.tsx +132 -317
  78. package/src/components/ams/AmsProvider.tsx +10 -0
  79. package/src/components/ams/AssetRegistryTable.tsx +53 -8
  80. package/src/components/forms/FormRow.tsx +37 -0
  81. package/src/components/forms/FormSection.tsx +39 -0
  82. package/src/components/forms/forms.css +89 -0
  83. package/src/components/forms/index.ts +2 -0
  84. package/src/components/tis-editor/TisConfigEditor.css +121 -0
  85. package/src/components/tis-editor/TisConfigEditor.tsx +321 -0
  86. package/src/components/tis-editor/editor/AnalysisEditor.tsx +54 -0
  87. package/src/components/tis-editor/editor/AssetRefsEditor.tsx +187 -0
  88. package/src/components/tis-editor/editor/ChartViewDialog.tsx +170 -0
  89. package/src/components/tis-editor/editor/FieldArrayEditor.tsx +131 -0
  90. package/src/components/tis-editor/editor/IdentitySection.tsx +36 -0
  91. package/src/components/tis-editor/editor/MethodFormEditor.tsx +176 -0
  92. package/src/components/tis-editor/editor/RawDataEditor.tsx +117 -0
  93. package/src/components/tis-editor/editor/SaveDiffDialog.tsx +160 -0
  94. package/src/components/tis-editor/editor/TestFieldDialog.tsx +134 -0
  95. package/src/components/tis-editor/editor/ViewsEditor.tsx +101 -0
  96. package/src/components/tis-editor/types.ts +95 -0
  97. package/src/components/tis-editor/validation.ts +104 -0
  98. package/src/hooks/useAmsAssetTypes.ts +70 -0
  99. 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 number input that encapsulates various features
12
- * such as custom numeric formatting, optional currency formatting, increment and decrement
13
- * buttons, and validation. This component uses the PrimeReact `InputNumber` control
14
- * to provide a rich input experience, including handling both decimal and currency modes,
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
- * Example Usage:
38
- * ```tsx
39
- * <ValueInput
40
- * label="Quantity"
41
- * value={10}
42
- * min={1}
43
- * max={100}
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
- * This example creates a `ValueInput` component for entering quantities, with values ranging from 1 to 100,
55
- * allowing up to 2 decimal places. Increment and decrement buttons are visible, and the new value is logged
56
- * to the console when accepted.
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 { InputNumber, type InputNumberProps } from 'primereact/inputnumber';
63
- import { EventEmitterContext } from "../core/EventEmitterContext";
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 "./ValueInput.css";
44
+ import './ValueInput.css';
67
45
 
68
46
  export type ValueInputSize = 'small' | 'normal' | 'large';
69
47
 
70
- /**
71
- * Properties of the ValueInput component.
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
- * Minimum value for the field.
88
- */
89
- min?: number | undefined;
90
-
91
- /**
92
- * Minimum value for the field.
93
- */
94
- max?: number | undefined;
95
-
96
- /**
97
- * Minimum number of decimal points. The user will not
98
- * be required to type the decimal values, but this minimum
99
- * precision will always be displayed.
100
- * Must be less than or equal to maxPrecision, or
101
- * the component will throw an error.
102
- * @default 0
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 = undefined,
76
+ label,
209
77
  value = null,
210
- min = undefined,
211
- max = undefined,
212
- minPrecision = 0,
213
- maxPrecision = 3,
214
- mode = "decimal",
215
- currency = "USD",
216
- prefix = undefined,
217
- suffix = undefined,
218
- showButtons = false,
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 = undefined,
224
- placeholder = undefined,
225
- onValueChanged = undefined,
88
+ dispatchTopic,
89
+ placeholder,
90
+ onValueChanged,
226
91
  size = 'normal',
227
- ...restProps
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 [currentValue, setCurrentValue] = useState<number | null>(value);
231
- const [bufferedValue, setBufferedValue] = useState<number | null>(value);
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
- setBufferedValue(currentValue);
263
- setEditing(true);
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
- * The user has elected to accept the input value. Validate and store, if valid.
291
- */
292
- const handleAcceptValue = () => {
293
- if (editing && entryValue !== null ) {
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
- if (validateValue(entryValue)) {
296
- setCurrentValue(entryValue);
297
- setEditing(false);
298
- onValueChanged?.(entryValue);
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
- * The user wishes to cancel/reset to the previous value.
314
- */
315
- const handleResetValue = () => {
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
- return label !== undefined && label !== null && label !== '';
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
- { isLabelDefined() &&
156
+ {isLabelDefined && (
332
157
  <span className="p-inputgroup-addon">{label}</span>
333
- }
334
- <InputNumber
335
- {...restProps}
336
- ref={inputRef}
337
- className={clsx('value-input-field', `size-${size}`, restProps.className)}
338
- invalid={invalidValue}
339
- min={min}
340
- max={max}
341
- minFractionDigits={minPrecision}
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={() => handleAcceptValue()}
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
- onClickCapture={() => handleResetValue()}
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;
@@ -55,6 +55,16 @@ export interface AmsRole {
55
55
  * feeding NI bridge channel calibration). Empty for purely
56
56
  * test-method-driven roles. */
57
57
  used_by_modules: string[];
58
+ /** Optional per-field seed values declared on the asset_ref's
59
+ * `defaults` map. AIS uses these to pre-fill nameplate inputs when
60
+ * the operator creates a new asset for this role — the operator
61
+ * confirms or edits, the values are never enforced. Absent when no
62
+ * asset_ref declared defaults (the common case, since built-in
63
+ * load_cell etc. didn't support defaults before the feature
64
+ * landed). Keys are field names from the asset_type's schema;
65
+ * values are untyped JSON (numbers, strings, booleans) matching
66
+ * the field's declared `type`. */
67
+ defaults?: Record<string, any>;
58
68
  }
59
69
  export type AmsRoleRegistry = { [assetType: string]: AmsRole[] };
60
70
 
@@ -111,6 +111,32 @@ function subLocationsFor(schemas: any, assetType: string): SubLocationsSchema |
111
111
  return sl as SubLocationsSchema;
112
112
  }
113
113
 
114
+ /** Build a fresh `customFields` seed from a role's `defaults` map,
115
+ * narrowed to fields the asset_type schema actually declares. Server
116
+ * validation rejects unknown default keys at project load, so in
117
+ * normal operation every key will match a declared field; the
118
+ * narrowing here just protects against schema/defaults drift while a
119
+ * project is being edited.
120
+ *
121
+ * Returns string-typed values because the dialog's inputs are text-
122
+ * based; the existing `coerceField` helper converts back on submit.
123
+ * Empty / missing defaults are skipped (rather than emitting `""`) so
124
+ * required-field gating still fires for fields the role didn't seed. */
125
+ function seedCustomFromRoleDefaults(
126
+ role: AmsRole | undefined,
127
+ fields: SchemaField[],
128
+ ): Record<string, string> {
129
+ const out: Record<string, string> = {};
130
+ if (!role || !role.defaults) return out;
131
+ const declared = new Set(fields.map(f => f.name));
132
+ for (const [k, v] of Object.entries(role.defaults)) {
133
+ if (!declared.has(k)) continue;
134
+ if (v === undefined || v === null) continue;
135
+ out[k] = String(v);
136
+ }
137
+ return out;
138
+ }
139
+
114
140
  /** Coerce a per-cell string from the matrix input back to its declared
115
141
  * type. Numeric strings → JSON numbers; booleans → bool; everything
116
142
  * else stays as a string. Matches the top-level fields coercion. */
@@ -142,6 +168,8 @@ export const AssetRegistryTable: React.FC = () => {
142
168
  // when an operator clicks Register on one of its rows. Catch it
143
169
  // here and open the Add dialog pre-populated with the asset_type
144
170
  // and role — the operator just fills in the nameplate values.
171
+ // If the matching role declares `defaults`, those seed the
172
+ // nameplate inputs too (same path as onRoleChange).
145
173
  useEffect(() => {
146
174
  const handler = (e: Event) => {
147
175
  const detail = (e as CustomEvent).detail as
@@ -149,17 +177,20 @@ export const AssetRegistryTable: React.FC = () => {
149
177
  const assetType = detail?.assetType ?? '';
150
178
  const location = detail?.location ?? '';
151
179
  if (!assetType) return;
180
+ const role = (roles[assetType] ?? []).find(r => r.location === location);
181
+ const declaredFields = fieldsFor(schemas, assetType);
152
182
  setAddState({
153
183
  ...EMPTY_ADD,
154
184
  open: true,
155
185
  assetType,
156
186
  roleSelection: location,
157
187
  location,
188
+ customFields: seedCustomFromRoleDefaults(role, declaredFields),
158
189
  });
159
190
  };
160
191
  window.addEventListener('ams:prefill-add', handler);
161
192
  return () => window.removeEventListener('ams:prefill-add', handler);
162
- }, []);
193
+ }, [roles, schemas]);
163
194
 
164
195
  const typeOptions = useMemo(
165
196
  () => Object.keys(schemas).map(k => ({ label: schemas[k]?.label ?? k, value: k })),
@@ -285,15 +316,20 @@ export const AssetRegistryTable: React.FC = () => {
285
316
  * hardware), or leave it empty so they make an explicit choice
286
317
  * when there are multiple. Hide the field entirely when none.
287
318
  * Also resets the nameplate-field map — fields are type-specific
288
- * and the previous type's inputs would not be relevant. */
319
+ * and the previous type's inputs would not be relevant. When the
320
+ * auto-selected role declares `defaults`, seed those into the
321
+ * nameplate inputs so the operator only has to confirm or edit. */
289
322
  const onAssetTypeChange = (newType: string) => {
290
323
  const list = roles[newType] ?? [];
291
- const base = list.length === 1
292
- ? { roleSelection: list[0].location, location: list[0].location }
324
+ const autoRole = list.length === 1 ? list[0] : undefined;
325
+ const base = autoRole
326
+ ? { roleSelection: autoRole.location, location: autoRole.location }
293
327
  : { roleSelection: '', location: '' };
328
+ const newFields = fieldsFor(schemas, newType);
294
329
  setAddState(s => ({
295
330
  ...s, assetType: newType, ...base,
296
- customFields: {}, subLocationFields: {},
331
+ customFields: seedCustomFromRoleDefaults(autoRole, newFields),
332
+ subLocationFields: {},
297
333
  }));
298
334
  };
299
335
 
@@ -315,13 +351,22 @@ export const AssetRegistryTable: React.FC = () => {
315
351
  );
316
352
 
317
353
  /** Role dropdown change handler. ROLE_OTHER puts us into free-form
318
- * mode where the operator types into a text field. */
354
+ * mode where the operator types into a text field. When picking a
355
+ * known role with declared `defaults`, seed the nameplate inputs
356
+ * from those values so the operator only has to confirm or edit.
357
+ * Switching role is treated as an explicit reseed; values typed
358
+ * into the previous role's inputs are replaced — switching role
359
+ * is a discrete intent, not a continuous edit. */
319
360
  const onRoleChange = (value: string) => {
320
361
  if (value === ROLE_OTHER) {
321
362
  setAddState(s => ({ ...s, roleSelection: ROLE_OTHER, location: '' }));
322
- } else {
323
- setAddState(s => ({ ...s, roleSelection: value, location: value }));
363
+ return;
324
364
  }
365
+ const role = rolesForType.find(r => r.location === value);
366
+ setAddState(s => ({
367
+ ...s, roleSelection: value, location: value,
368
+ customFields: seedCustomFromRoleDefaults(role, fieldsForType),
369
+ }));
325
370
  };
326
371
 
327
372
  /** Disable Create until the operator has picked a role (or supplied