@vaadin/field-highlighter 25.3.0-alpha11 → 25.3.0-alpha12
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/field-highlighter",
|
|
3
|
-
"version": "25.3.0-
|
|
3
|
+
"version": "25.3.0-alpha12",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -32,33 +32,33 @@
|
|
|
32
32
|
"field"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@vaadin/a11y-base": "25.3.0-
|
|
36
|
-
"@vaadin/component-base": "25.3.0-
|
|
37
|
-
"@vaadin/overlay": "25.3.0-
|
|
38
|
-
"@vaadin/popover": "25.3.0-
|
|
39
|
-
"@vaadin/tooltip": "25.3.0-
|
|
40
|
-
"@vaadin/vaadin-themable-mixin": "25.3.0-
|
|
35
|
+
"@vaadin/a11y-base": "25.3.0-alpha12",
|
|
36
|
+
"@vaadin/component-base": "25.3.0-alpha12",
|
|
37
|
+
"@vaadin/overlay": "25.3.0-alpha12",
|
|
38
|
+
"@vaadin/popover": "25.3.0-alpha12",
|
|
39
|
+
"@vaadin/tooltip": "25.3.0-alpha12",
|
|
40
|
+
"@vaadin/vaadin-themable-mixin": "25.3.0-alpha12",
|
|
41
41
|
"lit": "^3.0.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@vaadin/aura": "25.3.0-
|
|
45
|
-
"@vaadin/chai-plugins": "25.3.0-
|
|
46
|
-
"@vaadin/checkbox": "25.3.0-
|
|
47
|
-
"@vaadin/checkbox-group": "25.3.0-
|
|
48
|
-
"@vaadin/custom-field": "25.3.0-
|
|
49
|
-
"@vaadin/date-picker": "25.3.0-
|
|
50
|
-
"@vaadin/date-time-picker": "25.3.0-
|
|
51
|
-
"@vaadin/item": "25.3.0-
|
|
52
|
-
"@vaadin/list-box": "25.3.0-
|
|
53
|
-
"@vaadin/radio-group": "25.3.0-
|
|
54
|
-
"@vaadin/select": "25.3.0-
|
|
55
|
-
"@vaadin/test-runner-commands": "25.3.0-
|
|
44
|
+
"@vaadin/aura": "25.3.0-alpha12",
|
|
45
|
+
"@vaadin/chai-plugins": "25.3.0-alpha12",
|
|
46
|
+
"@vaadin/checkbox": "25.3.0-alpha12",
|
|
47
|
+
"@vaadin/checkbox-group": "25.3.0-alpha12",
|
|
48
|
+
"@vaadin/custom-field": "25.3.0-alpha12",
|
|
49
|
+
"@vaadin/date-picker": "25.3.0-alpha12",
|
|
50
|
+
"@vaadin/date-time-picker": "25.3.0-alpha12",
|
|
51
|
+
"@vaadin/item": "25.3.0-alpha12",
|
|
52
|
+
"@vaadin/list-box": "25.3.0-alpha12",
|
|
53
|
+
"@vaadin/radio-group": "25.3.0-alpha12",
|
|
54
|
+
"@vaadin/select": "25.3.0-alpha12",
|
|
55
|
+
"@vaadin/test-runner-commands": "25.3.0-alpha12",
|
|
56
56
|
"@vaadin/testing-helpers": "^2.0.0",
|
|
57
|
-
"@vaadin/text-area": "25.3.0-
|
|
58
|
-
"@vaadin/text-field": "25.3.0-
|
|
59
|
-
"@vaadin/time-picker": "25.3.0-
|
|
60
|
-
"@vaadin/vaadin-lumo-styles": "25.3.0-
|
|
57
|
+
"@vaadin/text-area": "25.3.0-alpha12",
|
|
58
|
+
"@vaadin/text-field": "25.3.0-alpha12",
|
|
59
|
+
"@vaadin/time-picker": "25.3.0-alpha12",
|
|
60
|
+
"@vaadin/vaadin-lumo-styles": "25.3.0-alpha12",
|
|
61
61
|
"sinon": "^22.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "0f0337783efe38332f5dc6a8968f207d2982de4b"
|
|
64
64
|
}
|
|
@@ -181,6 +181,65 @@ export const aiFieldMarkerStyles = css`
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
/* The confidence indicator: a sibling of the marker slotted into the
|
|
185
|
+
field's helper text section. The level class name picks the color and how
|
|
186
|
+
much of the pie icon is filled. */
|
|
187
|
+
:has(> vaadin-ai-field-marker) > [slot='helper'].ai-confidence {
|
|
188
|
+
display: flex;
|
|
189
|
+
align-items: center;
|
|
190
|
+
gap: var(--vaadin-gap-s);
|
|
191
|
+
color: var(--_vaadin-ai-field-marker-confidence-color);
|
|
192
|
+
|
|
193
|
+
&::before {
|
|
194
|
+
content: '';
|
|
195
|
+
flex: none;
|
|
196
|
+
box-sizing: border-box;
|
|
197
|
+
width: var(--vaadin-icon-size, 1lh);
|
|
198
|
+
height: var(--vaadin-icon-size, 1lh);
|
|
199
|
+
/* The padding insets the pie from the ring: the wedge is clipped to the
|
|
200
|
+
content box, while the tint fills the whole circle behind it. */
|
|
201
|
+
padding: calc(var(--vaadin-icon-size, 1lh) / 12);
|
|
202
|
+
border: 1px solid color-mix(in srgb, currentColor 50%, transparent);
|
|
203
|
+
border-radius: 50%;
|
|
204
|
+
background-color: color-mix(in srgb, currentColor 15%, transparent);
|
|
205
|
+
background-image: conic-gradient(currentColor var(--_vaadin-ai-field-marker-confidence-fill, 0%), #0000 0%);
|
|
206
|
+
background-clip: content-box, border-box;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/* The levels are told apart by how much of the pie is filled, so the base
|
|
210
|
+
styles keep them in the same neutral color. The themes map the custom
|
|
211
|
+
properties to their own semantic colors. */
|
|
212
|
+
&.ai-confidence-low {
|
|
213
|
+
--_vaadin-ai-field-marker-confidence-color: var(
|
|
214
|
+
--vaadin-ai-field-marker-confidence-low-color,
|
|
215
|
+
var(--vaadin-text-color-secondary)
|
|
216
|
+
);
|
|
217
|
+
--_vaadin-ai-field-marker-confidence-fill: 25%;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
&.ai-confidence-medium {
|
|
221
|
+
--_vaadin-ai-field-marker-confidence-color: var(
|
|
222
|
+
--vaadin-ai-field-marker-confidence-medium-color,
|
|
223
|
+
var(--vaadin-text-color-secondary)
|
|
224
|
+
);
|
|
225
|
+
--_vaadin-ai-field-marker-confidence-fill: 50%;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
&.ai-confidence-high {
|
|
229
|
+
--_vaadin-ai-field-marker-confidence-color: var(
|
|
230
|
+
--vaadin-ai-field-marker-confidence-high-color,
|
|
231
|
+
var(--vaadin-text-color-secondary)
|
|
232
|
+
);
|
|
233
|
+
--_vaadin-ai-field-marker-confidence-fill: 75%;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/* While the AI is working, the confidence describes a value that is about
|
|
238
|
+
to be replaced, so hide it along with the marker. */
|
|
239
|
+
[ai-working] > [slot='helper'].ai-confidence {
|
|
240
|
+
display: none;
|
|
241
|
+
}
|
|
242
|
+
|
|
184
243
|
[ai-working],
|
|
185
244
|
:has(> vaadin-ai-field-marker)::part(input-field),
|
|
186
245
|
:has(> vaadin-ai-field-marker)::part(input-fields),
|
|
@@ -28,6 +28,15 @@ export interface AiFieldMarkerI18n {
|
|
|
28
28
|
* The tooltip text of the badge button.
|
|
29
29
|
*/
|
|
30
30
|
badgeTooltip?: string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The texts of the confidence indicator.
|
|
34
|
+
*/
|
|
35
|
+
confidence?: {
|
|
36
|
+
low?: string;
|
|
37
|
+
medium?: string;
|
|
38
|
+
high?: string;
|
|
39
|
+
};
|
|
31
40
|
}
|
|
32
41
|
|
|
33
42
|
/**
|
|
@@ -53,20 +62,32 @@ export type AiFieldRevertEvent = CustomEvent<{ value: unknown }>;
|
|
|
53
62
|
* in progress, set the `working` property to show an "AI is working" shimmer
|
|
54
63
|
* on the field along with a client-side read-only guard.
|
|
55
64
|
*
|
|
65
|
+
* Set the `confidence` property to show the confidence level of the filled
|
|
66
|
+
* value (`low`, `medium` or `high`) as an indicator in the field's helper
|
|
67
|
+
* text section, ahead of a helper the field itself may have. While the
|
|
68
|
+
* indicator is shown, the field is marked with `has-helper`, so that the
|
|
69
|
+
* helper text section is laid out the same as for a helper of its own.
|
|
70
|
+
*
|
|
56
71
|
* ### Styling
|
|
57
72
|
*
|
|
58
|
-
* The following state
|
|
73
|
+
* The following state attributes are set on the field element for styling:
|
|
59
74
|
*
|
|
60
|
-
* Attribute
|
|
61
|
-
*
|
|
62
|
-
* `ai-working`
|
|
75
|
+
* Attribute | Description
|
|
76
|
+
* ----------------|-------------
|
|
77
|
+
* `ai-working` | Set while an AI is working on the field.
|
|
78
|
+
*
|
|
79
|
+
* The confidence indicator is rendered into the field's light DOM as a
|
|
80
|
+
* `<span>` with the `ai-confidence` class name and the level as an additional
|
|
81
|
+
* `ai-confidence-low`, `ai-confidence-medium` or `ai-confidence-high` one.
|
|
63
82
|
*
|
|
64
83
|
* The following custom CSS properties are available for styling:
|
|
65
84
|
*
|
|
66
|
-
* Custom CSS property
|
|
67
|
-
*
|
|
68
|
-
* `--vaadin-ai-field-marker-badge-icon-color`
|
|
69
|
-
* `--vaadin-ai-field-marker-
|
|
85
|
+
* Custom CSS property |
|
|
86
|
+
* :----------------------------------------------------|
|
|
87
|
+
* `--vaadin-ai-field-marker-badge-icon-color` |
|
|
88
|
+
* `--vaadin-ai-field-marker-confidence-high-color` |
|
|
89
|
+
* `--vaadin-ai-field-marker-confidence-low-color` |
|
|
90
|
+
* `--vaadin-ai-field-marker-confidence-medium-color` |
|
|
70
91
|
*
|
|
71
92
|
* See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
|
|
72
93
|
*
|
|
@@ -89,7 +110,13 @@ declare class AiFieldMarker extends I18nMixin<typeof HTMLElement, AiFieldMarkerI
|
|
|
89
110
|
* // The accessible label of the badge button and the popover dialog.
|
|
90
111
|
* badgeLabel: 'AI-provided value',
|
|
91
112
|
* // The tooltip text of the badge button.
|
|
92
|
-
* badgeTooltip: 'Field value modified by AI.\nClick for details'
|
|
113
|
+
* badgeTooltip: 'Field value modified by AI.\nClick for details',
|
|
114
|
+
* // The texts of the confidence indicator.
|
|
115
|
+
* confidence: {
|
|
116
|
+
* low: 'Low confidence',
|
|
117
|
+
* medium: 'Medium confidence',
|
|
118
|
+
* high: 'High confidence'
|
|
119
|
+
* }
|
|
93
120
|
* }
|
|
94
121
|
* ```
|
|
95
122
|
*/
|
|
@@ -105,6 +132,14 @@ declare class AiFieldMarker extends I18nMixin<typeof HTMLElement, AiFieldMarkerI
|
|
|
105
132
|
* the field is marked with `aria-busy`.
|
|
106
133
|
*/
|
|
107
134
|
working: boolean;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The confidence level of the AI-filled value, shown as an indicator
|
|
138
|
+
* in the field's helper text section. Possible values are `low`,
|
|
139
|
+
* `medium` and `high`; when not set, no indicator is shown. The
|
|
140
|
+
* indicator texts can be localized with the `i18n` property.
|
|
141
|
+
*/
|
|
142
|
+
confidence: 'high' | 'low' | 'medium' | null;
|
|
108
143
|
}
|
|
109
144
|
|
|
110
145
|
declare global {
|
|
@@ -11,7 +11,11 @@ import { getDeepActiveElement, getTabbableElements, isKeyboardActive } from '@va
|
|
|
11
11
|
import { registerCSSProperty } from '@vaadin/component-base/src/css-utils.js';
|
|
12
12
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
13
13
|
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
addValuesToAttribute,
|
|
16
|
+
hasNodeContent,
|
|
17
|
+
removeValuesFromAttribute,
|
|
18
|
+
} from '@vaadin/component-base/src/dom-utils.js';
|
|
15
19
|
import { I18nMixin } from '@vaadin/component-base/src/i18n-mixin.js';
|
|
16
20
|
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
|
|
17
21
|
import { SlotStylesMixin } from '@vaadin/component-base/src/slot-styles-mixin.js';
|
|
@@ -23,6 +27,11 @@ const DEFAULT_I18N = {
|
|
|
23
27
|
revert: 'Revert Value',
|
|
24
28
|
badgeLabel: 'AI-provided value',
|
|
25
29
|
badgeTooltip: 'Field value modified by AI.\nClick for details',
|
|
30
|
+
confidence: {
|
|
31
|
+
low: 'Low confidence',
|
|
32
|
+
medium: 'Medium confidence',
|
|
33
|
+
high: 'High confidence',
|
|
34
|
+
},
|
|
26
35
|
};
|
|
27
36
|
|
|
28
37
|
// Half of the 1s working shimmer slide (`--vaadin-ai-field-marker-slide` in
|
|
@@ -35,6 +44,14 @@ const MARKER_SLOT = 'ai-field-marker';
|
|
|
35
44
|
/** Marks the `<style>` element the marker injects into a field's shadow root. */
|
|
36
45
|
const MARKER_STYLE_ATTRIBUTE = 'ai-field-marker-styles';
|
|
37
46
|
|
|
47
|
+
/**
|
|
48
|
+
* The class name of the confidence indicator the marker adds to the field's
|
|
49
|
+
* light DOM; the level goes on a suffixed class name of its own. Prefixed
|
|
50
|
+
* with `ai-`, since the indicator sits among the application's own children
|
|
51
|
+
* of the field, where a plain `confidence` or `low` would be ambiguous.
|
|
52
|
+
*/
|
|
53
|
+
const CONFIDENCE_CLASS = 'ai-confidence';
|
|
54
|
+
|
|
38
55
|
// The position the shimmer's mask is at, animated by the marker's keyframes.
|
|
39
56
|
// Registered here rather than with an @property rule in the marker stylesheet,
|
|
40
57
|
// which is injected into the field's root node: a registration only takes effect
|
|
@@ -210,20 +227,32 @@ class DelayedFieldValue {
|
|
|
210
227
|
* directly into the marker's light DOM, so that document-level themes
|
|
211
228
|
* and user stylesheets can reach them.
|
|
212
229
|
*
|
|
230
|
+
* Set the `confidence` property to show the confidence level of the filled
|
|
231
|
+
* value (`low`, `medium` or `high`) as an indicator in the field's helper
|
|
232
|
+
* text section, ahead of a helper the field itself may have. While the
|
|
233
|
+
* indicator is shown, the field is marked with `has-helper`, so that the
|
|
234
|
+
* helper text section is laid out the same as for a helper of its own.
|
|
235
|
+
*
|
|
213
236
|
* ### Styling
|
|
214
237
|
*
|
|
215
|
-
* The following state
|
|
238
|
+
* The following state attributes are set on the field element for styling:
|
|
239
|
+
*
|
|
240
|
+
* Attribute | Description
|
|
241
|
+
* ----------------|-------------
|
|
242
|
+
* `ai-working` | Set while an AI is working on the field.
|
|
216
243
|
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
* `ai-
|
|
244
|
+
* The confidence indicator is rendered into the field's light DOM as a
|
|
245
|
+
* `<span>` with the `ai-confidence` class name and the level as an additional
|
|
246
|
+
* `ai-confidence-low`, `ai-confidence-medium` or `ai-confidence-high` one.
|
|
220
247
|
*
|
|
221
248
|
* The following custom CSS properties are available for styling:
|
|
222
249
|
*
|
|
223
|
-
* Custom CSS property
|
|
224
|
-
*
|
|
225
|
-
* `--vaadin-ai-field-marker-badge-icon-color`
|
|
226
|
-
* `--vaadin-ai-field-marker-
|
|
250
|
+
* Custom CSS property |
|
|
251
|
+
* :----------------------------------------------------|
|
|
252
|
+
* `--vaadin-ai-field-marker-badge-icon-color` |
|
|
253
|
+
* `--vaadin-ai-field-marker-confidence-high-color` |
|
|
254
|
+
* `--vaadin-ai-field-marker-confidence-low-color` |
|
|
255
|
+
* `--vaadin-ai-field-marker-confidence-medium-color` |
|
|
227
256
|
*
|
|
228
257
|
* See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
|
|
229
258
|
*
|
|
@@ -257,6 +286,17 @@ class AiFieldMarker extends SlotStylesMixin(I18nMixin(DirMixin(PolylitMixin(LitE
|
|
|
257
286
|
type: Boolean,
|
|
258
287
|
value: false,
|
|
259
288
|
},
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* The confidence level of the AI-filled value, shown as an indicator
|
|
292
|
+
* in the field's helper text section. Possible values are `low`,
|
|
293
|
+
* `medium` and `high`; when not set, no indicator is shown. The
|
|
294
|
+
* indicator texts can be localized with the `i18n` property.
|
|
295
|
+
*/
|
|
296
|
+
confidence: {
|
|
297
|
+
type: String,
|
|
298
|
+
value: null,
|
|
299
|
+
},
|
|
260
300
|
};
|
|
261
301
|
}
|
|
262
302
|
|
|
@@ -278,6 +318,20 @@ class AiFieldMarker extends SlotStylesMixin(I18nMixin(DirMixin(PolylitMixin(LitE
|
|
|
278
318
|
/** The field value captured for the revert event detail. */
|
|
279
319
|
#capturedValue;
|
|
280
320
|
|
|
321
|
+
/**
|
|
322
|
+
* The confidence indicator added to the field's light DOM and rendered
|
|
323
|
+
* in the field's helper text section. Set while `confidence` is set on
|
|
324
|
+
* a marked field.
|
|
325
|
+
*/
|
|
326
|
+
#confidenceNode = null;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Observes the field's `has-helper` attribute while the confidence
|
|
330
|
+
* indicator is shown, so that the marker can re-assert it if the field
|
|
331
|
+
* recomputes it from its own helper content. Created on first use.
|
|
332
|
+
*/
|
|
333
|
+
#helperStateObserver = null;
|
|
334
|
+
|
|
281
335
|
/**
|
|
282
336
|
* While in the working state, the elements whose client-side `readonly`
|
|
283
337
|
* state was overridden — the field itself and, for a `vaadin-custom-field`,
|
|
@@ -367,7 +421,13 @@ class AiFieldMarker extends SlotStylesMixin(I18nMixin(DirMixin(PolylitMixin(LitE
|
|
|
367
421
|
* // The accessible label of the badge button and the popover dialog.
|
|
368
422
|
* badgeLabel: 'AI-provided value',
|
|
369
423
|
* // The tooltip text of the badge button.
|
|
370
|
-
* badgeTooltip: 'Field value modified by AI.\nClick for details'
|
|
424
|
+
* badgeTooltip: 'Field value modified by AI.\nClick for details',
|
|
425
|
+
* // The texts of the confidence indicator.
|
|
426
|
+
* confidence: {
|
|
427
|
+
* low: 'Low confidence',
|
|
428
|
+
* medium: 'Medium confidence',
|
|
429
|
+
* high: 'High confidence'
|
|
430
|
+
* }
|
|
371
431
|
* }
|
|
372
432
|
* ```
|
|
373
433
|
*
|
|
@@ -449,6 +509,8 @@ class AiFieldMarker extends SlotStylesMixin(I18nMixin(DirMixin(PolylitMixin(LitE
|
|
|
449
509
|
|
|
450
510
|
this.#stopWorking(true);
|
|
451
511
|
|
|
512
|
+
this.#removeConfidenceNode();
|
|
513
|
+
|
|
452
514
|
if (this.#descNode) {
|
|
453
515
|
removeValuesFromAttribute(this.#describedElement, 'aria-describedby', this.#descNode.id);
|
|
454
516
|
this.#descNode.remove();
|
|
@@ -483,6 +545,10 @@ class AiFieldMarker extends SlotStylesMixin(I18nMixin(DirMixin(PolylitMixin(LitE
|
|
|
483
545
|
return;
|
|
484
546
|
}
|
|
485
547
|
|
|
548
|
+
if (props.has('confidence') || props.has('__effectiveI18n')) {
|
|
549
|
+
this.#updateConfidence();
|
|
550
|
+
}
|
|
551
|
+
|
|
486
552
|
if (props.has('working')) {
|
|
487
553
|
if (this.working) {
|
|
488
554
|
this.#startWorking();
|
|
@@ -493,6 +559,12 @@ class AiFieldMarker extends SlotStylesMixin(I18nMixin(DirMixin(PolylitMixin(LitE
|
|
|
493
559
|
this.#capturedValue = this.#annotatedValue();
|
|
494
560
|
this.#announcePending = true;
|
|
495
561
|
}
|
|
562
|
+
|
|
563
|
+
// The indicator is hidden while working, so the helper text section is
|
|
564
|
+
// only claimed for it — and the indicator described — once the working
|
|
565
|
+
// state ends.
|
|
566
|
+
this.#updateConfidenceDescription();
|
|
567
|
+
this.#updateFieldHelperState();
|
|
496
568
|
}
|
|
497
569
|
|
|
498
570
|
// Announce after the update so the announcement reflects a message set in
|
|
@@ -594,6 +666,10 @@ class AiFieldMarker extends SlotStylesMixin(I18nMixin(DirMixin(PolylitMixin(LitE
|
|
|
594
666
|
this.#describedElement = describedElement;
|
|
595
667
|
}
|
|
596
668
|
|
|
669
|
+
// Apply the confidence indicator directly: on a reconnect no property
|
|
670
|
+
// change triggers updated(), which handles the first connect.
|
|
671
|
+
this.#updateConfidence();
|
|
672
|
+
|
|
597
673
|
// Capture the AI-filled value so the revert event can carry it.
|
|
598
674
|
this.#capturedValue = this.#annotatedValue();
|
|
599
675
|
|
|
@@ -619,6 +695,133 @@ class AiFieldMarker extends SlotStylesMixin(I18nMixin(DirMixin(PolylitMixin(LitE
|
|
|
619
695
|
return this.#valueDelay ? this.#valueDelay.latestValue : field.value;
|
|
620
696
|
}
|
|
621
697
|
|
|
698
|
+
/**
|
|
699
|
+
* Syncs the confidence indicator in the field's helper text section with
|
|
700
|
+
* the `confidence` property: a `<span>` slotted into the field's helper
|
|
701
|
+
* slot, with the `ai-confidence` and `ai-confidence-<level>` class names
|
|
702
|
+
* and the localized level text as content.
|
|
703
|
+
*/
|
|
704
|
+
#updateConfidence() {
|
|
705
|
+
const field = this.#field;
|
|
706
|
+
if (!field) {
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
const level = this.confidence;
|
|
711
|
+
if (!level) {
|
|
712
|
+
this.#removeConfidenceNode();
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
if (!this.#confidenceNode) {
|
|
717
|
+
const node = document.createElement('span');
|
|
718
|
+
node.setAttribute('slot', 'helper');
|
|
719
|
+
// Hide the indicator from the field's helper slot controller, which
|
|
720
|
+
// would otherwise evict the field's own helper element in favor of
|
|
721
|
+
// the indicator. The browser still renders it in the helper slot.
|
|
722
|
+
node.setAttribute('data-slot-ignore', '');
|
|
723
|
+
node.id = `ai-field-marker-confidence-${generateUniqueId()}`;
|
|
724
|
+
// Insert ahead of a helper the field already has, so that the indicator
|
|
725
|
+
// comes first in the helper text section. A helper added later ends up
|
|
726
|
+
// after the indicator, since the field appends it.
|
|
727
|
+
field.insertBefore(node, field.querySelector(':scope > [slot="helper"]'));
|
|
728
|
+
this.#confidenceNode = node;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
this.#confidenceNode.className = `${CONFIDENCE_CLASS} ${CONFIDENCE_CLASS}-${level}`;
|
|
732
|
+
this.#confidenceNode.textContent = this.__effectiveI18n.confidence[level] ?? '';
|
|
733
|
+
this.#updateConfidenceDescription();
|
|
734
|
+
this.#updateFieldHelperState();
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* Keeps the indicator's id in the described element's `aria-describedby`
|
|
739
|
+
* only while the indicator is shown: a visually hidden indicator would
|
|
740
|
+
* still get read as part of the field's description, although it describes
|
|
741
|
+
* a value the AI is about to replace.
|
|
742
|
+
*/
|
|
743
|
+
#updateConfidenceDescription() {
|
|
744
|
+
const node = this.#confidenceNode;
|
|
745
|
+
if (!node || !this.#describedElement) {
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
if (this.working) {
|
|
750
|
+
removeValuesFromAttribute(this.#describedElement, 'aria-describedby', node.id);
|
|
751
|
+
} else {
|
|
752
|
+
addValuesToAttribute(this.#describedElement, 'aria-describedby', node.id);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
/**
|
|
757
|
+
* Keeps the field's `has-helper` attribute set while the indicator is
|
|
758
|
+
* shown, since it is content in the field's helper text section although
|
|
759
|
+
* the field's own helper is not what provides it. The attribute is what
|
|
760
|
+
* both the field and the themes key their helper text section styles on —
|
|
761
|
+
* from showing the section at all to placing it above the field for the
|
|
762
|
+
* `helper-above-field` theme.
|
|
763
|
+
*
|
|
764
|
+
* The field recomputes the attribute from its own helper content, which
|
|
765
|
+
* never includes the indicator, so a recomputation can drop it while the
|
|
766
|
+
* indicator is still shown. An observer re-asserts it in that case.
|
|
767
|
+
*/
|
|
768
|
+
#updateFieldHelperState() {
|
|
769
|
+
const field = this.#field;
|
|
770
|
+
|
|
771
|
+
// While the AI is working the indicator is hidden, so the field should
|
|
772
|
+
// only reserve the helper text section for a helper of its own.
|
|
773
|
+
if (this.#confidenceNode && !this.working) {
|
|
774
|
+
field.toggleAttribute('has-helper', true);
|
|
775
|
+
|
|
776
|
+
this.#helperStateObserver ??= new MutationObserver(() => {
|
|
777
|
+
// Read the field live: the observer is reused when the marker moves
|
|
778
|
+
// to another field, so a captured one could be a previous field.
|
|
779
|
+
const observedField = this.#field;
|
|
780
|
+
if (observedField && this.#confidenceNode && !this.working && !observedField.hasAttribute('has-helper')) {
|
|
781
|
+
observedField.toggleAttribute('has-helper', true);
|
|
782
|
+
}
|
|
783
|
+
});
|
|
784
|
+
this.#helperStateObserver.observe(field, { attributes: true, attributeFilter: ['has-helper'] });
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
this.#helperStateObserver?.disconnect();
|
|
789
|
+
|
|
790
|
+
// The field keeps the attribute when its own helper provides content,
|
|
791
|
+
// which it may have gained while the indicator was shown.
|
|
792
|
+
if (!this.#hasFieldHelper()) {
|
|
793
|
+
field.removeAttribute('has-helper');
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Whether the field has helper content of its own, i.e. helper slot content
|
|
799
|
+
* other than the indicator. Judged with the same content check the field
|
|
800
|
+
* itself uses for its `has-helper` attribute.
|
|
801
|
+
*
|
|
802
|
+
* @return {boolean}
|
|
803
|
+
*/
|
|
804
|
+
#hasFieldHelper() {
|
|
805
|
+
return [...this.#field.querySelectorAll(':scope > [slot="helper"]')].some(
|
|
806
|
+
(node) => node !== this.#confidenceNode && hasNodeContent(node),
|
|
807
|
+
);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/** Removes the confidence indicator. */
|
|
811
|
+
#removeConfidenceNode() {
|
|
812
|
+
const node = this.#confidenceNode;
|
|
813
|
+
if (!node) {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
if (this.#describedElement) {
|
|
818
|
+
removeValuesFromAttribute(this.#describedElement, 'aria-describedby', node.id);
|
|
819
|
+
}
|
|
820
|
+
node.remove();
|
|
821
|
+
this.#confidenceNode = null;
|
|
822
|
+
this.#updateFieldHelperState();
|
|
823
|
+
}
|
|
824
|
+
|
|
622
825
|
/**
|
|
623
826
|
* Enters the "AI is working" state: shows the shimmer and makes the field
|
|
624
827
|
* read-only on the client so the user cannot edit a value the AI is about
|