@vitrinka/web 0.9.3 → 0.10.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/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @vitrinka/web
2
2
 
3
+ ## 0.10.0
4
+
5
+ - **A report says where it came from.** Report a problem takes a
6
+ `context` option and a `setContext(map)` method on the handle and the
7
+ element: a small map your app declares (`{environment: 'demo',
8
+ organization: {id: 'org_42', label: 'Turena'}}`) that the next report
9
+ carries as `context` on `POST /api/v1/reports`. At most 8 keys of
10
+ `[a-z0-9_]` (1 to 32 characters); each value a string of 1 to 100
11
+ characters or `{id, label?}`, trimmed before it is counted and sent
12
+ trimmed. `setContext` replaces the whole map, and
13
+ `{}` or null clears it; an empty map sends nothing. An invalid key or
14
+ value is dropped and warned about once in the console, naming it and the
15
+ limit, never thrown. What you pass is claimed; the same map in your
16
+ signed token's `ctx` claim is verified and wins for a key in both. The
17
+ key `environment` also sets the filed task's environment. A vitrinka
18
+ that takes no context yet gets the report without it. Types:
19
+ `ReportContext`, `ReportContextValue`, `ReportContextInput`.
20
+
21
+ ## 0.9.4
22
+
23
+ - **Escape belongs to reporting while reporting has the focus.** A host
24
+ modal's document-capture Escape listener could close the app's editor
25
+ before the report card handled it, leaving the card open. Reporting now
26
+ handles its Escape at window capture, preserving its menu/settings/marking
27
+ steps and shortcut recording while leaving the app dialog and draft alone.
28
+
3
29
  ## 0.9.3
4
30
 
5
31
  - **Reporting stays in the window, not the app's modal.** The floating
