@design.estate/dees-catalog 21.35.0 → 21.36.1

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 (37) hide show
  1. package/dist_bundle/bundle.js +614 -66
  2. package/dist_bundle/bundle.js.map +1 -1
  3. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-5CNZ4UM3.js → chunk-3YTKY5IS.js} +6 -2
  4. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-5CNZ4UM3.js.map → chunk-3YTKY5IS.js.map} +1 -1
  5. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-PHFZ5EZN.js → chunk-5UGXWLMH.js} +3 -3
  6. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-KY5Z6Y6T.js → chunk-ZCZ72OW4.js} +2 -2
  7. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{de-AGABQ27E.js → de-PERXVUIS.js} +6 -2
  8. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{de-AGABQ27E.js.map → de-PERXVUIS.js.map} +1 -1
  9. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-modal-QBFEQURL.js → dees-modal-4QORKLGX.js} +3 -3
  10. package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-workspace-terminal-UYSWDBV4.js → dees-workspace-terminal-7SYZG2AB.js} +4 -4
  11. package/dist_ts_web/00_commitinfo_data.js +1 -1
  12. package/dist_ts_web/elements/00group-harness/dees-harness-chat/dees-harness-chat.d.ts +5 -1
  13. package/dist_ts_web/elements/00group-harness/dees-harness-chat/dees-harness-chat.js +11 -1
  14. package/dist_ts_web/elements/00group-harness/dees-harness-message-list/dees-harness-message-list.d.ts +28 -1
  15. package/dist_ts_web/elements/00group-harness/dees-harness-message-list/dees-harness-message-list.js +78 -1
  16. package/dist_ts_web/elements/00group-harness/dees-harness-question-card/dees-harness-question-card.d.ts +75 -3
  17. package/dist_ts_web/elements/00group-harness/dees-harness-question-card/dees-harness-question-card.demo.js +140 -44
  18. package/dist_ts_web/elements/00group-harness/dees-harness-question-card/dees-harness-question-card.js +502 -16
  19. package/dist_ts_web/elements/00group-harness/interfaces.d.ts +72 -0
  20. package/dist_ts_web/i18n/de.d.ts +16 -0
  21. package/dist_ts_web/i18n/de.js +5 -1
  22. package/dist_ts_web/i18n/messages.d.ts +16 -0
  23. package/dist_ts_web/i18n/messages.js +5 -1
  24. package/package.json +1 -1
  25. package/readme.md +38 -1
  26. package/ts_web/00_commitinfo_data.ts +1 -1
  27. package/ts_web/elements/00group-harness/dees-harness-chat/dees-harness-chat.ts +17 -0
  28. package/ts_web/elements/00group-harness/dees-harness-message-list/dees-harness-message-list.ts +83 -0
  29. package/ts_web/elements/00group-harness/dees-harness-question-card/dees-harness-question-card.demo.ts +106 -2
  30. package/ts_web/elements/00group-harness/dees-harness-question-card/dees-harness-question-card.ts +486 -14
  31. package/ts_web/elements/00group-harness/interfaces.ts +77 -0
  32. package/ts_web/i18n/de.ts +4 -0
  33. package/ts_web/i18n/messages.ts +4 -0
  34. /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-PHFZ5EZN.js.map → chunk-5UGXWLMH.js.map} +0 -0
  35. /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{chunk-KY5Z6Y6T.js.map → chunk-ZCZ72OW4.js.map} +0 -0
  36. /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-modal-QBFEQURL.js.map → dees-modal-4QORKLGX.js.map} +0 -0
  37. /package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/{dees-workspace-terminal-UYSWDBV4.js.map → dees-workspace-terminal-7SYZG2AB.js.map} +0 -0
@@ -14,6 +14,7 @@ import { themeDefaultStyles } from '../../00theme.js';
14
14
  import { harnessActivityStyles, harnessControlStyles } from '../harness.styles.js';
15
15
  import { harnessProposalState, harnessQuestionSeverity, harnessWithoutCredentials } from '../harness.helpers.js';
