@design.estate/dees-catalog 24.1.0 → 24.2.0
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_bundle/bundle.js +3719 -2665
- package/dist_bundle/bundle.js.map +1 -1
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{addon-fit-XY7VCF6W.js → addon-fit-RDDY6CA4.js} +2 -2
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{addon-search-OQXRIIMV.js → addon-search-UT4OBXLU.js} +2 -2
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{addon-serialize-BV6MHBIQ.js → addon-serialize-U4KTWHZ2.js} +2 -2
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{addon-web-links-IYKN5JS7.js → addon-web-links-QMZRXLUR.js} +2 -2
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-BTYTET7H.js → chunk-347GWLFZ.js} +3 -3
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-MV6OSXZD.js → chunk-AR2XNHGF.js} +2 -1
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-NFVJ3L3L.js → chunk-LFHMAQWF.js} +2 -2
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-4DJP4JAJ.js → chunk-OPVBP4HP.js} +3 -3
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-FUMEXHR4.js → chunk-SSD44HAU.js} +33 -3
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-FUMEXHR4.js.map → chunk-SSD44HAU.js.map} +1 -1
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-K2UNUD5D.js → chunk-YUJKYSDX.js} +19 -19
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{de-XE2K545Z.js → de-5P7JLMRS.js} +32 -3
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{de-XE2K545Z.js.map → de-5P7JLMRS.js.map} +1 -1
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-modal-IIOB2SYP.js → dees-modal-PC4PYTOT.js} +4 -4
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-workspace-terminal-EEY5WEF4.js → dees-workspace-terminal-GFHNW2QR.js} +5 -5
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dist-2OQWGHFH.js → dist-2U2U7ROC.js} +3 -3
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dist-CRWOBKHW.js → dist-4S4PAFPC.js} +3 -3
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dist-J3O6DO5O.js → dist-5P27Y36A.js} +3 -3
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dist-IIHC67RE.js → dist-6GIZONLS.js} +3 -3
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dist-ERBPCUJB.js → dist-CRHDJ3CC.js} +4 -4
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dist-3OMAY2ID.js → dist-OASEKGFQ.js} +3 -3
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dist-FJCH275Q.js → dist-UJJOGV5H.js} +4 -4
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{echarts-Z2APN5DY.js → echarts-QMOTMVTN.js} +2 -2
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{highlightjs-2VS4UD5C.js → highlightjs-CH6EL3U4.js} +2 -2
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{lightweight-charts.production-BYPU2BNH.js → lightweight-charts.production-VKUEJKDY.js} +2 -2
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{xterm-44R3YQOT.js → xterm-KAKUMKDA.js} +2 -2
- package/dist_ts_web/00_commitinfo_data.js +1 -1
- package/dist_ts_web/elements/00group-dataview/dees-table/styles.js +1 -1
- package/dist_ts_web/elements/00group-harness/dees-harness-chat/dees-harness-chat.d.ts +7 -1
- package/dist_ts_web/elements/00group-harness/dees-harness-chat/dees-harness-chat.js +17 -2
- package/dist_ts_web/elements/00group-harness/dees-harness-elicitation-card/dees-harness-elicitation-card.d.ts +79 -0
- package/dist_ts_web/elements/00group-harness/dees-harness-elicitation-card/dees-harness-elicitation-card.demo.d.ts +1 -0
- package/dist_ts_web/elements/00group-harness/dees-harness-elicitation-card/dees-harness-elicitation-card.demo.js +87 -0
- package/dist_ts_web/elements/00group-harness/dees-harness-elicitation-card/dees-harness-elicitation-card.js +995 -0
- package/dist_ts_web/elements/00group-harness/dees-harness-elicitation-card/index.d.ts +1 -0
- package/dist_ts_web/elements/00group-harness/dees-harness-elicitation-card/index.js +2 -0
- package/dist_ts_web/elements/00group-harness/dees-harness-message-list/dees-harness-message-list.d.ts +14 -1
- package/dist_ts_web/elements/00group-harness/dees-harness-message-list/dees-harness-message-list.js +60 -5
- package/dist_ts_web/elements/00group-harness/dees-harness-session-list/dees-harness-session-list.d.ts +9 -1
- package/dist_ts_web/elements/00group-harness/dees-harness-session-list/dees-harness-session-list.demo.js +25 -3
- package/dist_ts_web/elements/00group-harness/dees-harness-session-list/dees-harness-session-list.js +57 -5
- package/dist_ts_web/elements/00group-harness/index.d.ts +1 -0
- package/dist_ts_web/elements/00group-harness/index.js +2 -1
- package/dist_ts_web/elements/00group-harness/interfaces.d.ts +141 -0
- package/dist_ts_web/i18n/de.d.ts +116 -0
- package/dist_ts_web/i18n/de.js +30 -1
- package/dist_ts_web/i18n/messages.d.ts +116 -0
- package/dist_ts_web/i18n/messages.js +31 -1
- package/package.json +2 -2
- package/readme.md +45 -5
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/elements/00group-dataview/dees-table/styles.ts +1 -1
- package/ts_web/elements/00group-harness/dees-harness-chat/dees-harness-chat.ts +11 -0
- package/ts_web/elements/00group-harness/dees-harness-elicitation-card/dees-harness-elicitation-card.demo.ts +100 -0
- package/ts_web/elements/00group-harness/dees-harness-elicitation-card/dees-harness-elicitation-card.ts +997 -0
- package/ts_web/elements/00group-harness/dees-harness-elicitation-card/index.ts +1 -0
- package/ts_web/elements/00group-harness/dees-harness-message-list/dees-harness-message-list.ts +62 -2
- package/ts_web/elements/00group-harness/dees-harness-session-list/dees-harness-session-list.demo.ts +24 -2
- package/ts_web/elements/00group-harness/dees-harness-session-list/dees-harness-session-list.ts +57 -4
- package/ts_web/elements/00group-harness/index.ts +1 -0
- package/ts_web/elements/00group-harness/interfaces.ts +172 -0
- package/ts_web/i18n/de.ts +29 -0
- package/ts_web/i18n/messages.ts +30 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{addon-fit-XY7VCF6W.js.map → addon-fit-RDDY6CA4.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{addon-search-OQXRIIMV.js.map → addon-search-UT4OBXLU.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{addon-serialize-BV6MHBIQ.js.map → addon-serialize-U4KTWHZ2.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{addon-web-links-IYKN5JS7.js.map → addon-web-links-QMZRXLUR.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-BTYTET7H.js.map → chunk-347GWLFZ.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-MV6OSXZD.js.map → chunk-AR2XNHGF.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-NFVJ3L3L.js.map → chunk-LFHMAQWF.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-4DJP4JAJ.js.map → chunk-OPVBP4HP.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-K2UNUD5D.js.map → chunk-YUJKYSDX.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-modal-IIOB2SYP.js.map → dees-modal-PC4PYTOT.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-workspace-terminal-EEY5WEF4.js.map → dees-workspace-terminal-GFHNW2QR.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dist-2OQWGHFH.js.map → dist-2U2U7ROC.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dist-CRWOBKHW.js.map → dist-4S4PAFPC.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dist-J3O6DO5O.js.map → dist-5P27Y36A.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dist-IIHC67RE.js.map → dist-6GIZONLS.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dist-3OMAY2ID.js.map → dist-CRHDJ3CC.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dist-ERBPCUJB.js.map → dist-OASEKGFQ.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dist-FJCH275Q.js.map → dist-UJJOGV5H.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{echarts-Z2APN5DY.js.map → echarts-QMOTMVTN.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{highlightjs-2VS4UD5C.js.map → highlightjs-CH6EL3U4.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{lightweight-charts.production-BYPU2BNH.js.map → lightweight-charts.production-VKUEJKDY.js.map} +0 -0
- /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{xterm-44R3YQOT.js.map → xterm-KAKUMKDA.js.map} +0 -0
|
@@ -0,0 +1,997 @@
|
|
|
1
|
+
import { demoFunc } from './dees-harness-elicitation-card.demo.js';
|
|
2
|
+
import {
|
|
3
|
+
DeesElement,
|
|
4
|
+
html,
|
|
5
|
+
css,
|
|
6
|
+
customElement,
|
|
7
|
+
type TemplateResult,
|
|
8
|
+
property,
|
|
9
|
+
state,
|
|
10
|
+
cssManager,
|
|
11
|
+
} from '@design.estate/dees-element';
|
|
12
|
+
import { dcLocalize } from '../../../i18n/localize.js';
|
|
13
|
+
import { themeDefaultStyles, type TTone } from '../../00theme.js';
|
|
14
|
+
import { visuallyHidden } from '../../00visuallyhidden.js';
|
|
15
|
+
import { harnessControlStyles } from '../harness.styles.js';
|
|
16
|
+
import type {
|
|
17
|
+
IHarnessElicitationOption,
|
|
18
|
+
IHarnessElicitationRefusal,
|
|
19
|
+
IHarnessElicitationRequest,
|
|
20
|
+
IHarnessElicitationResponseDetail,
|
|
21
|
+
THarnessElicitationAction,
|
|
22
|
+
THarnessElicitationContent,
|
|
23
|
+
THarnessElicitationField,
|
|
24
|
+
THarnessElicitationTextFormat,
|
|
25
|
+
THarnessElicitationValue,
|
|
26
|
+
} from '../interfaces.js';
|
|
27
|
+
import type { IActionFooterAction } from '../../00group-button/dees-actionfooter/dees-actionfooter.js';
|
|
28
|
+
import '../../00group-button/dees-actionfooter/dees-actionfooter.js';
|
|
29
|
+
import '../../00group-feedback/dees-badge/dees-badge.js';
|
|
30
|
+
import '../../00group-utility/dees-icon/dees-icon.js';
|
|
31
|
+
|
|
32
|
+
declare global {
|
|
33
|
+
interface HTMLElementTagNameMap {
|
|
34
|
+
'dees-harness-elicitation-card': DeesHarnessElicitationCard;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** What the owner has entered in a field so far: the text of a text or number field, a yes or no, the chosen values. */
|
|
39
|
+
type TDraft =
|
|
40
|
+
| { kind: 'text' | 'number'; text: string }
|
|
41
|
+
| { kind: 'boolean'; value: boolean | undefined }
|
|
42
|
+
| { kind: 'choice'; value: string | undefined }
|
|
43
|
+
| { kind: 'choices'; values: readonly string[] };
|
|
44
|
+
|
|
45
|
+
/** A field as the owner left it: the value an answer carries (none for an empty field), or why it cannot be sent yet. */
|
|
46
|
+
interface IFieldCheck {
|
|
47
|
+
value: THarnessElicitationValue | undefined;
|
|
48
|
+
/** a required field is empty */
|
|
49
|
+
missing: boolean;
|
|
50
|
+
/** what does not fit the field's rules, in the reader's words; never the value itself */
|
|
51
|
+
problem: string | undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The title's icon of each mode. */
|
|
55
|
+
const MODE_ICON: Record<IHarnessElicitationRequest['mode'], string> = {
|
|
56
|
+
form: 'lucide:ClipboardPen',
|
|
57
|
+
url: 'lucide:Globe',
|
|
58
|
+
unsupported: 'lucide:Ban',
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** The badge of each answer. */
|
|
62
|
+
const ANSWER_TONE: Record<THarnessElicitationAction, TTone> = {
|
|
63
|
+
accept: 'success',
|
|
64
|
+
decline: 'neutral',
|
|
65
|
+
cancel: 'neutral',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* In an address, every character that does not show as itself: controls, format characters (the
|
|
70
|
+
* ones that turn text around, zero-width ones), line and paragraph separators, and every space but
|
|
71
|
+
* U+0020. Each is shown by its code point instead.
|
|
72
|
+
*/
|
|
73
|
+
const URL_HIDDEN = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/gu;
|
|
74
|
+
|
|
75
|
+
/** In a server's words: controls other than tab and line ends, and the characters that turn text around. */
|
|
76
|
+
const TEXT_HIDDEN = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F\u202A-\u202E\u2066-\u2069]/gu;
|
|
77
|
+
|
|
78
|
+
const codePointOf = (charArg: string): string =>
|
|
79
|
+
`U+${charArg.codePointAt(0)!.toString(16).toUpperCase().padStart(4, '0')}`;
|
|
80
|
+
|
|
81
|
+
/** Lengths count characters (Unicode code points), as JSON Schema and the server count them, not UTF-16 code units. */
|
|
82
|
+
const codePoints = (valueArg: string): number => [...valueArg].length;
|
|
83
|
+
|
|
84
|
+
/** Each decimal separator's pattern of a number as typed, made once. */
|
|
85
|
+
const numberTexts = new Map<string, RegExp>();
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A number as typed with the reader's decimal separator: digits with an optional sign, that
|
|
89
|
+
* separator once, and an exponent. Nothing groups the digits: a text with any other separator in
|
|
90
|
+
* it (`1,000` or `1.000` where the decimal separator is the other one) is no number, never read
|
|
91
|
+
* as another one.
|
|
92
|
+
*/
|
|
93
|
+
const numberText = (decimalArg: string): RegExp => {
|
|
94
|
+
let pattern = numberTexts.get(decimalArg);
|
|
95
|
+
if (!pattern) {
|
|
96
|
+
const separator = decimalArg.replace(/[$()*+.?[\\\]^{|}]/gu, '\\$&');
|
|
97
|
+
pattern = new RegExp(`^[-+]?(?:\\d+(?:${separator}\\d*)?|${separator}\\d+)(?:[eE][-+]?\\d+)?$`, 'u');
|
|
98
|
+
numberTexts.set(decimalArg, pattern);
|
|
99
|
+
}
|
|
100
|
+
return pattern;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const parseNumber = (textArg: string, decimalArg: string): number | undefined => {
|
|
104
|
+
const text = textArg.trim();
|
|
105
|
+
if (!numberText(decimalArg).test(text)) return undefined;
|
|
106
|
+
const value = Number(text.replace(decimalArg, '.'));
|
|
107
|
+
return Number.isFinite(value) ? value : undefined;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const validDate = (yearArg: string, monthArg: string, dayArg: string): boolean => {
|
|
111
|
+
const year = Number(yearArg);
|
|
112
|
+
const month = Number(monthArg);
|
|
113
|
+
const day = Number(dayArg);
|
|
114
|
+
if (month < 1 || month > 12 || day < 1) return false;
|
|
115
|
+
return day <= new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/** The checks a server makes of a text's format (MCP's string formats), so the card holds back what it would refuse. */
|
|
119
|
+
const FORMAT_VALID: Record<THarnessElicitationTextFormat, (valueArg: string) => boolean> = {
|
|
120
|
+
// one @ between a local part and a domain, neither with white space
|
|
121
|
+
email: (valueArg) => /^[^\s@]+@[^\s@]+$/u.test(valueArg),
|
|
122
|
+
// an absolute URI: a scheme, then what URL parsing accepts
|
|
123
|
+
uri: (valueArg) => {
|
|
124
|
+
if (!/^[A-Za-z][A-Za-z0-9+.-]*:\S*$/u.test(valueArg)) return false;
|
|
125
|
+
try {
|
|
126
|
+
new URL(valueArg);
|
|
127
|
+
return true;
|
|
128
|
+
} catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
// RFC 3339 full-date
|
|
133
|
+
date: (valueArg) => {
|
|
134
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/u.exec(valueArg);
|
|
135
|
+
return match !== null && validDate(match[1]!, match[2]!, match[3]!);
|
|
136
|
+
},
|
|
137
|
+
// RFC 3339 date-time
|
|
138
|
+
'date-time': (valueArg) => {
|
|
139
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:[Zz]|[+-](\d{2}):(\d{2}))$/u.exec(valueArg);
|
|
140
|
+
if (!match || !validDate(match[1]!, match[2]!, match[3]!)) return false;
|
|
141
|
+
if (Number(match[4]) > 23 || Number(match[5]) > 59 || Number(match[6]) > 60) return false;
|
|
142
|
+
return match[7] === undefined || (Number(match[7]) <= 23 && Number(match[8]) <= 59);
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/** A field's draft before the owner touches it: its default, where it has one, a number's with the reader's decimal separator. */
|
|
147
|
+
const defaultDraft = (fieldArg: THarnessElicitationField, decimalArg: string): TDraft => {
|
|
148
|
+
switch (fieldArg.kind) {
|
|
149
|
+
case 'text':
|
|
150
|
+
return { kind: 'text', text: fieldArg.default ?? '' };
|
|
151
|
+
case 'number':
|
|
152
|
+
return { kind: 'number', text: fieldArg.default === undefined ? '' : String(fieldArg.default).replace('.', decimalArg) };
|
|
153
|
+
case 'boolean':
|
|
154
|
+
return { kind: 'boolean', value: fieldArg.default };
|
|
155
|
+
case 'choice':
|
|
156
|
+
return {
|
|
157
|
+
kind: 'choice',
|
|
158
|
+
value: fieldArg.options.some((option) => option.value === fieldArg.default) ? fieldArg.default : undefined,
|
|
159
|
+
};
|
|
160
|
+
case 'choices': {
|
|
161
|
+
const chosen = new Set(fieldArg.default ?? []);
|
|
162
|
+
return { kind: 'choices', values: fieldArg.options.filter((option) => chosen.has(option.value)).map((option) => option.value) };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/** Whether a draft was made for a field of this kind. */
|
|
168
|
+
const draftFits = (fieldArg: THarnessElicitationField, draftArg: TDraft): boolean => draftArg.kind === fieldArg.kind;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* A request as the host gave it, to tell whether the host changed it after an answer. It holds no
|
|
172
|
+
* value the owner entered: the request never carries one.
|
|
173
|
+
*/
|
|
174
|
+
const signatureOf = (requestArg: IHarnessElicitationRequest): string => JSON.stringify(requestArg);
|
|
175
|
+
|
|
176
|
+
/** A key that types a character, rather than one that moves, deletes or runs a shortcut. */
|
|
177
|
+
const typesCharacter = (eventArg: KeyboardEvent): boolean =>
|
|
178
|
+
([...eventArg.key].length === 1 || ['Process', 'Dead', 'Unidentified'].includes(eventArg.key))
|
|
179
|
+
&& !eventArg.metaKey
|
|
180
|
+
&& !(eventArg.ctrlKey && !eventArg.altKey);
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* An MCP server of a session asks the owner for input (MCP elicitation). The card shows who asks
|
|
184
|
+
* and what, as plain text, and answers with `harness-elicitation-response` (bubbles, composed;
|
|
185
|
+
* `IHarnessElicitationResponseDetail`), the one event that carries what the owner entered.
|
|
186
|
+
*
|
|
187
|
+
* - `form`: the fields, each of MCP's flat primitive kinds: text (checked against its format and
|
|
188
|
+
* its lengths in characters), a number (in the reader's decimal separator, its digits never
|
|
189
|
+
* grouped), a yes or no, a single choice, several choices. Send
|
|
190
|
+
* waits while a required field is empty or a value does not fit; it sends the values typed
|
|
191
|
+
* (numbers as numbers, yes or no as booleans, several choices as a list), an empty optional
|
|
192
|
+
* field left out. Decline and Cancel send nothing.
|
|
193
|
+
* - `url`: the address as text, shown exactly, every character that would not show (a control,
|
|
194
|
+
* one that turns text around) by its code point. The card never opens, fetches or links it:
|
|
195
|
+
* "Mark as done" reports that the owner visited it, without content.
|
|
196
|
+
* - `unsupported`: the host's reason, and Decline and Cancel only.
|
|
197
|
+
*
|
|
198
|
+
* What the owner enters stays in this element alone: never in `request`, an attribute or a
|
|
199
|
+
* property, and never in an event but the answer. The typing events of its fields stop at the
|
|
200
|
+
* card. A refusal of the host (`refusals`) asks again with the values kept; a request of another
|
|
201
|
+
* id, and the card leaving the page, forget them. After an answer the card shows how it was
|
|
202
|
+
* answered, never what was entered, and takes no other answer until the host changes the request.
|
|
203
|
+
*/
|
|
204
|
+
@customElement('dees-harness-elicitation-card')
|
|
205
|
+
export class DeesHarnessElicitationCard extends DeesElement {
|
|
206
|
+
public static demo = demoFunc;
|
|
207
|
+
public static demoGroups = ['Agent Chat'];
|
|
208
|
+
|
|
209
|
+
private readonly t = dcLocalize(this);
|
|
210
|
+
|
|
211
|
+
@property({ attribute: false })
|
|
212
|
+
accessor request: IHarnessElicitationRequest | undefined = undefined;
|
|
213
|
+
|
|
214
|
+
/** The host is not ready for an answer: the card takes none. */
|
|
215
|
+
@property({ type: Boolean, reflect: true })
|
|
216
|
+
accessor busy: boolean = false;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* How the owner answered, the request as it was then, and the host's refusals it carried (the
|
|
220
|
+
* array itself): the card takes no other answer until the host changes the request.
|
|
221
|
+
*/
|
|
222
|
+
@state()
|
|
223
|
+
private accessor answered: {
|
|
224
|
+
action: THarnessElicitationAction;
|
|
225
|
+
signature: string;
|
|
226
|
+
refusals: IHarnessElicitationRequest['refusals'];
|
|
227
|
+
} | undefined = undefined;
|
|
228
|
+
|
|
229
|
+
/** What the owner entered, by field name: kept by this element alone, never in a property, attribute or event. */
|
|
230
|
+
#drafts = new Map<string, TDraft>();
|
|
231
|
+
|
|
232
|
+
/** The id of the request the drafts and the answer belong to. */
|
|
233
|
+
#requestId: string | undefined;
|
|
234
|
+
|
|
235
|
+
/** The footer's actions, kept while their words and availability stay, so the footer knows a running one by its object. */
|
|
236
|
+
#footer: { key: string; actions: IActionFooterAction[] } | undefined;
|
|
237
|
+
|
|
238
|
+
public static styles = [
|
|
239
|
+
themeDefaultStyles,
|
|
240
|
+
cssManager.defaultStyles,
|
|
241
|
+
harnessControlStyles,
|
|
242
|
+
css`
|
|
243
|
+
:host {
|
|
244
|
+
display: block;
|
|
245
|
+
font-family: var(--dees-font-family);
|
|
246
|
+
overflow: clip;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/* A surface that waits for the reader shares the composer card's: the control surface. */
|
|
250
|
+
.card {
|
|
251
|
+
overflow: clip;
|
|
252
|
+
border: var(--dees-line-width-hairline) solid var(--dees-color-border-default);
|
|
253
|
+
border-radius: var(--dees-radius-xl);
|
|
254
|
+
corner-shape: var(--dees-corner-shape);
|
|
255
|
+
background: var(--dees-color-control-bg);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.body {
|
|
259
|
+
display: grid;
|
|
260
|
+
gap: var(--dees-spacing-md);
|
|
261
|
+
padding: var(--dees-spacing-lg);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
dees-actionfooter {
|
|
265
|
+
--dees-actionfooter-inset: var(--dees-spacing-lg);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.titleRow {
|
|
269
|
+
display: flex;
|
|
270
|
+
align-items: flex-start;
|
|
271
|
+
gap: var(--dees-spacing-sm);
|
|
272
|
+
min-width: 0;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.titleRow dees-icon {
|
|
276
|
+
flex: 0 0 auto;
|
|
277
|
+
padding: var(--dees-spacing-xs);
|
|
278
|
+
border-radius: var(--dees-radius-md);
|
|
279
|
+
background: var(--dees-color-nav-selected);
|
|
280
|
+
color: var(--dees-color-accent-primary);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.titleText {
|
|
284
|
+
display: grid;
|
|
285
|
+
gap: var(--dees-spacing-2xs);
|
|
286
|
+
min-width: 0;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.server {
|
|
290
|
+
color: var(--dees-color-text-secondary);
|
|
291
|
+
font-size: var(--dees-font-caption1-size);
|
|
292
|
+
overflow-wrap: anywhere;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/* the server's own words: plain text, its lines kept, its direction its own */
|
|
296
|
+
.message {
|
|
297
|
+
margin: 0;
|
|
298
|
+
color: var(--dees-color-text-primary);
|
|
299
|
+
font-size: var(--dees-font-control-size);
|
|
300
|
+
font-weight: 600;
|
|
301
|
+
line-height: 1.4;
|
|
302
|
+
white-space: pre-wrap;
|
|
303
|
+
overflow-wrap: anywhere;
|
|
304
|
+
unicode-bidi: plaintext;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/* a character that would not show, shown by its code point */
|
|
308
|
+
.hiddenChar {
|
|
309
|
+
display: inline-block;
|
|
310
|
+
margin: 0 var(--dees-spacing-2xs);
|
|
311
|
+
padding: 0 var(--dees-spacing-2xs);
|
|
312
|
+
border: var(--dees-line-width-hairline) solid var(--dees-color-accent-warning);
|
|
313
|
+
border-radius: var(--dees-radius-xs);
|
|
314
|
+
corner-shape: var(--dees-corner-shape);
|
|
315
|
+
background: var(--dees-color-badge-warning-bg);
|
|
316
|
+
color: var(--dees-color-badge-warning-fg);
|
|
317
|
+
font-family: var(--dees-font-family-mono);
|
|
318
|
+
font-size: var(--dees-font-caption2-size);
|
|
319
|
+
font-weight: 500;
|
|
320
|
+
line-height: 1.4;
|
|
321
|
+
white-space: nowrap;
|
|
322
|
+
unicode-bidi: isolate;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.refusal {
|
|
326
|
+
margin: 0;
|
|
327
|
+
padding: var(--dees-spacing-sm) var(--dees-spacing-md);
|
|
328
|
+
border: var(--dees-line-width-hairline) solid var(--dees-color-accent-error);
|
|
329
|
+
border-radius: var(--dees-radius-lg);
|
|
330
|
+
corner-shape: var(--dees-corner-shape);
|
|
331
|
+
background: var(--dees-color-badge-error-bg);
|
|
332
|
+
color: var(--dees-color-badge-error-fg);
|
|
333
|
+
font-size: var(--dees-font-control-size-sm);
|
|
334
|
+
overflow-wrap: anywhere;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
.fields {
|
|
338
|
+
display: grid;
|
|
339
|
+
gap: var(--dees-spacing-md);
|
|
340
|
+
min-width: 0;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
.field {
|
|
344
|
+
display: grid;
|
|
345
|
+
gap: var(--dees-spacing-xs);
|
|
346
|
+
min-width: 0;
|
|
347
|
+
margin: 0;
|
|
348
|
+
padding: 0;
|
|
349
|
+
border: none;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
.fieldLabel {
|
|
353
|
+
justify-self: start;
|
|
354
|
+
padding: 0;
|
|
355
|
+
color: var(--dees-color-text-secondary);
|
|
356
|
+
font-size: var(--dees-font-control-size-sm);
|
|
357
|
+
font-weight: 500;
|
|
358
|
+
overflow-wrap: anywhere;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
.fieldLabel .required {
|
|
362
|
+
margin-left: var(--dees-spacing-2xs);
|
|
363
|
+
color: var(--dees-color-accent-error);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
.input {
|
|
367
|
+
min-width: 0;
|
|
368
|
+
height: var(--dees-control-height-md);
|
|
369
|
+
padding: 0 var(--dees-spacing-sm);
|
|
370
|
+
border: var(--dees-line-width-hairline) solid var(--dees-color-border-default);
|
|
371
|
+
border-radius: var(--dees-radius-md);
|
|
372
|
+
corner-shape: var(--dees-corner-shape);
|
|
373
|
+
background: var(--dees-color-bg-primary);
|
|
374
|
+
color: var(--dees-color-text-primary);
|
|
375
|
+
font-family: inherit;
|
|
376
|
+
font-size: var(--dees-font-control-size-sm);
|
|
377
|
+
outline: none;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
.input:focus {
|
|
381
|
+
border-color: var(--dees-color-accent-primary);
|
|
382
|
+
box-shadow: 0 0 0 var(--dees-line-width-focus-ring) var(--dees-color-focus-ring);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
.input[aria-invalid='true'] {
|
|
386
|
+
border-color: var(--dees-color-accent-error);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
.input:disabled,
|
|
390
|
+
.optionRow:has(input:disabled) {
|
|
391
|
+
cursor: default;
|
|
392
|
+
opacity: 0.6;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
.options {
|
|
396
|
+
display: grid;
|
|
397
|
+
gap: var(--dees-spacing-2xs);
|
|
398
|
+
min-width: 0;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
.optionRow {
|
|
402
|
+
display: flex;
|
|
403
|
+
align-items: center;
|
|
404
|
+
gap: var(--dees-spacing-sm);
|
|
405
|
+
min-width: 0;
|
|
406
|
+
color: var(--dees-color-text-primary);
|
|
407
|
+
font-size: var(--dees-font-control-size-sm);
|
|
408
|
+
cursor: pointer;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
.optionRow input {
|
|
412
|
+
flex: none;
|
|
413
|
+
width: 16px;
|
|
414
|
+
height: 16px;
|
|
415
|
+
margin: 0;
|
|
416
|
+
accent-color: var(--dees-color-accent-primary);
|
|
417
|
+
cursor: inherit;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
.optionLabel {
|
|
421
|
+
min-width: 0;
|
|
422
|
+
overflow-wrap: anywhere;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
.clear {
|
|
426
|
+
justify-self: start;
|
|
427
|
+
padding: 0;
|
|
428
|
+
border: none;
|
|
429
|
+
background: none;
|
|
430
|
+
color: var(--dees-color-accent-primary);
|
|
431
|
+
font: inherit;
|
|
432
|
+
font-size: var(--dees-font-caption1-size);
|
|
433
|
+
cursor: pointer;
|
|
434
|
+
border-radius: var(--dees-radius-xs);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
.clear:hover {
|
|
438
|
+
text-decoration: underline;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
.fieldHint,
|
|
442
|
+
.fieldProblem,
|
|
443
|
+
.fieldRefusal,
|
|
444
|
+
.note {
|
|
445
|
+
margin: 0;
|
|
446
|
+
color: var(--dees-color-text-secondary);
|
|
447
|
+
font-size: var(--dees-font-caption1-size);
|
|
448
|
+
overflow-wrap: anywhere;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
.fieldProblem,
|
|
452
|
+
.fieldRefusal {
|
|
453
|
+
color: var(--dees-color-text-error);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/* the address as text: shown whole and exactly, never a link */
|
|
457
|
+
.address {
|
|
458
|
+
display: grid;
|
|
459
|
+
gap: var(--dees-spacing-xs);
|
|
460
|
+
min-width: 0;
|
|
461
|
+
padding: var(--dees-spacing-sm) var(--dees-spacing-sm-plus);
|
|
462
|
+
border: var(--dees-line-width-hairline) solid var(--dees-color-border-subtle);
|
|
463
|
+
border-radius: var(--dees-radius-md);
|
|
464
|
+
corner-shape: var(--dees-corner-shape);
|
|
465
|
+
background: var(--dees-color-bg-secondary);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
.addressLabel {
|
|
469
|
+
color: var(--dees-color-text-secondary);
|
|
470
|
+
font-size: var(--dees-font-caption1-size);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
.addressText {
|
|
474
|
+
color: var(--dees-color-text-primary);
|
|
475
|
+
font-family: var(--dees-font-family-mono);
|
|
476
|
+
font-size: var(--dees-font-control-size-sm);
|
|
477
|
+
white-space: pre-wrap;
|
|
478
|
+
overflow-wrap: anywhere;
|
|
479
|
+
word-break: break-all;
|
|
480
|
+
direction: ltr;
|
|
481
|
+
unicode-bidi: isolate;
|
|
482
|
+
user-select: text;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
.reason {
|
|
486
|
+
margin: 0;
|
|
487
|
+
color: var(--dees-color-text-primary);
|
|
488
|
+
font-size: var(--dees-font-control-size-sm);
|
|
489
|
+
white-space: pre-wrap;
|
|
490
|
+
overflow-wrap: anywhere;
|
|
491
|
+
unicode-bidi: plaintext;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
.decision {
|
|
495
|
+
display: flex;
|
|
496
|
+
flex-wrap: wrap;
|
|
497
|
+
align-items: center;
|
|
498
|
+
gap: var(--dees-spacing-sm);
|
|
499
|
+
border-radius: var(--dees-radius-xs);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
.decision:focus {
|
|
503
|
+
outline: none;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
.decision:focus-visible {
|
|
507
|
+
outline: var(--dees-line-width-focus-ring) solid var(--dees-color-focus-ring);
|
|
508
|
+
outline-offset: var(--dees-spacing-2xs);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
.clear:focus-visible {
|
|
512
|
+
outline: var(--dees-line-width-focus-ring) solid var(--dees-color-focus-ring);
|
|
513
|
+
outline-offset: var(--dees-spacing-2xs);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
.srOnly {
|
|
517
|
+
${visuallyHidden}
|
|
518
|
+
}
|
|
519
|
+
`,
|
|
520
|
+
];
|
|
521
|
+
|
|
522
|
+
/** Whether the card takes no answer: the host is busy, or the owner answered and the host has not changed the request since. */
|
|
523
|
+
private get locked(): boolean {
|
|
524
|
+
return this.busy || this.answered !== undefined;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/** The draft of a field, made from its default where the owner has not touched it. */
|
|
528
|
+
#draftOf(fieldArg: THarnessElicitationField): TDraft {
|
|
529
|
+
const draft = this.#drafts.get(fieldArg.name);
|
|
530
|
+
return draft && draftFits(fieldArg, draft) ? draft : defaultDraft(fieldArg, this.decimalSeparator);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/** The reader's decimal separator, as the provided `I18n` writes numbers: `.` without one. */
|
|
534
|
+
private get decimalSeparator(): string {
|
|
535
|
+
return this.t.format.intlNumberFormat({}).formatToParts(0.5).find((part) => part.type === 'decimal')?.value ?? '.';
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
#setDraft(fieldArg: THarnessElicitationField, draftArg: TDraft): void {
|
|
539
|
+
if (this.locked) return;
|
|
540
|
+
this.#drafts.set(fieldArg.name, draftArg);
|
|
541
|
+
this.requestUpdate();
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/** Forgets everything the owner entered: the card shows every field at its default again. */
|
|
545
|
+
#forgetDrafts(): void {
|
|
546
|
+
this.#drafts = new Map<string, TDraft>();
|
|
547
|
+
this.requestUpdate();
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/** A field as the owner left it: the value it sends, whether a required one is empty, and what does not fit. */
|
|
551
|
+
private checkField(fieldArg: THarnessElicitationField): IFieldCheck {
|
|
552
|
+
const draft = this.#draftOf(fieldArg);
|
|
553
|
+
const empty: IFieldCheck = { value: undefined, missing: fieldArg.required, problem: undefined };
|
|
554
|
+
switch (fieldArg.kind) {
|
|
555
|
+
case 'text': {
|
|
556
|
+
const text = draft.kind === 'text' ? draft.text : '';
|
|
557
|
+
if (text === '') return empty;
|
|
558
|
+
const count = codePoints(text);
|
|
559
|
+
const problem = fieldArg.minLength !== undefined && count < fieldArg.minLength
|
|
560
|
+
? this.t('elicitation.tooShort', { min: fieldArg.minLength, count })
|
|
561
|
+
: fieldArg.maxLength !== undefined && count > fieldArg.maxLength
|
|
562
|
+
? this.t('elicitation.tooLong', { max: fieldArg.maxLength, count })
|
|
563
|
+
: fieldArg.format !== undefined && !FORMAT_VALID[fieldArg.format](text)
|
|
564
|
+
? this.t('elicitation.format', { format: fieldArg.format === 'date-time' ? 'dateTime' : fieldArg.format })
|
|
565
|
+
: undefined;
|
|
566
|
+
return { value: text, missing: false, problem };
|
|
567
|
+
}
|
|
568
|
+
case 'number': {
|
|
569
|
+
const text = draft.kind === 'number' ? draft.text : '';
|
|
570
|
+
if (text.trim() === '') return empty;
|
|
571
|
+
const value = parseNumber(text, this.decimalSeparator);
|
|
572
|
+
const problem = value === undefined
|
|
573
|
+
? this.t('elicitation.notNumber')
|
|
574
|
+
: fieldArg.integer && !Number.isInteger(value)
|
|
575
|
+
? this.t('elicitation.notWhole')
|
|
576
|
+
: fieldArg.minimum !== undefined && value < fieldArg.minimum
|
|
577
|
+
? this.t('elicitation.belowMin', { min: fieldArg.minimum })
|
|
578
|
+
: fieldArg.maximum !== undefined && value > fieldArg.maximum
|
|
579
|
+
? this.t('elicitation.aboveMax', { max: fieldArg.maximum })
|
|
580
|
+
: undefined;
|
|
581
|
+
return { value, missing: false, problem };
|
|
582
|
+
}
|
|
583
|
+
case 'boolean': {
|
|
584
|
+
const value = draft.kind === 'boolean' ? draft.value : undefined;
|
|
585
|
+
return value === undefined ? empty : { value, missing: false, problem: undefined };
|
|
586
|
+
}
|
|
587
|
+
case 'choice': {
|
|
588
|
+
const value = draft.kind === 'choice' ? draft.value : undefined;
|
|
589
|
+
return value === undefined ? empty : { value, missing: false, problem: undefined };
|
|
590
|
+
}
|
|
591
|
+
case 'choices': {
|
|
592
|
+
const chosen = new Set(draft.kind === 'choices' ? draft.values : []);
|
|
593
|
+
// in the order the field lists them, each once
|
|
594
|
+
const values = fieldArg.options.filter((option) => chosen.has(option.value)).map((option) => option.value);
|
|
595
|
+
// nothing chosen of an optional field leaves it out; a required one answers with none chosen
|
|
596
|
+
if (values.length === 0 && !fieldArg.required) return { value: undefined, missing: false, problem: undefined };
|
|
597
|
+
const problem = fieldArg.minItems !== undefined && values.length < fieldArg.minItems
|
|
598
|
+
? this.t('elicitation.tooFewChoices', { min: fieldArg.minItems })
|
|
599
|
+
: fieldArg.maxItems !== undefined && values.length > fieldArg.maxItems
|
|
600
|
+
? this.t('elicitation.tooManyChoices', { max: fieldArg.maxItems })
|
|
601
|
+
: undefined;
|
|
602
|
+
return { value: values, missing: false, problem };
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/** The form's answer, once every required field is filled in and every value fits. */
|
|
608
|
+
private checkForm(fieldsArg: readonly THarnessElicitationField[]): { ready: boolean; missing: boolean; content: THarnessElicitationContent } {
|
|
609
|
+
let ready = true;
|
|
610
|
+
let missing = false;
|
|
611
|
+
const entries: Array<[string, THarnessElicitationValue]> = [];
|
|
612
|
+
for (const field of fieldsArg) {
|
|
613
|
+
const check = this.checkField(field);
|
|
614
|
+
if (check.missing) missing = true;
|
|
615
|
+
if (check.missing || check.problem !== undefined) ready = false;
|
|
616
|
+
if (check.value !== undefined) entries.push([field.name, check.value]);
|
|
617
|
+
}
|
|
618
|
+
// `fromEntries` defines each name as a property of its own, also a name such as `__proto__`
|
|
619
|
+
return { ready, missing, content: Object.fromEntries(entries) };
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/** Text shown as the server or host wrote it, every character `patternArg` names shown by its code point. */
|
|
623
|
+
private visible(textArg: string, patternArg: RegExp): Array<string | TemplateResult> {
|
|
624
|
+
const parts: Array<string | TemplateResult> = [];
|
|
625
|
+
let last = 0;
|
|
626
|
+
for (const match of textArg.matchAll(patternArg)) {
|
|
627
|
+
const index = match.index!;
|
|
628
|
+
if (index > last) parts.push(textArg.slice(last, index));
|
|
629
|
+
const code = codePointOf(match[0]);
|
|
630
|
+
parts.push(html`<span class="hiddenChar" title=${this.t('elicitation.hiddenChar', { code })}>${code}</span>`);
|
|
631
|
+
last = index + match[0].length;
|
|
632
|
+
}
|
|
633
|
+
if (last < textArg.length) parts.push(textArg.slice(last));
|
|
634
|
+
return parts;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
public render(): TemplateResult {
|
|
638
|
+
const request = this.request;
|
|
639
|
+
if (!request) return html``;
|
|
640
|
+
const answered = this.answered;
|
|
641
|
+
return html`
|
|
642
|
+
<div class="card mode-${request.mode} ${answered ? 'answered' : 'waiting'}">
|
|
643
|
+
<div class="body">
|
|
644
|
+
<div class="titleRow">
|
|
645
|
+
<dees-icon icon=${MODE_ICON[request.mode]} iconSize="15" aria-hidden="true"></dees-icon>
|
|
646
|
+
<div class="titleText">
|
|
647
|
+
<span class="server">${this.visible(
|
|
648
|
+
request.serverName ? this.t('elicitation.asks', { server: request.serverName }) : this.t('elicitation.asksUnnamed'),
|
|
649
|
+
TEXT_HIDDEN,
|
|
650
|
+
)}</span>
|
|
651
|
+
<p class="message">${this.visible(request.message, TEXT_HIDDEN)}</p>
|
|
652
|
+
</div>
|
|
653
|
+
</div>
|
|
654
|
+
${answered
|
|
655
|
+
? html`
|
|
656
|
+
<div class="decision" tabindex="-1">
|
|
657
|
+
<dees-badge tone=${ANSWER_TONE[answered.action]} .text=${this.t('elicitation.answered', { action: answered.action })} rounded></dees-badge>
|
|
658
|
+
</div>
|
|
659
|
+
`
|
|
660
|
+
: html`
|
|
661
|
+
${this.renderRefusals(request)}
|
|
662
|
+
${request.mode === 'form'
|
|
663
|
+
? this.renderForm(request.fields)
|
|
664
|
+
: request.mode === 'url'
|
|
665
|
+
? this.renderUrl(request.url)
|
|
666
|
+
: this.renderUnsupported(request.reason)}
|
|
667
|
+
`}
|
|
668
|
+
</div>
|
|
669
|
+
${answered
|
|
670
|
+
? ''
|
|
671
|
+
: html`
|
|
672
|
+
<dees-actionfooter
|
|
673
|
+
source="harness-elicitation-card"
|
|
674
|
+
.actions=${this.actionsFor(request)}
|
|
675
|
+
.disabled=${this.busy}
|
|
676
|
+
></dees-actionfooter>
|
|
677
|
+
`}
|
|
678
|
+
</div>
|
|
679
|
+
`;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/** The host's refusals of the last answer that name no field of the form, over it; a refusal of a field alone says to look at the fields. */
|
|
683
|
+
private renderRefusals(requestArg: IHarnessElicitationRequest): TemplateResult | string {
|
|
684
|
+
const refusals = requestArg.refusals ?? [];
|
|
685
|
+
if (!refusals.length) return '';
|
|
686
|
+
const fieldNames = new Set(requestArg.mode === 'form' ? requestArg.fields.map((field) => field.name) : []);
|
|
687
|
+
const general = refusals.filter((refusal) => refusal.field === undefined || !fieldNames.has(refusal.field));
|
|
688
|
+
return html`
|
|
689
|
+
<div class="refusals" role="alert">
|
|
690
|
+
${general.length
|
|
691
|
+
? general.map((refusal) => html`<p class="refusal">${this.visible(refusal.reason, TEXT_HIDDEN)}</p>`)
|
|
692
|
+
: html`<p class="refusal">${this.t('elicitation.refused')}</p>`}
|
|
693
|
+
</div>
|
|
694
|
+
`;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
private renderForm(fieldsArg: readonly THarnessElicitationField[]): TemplateResult {
|
|
698
|
+
const form = this.checkForm(fieldsArg);
|
|
699
|
+
return html`
|
|
700
|
+
${fieldsArg.length
|
|
701
|
+
? html`<div class="fields">${fieldsArg.map((field, index) => this.renderField(field, index))}</div>`
|
|
702
|
+
: ''}
|
|
703
|
+
${form.missing ? html`<p class="note formMissing">${this.t('elicitation.missing')}</p>` : ''}
|
|
704
|
+
`;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/** One field: its label (a star for a required one), its control, its description, and what holds it back. */
|
|
708
|
+
private renderField(fieldArg: THarnessElicitationField, indexArg: number): TemplateResult {
|
|
709
|
+
const id = `elicitation-field-${indexArg}`;
|
|
710
|
+
const check = this.checkField(fieldArg);
|
|
711
|
+
const refusals: readonly IHarnessElicitationRefusal[] = (this.request?.refusals ?? []).filter((refusal) => refusal.field === fieldArg.name);
|
|
712
|
+
const invalid = check.problem !== undefined || refusals.length > 0;
|
|
713
|
+
const describedBy = [
|
|
714
|
+
fieldArg.description ? `${id}-hint` : '',
|
|
715
|
+
check.problem !== undefined ? `${id}-problem` : '',
|
|
716
|
+
...refusals.map((_refusal, refusalIndex) => `${id}-refusal-${refusalIndex}`),
|
|
717
|
+
].filter(Boolean).join(' ');
|
|
718
|
+
const label = html`${fieldArg.title ?? fieldArg.name}${fieldArg.required
|
|
719
|
+
? html`<span class="required" aria-hidden="true">*</span>`
|
|
720
|
+
: ''}`;
|
|
721
|
+
const textual = fieldArg.kind === 'text' || fieldArg.kind === 'number';
|
|
722
|
+
return html`
|
|
723
|
+
<div class="field" data-field=${indexArg}>
|
|
724
|
+
${textual
|
|
725
|
+
? html`<label class="fieldLabel" for=${id}>${label}</label>`
|
|
726
|
+
: html`<span class="fieldLabel" id="${id}-label">${label}</span>`}
|
|
727
|
+
${this.renderControl(fieldArg, id, invalid, describedBy)}
|
|
728
|
+
${fieldArg.description ? html`<p class="fieldHint" id="${id}-hint">${fieldArg.description}</p>` : ''}
|
|
729
|
+
${check.problem !== undefined ? html`<p class="fieldProblem" id="${id}-problem">${check.problem}</p>` : ''}
|
|
730
|
+
${refusals.map((refusal, refusalIndex) => html`
|
|
731
|
+
<p class="fieldRefusal" id="${id}-refusal-${refusalIndex}">${this.visible(refusal.reason, TEXT_HIDDEN)}</p>
|
|
732
|
+
`)}
|
|
733
|
+
</div>
|
|
734
|
+
`;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
private renderControl(fieldArg: THarnessElicitationField, idArg: string, invalidArg: boolean, describedByArg: string): TemplateResult {
|
|
738
|
+
const locked = this.locked;
|
|
739
|
+
const draft = this.#draftOf(fieldArg);
|
|
740
|
+
switch (fieldArg.kind) {
|
|
741
|
+
case 'text':
|
|
742
|
+
case 'number': {
|
|
743
|
+
const text = draft.kind === 'text' || draft.kind === 'number' ? draft.text : '';
|
|
744
|
+
const inputMode = fieldArg.kind === 'number'
|
|
745
|
+
? (fieldArg.minimum !== undefined && fieldArg.minimum >= 0 ? (fieldArg.integer ? 'numeric' : 'decimal') : 'text')
|
|
746
|
+
: fieldArg.format === 'email' ? 'email' : fieldArg.format === 'uri' ? 'url' : 'text';
|
|
747
|
+
const placeholder = fieldArg.kind === 'text' && fieldArg.format === 'date'
|
|
748
|
+
? this.t('elicitation.dateHint')
|
|
749
|
+
: fieldArg.kind === 'text' && fieldArg.format === 'date-time'
|
|
750
|
+
? this.t('elicitation.dateTimeHint')
|
|
751
|
+
: '';
|
|
752
|
+
// never a maxlength: the browser would count UTF-16 code units and cut what is pasted
|
|
753
|
+
return html`
|
|
754
|
+
<input
|
|
755
|
+
id=${idArg}
|
|
756
|
+
class="input"
|
|
757
|
+
type="text"
|
|
758
|
+
inputmode=${inputMode}
|
|
759
|
+
placeholder=${placeholder}
|
|
760
|
+
autocomplete="off"
|
|
761
|
+
autocapitalize="off"
|
|
762
|
+
spellcheck="false"
|
|
763
|
+
aria-required=${fieldArg.required ? 'true' : 'false'}
|
|
764
|
+
aria-invalid=${invalidArg ? 'true' : 'false'}
|
|
765
|
+
aria-describedby=${describedByArg}
|
|
766
|
+
.value=${text}
|
|
767
|
+
?disabled=${locked}
|
|
768
|
+
@input=${(eventArg: Event) => this.#setDraft(fieldArg, {
|
|
769
|
+
kind: fieldArg.kind,
|
|
770
|
+
text: (eventArg.currentTarget as HTMLInputElement).value,
|
|
771
|
+
})}
|
|
772
|
+
/>
|
|
773
|
+
`;
|
|
774
|
+
}
|
|
775
|
+
case 'boolean': {
|
|
776
|
+
const value = draft.kind === 'boolean' ? draft.value : undefined;
|
|
777
|
+
const options: Array<{ label: string; value: boolean }> = [
|
|
778
|
+
{ label: this.t('elicitation.yes'), value: true },
|
|
779
|
+
{ label: this.t('elicitation.no'), value: false },
|
|
780
|
+
];
|
|
781
|
+
return html`
|
|
782
|
+
<div
|
|
783
|
+
class="options"
|
|
784
|
+
role="radiogroup"
|
|
785
|
+
aria-labelledby="${idArg}-label"
|
|
786
|
+
aria-required=${fieldArg.required ? 'true' : 'false'}
|
|
787
|
+
aria-invalid=${invalidArg ? 'true' : 'false'}
|
|
788
|
+
aria-describedby=${describedByArg}
|
|
789
|
+
>
|
|
790
|
+
${options.map((option) => html`
|
|
791
|
+
<label class="optionRow">
|
|
792
|
+
<input
|
|
793
|
+
type="radio"
|
|
794
|
+
name=${idArg}
|
|
795
|
+
.checked=${value === option.value}
|
|
796
|
+
?disabled=${locked}
|
|
797
|
+
@change=${() => this.#setDraft(fieldArg, { kind: 'boolean', value: option.value })}
|
|
798
|
+
/>
|
|
799
|
+
<span class="optionLabel">${option.label}</span>
|
|
800
|
+
</label>
|
|
801
|
+
`)}
|
|
802
|
+
</div>
|
|
803
|
+
${!fieldArg.required && value !== undefined ? this.renderClear(() => this.#setDraft(fieldArg, { kind: 'boolean', value: undefined })) : ''}
|
|
804
|
+
`;
|
|
805
|
+
}
|
|
806
|
+
case 'choice': {
|
|
807
|
+
const value = draft.kind === 'choice' ? draft.value : undefined;
|
|
808
|
+
return html`
|
|
809
|
+
<div
|
|
810
|
+
class="options"
|
|
811
|
+
role="radiogroup"
|
|
812
|
+
aria-labelledby="${idArg}-label"
|
|
813
|
+
aria-required=${fieldArg.required ? 'true' : 'false'}
|
|
814
|
+
aria-invalid=${invalidArg ? 'true' : 'false'}
|
|
815
|
+
aria-describedby=${describedByArg}
|
|
816
|
+
>
|
|
817
|
+
${fieldArg.options.map((option: IHarnessElicitationOption) => html`
|
|
818
|
+
<label class="optionRow">
|
|
819
|
+
<input
|
|
820
|
+
type="radio"
|
|
821
|
+
name=${idArg}
|
|
822
|
+
.checked=${value === option.value}
|
|
823
|
+
?disabled=${locked}
|
|
824
|
+
@change=${() => this.#setDraft(fieldArg, { kind: 'choice', value: option.value })}
|
|
825
|
+
/>
|
|
826
|
+
<span class="optionLabel">${option.label}</span>
|
|
827
|
+
</label>
|
|
828
|
+
`)}
|
|
829
|
+
</div>
|
|
830
|
+
${!fieldArg.required && value !== undefined ? this.renderClear(() => this.#setDraft(fieldArg, { kind: 'choice', value: undefined })) : ''}
|
|
831
|
+
`;
|
|
832
|
+
}
|
|
833
|
+
case 'choices': {
|
|
834
|
+
const values = new Set(draft.kind === 'choices' ? draft.values : []);
|
|
835
|
+
return html`
|
|
836
|
+
<div
|
|
837
|
+
class="options"
|
|
838
|
+
role="group"
|
|
839
|
+
aria-labelledby="${idArg}-label"
|
|
840
|
+
aria-invalid=${invalidArg ? 'true' : 'false'}
|
|
841
|
+
aria-describedby=${describedByArg}
|
|
842
|
+
>
|
|
843
|
+
${fieldArg.options.map((option: IHarnessElicitationOption) => html`
|
|
844
|
+
<label class="optionRow">
|
|
845
|
+
<input
|
|
846
|
+
type="checkbox"
|
|
847
|
+
.checked=${values.has(option.value)}
|
|
848
|
+
?disabled=${locked}
|
|
849
|
+
@change=${(eventArg: Event) => {
|
|
850
|
+
const next = new Set(values);
|
|
851
|
+
if ((eventArg.currentTarget as HTMLInputElement).checked) next.add(option.value);
|
|
852
|
+
else next.delete(option.value);
|
|
853
|
+
this.#setDraft(fieldArg, { kind: 'choices', values: [...next] });
|
|
854
|
+
}}
|
|
855
|
+
/>
|
|
856
|
+
<span class="optionLabel">${option.label}</span>
|
|
857
|
+
</label>
|
|
858
|
+
`)}
|
|
859
|
+
</div>
|
|
860
|
+
`;
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
private renderClear(clearArg: () => void): TemplateResult {
|
|
866
|
+
return html`<button class="clear" type="button" ?disabled=${this.locked} @click=${clearArg}>${this.t('elicitation.clear')}</button>`;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/** The address as text, exactly: no link, nothing that opens or loads it. */
|
|
870
|
+
private renderUrl(urlArg: string): TemplateResult {
|
|
871
|
+
return html`
|
|
872
|
+
<div class="address">
|
|
873
|
+
<span class="addressLabel" aria-hidden="true">${this.t('elicitation.urlLabel')}</span>
|
|
874
|
+
<code class="addressText"><span class="srOnly">${this.t('elicitation.urlLabel')}: </span>${this.visible(urlArg, URL_HIDDEN)}</code>
|
|
875
|
+
</div>
|
|
876
|
+
<p class="note">${this.t('elicitation.urlNote')}</p>
|
|
877
|
+
`;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
private renderUnsupported(reasonArg: string): TemplateResult {
|
|
881
|
+
return html`
|
|
882
|
+
<p class="reason">${this.visible(reasonArg, TEXT_HIDDEN)}</p>
|
|
883
|
+
<p class="note">${this.t('elicitation.unsupportedNote')}</p>
|
|
884
|
+
`;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Decline and Cancel, then the accept of the mode as the primary: Send for a form (waiting while
|
|
889
|
+
* it is not ready), Mark as done for an address. A request the host cannot collect has no accept.
|
|
890
|
+
*/
|
|
891
|
+
private actionsFor(requestArg: IHarnessElicitationRequest): IActionFooterAction[] {
|
|
892
|
+
const decline = this.t('elicitation.decline');
|
|
893
|
+
const cancel = this.t('elicitation.cancel');
|
|
894
|
+
const accept = requestArg.mode === 'form' ? this.t('elicitation.send') : this.t('elicitation.markDone');
|
|
895
|
+
const held = requestArg.mode === 'form' && !this.checkForm(requestArg.fields).ready;
|
|
896
|
+
const key = [requestArg.mode, decline, cancel, accept, held].join('\u0000');
|
|
897
|
+
if (this.#footer?.key !== key) {
|
|
898
|
+
this.#footer = {
|
|
899
|
+
key,
|
|
900
|
+
actions: [
|
|
901
|
+
{ name: decline, primary: false, action: async () => this.respond('decline') },
|
|
902
|
+
{ name: cancel, primary: false, action: async () => this.respond('cancel') },
|
|
903
|
+
...(requestArg.mode === 'unsupported'
|
|
904
|
+
? []
|
|
905
|
+
: [{ name: accept, primary: true, disabled: held, action: async () => this.respond('accept') }]),
|
|
906
|
+
],
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
return this.#footer.actions;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/** Answers the request: the form's content with an accept of a form, nothing else with any other answer. */
|
|
913
|
+
private respond(actionArg: THarnessElicitationAction): void {
|
|
914
|
+
const request = this.request;
|
|
915
|
+
if (!request || this.locked) return;
|
|
916
|
+
if (actionArg === 'accept' && request.mode === 'unsupported') return;
|
|
917
|
+
let content: THarnessElicitationContent | undefined;
|
|
918
|
+
if (actionArg === 'accept' && request.mode === 'form') {
|
|
919
|
+
const form = this.checkForm(request.fields);
|
|
920
|
+
if (!form.ready) return;
|
|
921
|
+
content = form.content;
|
|
922
|
+
}
|
|
923
|
+
// the footer leaves with the answer: its focus moves to the decision that takes its place
|
|
924
|
+
const footerFocused = this.shadowRoot?.activeElement?.localName === 'dees-actionfooter';
|
|
925
|
+
this.answered = { action: actionArg, signature: signatureOf(request), refusals: request.refusals };
|
|
926
|
+
if (footerFocused) {
|
|
927
|
+
void this.updateComplete.then(() => this.shadowRoot?.querySelector<HTMLElement>('.decision')?.focus());
|
|
928
|
+
}
|
|
929
|
+
const detail: IHarnessElicitationResponseDetail = content
|
|
930
|
+
? { requestId: request.id, action: actionArg, content }
|
|
931
|
+
: { requestId: request.id, action: actionArg };
|
|
932
|
+
this.dispatchEvent(new CustomEvent<IHarnessElicitationResponseDetail>('harness-elicitation-response', {
|
|
933
|
+
detail,
|
|
934
|
+
bubbles: true,
|
|
935
|
+
composed: true,
|
|
936
|
+
}));
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* Typing in a field raises events that cross into the page, and an input or a key event can
|
|
941
|
+
* carry what is typed: they stop at the card, after its own fields took them. A key that only
|
|
942
|
+
* moves, deletes or runs a shortcut passes on.
|
|
943
|
+
*/
|
|
944
|
+
readonly #holdTyping = (eventArg: Event): void => {
|
|
945
|
+
const origin = eventArg.composedPath()[0];
|
|
946
|
+
if (!(origin instanceof HTMLInputElement)) return;
|
|
947
|
+
if (eventArg instanceof KeyboardEvent && (!origin.classList.contains('input') || !typesCharacter(eventArg))) return;
|
|
948
|
+
eventArg.stopPropagation();
|
|
949
|
+
};
|
|
950
|
+
|
|
951
|
+
protected createRenderRoot(): HTMLElement | DocumentFragment {
|
|
952
|
+
const root = super.createRenderRoot();
|
|
953
|
+
for (const type of ['beforeinput', 'input', 'textInput', 'compositionstart', 'compositionupdate', 'compositionend', 'paste', 'drop', 'keydown', 'keypress', 'keyup']) {
|
|
954
|
+
root.addEventListener(type, this.#holdTyping);
|
|
955
|
+
}
|
|
956
|
+
return root;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
public willUpdate(changedProperties: Map<PropertyKey, unknown>): void {
|
|
960
|
+
super.willUpdate(changedProperties);
|
|
961
|
+
const request = this.request;
|
|
962
|
+
// another request: nothing entered for the last one, and no answer to it, carries over
|
|
963
|
+
if (request?.id !== this.#requestId) {
|
|
964
|
+
this.#requestId = request?.id;
|
|
965
|
+
this.#drafts = new Map<string, TDraft>();
|
|
966
|
+
this.answered = undefined;
|
|
967
|
+
}
|
|
968
|
+
if (request?.mode === 'form') {
|
|
969
|
+
// a field the request no longer has takes what was entered in it along
|
|
970
|
+
const names = new Set(request.fields.map((field) => field.name));
|
|
971
|
+
for (const name of [...this.#drafts.keys()]) if (!names.has(name)) this.#drafts.delete(name);
|
|
972
|
+
}
|
|
973
|
+
// the host changed the request since the answer: the card takes an answer again
|
|
974
|
+
if (this.answered && (!request || this.#changedSinceAnswer(request, this.answered))) this.answered = undefined;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* Whether the host changed the request since the owner answered it: it reads otherwise, or it
|
|
979
|
+
* carries a refusal the host made since, a `refusals` array other than the one answered, even
|
|
980
|
+
* one that reads as that did (the host refused the same way again).
|
|
981
|
+
*/
|
|
982
|
+
#changedSinceAnswer(
|
|
983
|
+
requestArg: IHarnessElicitationRequest,
|
|
984
|
+
answeredArg: { signature: string; refusals: IHarnessElicitationRequest['refusals'] },
|
|
985
|
+
): boolean {
|
|
986
|
+
if (signatureOf(requestArg) !== answeredArg.signature) return true;
|
|
987
|
+
return requestArg.refusals !== undefined && requestArg.refusals.length > 0 && requestArg.refusals !== answeredArg.refusals;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
public async disconnectedCallback(): Promise<void> {
|
|
991
|
+
// a card a keyed list moves is connected again before this runs, and keeps what was entered
|
|
992
|
+
queueMicrotask(() => {
|
|
993
|
+
if (!this.isConnected) this.#forgetDrafts();
|
|
994
|
+
});
|
|
995
|
+
await super.disconnectedCallback();
|
|
996
|
+
}
|
|
997
|
+
}
|