package/README.md CHANGED
@@ -377,10 +377,11 @@ function ReportAProblem({ locale, token }: { locale: string; token?: string }) {
377
377
  | `face` | `report` (default) or `recorder` — the recorder pill on the same engine (npm only; it takes a `vkr_` key or the device link). A linked member also switches in place: **The face switch** below |
378
378
  | `capture` | narrow the capture profile: `{storage: 'memory', windowSec, maxBytes, classes}` |
379
379
  | `identity` | as `identify()` below |
380
+ | `context` | as `setContext()` below: **Context** |
380
381
  | `appVersion`, `sanitizeUrl` | as on the recorder |
381
382
 
382
383
  The handle (and the element) has `open()`, `close()`, `identify()`,
383
- `setLocale()` and `face`, the face on screen (`recorder` while a member has
384
+ `setContext()`, `setLocale()` and `face`, the face on screen (`recorder` while a member has
384
385
  switched to the pill); the handle also `unmount()`s. For the tag from npm, call
385
386
  `defineReportElement()` once. Closing the card hands focus back to whatever
386
387
  had it when the card opened (your control, the field the shortcut fired in),
@@ -417,6 +418,28 @@ on the page; a widget's own `identify()` wins (`null` makes that widget
417
418
  anonymous, `undefined` hands it back to the page-wide one). Identity lives
418
419
  in memory only; pass it on every load.
419
420
 
421
+ **Context.** Tell vitrinka where a report came from: a small map the report
422
+ carries as `context`, at most 8 keys of `[a-z0-9_]` (1 to 32 characters),
423
+ each value a string of 1 to 100 characters or `{id, label?}` (an id of 1 to
424
+ 100 characters, a label of at most 100). Values, ids and labels are trimmed
425
+ before they are counted, and the trimmed text is sent, so a whitespace-only
426
+ value is dropped. The key `environment` also sets the
427
+ filed task's environment, over the project's host rule.
428
+
429
+ ```ts
430
+ import { mountReport, type ReportContext } from '@vitrinka/web/report';
431
+
432
+ const report = mountReport({ key: 'vkb_…', context: { environment: 'demo' } });
433
+ const context: ReportContext = { environment: 'demo', organization: { id: 'org_42', label: 'Turena' } };
434
+ report.setContext(context); // replaces the whole map for the next report
435
+ report.setContext(null); // clears it ({} too): nothing is sent
436
+ ```
437
+
438
+ What you pass here is claimed. Put the same map in your signed token's `ctx`
439
+ claim to have it verified: for a key in both, the signed value wins. An
440
+ invalid key or value is dropped from what is sent and warned about once in
441
+ the console, naming the key and the limit; nothing is thrown.
442
+
420
443
  **The account and the menu.** The header's chip shows the reporter's
421
444
  initials and first name — the person your token names (the name as
422
445
  vitrinka returns it) or the email you asserted — else **?**. It opens the
@@ -1,3 +1,3 @@
1
1
  /** Sent as `meta.recorder` and written as `data-vitrinka-page`; bumped with the package version. */
2
- export declare const RECORDER_VERSION = "0.9.3";
3
- export declare const RECORDER_ID = "web/0.9.3";
2
+ export declare const RECORDER_VERSION = "0.10.0";
3
+ export declare const RECORDER_ID = "web/0.10.0";
@@ -1,3 +1,3 @@
1
1
  /** Sent as `meta.recorder` and written as `data-vitrinka-page`; bumped with the package version. */
2
- export const RECORDER_VERSION = '0.9.3';
2
+ export const RECORDER_VERSION = '0.10.0';
3
3
  export const RECORDER_ID = `web/${RECORDER_VERSION}`;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The context a host app declares on a report (vt-9515): a small map the
3
+ * server files with it, e.g. `{environment: 'demo', organization: {id:
4
+ * 'org_42', label: 'Turena'}}`. The contract is frozen and the server checks
5
+ * the same limits: at most 8 keys; a key is 1 to 32 characters of
6
+ * [a-z0-9_]; a value is a string of 1 to 100 characters, or `{id, label?}`
7
+ * with an id of 1 to 100 characters and a label of at most 100. A value, id
8
+ * and label are trimmed first and the trimmed text is sent. Characters are
9
+ * Unicode code points, never UTF-16 units.
10
+ *
11
+ * What the host passes here is CLAIMED (unverified). The same map in the
12
+ * `ctx` claim of the identity token the host's server signed is VERIFIED and
13
+ * wins for a key in both; the widget never reads or rewrites that token.
14
+ * The reserved key `environment` also sets the filed task's environment.
15
+ *
16
+ * The widget validates on the client so a bad entry never costs the report:
17
+ * an invalid key or value is dropped from what is sent and warned about
18
+ * once per page, naming the key and the limit; nothing is ever thrown into
19
+ * the host app.
20
+ */
21
+ /** One context value: a plain string, or an entity the host names by id (and a label people read). */
22
+ export type ReportContextValue = string | {
23
+ id: string;
24
+ label?: string;
25
+ };
26
+ /** The map a report carries as `context`: at most 8 keys of [a-z0-9_]{1,32}. */
27
+ export type ReportContext = Record<string, ReportContextValue>;
28
+ /** What `setContext` and the `context` option accept: a map, or null/undefined to clear it. */
29
+ export type ReportContextInput = ReportContext | null | undefined;
30
+ export declare const CONTEXT_MAX_KEYS = 8;
31
+ export interface CleanedContext {
32
+ context: ReportContext;
33
+ /** One line per dropped entry: the key, quoted, and the rule it broke. */
34
+ dropped: string[];
35
+ }
36
+ /**
37
+ * The valid part of `input` (a fresh copy, so a later mutation of the
38
+ * host's object never reaches a report) and what was dropped. Entries go in
39
+ * the host's key order; past the eighth valid key the rest are dropped.
40
+ */
41
+ export declare function cleanContext(input: unknown): CleanedContext;
42
+ /** The valid part of `input`; each dropped entry is warned about once per page, never thrown. */
43
+ export declare function normalizeContext(input: unknown): ReportContext;
44
+ /** The report body's `context` field: absent for an empty map, so nothing is sent. */
45
+ export declare function contextField(context: ReportContext): {
46
+ context?: ReportContext;
47
+ };
@@ -0,0 +1,134 @@
1
+ /**
2
+ * The context a host app declares on a report (vt-9515): a small map the
3
+ * server files with it, e.g. `{environment: 'demo', organization: {id:
4
+ * 'org_42', label: 'Turena'}}`. The contract is frozen and the server checks
5
+ * the same limits: at most 8 keys; a key is 1 to 32 characters of
6
+ * [a-z0-9_]; a value is a string of 1 to 100 characters, or `{id, label?}`
7
+ * with an id of 1 to 100 characters and a label of at most 100. A value, id
8
+ * and label are trimmed first and the trimmed text is sent. Characters are
9
+ * Unicode code points, never UTF-16 units.
10
+ *
11
+ * What the host passes here is CLAIMED (unverified). The same map in the
12
+ * `ctx` claim of the identity token the host's server signed is VERIFIED and
13
+ * wins for a key in both; the widget never reads or rewrites that token.
14
+ * The reserved key `environment` also sets the filed task's environment.
15
+ *
16
+ * The widget validates on the client so a bad entry never costs the report:
17
+ * an invalid key or value is dropped from what is sent and warned about
18
+ * once per page, naming the key and the limit; nothing is ever thrown into
19
+ * the host app.
20
+ */
21
+ export const CONTEXT_MAX_KEYS = 8;
22
+ const KEY = /^[a-z0-9_]{1,32}$/;
23
+ const VALUE_MAX = 100;
24
+ const KEY_RULE = 'a key is 1 to 32 characters of [a-z0-9_]';
25
+ const VALUE_RULE = `a value is a string of 1 to ${VALUE_MAX} characters after trimming, or {id, label?}`;
26
+ const ID_RULE = `an id is 1 to ${VALUE_MAX} characters after trimming`;
27
+ const LABEL_RULE = `a label is at most ${VALUE_MAX} characters after trimming`;
28
+ const COUNT_RULE = `a context holds at most ${CONTEXT_MAX_KEYS} keys`;
29
+ const UNREADABLE_RULE = 'reading it threw in the host app';
30
+ /** Code points, as the contract counts characters (an emoji is one, not two UTF-16 units). */
31
+ function chars(s) {
32
+ let n = 0;
33
+ for (const _ of s)
34
+ n++;
35
+ return n;
36
+ }
37
+ function isPlainObject(v) {
38
+ if (typeof v !== 'object' || v === null || Array.isArray(v))
39
+ return false;
40
+ const proto = Object.getPrototypeOf(v);
41
+ return proto === Object.prototype || proto === null;
42
+ }
43
+ /**
44
+ * A clean copy of one value, or the rule it breaks. A value, an id and a
45
+ * label are trimmed first, then counted, and the trimmed text is what is
46
+ * sent: the server holds the same rule, and a whitespace-only value it once
47
+ * refused with a 422 for the whole report is dropped here instead (vt-9515).
48
+ */
49
+ function cleanValue(v) {
50
+ if (typeof v === 'string') {
51
+ const s = v.trim();
52
+ const n = chars(s);
53
+ return n >= 1 && n <= VALUE_MAX ? s : { broken: VALUE_RULE };
54
+ }
55
+ if (!isPlainObject(v))
56
+ return { broken: VALUE_RULE };
57
+ if (typeof v.id !== 'string')
58
+ return { broken: ID_RULE };
59
+ const id = v.id.trim();
60
+ if (chars(id) < 1 || chars(id) > VALUE_MAX)
61
+ return { broken: ID_RULE };
62
+ if (v.label === undefined)
63
+ return { id };
64
+ if (typeof v.label !== 'string')
65
+ return { broken: LABEL_RULE };
66
+ const label = v.label.trim();
67
+ if (chars(label) > VALUE_MAX)
68
+ return { broken: LABEL_RULE };
69
+ // Only id and label leave: anything else on the host's object is not part of the contract.
70
+ return { id, label };
71
+ }
72
+ /**
73
+ * The valid part of `input` (a fresh copy, so a later mutation of the
74
+ * host's object never reaches a report) and what was dropped. Entries go in
75
+ * the host's key order; past the eighth valid key the rest are dropped.
76
+ */
77
+ export function cleanContext(input) {
78
+ if (input === null || input === undefined)
79
+ return { context: {}, dropped: [] };
80
+ // The map and its entries are the host's objects: an accessor or a proxy trap
81
+ // of theirs may throw. That costs the entry it guards (or the map), named in
82
+ // the warning like any other drop, never the host's render or the report.
83
+ let keys;
84
+ try {
85
+ if (!isPlainObject(input))
86
+ return { context: {}, dropped: ['the whole context (a context is a plain object of keys to values)'] };
87
+ keys = Object.keys(input);
88
+ }
89
+ catch {
90
+ return { context: {}, dropped: [`the whole context (${UNREADABLE_RULE})`] };
91
+ }
92
+ const kept = [];
93
+ const dropped = [];
94
+ for (const key of keys) {
95
+ if (!KEY.test(key)) {
96
+ dropped.push(`${JSON.stringify(key)} (${KEY_RULE})`);
97
+ continue;
98
+ }
99
+ let value;
100
+ try {
101
+ value = cleanValue(input[key]);
102
+ }
103
+ catch {
104
+ value = { broken: UNREADABLE_RULE };
105
+ }
106
+ if (typeof value === 'object' && 'broken' in value) {
107
+ dropped.push(`${JSON.stringify(key)} (${value.broken})`);
108
+ continue;
109
+ }
110
+ if (kept.length >= CONTEXT_MAX_KEYS) {
111
+ dropped.push(`${JSON.stringify(key)} (${COUNT_RULE})`);
112
+ continue;
113
+ }
114
+ kept.push([key, value]);
115
+ }
116
+ // fromEntries defines own properties, so a `__proto__` key stays a key and never a prototype.
117
+ return { context: Object.fromEntries(kept), dropped };
118
+ }
119
+ /** Problems already warned about on this page: a host that sets the same bad map on every render hears it once. */
120
+ const warned = new Set();
121
+ /** The valid part of `input`; each dropped entry is warned about once per page, never thrown. */
122
+ export function normalizeContext(input) {
123
+ const { context, dropped } = cleanContext(input);
124
+ const fresh = dropped.filter((d) => !warned.has(d));
125
+ for (const d of fresh)
126
+ warned.add(d);
127
+ if (fresh.length)
128
+ console.warn(`vitrinka: setContext dropped ${fresh.join('; ')}. The report goes without ${fresh.length === 1 ? 'it' : 'them'}.`);
129
+ return context;
130
+ }
131
+ /** The report body's `context` field: absent for an empty map, so nothing is sent. */
132
+ export function contextField(context) {
133
+ return Object.keys(context).length ? { context } : {};
134
+ }
@@ -1,3 +1,4 @@
1
+ import { type ReportContextInput } from './context';
1
2
  import type { RecordLoader } from './engine';
2
3
  import { type Locale } from './i18n';
3
4
  import type { IdentifyInput } from './identity';
@@ -27,6 +28,11 @@ export interface ReportOptions extends ReportScriptOptions {
27
28
  openSelector?: string;
28
29
  /** Who reports: a token your server signed, or an asserted email. */
29
30
  identity?: IdentifyInput;
31
+ /**
32
+ * Claimed context the report carries (vt-9515): at most 8 keys of [a-z0-9_]{1,32}, each a string of
33
+ * 1 to 100 characters or {id, label?}, each trimmed before it is counted. The same map in the signed token's `ctx` claim is verified and wins.
34
+ */
35
+ context?: ReportContextInput;
30
36
  /** Where the element goes (default `document.body`). */
31
37
  parent?: Element;
32
38
  }
@@ -37,6 +43,8 @@ export interface ReportHandle {
37
43
  open(): void;
38
44
  close(): void;
39
45
  identify(who: IdentifyInput): void;
46
+ /** Replace the whole context the next report carries; `{}` or null clears it. Invalid entries are dropped and warned about. */
47
+ setContext(next: ReportContextInput): void;
40
48
  setLocale(locale: Locale | string): void;
41
49
  unmount(): void;
42
50
  }
@@ -50,6 +58,8 @@ export interface VitrinkaReportElement extends HTMLElement {
50
58
  open(): void;
51
59
  close(): void;
52
60
  identify(who: IdentifyInput): void;
61
+ /** Replace the whole context the next report carries; `{}` or null clears it. */
62
+ setContext(next: ReportContextInput): void;
53
63
  setLocale(locale: Locale | string): void;
54
64
  }
55
65
  declare global {
@@ -20,6 +20,7 @@
20
20
  * except while the pill records or starts to.
21
21
  */
22
22
  import { listen } from '../recorder/hud/listen';
23
+ import { normalizeContext } from './context';
23
24
  import { memberLinked, pillRecording, rememberFace, startFace, watchMemberLink } from './face';
24
25
  import { parseLocale } from './i18n';
25
26
  import { hitsOpener, ReportWidget } from './widget';
@@ -54,6 +55,8 @@ export function defineReportElement(faces) {
54
55
  warnedRecording = false;
55
56
  offLink = null;
56
57
  pendingIdentity = undefined;
58
+ /** Validated once here, so a remount never warns again; survives a face switch like the identity. */
59
+ context = {};
57
60
  get face() {
58
61
  return this.shown ?? 'report';
59
62
  }
@@ -101,6 +104,10 @@ export function defineReportElement(faces) {
101
104
  this.pendingIdentity = who;
102
105
  this.widget?.identify(who);
103
106
  }
107
+ setContext(next) {
108
+ this.context = normalizeContext(next);
109
+ this.widget?.setContext(this.context);
110
+ }
104
111
  setLocale(locale) {
105
112
  // The attribute is the one source: it repaints through attributeChangedCallback.
106
113
  this.setAttribute('locale', String(locale));
@@ -182,6 +189,7 @@ export function defineReportElement(faces) {
182
189
  button: this.getAttribute('button') !== 'false',
183
190
  openSelector: this.getAttribute('open-selector'),
184
191
  identity: this.pendingIdentity,
192
+ context: this.context,
185
193
  appVersion: this.options.appVersion,
186
194
  capture: this.options.capture,
187
195
  sanitizeUrl: this.options.sanitizeUrl,
@@ -264,6 +272,8 @@ export function mountReport(opts, faces) {
264
272
  // null is a choice (anonymous, whatever the page-wide identity); only undefined defers.
265
273
  if (opts.identity !== undefined)
266
274
  el.identify(opts.identity);
275
+ if (opts.context !== undefined)
276
+ el.setContext(opts.context);
267
277
  (opts.parent ?? document.body).append(el);
268
278
  return {
269
279
  get face() {
@@ -272,6 +282,7 @@ export function mountReport(opts, faces) {
272
282
  open: () => el.open(),
273
283
  close: () => el.close(),
274
284
  identify: (who) => el.identify(who),
285
+ setContext: (next) => el.setContext(next),
275
286
  setLocale: (l) => el.setLocale(l),
276
287
  unmount: () => el.remove(),
277
288
  };
@@ -300,6 +311,7 @@ function mountRecorder(opts, faces) {
300
311
  open: inert,
301
312
  close: inert,
302
313
  identify: inert,
314
+ setContext: inert,
303
315
  setLocale: inert,
304
316
  unmount: () => {
305
317
  gone = true;
@@ -1,5 +1,6 @@
1
1
  import { type ReportHandle, type ReportOptions } from './element';
2
2
  export type { CaptureClass, CaptureNarrowing, CaptureProfile, CaptureStorage } from './profile';
3
+ export type { ReportContext, ReportContextInput, ReportContextValue } from './context';
3
4
  export type { Locale } from './i18n';
4
5
  export type { IdentifyInput, Identity } from './identity';
5
6
  export type { Marker, MarkerShape, WireMarker } from './markers';
@@ -1,3 +1,4 @@
1
+ import { type ReportContext } from './context';
1
2
  import { type RecordLoader } from './engine';
2
3
  import { type Locale } from './i18n';
3
4
  import { type IdentifyInput } from './identity';
@@ -12,6 +13,8 @@ export interface WidgetOptions {
12
13
  /** CSS selector of the host's own control(s) that open the card. */
13
14
  openSelector?: string | null;
14
15
  identity?: IdentifyInput;
16
+ /** The host's claimed context, already validated by element.ts (context.ts, vt-9515). */
17
+ context?: ReportContext;
15
18
  appVersion?: string;
16
19
  capture?: CaptureNarrowing;
17
20
  sanitizeUrl?: (url: string) => string;
@@ -30,6 +33,8 @@ export declare class ReportWidget {
30
33
  private openSelector;
31
34
  /** This widget's own word: undefined defers to the page-wide identity; null is anonymous. */
32
35
  private identity;
36
+ /** What the next report carries as `context` (vt-9515): replaced whole by setContext, empty sends none. */
37
+ private context;
33
38
  private keybind;
34
39
  private isOpen;
35
40
  /** Where focus was when the card opened, outside the report: close() hands it back. */
@@ -128,6 +133,8 @@ export declare class ReportWidget {
128
133
  */
129
134
  setRecordSwitch(fn: (() => void) | null): void;
130
135
  identify(input: IdentifyInput): void;
136
+ /** Replace what the next report carries as `context` (vt-9515); element.ts has validated it. A report already created keeps what it was created with. */
137
+ setContext(context: ReportContext): void;
131
138
  unmount(): void;
132
139
  private bind;
133
140
  private show;
@@ -36,6 +36,7 @@ import { listen } from '../recorder/hud/listen';
36
36
  import { forgetLink } from '../recorder/link';
37
37
  import { RECORDER_VERSION } from '../recorder/version';
38
38
  import { admit, DEFAULT_ATTACHMENT_CAPS, formatBytes, pastedName, typesLabel } from './attachments';
39
+ import { contextField } from './context';
39
40
  import { cornerToward, DRAG_THRESHOLD, nearestCorner, readDock, saveDock } from './drag';
40
41
  import { memberLinked, memberLinkGone, memberTokenFor, rememberDisplayMode, watchMemberLink } from './face';
41
42
  import { acquireEngine, releaseEngine } from './engine';
@@ -426,6 +427,8 @@ export class ReportWidget {
426
427
  openSelector;
427
428
  /** This widget's own word: undefined defers to the page-wide identity; null is anonymous. */
428
429
  identity;
430
+ /** What the next report carries as `context` (vt-9515): replaced whole by setContext, empty sends none. */
431
+ context;
429
432
  keybind;
430
433
  isOpen = false;
431
434
  /** Where focus was when the card opened, outside the report: close() hands it back. */
@@ -523,6 +526,7 @@ export class ReportWidget {
523
526
  this.button = opts.button;
524
527
  this.openSelector = opts.openSelector ?? null;
525
528
  this.identity = opts.identity === undefined ? undefined : normalizeIdentity(opts.identity);
529
+ this.context = opts.context ?? {};
526
530
  this.keybind = loadKeybind();
527
531
  this.hud = createHudHost();
528
532
  this.e = buildDom(this.hud.mount);
@@ -635,6 +639,10 @@ export class ReportWidget {
635
639
  this.identity = input === undefined ? undefined : normalizeIdentity(input);
636
640
  this.whoChanged();
637
641
  }
642
+ /** Replace what the next report carries as `context` (vt-9515); element.ts has validated it. A report already created keeps what it was created with. */
643
+ setContext(context) {
644
+ this.context = context;
645
+ }
638
646
  unmount() {
639
647
  this.stopRecordingBind();
640
648
  this.linkFlow?.abort.abort();
@@ -821,23 +829,6 @@ export class ReportWidget {
821
829
  this.paint();
822
830
  });
823
831
  }
824
- on(e.card, 'keydown', (ev) => {
825
- // Marking's own Escape (the window listener) already acted on it.
826
- if (ev.key !== 'Escape' || this.recordingBind || ev.defaultPrevented)
827
- return;
828
- ev.preventDefault();
829
- // Esc steps back one layer: an open popover, then a list or settings, then the card itself.
830
- if (this.menu) {
831
- const opener = this.menu === 'account' ? e.whoBtn : e.more;
832
- this.menu = null;
833
- this.paint();
834
- opener.focus();
835
- }
836
- else if (this.view !== 'describe' && this.view !== 'sent')
837
- this.show('describe');
838
- else
839
- this.close();
840
- });
841
832
  for (const [tool, btn] of e.toolButtons) {
842
833
  on(btn, 'click', (ev) => {
843
834
  this.tool = tool;
@@ -869,19 +860,37 @@ export class ReportWidget {
869
860
  this.offs.push(listen(e.mark, 'wheel', (ev) => ev.preventDefault()));
870
861
  this.offs.push(listen(e.mark, 'touchmove', (ev) => ev.preventDefault()));
871
862
  this.offs.push(listen(window, 'keydown', (ev) => {
872
- if (this.recordingBind)
873
- return;
874
- if (this.marking && ev.key === 'Escape') {
863
+ const inCard = ev.composedPath().includes(e.card);
864
+ // A modal's document-capture listener runs before a card listener.
865
+ // Own this Escape at window capture so it never dismisses the app's dialog.
866
+ if (ev.key === 'Escape' && this.isOpen && (this.marking || inCard)) {
875
867
  ev.preventDefault();
876
- // Esc answers an open "Discard?" with Keep, drops a keyboard mark being placed, and only then leaves marking — keeping the marks.
877
- if (this.confirming)
878
- e.keep.click();
879
- else if (this.kbDraft)
880
- this.cancelDraft();
868
+ ev.stopImmediatePropagation();
869
+ if (this.recordingBind) {
870
+ this.stopRecordingBind();
871
+ }
872
+ else if (this.marking) {
873
+ if (this.confirming)
874
+ e.keep.click();
875
+ else if (this.kbDraft)
876
+ this.cancelDraft();
877
+ else
878
+ this.endMarking(true);
879
+ }
880
+ else if (this.menu) {
881
+ const opener = this.menu === 'account' ? e.whoBtn : e.more;
882
+ this.menu = null;
883
+ this.paint();
884
+ opener.focus();
885
+ }
886
+ else if (this.view !== 'describe' && this.view !== 'sent')
887
+ this.show('describe');
881
888
  else
882
- this.endMarking(true);
889
+ this.close();
883
890
  return;
884
891
  }
892
+ if (this.recordingBind)
893
+ return;
885
894
  // ⌘Z / Ctrl+Z takes the newest mark back — unless a field is being typed in, whose own undo wins.
886
895
  if (this.marking && (ev.metaKey || ev.ctrlKey) && !ev.shiftKey && !ev.altKey && ev.key.toLowerCase() === 'z' && !typing()) {
887
896
  ev.preventDefault();
@@ -1702,6 +1711,7 @@ export class ReportWidget {
1702
1711
  ...(this.kind ? { type: this.kind } : {}),
1703
1712
  // A member linked on this base co-owns the report; the `vkb_` key stays the bearer.
1704
1713
  ...(member ? { memberToken: member } : {}),
1714
+ ...contextField(this.context),
1705
1715
  };
1706
1716
  }
1707
1717
  /** The words the report goes with: the description, else the first mark's note — either one is enough to send. */
@@ -28,7 +28,7 @@
28
28
  *
29
29
  * OPTIONAL FIELDS NEVER COST THE REPORT: a vitrinka older than a field refuses
30
30
  * it by name (400, `unknown field "<name>"`), and the create goes again without
31
- * each optional field it names — `type`, `memberToken` — once. `memberToken`
31
+ * each optional field it names — `type`, `memberToken`, `context` — once. `memberToken`
32
32
  * proves this browser's vitrinka member link (vt-8020), so the member co-owns
33
33
  * the report; `memberError` says the server did not take it, and the report
34
34
  * files regardless.
@@ -36,6 +36,7 @@
36
36
  import { type ApiTarget } from '../recorder/api';
37
37
  import { type BuiltCapture, type ConsoleEntry, type NetEntry } from './engine';
38
38
  import type { Locale, ReportKind } from './i18n';
39
+ import type { ReportContext } from './context';
39
40
  import type { Identity } from './identity';
40
41
  import type { WireMarker } from './markers';
41
42
  export interface ReportEnv {
@@ -66,6 +67,8 @@ export interface ReportEnvelope {
66
67
  type?: ReportKind;
67
68
  /** The vitrinka member link this browser holds for the widget's base (face.ts memberTokenFor), absent without one: the member co-owns the report. */
68
69
  memberToken?: string;
70
+ /** The host's claimed context (context.ts, vt-9515), already validated; absent when the map is empty. */
71
+ context?: ReportContext;
69
72
  }
70
73
  export interface SubmitReply {
71
74
  status: 'filed' | 'quarantined';
@@ -142,7 +145,7 @@ export declare class ReportJob {
142
145
  /**
143
146
  * The create leg, answering with the member link the accepted body carried
144
147
  * ('' none). A vitrinka older than an optional field refuses it by name;
145
- * the reporter's word (`type`) and the member link (`memberToken`) are
148
+ * the reporter's word (`type`), the member link (`memberToken`) and the host's context (`context`) are
146
149
  * optional, the report is not, so it goes again without each field named,
147
150
  * once. A refusal naming nothing still in the body fails the leg.
148
151
  */
@@ -28,7 +28,7 @@
28
28
  *
29
29
  * OPTIONAL FIELDS NEVER COST THE REPORT: a vitrinka older than a field refuses
30
30
  * it by name (400, `unknown field "<name>"`), and the create goes again without
31
- * each optional field it names — `type`, `memberToken` — once. `memberToken`
31
+ * each optional field it names — `type`, `memberToken`, `context` — once. `memberToken`
32
32
  * proves this browser's vitrinka member link (vt-8020), so the member co-owns
33
33
  * the report; `memberError` says the server did not take it, and the report
34
34
  * files regardless.
@@ -172,7 +172,7 @@ export class ReportJob {
172
172
  /**
173
173
  * The create leg, answering with the member link the accepted body carried
174
174
  * ('' none). A vitrinka older than an optional field refuses it by name;
175
- * the reporter's word (`type`) and the member link (`memberToken`) are
175
+ * the reporter's word (`type`), the member link (`memberToken`) and the host's context (`context`) are
176
176
  * optional, the report is not, so it goes again without each field named,
177
177
  * once. A refusal naming nothing still in the body fails the leg.
178
178
  */
@@ -195,6 +195,12 @@ export class ReportJob {
195
195
  const { memberToken: _dropped, ...rest } = body;
196
196
  body = rest;
197
197
  }
198
+ else if (field === 'context' && body.context !== undefined) {
199
+ // The host's claimed context is optional like the rest (vt-9515); a signed `ctx` claim rides the token and is not dropped.
200
+ console.warn('vitrinka: this server takes no report context yet; sending the report without it');
201
+ const { context: _dropped, ...rest } = body;
202
+ body = rest;
203
+ }
198
204
  else {
199
205
  throw e;
200
206
  }