16
16
  import {
17
+ harnessRecordsShown,
17
18
  harnessShownRecords,
18
19
  harnessRecordStyles,
19
20
  renderHarnessChanges,
@@ -24,6 +25,10 @@ import {
24
25
  import type {
25
26
  IHarnessProposalItem,
26
27
  IHarnessQuestionLinkDetail,
28
+ IHarnessQuestionPersonField,
29
+ IHarnessQuestionPersonResult,
30
+ IHarnessQuestionPersonValue,
31
+ IHarnessQuestionRejection,
27
32
  IHarnessQuestionRequest,
28
33
  IHarnessQuestionResponseDetail,
29
34
  IHarnessQuestionViewState,
@@ -57,6 +62,21 @@ const ITEM_ICON: Record<Exclude<THarnessQuestionSeverity, 'info'>, string> = {
57
62
  /** A credential's value while hidden: the same length for every secret, so it tells nothing of it. */
58
63
  const CREDENTIAL_MASK = '••••••••••••';
59
64
 
65
+ /** A person field's value by its change and its own id, which is unique within the change only. */
66
+ const personKey = (itemIdArg: string, fieldIdArg: string): string => `${itemIdArg}\u0000${fieldIdArg}`;
67
+
68
+ const NO_PERSON_RESULTS: readonly IHarnessQuestionPersonResult[] = [];
69
+
70
+ /** A link result's address, where it is an http or https one; any other is shown as text. */
71
+ const httpHref = (valueArg: string): string | undefined => {
72
+ try {
73
+ const url = new URL(valueArg);
74
+ return url.protocol === 'http:' || url.protocol === 'https:' ? url.href : undefined;
75
+ } catch {
76
+ return undefined;
77
+ }
78
+ };
79
+
60
80
  /** The badge of each decided state. */
61
81
  const STATE_BADGE: Record<Exclude<THarnessProposalState, 'pending'>, 'success' | 'default' | 'error'> = {
62
82
  confirmed: 'success',
@@ -89,6 +109,19 @@ const STATE_BADGE: Record<Exclude<THarnessProposalState, 'pending'>, 'success' |
89
109
  * while `busy`, and once its changes are under way. A change's `credential`
90
110
  * (a secret it issued) shows to the reader only, masked until asked for;
91
111
  * no event the card emits carries it.
112
+ *
113
+ * A change may need values from the person and from nobody else
114
+ * (`personFields`): entered under the change while the proposal waits, a
115
+ * secret one masked until shown, and sent with the confirmation only, as its
116
+ * `personValues`. A required field left empty or a value over its
117
+ * `maxLength` holds Confirm back; a decline sends none. The card keeps them
118
+ * neither in its view state nor once it answered, was given another request
119
+ * or left the page. What the confirmed changes return to the person, the host
120
+ * hands to the card as `personResults`, shown under their change (a secret
121
+ * masked until shown, a link only to an http or https address) and kept as
122
+ * briefly. A host that refuses a confirmation it was sent asks again with
123
+ * `rejectResponse()`: the card waits once more, keeps the changes the reader
124
+ * left out, and says why at each value the host named.
92
125
  */
93
126
  @customElement('dees-harness-question-card')
94
127
  export class DeesHarnessQuestionCard extends DeesElement {
@@ -128,7 +161,30 @@ export class DeesHarnessQuestionCard extends DeesElement {
128
161
  accessor credentialsShown: ReadonlySet<string> = new Set<string>();
129
162
 
130
163
  @state()
131
- accessor copyFeedback: { itemId: string; text: string; failed: boolean } | undefined = undefined;
164
+ accessor copyFeedback: { key: string; text: string; failed: boolean } | undefined = undefined;
165
+
166
+ /**
167
+ * What the confirmed changes returned to the person, from the host after its own confirmation:
168
+ * kept by this element alone, until it is given another request or leaves the page.
169
+ */
170
+ @property({ attribute: false })
171
+ accessor personResults: readonly IHarnessQuestionPersonResult[] = NO_PERSON_RESULTS;
172
+
173
+ /** what the person entered in `personFields`, by `personKey`; never in the view state, and gone with the answer */
174
+ @state()
175
+ accessor personValues: ReadonlyMap<string, string> = new Map<string, string>();
176
+
177
+ /** the secret fields the person shows as typed, by `personKey` */
178
+ @state()
179
+ accessor personFieldsShown: ReadonlySet<string> = new Set<string>();
180
+
181
+ /** the secret results the person asked to see, by result id */
182
+ @state()
183
+ accessor personResultsShown: ReadonlySet<string> = new Set<string>();
184
+
185
+ /** why the host refused the last confirmation, until the next answer; the view state keeps it over a remount */
186
+ @state()
187
+ accessor rejection: IHarnessQuestionRejection | undefined = undefined;
132
188
 
133
189
  private copyRequest = 0;
134
190
  private copyResetTimeout: ReturnType<typeof setTimeout> | undefined;
@@ -174,6 +230,35 @@ export class DeesHarnessQuestionCard extends DeesElement {
174
230
  return new Set((this.request.items ?? []).filter((item) => chosen.has(item.id)).map((item) => item.id));
175
231
  }
176
232
 
233
+ /** A change's person fields, those of a proposal only. */
234
+ private personFieldsOf(itemIdArg: string): readonly IHarnessQuestionPersonField[] {
235
+ if (this.request.kind !== 'proposal') return [];
236
+ return (this.request.personFields ?? []).filter((field) => field.itemId === itemIdArg);
237
+ }
238
+
239
+ /** The person fields a confirmation sends: those of the changes it includes. */
240
+ private get includedPersonFields(): readonly IHarnessQuestionPersonField[] {
241
+ if (this.request.kind !== 'proposal' || !this.request.personFields?.length) return [];
242
+ const leftOut = this.effectiveLeftOut;
243
+ const included = new Set((this.request.items ?? []).filter((item) => !leftOut.has(item.id)).map((item) => item.id));
244
+ return this.request.personFields.filter((field) => included.has(field.itemId));
245
+ }
246
+
247
+ private personValueOf(fieldArg: IHarnessQuestionPersonField): string {
248
+ return this.personValues.get(personKey(fieldArg.itemId, fieldArg.id)) ?? '';
249
+ }
250
+
251
+ /** Whether a required field of an included change is still empty. */
252
+ private get personFieldsMissing(): boolean {
253
+ return this.includedPersonFields.some((field) => field.required === true && this.personValueOf(field).trim() === '');
254
+ }
255
+
256
+ /** Whether the included changes have every value they need, none of them too long. */
257
+ private get personFieldsComplete(): boolean {
258
+ return !this.personFieldsMissing
259
+ && this.includedPersonFields.every((field) => this.personValueOf(field).length <= field.maxLength);
260
+ }
261
+
177
262
  /** Whether the card takes no answer: answered, waiting for the host (`busy`), or its changes under way or decided. */
178
263
  private get locked(): boolean {
179
264
  return this.busy || this.effectiveResponse !== undefined || this.proposalState !== 'pending';
@@ -479,6 +564,130 @@ export class DeesHarnessQuestionCard extends DeesElement {
479
564
  color: var(--dees-color-text-secondary);
480
565
  font-size: var(--dees-font-caption1-size, 11px);
481
566
  }
567
+
568
+ .personResultText {
569
+ flex: 1 1 12em;
570
+ min-width: 0;
571
+ color: var(--dees-color-text-primary);
572
+ overflow-wrap: anywhere;
573
+ }
574
+
575
+ .personResultLink {
576
+ flex: 1 1 12em;
577
+ min-width: 0;
578
+ color: var(--dees-color-accent-primary);
579
+ overflow-wrap: anywhere;
580
+ border-radius: var(--dees-radius-xs);
581
+ }
582
+
583
+ .personResultLink:focus-visible {
584
+ outline: var(--dees-line-width-focus-ring) solid var(--dees-color-focus-ring);
585
+ outline-offset: 2px;
586
+ }
587
+
588
+ .personFields {
589
+ display: grid;
590
+ gap: var(--dees-spacing-sm);
591
+ margin-top: 4px;
592
+ }
593
+
594
+ .personField {
595
+ display: grid;
596
+ gap: 4px;
597
+ min-width: 0;
598
+ }
599
+
600
+ .personLabel {
601
+ justify-self: start;
602
+ color: var(--dees-color-text-secondary);
603
+ font-weight: 500;
604
+ }
605
+
606
+ .personLabel .required {
607
+ margin-left: var(--dees-spacing-2xs);
608
+ color: var(--dees-color-accent-error);
609
+ }
610
+
611
+ .personInputRow {
612
+ display: flex;
613
+ align-items: center;
614
+ gap: var(--dees-spacing-sm);
615
+ min-width: 0;
616
+ }
617
+
618
+ .personInput {
619
+ flex: 1;
620
+ min-width: 0;
621
+ height: var(--dees-control-height-md);
622
+ padding: 0 var(--dees-spacing-sm);
623
+ border: var(--dees-line-width-hairline) solid var(--dees-color-border-default);
624
+ border-radius: var(--dees-radius-md);
625
+ corner-shape: var(--dees-corner-shape);
626
+ background: var(--dees-color-bg-primary);
627
+ color: var(--dees-color-text-primary);
628
+ font-family: inherit;
629
+ font-size: var(--dees-font-control-size-sm, 12px);
630
+ outline: none;
631
+ }
632
+
633
+ .personInput.secret {
634
+ font-family: var(--dees-font-family-mono);
635
+ }
636
+
637
+ textarea.personInput {
638
+ height: auto;
639
+ min-height: calc(var(--dees-control-height-md) * 2);
640
+ padding: 6px var(--dees-spacing-sm);
641
+ line-height: 1.4;
642
+ resize: vertical;
643
+ }
644
+
645
+ /* a secret of several lines has no password input: it is masked as one is */
646
+ textarea.personInput.masked {
647
+ -webkit-text-security: disc;
648
+ }
649
+
650
+ .personInput:focus {
651
+ border-color: var(--dees-color-accent-primary);
652
+ box-shadow: 0 0 0 var(--dees-line-width-focus-ring) var(--dees-color-focus-ring);
653
+ }
654
+
655
+ .personInput[aria-invalid='true'] {
656
+ border-color: var(--dees-color-accent-error);
657
+ }
658
+
659
+ .personInput:disabled {
660
+ cursor: default;
661
+ opacity: 0.6;
662
+ }
663
+
664
+ .personHint,
665
+ .personError,
666
+ .personNote {
667
+ margin: 0;
668
+ color: var(--dees-color-text-secondary);
669
+ font-size: var(--dees-font-caption1-size, 11px);
670
+ }
671
+
672
+ .personError {
673
+ color: var(--dees-color-text-error);
674
+ }
675
+
676
+ .personNote + .personNote {
677
+ margin-top: var(--dees-spacing-2xs);
678
+ }
679
+
680
+ .rejection {
681
+ margin: 0 0 12px;
682
+ padding: 8px 12px;
683
+ border: var(--dees-line-width-hairline) solid var(--dees-color-accent-error);
684
+ border-radius: var(--dees-radius-lg);
685
+ corner-shape: var(--dees-corner-shape);
686
+ background: var(--dees-color-badge-error-bg);
687
+ color: var(--dees-color-badge-error-fg);
688
+ font-size: var(--dees-font-control-size-sm, 12px);
689
+ overflow-wrap: anywhere;
690
+ }
482
691
  `,
483
692
  ];
484
693
 
@@ -589,8 +798,17 @@ export class DeesHarnessQuestionCard extends DeesElement {
589
798
  /** The proposed changes and, once decided, the state and what came of it. */
590
799
  private renderProposal(): TemplateResult {
591
800
  const items = this.request.items ?? [];
592
- const expanded = this.effectiveItemsExpanded;
593
801
  const proposalState = this.proposalState;
802
+ const pending = proposalState === 'pending';
803
+ // a change that asks the person for values, or returned some, is never folded away
804
+ const personItems = new Set([
805
+ ...(pending ? (this.request.personFields ?? []).map((field) => field.itemId) : []),
806
+ ...this.personResults.map((result) => result.itemId),
807
+ ]);
808
+ const unfolded = !this.effectiveItemsExpanded && items.slice(harnessRecordsShown).some((item) => personItems.has(item.id));
809
+ const expanded = this.effectiveItemsExpanded || unfolded;
810
+ const itemIds = new Set(items.map((item) => item.id));
811
+ const otherResults = this.personResults.filter((result) => !itemIds.has(result.itemId));
594
812
  // the reader chooses while the proposal waits; a confirmed one names what was left out
595
813
  const choosing = this.itemsDeclinable && proposalState === 'pending';
596
814
  const leftOut = choosing || proposalState === 'confirmed' || proposalState === 'failed'
@@ -633,14 +851,22 @@ export class DeesHarnessQuestionCard extends DeesElement {
633
851
  : html`<span class="itemLabel">${item.label}</span>`
634
852
  : ''}
635
853
  ${item.changes?.length ? renderHarnessChanges(this.t, item.changes) : ''}
854
+ ${pending && !isLeftOut && this.personFieldsOf(item.id).length
855
+ ? this.renderPersonFields(this.personFieldsOf(item.id))
856
+ : ''}
636
857
  ${item.credential ? this.renderCredential(item) : ''}
858
+ ${this.personResults.some((result) => result.itemId === item.id)
859
+ ? this.renderPersonResults(this.personResults.filter((result) => result.itemId === item.id))
860
+ : ''}
637
861
  </li>
638
862
  `;
639
863
  })}
640
864
  </ul>
641
- ${renderHarnessMoreRecords(this.t, items.length, expanded, this.toggleItems)}
865
+ ${unfolded ? '' : renderHarnessMoreRecords(this.t, items.length, expanded, this.toggleItems)}
642
866
  `
643
867
  : ''}
868
+ ${otherResults.length ? this.renderPersonResults(otherResults) : ''}
869
+ ${pending ? this.renderPersonNotes() : ''}
644
870
  ${proposalState === 'pending'
645
871
  ? ''
646
872
  : html`
@@ -659,7 +885,7 @@ export class DeesHarnessQuestionCard extends DeesElement {
659
885
  private renderCredential(itemArg: IHarnessProposalItem): TemplateResult {
660
886
  const credential = itemArg.credential!;
661
887
  const shown = this.credentialsShown.has(itemArg.id);
662
- const feedback = this.copyFeedback?.itemId === itemArg.id ? this.copyFeedback : undefined;
888
+ const feedback = this.copyFeedback?.key === `credential:${itemArg.id}` ? this.copyFeedback : undefined;
663
889
  return html`
664
890
  <div class="credential">
665
891
  <div class="credentialRow">
@@ -677,7 +903,7 @@ export class DeesHarnessQuestionCard extends DeesElement {
677
903
  class="credentialAction"
678
904
  type="button"
679
905
  aria-label=${this.t('question.credentialCopy', { label: credential.label })}
680
- @click=${() => this.copyCredential(itemArg)}
906
+ @click=${() => this.copySecret(`credential:${itemArg.id}`, credential.label, credential.value)}
681
907
  >${this.t('common.copy')}</button>
682
908
  <span class="credentialFeedback ${feedback?.failed ? 'failed' : ''}" role="status" aria-live="polite">${feedback?.text ?? ''}</span>
683
909
  </div>
@@ -686,31 +912,180 @@ export class DeesHarnessQuestionCard extends DeesElement {
686
912
  `;
687
913
  }
688
914
 
915
+ /** The values a change needs from the person, under it while the proposal waits. */
916
+ private renderPersonFields(fieldsArg: readonly IHarnessQuestionPersonField[]): TemplateResult {
917
+ return html`<div class="personFields">${fieldsArg.map((field) => this.renderPersonField(field))}</div>`;
918
+ }
919
+
920
+ /**
921
+ * One value for the person to enter: labelled, a secret masked until shown, its hint, and what
922
+ * holds it back: too long, or refused by the host. It is not cut at its `maxLength`: a pasted
923
+ * secret cut short would be a wrong one.
924
+ */
925
+ private renderPersonField(fieldArg: IHarnessQuestionPersonField): TemplateResult {
926
+ const key = personKey(fieldArg.itemId, fieldArg.id);
927
+ const domId = `person-field-${(this.request.personFields ?? []).indexOf(fieldArg)}`;
928
+ const value = this.personValues.get(key) ?? '';
929
+ const secret = fieldArg.input === 'secret';
930
+ const shown = this.personFieldsShown.has(key);
931
+ const error = value.length > fieldArg.maxLength
932
+ ? this.t('question.personTooLong', { max: fieldArg.maxLength, count: value.length })
933
+ : this.effectiveRejection?.fieldErrors?.find((entry) => entry.itemId === fieldArg.itemId && entry.fieldId === fieldArg.id)?.message;
934
+ const describedBy = [fieldArg.hint ? `${domId}-hint` : '', error ? `${domId}-error` : ''].filter(Boolean).join(' ');
935
+ const input = (eventArg: Event) => this.setPersonValue(fieldArg, (eventArg.currentTarget as HTMLInputElement | HTMLTextAreaElement).value);
936
+ // a secret is never the person's own login: browsers and password managers offer none for it
937
+ const autocomplete = secret ? 'new-password' : 'off';
938
+ return html`
939
+ <div class="personField">
940
+ <label class="personLabel" for=${domId}>${fieldArg.label}${fieldArg.required
941
+ ? html`<span class="required" aria-hidden="true">*</span>`
942
+ : ''}</label>
943
+ <div class="personInputRow">
944
+ ${fieldArg.multiline
945
+ ? html`
946
+ <textarea
947
+ id=${domId}
948
+ class="personInput ${secret ? 'secret' : ''} ${secret && !shown ? 'masked' : ''}"
949
+ rows="3"
950
+ autocomplete=${autocomplete}
951
+ spellcheck=${secret ? 'false' : 'true'}
952
+ aria-required=${fieldArg.required ? 'true' : 'false'}
953
+ aria-invalid=${error ? 'true' : 'false'}
954
+ aria-describedby=${describedBy}
955
+ .value=${value}
956
+ ?disabled=${this.locked}
957
+ @input=${input}
958
+ ></textarea>
959
+ `
960
+ : html`
961
+ <input
962
+ id=${domId}
963
+ class="personInput ${secret ? 'secret' : ''}"
964
+ type=${secret && !shown ? 'password' : 'text'}
965
+ autocomplete=${autocomplete}
966
+ spellcheck=${secret ? 'false' : 'true'}
967
+ aria-required=${fieldArg.required ? 'true' : 'false'}
968
+ aria-invalid=${error ? 'true' : 'false'}
969
+ aria-describedby=${describedBy}
970
+ .value=${value}
971
+ ?disabled=${this.locked}
972
+ @input=${input}
973
+ />
974
+ `}
975
+ ${secret
976
+ ? html`
977
+ <button
978
+ class="credentialAction"
979
+ type="button"
980
+ aria-controls=${domId}
981
+ aria-label=${this.t(shown ? 'question.credentialHide' : 'question.credentialShow', { label: fieldArg.label })}
982
+ @click=${() => this.togglePersonField(key)}
983
+ >${this.t(shown ? 'question.credentialHideShort' : 'question.credentialShowShort')}</button>
984
+ `
985
+ : ''}
986
+ </div>
987
+ ${fieldArg.hint ? html`<p class="personHint" id="${domId}-hint">${fieldArg.hint}</p>` : ''}
988
+ ${error ? html`<p class="personError" id="${domId}-error">${error}</p>` : ''}
989
+ </div>
990
+ `;
991
+ }
992
+
993
+ /**
994
+ * Under the changes of a waiting proposal: the host's refusal of the last confirmation, that
995
+ * what the person enters goes nowhere but with the confirmation, and what still holds it back.
996
+ */
997
+ private renderPersonNotes(): TemplateResult {
998
+ const rejection = this.effectiveRejection;
999
+ const rejectionText = rejection?.message ?? (rejection?.fieldErrors?.length ? this.t('question.rejected') : '');
1000
+ const fields = this.includedPersonFields.length > 0;
1001
+ return html`
1002
+ ${rejectionText ? html`<p class="rejection" role="alert">${rejectionText}</p>` : ''}
1003
+ ${fields ? html`<p class="personNote">${this.t('question.personFieldsNote')}</p>` : ''}
1004
+ ${fields && !this.locked && this.personFieldsMissing
1005
+ ? html`<p class="personNote personMissing">${this.t('question.personFieldsMissing')}</p>`
1006
+ : ''}
1007
+ `;
1008
+ }
1009
+
1010
+ /** What the confirmed changes returned to the person: a secret masked until shown, a link to an http or https address only. */
1011
+ private renderPersonResults(resultsArg: readonly IHarnessQuestionPersonResult[]): TemplateResult {
1012
+ return html`
1013
+ <div class="credential personResults">
1014
+ ${resultsArg.map((result) => html`
1015
+ <div class="credentialRow">
1016
+ <span class="credentialLabel">${result.label}</span>
1017
+ ${this.renderPersonResultValue(result)}
1018
+ </div>
1019
+ `)}
1020
+ <p class="credentialNote">${this.t('question.credentialNote')}</p>
1021
+ </div>
1022
+ `;
1023
+ }
1024
+
1025
+ private renderPersonResultValue(resultArg: IHarnessQuestionPersonResult): TemplateResult {
1026
+ if (resultArg.display === 'link') {
1027
+ const href = httpHref(resultArg.value);
1028
+ return href
1029
+ ? html`<a class="personResultLink" href=${href} target="_blank" rel="noopener noreferrer" referrerpolicy="no-referrer">${resultArg.value}</a>`
1030
+ : html`<span class="personResultText">${resultArg.value}</span>`;
1031
+ }
1032
+ if (resultArg.display !== 'secret') return html`<span class="personResultText">${resultArg.value}</span>`;
1033
+ const shown = this.personResultsShown.has(resultArg.id);
1034
+ const feedback = this.copyFeedback?.key === `result:${resultArg.id}` ? this.copyFeedback : undefined;
1035
+ return html`
1036
+ <code class="credentialValue">${shown
1037
+ ? resultArg.value
1038
+ : html`<span aria-hidden="true">${CREDENTIAL_MASK}</span><span class="srOnly">${this.t('question.credentialHidden')}</span>`}</code>
1039
+ <button
1040
+ class="credentialAction"
1041
+ type="button"
1042
+ aria-label=${this.t(shown ? 'question.credentialHide' : 'question.credentialShow', { label: resultArg.label })}
1043
+ @click=${() => this.togglePersonResult(resultArg.id)}
1044
+ >${this.t(shown ? 'question.credentialHideShort' : 'question.credentialShowShort')}</button>
1045
+ <button
1046
+ class="credentialAction"
1047
+ type="button"
1048
+ aria-label=${this.t('question.credentialCopy', { label: resultArg.label })}
1049
+ @click=${() => this.copySecret(`result:${resultArg.id}`, resultArg.label, resultArg.value)}
1050
+ >${this.t('common.copy')}</button>
1051
+ <span class="credentialFeedback ${feedback?.failed ? 'failed' : ''}" role="status" aria-live="polite">${feedback?.text ?? ''}</span>
1052
+ `;
1053
+ }
1054
+
689
1055
  /** Decline, and Confirm as the primary; kept while their words and Confirm's availability stay, so the footer knows a running one by its object. */
690
1056
  private get proposalActions(): IActionFooterAction[] {
691
1057
  const confirm = this.request.confirmLabel ?? this.t('question.proposalConfirm');
692
1058
  const decline = this.request.declineLabel ?? this.t('question.proposalDecline');
693
- // a proposal whose every change is left out has nothing to confirm
1059
+ // a proposal whose every change is left out has nothing to confirm, and one short of a value cannot be confirmed yet
694
1060
  const nothingIncluded = this.itemsDeclinable && this.effectiveLeftOut.size === (this.request.items?.length ?? 0);
1061
+ const held = !this.personFieldsComplete;
695
1062
  if (
696
1063
  this.footerActions?.confirm !== confirm
697
1064
  || this.footerActions.decline !== decline
698
1065
  || this.footerActions.nothingIncluded !== nothingIncluded
1066
+ || this.footerActions.held !== held
699
1067
  ) {
700
1068
  this.footerActions = {
701
1069
  confirm,
702
1070
  decline,
703
1071
  nothingIncluded,
1072
+ held,
704
1073
  actions: [
705
1074
  { name: decline, action: async () => this.respond(['decline']) },
706
- { name: confirm, primary: true, disabled: nothingIncluded, action: async () => this.respond(['confirm']) },
1075
+ { name: confirm, primary: true, disabled: nothingIncluded || held, action: async () => this.respond(['confirm']) },
707
1076
  ],
708
1077
  };
709
1078
  }
710
1079
  return this.footerActions.actions;
711
1080
  }
712
1081
 
713
- private footerActions: { confirm: string; decline: string; nothingIncluded: boolean; actions: IActionFooterAction[] } | undefined;
1082
+ private footerActions: {
1083
+ confirm: string;
1084
+ decline: string;
1085
+ nothingIncluded: boolean;
1086
+ held: boolean;
1087
+ actions: IActionFooterAction[];
1088
+ } | undefined;
714
1089
 
715
1090
  /** The reader includes a change in the proposal, or leaves it out. */
716
1091
  private setIncluded(itemIdArg: string, includedArg: boolean): void {
@@ -729,18 +1104,72 @@ export class DeesHarnessQuestionCard extends DeesElement {
729
1104
  this.credentialsShown = next;
730
1105
  }
731
1106
 
732
- private async copyCredential(itemArg: IHarnessProposalItem): Promise<void> {
733
- const credential = itemArg.credential!;
1107
+ private togglePersonField(keyArg: string): void {
1108
+ const next = new Set(this.personFieldsShown);
1109
+ if (next.has(keyArg)) next.delete(keyArg);
1110
+ else next.add(keyArg);
1111
+ this.personFieldsShown = next;
1112
+ }
1113
+
1114
+ private togglePersonResult(resultIdArg: string): void {
1115
+ const next = new Set(this.personResultsShown);
1116
+ if (next.has(resultIdArg)) next.delete(resultIdArg);
1117
+ else next.add(resultIdArg);
1118
+ this.personResultsShown = next;
1119
+ }
1120
+
1121
+ /** The person enters a value; one the host refused is answered by the edit. */
1122
+ private setPersonValue(fieldArg: IHarnessQuestionPersonField, valueArg: string): void {
1123
+ if (this.locked) return;
1124
+ const next = new Map(this.personValues);
1125
+ if (valueArg) next.set(personKey(fieldArg.itemId, fieldArg.id), valueArg);
1126
+ else next.delete(personKey(fieldArg.itemId, fieldArg.id));
1127
+ this.personValues = next;
1128
+ const refused = (entryArg: { itemId: string; fieldId: string }) => entryArg.itemId === fieldArg.itemId && entryArg.fieldId === fieldArg.id;
1129
+ const rejection = this.effectiveRejection;
1130
+ if (rejection?.fieldErrors?.some(refused)) {
1131
+ this.setRejection({ ...rejection, fieldErrors: rejection.fieldErrors.filter((entry) => !refused(entry)) });
1132
+ }
1133
+ }
1134
+
1135
+ /** The host's refusal the card shows: its own, or the one the view state kept over a remount. */
1136
+ private get effectiveRejection(): IHarnessQuestionRejection | undefined {
1137
+ return this.rejection ?? this.viewState?.rejection;
1138
+ }
1139
+
1140
+ private setRejection(rejectionArg: IHarnessQuestionRejection | undefined): void {
1141
+ this.rejection = rejectionArg;
1142
+ if (!this.viewState) return;
1143
+ if (rejectionArg) this.viewState.rejection = rejectionArg;
1144
+ else delete this.viewState.rejection;
1145
+ }
1146
+
1147
+ /** Forgets what the person entered and showed, and the host's refusal of it. */
1148
+ private clearPersonEntries(): void {
1149
+ this.personValues = new Map<string, string>();
1150
+ this.personFieldsShown = new Set<string>();
1151
+ this.rejection = undefined;
1152
+ }
1153
+
1154
+ /** Forgets everything person-only: what was entered, and what the changes returned. */
1155
+ private clearPersonState(): void {
1156
+ this.clearPersonEntries();
1157
+ this.personResults = NO_PERSON_RESULTS;
1158
+ this.personResultsShown = new Set<string>();
1159
+ if (this.copyFeedback?.key.startsWith('result:')) this.copyFeedback = undefined;
1160
+ }
1161
+
1162
+ private async copySecret(keyArg: string, labelArg: string, valueArg: string): Promise<void> {
734
1163
  const request = ++this.copyRequest;
735
1164
  clearTimeout(this.copyResetTimeout);
736
1165
  this.copyFeedback = undefined;
737
1166
  try {
738
- await navigator.clipboard.writeText(credential.value);
1167
+ await navigator.clipboard.writeText(valueArg);
739
1168
  if (!this.isConnected || request !== this.copyRequest) return;
740
- this.copyFeedback = { itemId: itemArg.id, text: this.t('question.credentialCopied', { label: credential.label }), failed: false };
1169
+ this.copyFeedback = { key: keyArg, text: this.t('question.credentialCopied', { label: labelArg }), failed: false };
741
1170
  } catch {
742
1171
  if (!this.isConnected || request !== this.copyRequest) return;
743
- this.copyFeedback = { itemId: itemArg.id, text: this.t('question.credentialCopyFailed'), failed: true };
1172
+ this.copyFeedback = { key: keyArg, text: this.t('question.credentialCopyFailed'), failed: true };
744
1173
  }
745
1174
  this.copyResetTimeout = setTimeout(() => {
746
1175
  this.copyFeedback = undefined;
@@ -780,12 +1209,20 @@ export class DeesHarnessQuestionCard extends DeesElement {
780
1209
  private respond(answers: string[]): void {
781
1210
  if (this.locked || !answers.length) return;
782
1211
  const items = this.request.items ?? [];
783
- const leftOut = answers[0] === 'confirm' && this.itemsDeclinable ? this.effectiveLeftOut : new Set<string>();
1212
+ const confirming = answers[0] === 'confirm';
1213
+ const leftOut = confirming && this.itemsDeclinable ? this.effectiveLeftOut : new Set<string>();
784
1214
  if (leftOut.size > 0 && leftOut.size === items.length) return;
1215
+ if (confirming && !this.personFieldsComplete) return;
1216
+ const personValues: IHarnessQuestionPersonValue[] = confirming
1217
+ ? this.includedPersonFields
1218
+ .map((field) => ({ itemId: field.itemId, fieldId: field.id, value: this.personValueOf(field) }))
1219
+ .filter((entry) => entry.value !== '')
1220
+ : [];
785
1221
  // the footer leaves with the answer: its focus moves to the decision that takes its place
786
1222
  const footerFocused = this.shadowRoot?.activeElement?.localName === 'dees-actionfooter';
787
1223
  this.answered = answers;
788
1224
  if (this.viewState) this.viewState.answered = answers;
1225
+ this.setRejection(undefined);
789
1226
  if (footerFocused) {
790
1227
  void this.updateComplete.then(() => this.shadowRoot?.querySelector<HTMLElement>('.decision')?.focus());
791
1228
  }
@@ -795,11 +1232,42 @@ export class DeesHarnessQuestionCard extends DeesElement {
795
1232
  request: harnessWithoutCredentials(this.request),
796
1233
  };
797
1234
  if (leftOut.size > 0) detail.declinedItemIds = items.filter((item) => leftOut.has(item.id)).map((item) => item.id);
1235
+ if (personValues.length) detail.personValues = personValues;
798
1236
  this.dispatchEvent(new CustomEvent<IHarnessQuestionResponseDetail>('harness-question-response', {
799
1237
  detail,
800
1238
  bubbles: true,
801
1239
  composed: true,
802
1240
  }));
1241
+ // what the person entered leaves with this answer alone: nothing keeps it for another
1242
+ this.clearPersonEntries();
1243
+ }
1244
+
1245
+ /**
1246
+ * The host refused the answer it was sent, such as a confirmation its server turned down: the
1247
+ * card waits for an answer again, keeps the changes the reader left out, and shows the host's
1248
+ * `message` and the error of each value it names. What the person entered went with the answer
1249
+ * and is entered anew. The refusal stands until the next answer, in the view state as well, so a
1250
+ * card the transcript remounts still shows it. A question that is not a proposal, a card whose
1251
+ * request carries the host's `response`, and one the host decided otherwise stay as they are: `false`.
1252
+ */
1253
+ public rejectResponse(rejectionArg: IHarnessQuestionRejection = {}): boolean {
1254
+ if (this.request.kind !== 'proposal' || this.request.response !== undefined) return false;
1255
+ if (harnessProposalState(this.request, undefined) !== 'pending') return false;
1256
+ this.answered = undefined;
1257
+ if (this.viewState) this.viewState.answered = undefined;
1258
+ this.setRejection(rejectionArg);
1259
+ return true;
1260
+ }
1261
+
1262
+ public willUpdate(changedProperties: Map<PropertyKey, unknown>): void {
1263
+ super.willUpdate(changedProperties);
1264
+ const previous = changedProperties.get('request') as IHarnessQuestionRequest | undefined;
1265
+ // another request: nothing entered for the last one, refused of it or returned by it carries over
1266
+ if (previous && previous.id !== this.request.id) {
1267
+ this.clearPersonEntries();
1268
+ this.personResultsShown = new Set<string>();
1269
+ if (!changedProperties.has('personResults')) this.personResults = NO_PERSON_RESULTS;
1270
+ }
803
1271
  }
804
1272
 
805
1273
  public async disconnectedCallback(): Promise<void> {
@@ -808,6 +1276,10 @@ export class DeesHarnessQuestionCard extends DeesElement {
808
1276
  this.copyResetTimeout = undefined;
809
1277
  this.copyFeedback = undefined;
810
1278
  this.credentialsShown = new Set<string>();
1279
+ // a card a keyed list moves is connected again before this runs, and keeps what it shows
1280
+ queueMicrotask(() => {
1281
+ if (!this.isConnected) this.clearPersonState();
1282
+ });
811
1283
  await super.disconnectedCallback();
812
1284
  }
813
1285
  }