@vitrinka/web 0.7.1 → 0.8.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/README.md +117 -19
  3. package/build/hud.iife.js +11 -11
  4. package/build/recorder/config.d.ts +6 -2
  5. package/build/recorder/hud/Hud.d.ts +3 -1
  6. package/build/recorder/hud/Hud.js +2 -2
  7. package/build/recorder/hud/Menu.d.ts +7 -1
  8. package/build/recorder/hud/Menu.js +2 -2
  9. package/build/recorder/hud/host.d.ts +13 -0
  10. package/build/recorder/hud/host.js +96 -1
  11. package/build/recorder/hud/icons.d.ts +2 -0
  12. package/build/recorder/hud/icons.js +4 -0
  13. package/build/recorder/hud/mount.d.ts +2 -0
  14. package/build/recorder/hud/mount.js +1 -0
  15. package/build/recorder/index.d.ts +6 -0
  16. package/build/recorder/index.js +3 -0
  17. package/build/recorder/lead.js +12 -2
  18. package/build/recorder/link.js +1 -1
  19. package/build/recorder/version.d.ts +2 -2
  20. package/build/recorder/version.js +1 -1
  21. package/build/report/attachments.d.ts +56 -0
  22. package/build/report/attachments.js +91 -0
  23. package/build/report/drag.d.ts +18 -0
  24. package/build/report/drag.js +34 -0
  25. package/build/report/element.d.ts +11 -2
  26. package/build/report/element.js +106 -15
  27. package/build/report/engine.d.ts +5 -1
  28. package/build/report/engine.js +7 -1
  29. package/build/report/face.d.ts +23 -0
  30. package/build/report/face.js +92 -0
  31. package/build/report/i18n.d.ts +75 -3
  32. package/build/report/i18n.js +125 -6
  33. package/build/report/place.d.ts +26 -0
  34. package/build/report/place.js +33 -0
  35. package/build/report/reader.d.ts +42 -0
  36. package/build/report/reader.js +39 -0
  37. package/build/report/recorder-face.js +6 -2
  38. package/build/report/sent.d.ts +16 -0
  39. package/build/report/sent.js +39 -0
  40. package/build/report/settings.d.ts +32 -0
  41. package/build/report/settings.js +47 -0
  42. package/build/report/styles.d.ts +1 -1
  43. package/build/report/styles.js +216 -52
  44. package/build/report/widget.d.ts +109 -3
  45. package/build/report/widget.js +1063 -99
  46. package/build/report/wire.d.ts +20 -9
  47. package/build/report/wire.js +44 -9
  48. package/build/report-widget.mjs +223 -59
  49. package/package.json +1 -1
@@ -54,8 +54,12 @@ export declare function addOwnBase(url: string): () => void;
54
54
  export declare function isVitrinkaUrl(url: string): boolean;
55
55
  /** Storage key of the linked token (`vitrinka.recorder.link` in localStorage). */
56
56
  export declare const LINK_KEY = "link";
57
- export declare function readLink(): Linked | null;
58
- export declare function storeLink(link: Linked): void;
57
+ /** The stored device link; `base` names the vitrinka it was minted on (absent on links stored before web 0.8). */
58
+ export interface StoredLink extends Linked {
59
+ base?: string;
60
+ }
61
+ export declare function readLink(): StoredLink | null;
62
+ export declare function storeLink(link: StoredLink): void;
59
63
  export declare function clearLink(): void;
60
64
  /** Has the recorder something to authenticate with? */
61
65
  export declare function vitrinkaLinked(): boolean;
@@ -19,5 +19,7 @@ export interface HudProps {
19
19
  defaultTitle: () => string;
20
20
  /** Where the HUD remembers its own UI state (the dock spot). */
21
21
  storage: RecorderStorage;
22
+ /** The menu's "Report a problem" (the report face's way back); absent = no row. */
23
+ onReportFace?: () => void;
22
24
  }
23
- export declare function Hud({ controller, hostMount, defaultTitle, storage }: HudProps): ReactElement;
25
+ export declare function Hud({ controller, hostMount, defaultTitle, storage, onReportFace }: HudProps): ReactElement;
@@ -67,7 +67,7 @@ function useNow(active) {
67
67
  return active ? now : Date.now();
68
68
  }
69
69
  const errorText = (e) => (e instanceof Error ? e.message : String(e));
70
- export function Hud({ controller, hostMount, defaultTitle, storage }) {
70
+ export function Hud({ controller, hostMount, defaultTitle, storage, onReportFace }) {
71
71
  const snap = useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot);
72
72
  const rec = snap.recording;
73
73
  const [sheet, setSheet] = useState(null);
@@ -742,7 +742,7 @@ export function Hud({ controller, hostMount, defaultTitle, storage }) {
742
742
  return (_jsxs("div", { ref: rootRef, className: "hud", "data-size": snap.prefs.size, "data-spot": 'spot' in place ? place.spot : undefined, ...(hidden ? { 'data-following': following, style: { display: 'none' } } : {}), children: [_jsx("style", { children: HUD_CSS }), annotating && (rec || marking) ? _jsx(AnnotateOverlay, { onPick: onPick, onCancel: cancelAnnotate }) : null, _jsxs("div", { ref: dock.ref, className: dock.dragging ? 'dock dragging' : 'dock', ...dockAttrs, onClickCapture: dock.onClickCapture, children: [_jsx(RecorderPill, { snap: snap, now: now, flow: flow, flash: flash, composing: sheet !== null, starting: starting, menuOpen: menu, place: place, dragging: dock.dragging, handle: dock.handle, pillRef: pillRef, onMove: dock.moveTo, onLink: beginLink, onStart: onStart, onPause: onPause, onNote: openNote, onAnnotate: toggleAnnotate, onMenu: toggleMenu, onAskStop: askStop, onConfirm: onConfirm, onCancel: onCancel, onRetry: onRetry, onDismiss: onDismiss, onRetryBuild: onRetryBuild, canRetryBuild: typeof controller.retryBuild === 'function', onTrayOpen: setTrayOpen, ...(controller.listNotes ? { notesCount: rows.length } : {}), onNotes: openNotes }), parked && !sheet && rec && !annotating && 'spot' in place ? (_jsx(DraftDrop, { text: draft, crop: parked.crop ?? null, side: colOf(place.spot) === 'r' ? 'start' : 'end', onResume: () => {
743
743
  setSheet(parked);
744
744
  setParked(null);
745
- } })) : null] }), menuP.mounted ? (_jsx(Menu, { snap: snap, now: now, place: place, className: `grow ${menuP.cls}`, menuRef: menuRef, onClose: () => setMenu(false), onMove: dock.moveTo, onSize: (size) => void controller.setPrefs({ size }), onVerbose: (verbose) => void controller.setPrefs({ verbose }), onAskUnlink: askUnlink, onLink: beginLink, ...(snap.canReport && controller.report ? { onReport: openReport } : {}) })) : null, _jsx(Tooltip, { root: rootRef, side: side, suppressed: dock.dragging || menu || layerOpen }), detailP.mounted && detailRec ? (_jsx("div", { ref: detailRef, className: [
745
+ } })) : null] }), menuP.mounted ? (_jsx(Menu, { snap: snap, now: now, place: place, className: `grow ${menuP.cls}`, menuRef: menuRef, onClose: () => setMenu(false), onMove: dock.moveTo, onSize: (size) => void controller.setPrefs({ size }), onVerbose: (verbose) => void controller.setPrefs({ verbose }), onAskUnlink: askUnlink, onLink: beginLink, ...(snap.canReport && controller.report ? { onReport: openReport } : {}), onReportFace: onReportFace })) : null, _jsx(Tooltip, { root: rootRef, side: side, suppressed: dock.dragging || menu || layerOpen }), detailP.mounted && detailRec ? (_jsx("div", { ref: detailRef, className: [
746
746
  'float detail grow',
747
747
  detailP.cls,
748
748
  snap.prefs.verbose ? '' : 'line',
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * The ⋯ menu: who the recorder is linked as, "Report a bug", the open board,
3
- * the device's recent recordings and "Go to vitrinka", then the HUD's own settings —
3
+ * the device's recent recordings, "Report a problem" (the report face's way
4
+ * back, idle only) and "Go to vitrinka", then the HUD's own settings —
4
5
  * size, verbose details, position (a miniature screen of the eight spots) —
5
6
  * and Unlink. A fixed float placed beside the dock by the caller; ↑/↓ move
6
7
  * between items, Esc closes.
@@ -28,5 +29,10 @@ export interface MenuProps {
28
29
  onLink: () => void;
29
30
  /** Opens the bug report sheet; the row shows only when set. */
30
31
  onReport?: () => void;
32
+ /**
33
+ * Swaps the pill for the report face (vt-8020 D8); the row shows only when
34
+ * set, and only while idle — leaving mid-recording would strand the session.
35
+ */
36
+ onReportFace?: () => void;
31
37
  }
32
38
  export declare function Menu(p: MenuProps): ReactElement;
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { BugIcon, HomeIcon, NewTabIcon, UnlinkIcon } from './icons';
2
+ import { BugIcon, HomeIcon, NewTabIcon, ReportIcon, UnlinkIcon } from './icons';
3
3
  import { isVertical, SPOT_NAMES, SPOTS } from './spots';
4
4
  import { fmtAgo, fmtDuration } from './status';
5
5
  const SIZES = [
@@ -58,7 +58,7 @@ export function Menu(p) {
58
58
  const status = live ? 'recording' : r.status;
59
59
  const body = (_jsxs(_Fragment, { children: [_jsxs("span", { className: "r-main", children: [_jsx("span", { className: "r-title", children: r.title || 'Untitled recording' }), _jsxs("span", { className: "r-meta", children: [_jsx("i", { "data-status": status }), meta.join(' · ')] })] }), r.boardUrl ? (_jsx("span", { className: "end", children: _jsx(NewTabIcon, {}) })) : null] }));
60
60
  return r.boardUrl ? (_jsx("a", { role: "menuitem", className: "mi recent", href: r.boardUrl, target: "_blank", rel: "noopener noreferrer", onClick: p.onClose, "data-e2e": "recent", children: body }, r.sessionId)) : (_jsx("div", { role: "menuitem", "aria-disabled": "true", className: "mi recent", "data-e2e": "recent", children: body }, r.sessionId));
61
- }), _jsxs("a", { role: "menuitem", className: "mi", href: snap.workspaceUrl, target: "_blank", rel: "noopener noreferrer", onClick: p.onClose, children: [_jsx(HomeIcon, {}), " Go to vitrinka", _jsx("span", { className: "end", children: _jsx(NewTabIcon, {}) })] }), _jsx("div", { className: "m-rule" }), _jsxs("div", { className: "m-row", children: [_jsx("span", { id: "vt-size", children: "Size" }), _jsx("span", { className: "sizes", role: "group", "aria-labelledby": "vt-size", style: { '--i': String(Math.max(0, sizeIndex)) }, children: SIZES.map((s) => (_jsx("button", { type: "button", role: "menuitemradio", "aria-checked": snap.prefs.size === s.size, "aria-label": `Size ${s.name}`, onClick: () => p.onSize(s.size), children: s.label }, s.size))) })] }), _jsxs("div", { className: "m-row toggle", role: "menuitemcheckbox", "aria-checked": snap.prefs.verbose, tabIndex: 0, onClick: () => p.onVerbose(!snap.prefs.verbose), onKeyDown: (e) => {
61
+ }), p.onReportFace && !rec ? (_jsxs("button", { type: "button", role: "menuitem", className: "mi", onClick: act(p.onReportFace), children: [_jsx(ReportIcon, {}), " Report a problem"] })) : null, _jsxs("a", { role: "menuitem", className: "mi", href: snap.workspaceUrl, target: "_blank", rel: "noopener noreferrer", onClick: p.onClose, children: [_jsx(HomeIcon, {}), " Go to vitrinka", _jsx("span", { className: "end", children: _jsx(NewTabIcon, {}) })] }), _jsx("div", { className: "m-rule" }), _jsxs("div", { className: "m-row", children: [_jsx("span", { id: "vt-size", children: "Size" }), _jsx("span", { className: "sizes", role: "group", "aria-labelledby": "vt-size", style: { '--i': String(Math.max(0, sizeIndex)) }, children: SIZES.map((s) => (_jsx("button", { type: "button", role: "menuitemradio", "aria-checked": snap.prefs.size === s.size, "aria-label": `Size ${s.name}`, onClick: () => p.onSize(s.size), children: s.label }, s.size))) })] }), _jsxs("div", { className: "m-row toggle", role: "menuitemcheckbox", "aria-checked": snap.prefs.verbose, tabIndex: 0, onClick: () => p.onVerbose(!snap.prefs.verbose), onKeyDown: (e) => {
62
62
  if (e.key !== 'Enter' && e.key !== ' ')
63
63
  return;
64
64
  e.preventDefault();
@@ -1,4 +1,17 @@
1
1
  export declare function shield(el: HTMLElement): void;
2
+ export interface GuardedKey {
3
+ key: string;
4
+ code: string;
5
+ altKey: boolean;
6
+ ctrlKey: boolean;
7
+ metaKey: boolean;
8
+ getModifierState?: (key: string) => boolean;
9
+ composedPath: () => readonly unknown[];
10
+ }
11
+ /** A key that edits text: a character, the caret and delete keys, or a text-editing chord. Enter, Escape and Tab never are. */
12
+ export declare function typingKey(e: Omit<GuardedKey, 'composedPath'>): boolean;
13
+ /** The guard's whole rule: a typing key whose real target (`composedPath()[0]`) is a text field inside a HUD or sheet host. */
14
+ export declare function guardsKey(e: GuardedKey): boolean;
2
15
  export interface HudHost {
3
16
  host: HTMLElement;
4
17
  /** The React mount point inside the shadow root. */
@@ -13,6 +13,7 @@
13
13
  */
14
14
  import { RRWEB_BLOCK_ATTR } from '../block';
15
15
  import { HOST_STYLE, SHEET_HOST_STYLE } from './host-style';
16
+ import { listen } from './listen';
16
17
  const SHIELDED = [
17
18
  'pointerdown', 'pointerup', 'pointermove', 'pointerover', 'pointerout', 'pointercancel',
18
19
  'mousedown', 'mouseup', 'mousemove', 'mouseover', 'mouseout', 'click', 'dblclick', 'auxclick',
@@ -25,6 +26,91 @@ export function shield(el) {
25
26
  for (const t of SHIELDED)
26
27
  el.addEventListener(t, (e) => e.stopPropagation());
27
28
  }
29
+ /**
30
+ * The KEY GUARD (vt-8020 S14): the bubble-phase shield above comes too late
31
+ * for a host that listens in the CAPTURE phase on window or document (the
32
+ * PWF designer's BPMN modeler binds 'e' that way) — and shadow retargeting
33
+ * shows that listener our host element as `event.target`, never the field,
34
+ * so its "ignore keys while typing" check fails and typing 'e' in a note
35
+ * fires the host's tool. One window capture listener runs ahead of every
36
+ * document- and element-level one: a key typed into one of our fields stops
37
+ * there. Text still lands — stopping propagation never cancels the default
38
+ * action — and Enter, Escape and Tab pass untouched, so the widgets' own
39
+ * handlers (send, close, focus order) keep working; so do chords with
40
+ * Ctrl/⌘/Alt that are not text editing (the reporter's shortcut, the pill's
41
+ * ⌥⇧ chords). A window capture listener the page registered BEFORE the first
42
+ * host still runs first: nothing can precede it.
43
+ */
44
+ const GUARDED = ['keydown', 'keyup', 'keypress'];
45
+ const HOST_DATA = ['vitrinkaHud', 'vitrinkaSheet'];
46
+ /** Moving the caret or deleting, on their own or with a modifier (word and line steps). */
47
+ const CARET_KEYS = new Set(['Backspace', 'Delete', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End', 'PageUp', 'PageDown']);
48
+ /** ⌘/Ctrl + these are the field's own editing (select all, copy, cut, paste, undo, redo) — a host's would act on its canvas instead. */
49
+ const EDIT_CODES = new Set(['KeyA', 'KeyC', 'KeyX', 'KeyV', 'KeyZ', 'KeyY']);
50
+ /** Input types a person types text into; a checkbox's Space is not typing. */
51
+ const TEXT_INPUTS = new Set(['text', 'search', 'email', 'url', 'tel', 'password', 'number']);
52
+ /** A key that edits text: a character, the caret and delete keys, or a text-editing chord. Enter, Escape and Tab never are. */
53
+ export function typingKey(e) {
54
+ const char = e.key.length === 1;
55
+ // AltGr (Ctrl+Alt on Windows) types @, {, € on Czech and other layouts.
56
+ if (char && e.getModifierState?.('AltGraph'))
57
+ return true;
58
+ if (!e.altKey && !e.ctrlKey && !e.metaKey)
59
+ return char || CARET_KEYS.has(e.key);
60
+ if (CARET_KEYS.has(e.key))
61
+ return true;
62
+ return (e.ctrlKey || e.metaKey) && !e.altKey && EDIT_CODES.has(e.code);
63
+ }
64
+ function editable(n) {
65
+ if (typeof n !== 'object' || n === null)
66
+ return false;
67
+ if ('isContentEditable' in n && n.isContentEditable === true)
68
+ return true;
69
+ const tag = 'tagName' in n && typeof n.tagName === 'string' ? n.tagName : '';
70
+ if (tag === 'TEXTAREA')
71
+ return true;
72
+ return tag === 'INPUT' && 'type' in n && typeof n.type === 'string' && TEXT_INPUTS.has(n.type);
73
+ }
74
+ function ourHost(n) {
75
+ if (typeof n !== 'object' || n === null || !('dataset' in n))
76
+ return false;
77
+ const data = n.dataset;
78
+ return typeof data === 'object' && data !== null && HOST_DATA.some((k) => k in data);
79
+ }
80
+ /** The guard's whole rule: a typing key whose real target (`composedPath()[0]`) is a text field inside a HUD or sheet host. */
81
+ export function guardsKey(e) {
82
+ if (!typingKey(e))
83
+ return false;
84
+ const path = e.composedPath();
85
+ return editable(path[0]) && path.some(ourHost);
86
+ }
87
+ let guardHolders = 0;
88
+ let unguard = null;
89
+ /** Installs the page's one key guard with the first host; the last host's release removes it. */
90
+ function holdKeyGuard() {
91
+ guardHolders++;
92
+ if (!unguard && typeof window !== 'undefined') {
93
+ const guard = (e) => {
94
+ if (guardsKey(e))
95
+ e.stopImmediatePropagation();
96
+ };
97
+ const offs = GUARDED.map((t) => listen(window, t, guard, { capture: true }));
98
+ unguard = () => {
99
+ for (const off of offs)
100
+ off();
101
+ };
102
+ }
103
+ let held = true;
104
+ return () => {
105
+ if (!held)
106
+ return;
107
+ held = false;
108
+ if (--guardHolders > 0)
109
+ return;
110
+ unguard?.();
111
+ unguard = null;
112
+ };
113
+ }
28
114
  export function createHudHost() {
29
115
  const host = document.createElement('div');
30
116
  host.setAttribute(RRWEB_BLOCK_ATTR, '');
@@ -34,6 +120,7 @@ export function createHudHost() {
34
120
  const mount = document.createElement('div');
35
121
  root.append(mount);
36
122
  shield(host);
123
+ const releaseGuard = holdKeyGuard();
37
124
  document.documentElement.append(host);
38
125
  const canPop = typeof host.showPopover === 'function';
39
126
  const raise = () => {
@@ -114,6 +201,7 @@ export function createHudHost() {
114
201
  host,
115
202
  mount,
116
203
  destroy: () => {
204
+ releaseGuard();
117
205
  mo.disconnect();
118
206
  if (scanRaf !== 0 && typeof cancelAnimationFrame === 'function')
119
207
  cancelAnimationFrame(scanRaf);
@@ -160,8 +248,15 @@ export function createSheetHost(target) {
160
248
  const mount = document.createElement('div');
161
249
  root.append(mount);
162
250
  shield(el);
251
+ const releaseGuard = holdKeyGuard();
163
252
  target.append(el);
164
- return { mount, destroy: () => el.remove() };
253
+ return {
254
+ mount,
255
+ destroy: () => {
256
+ releaseGuard();
257
+ el.remove();
258
+ },
259
+ };
165
260
  }
166
261
  /** Is `t` inside any HUD surface (host or a portaled sheet)? */
167
262
  export function insideHud(t) {
@@ -29,4 +29,6 @@ export declare function AlertIcon(): ReactElement;
29
29
  export declare function SpinnerIcon(): ReactElement;
30
30
  export declare function UnlinkIcon(): ReactElement;
31
31
  export declare function BugIcon(): ReactElement;
32
+ /** A speech bubble with "!" — Report a problem, the report face. */
33
+ export declare function ReportIcon(): ReactElement;
32
34
  export declare function HomeIcon(): ReactElement;
@@ -76,6 +76,10 @@ export function UnlinkIcon() {
76
76
  export function BugIcon() {
77
77
  return (_jsxs("svg", { ...base, children: [_jsx("path", { d: "m8 2 1.88 1.88" }), _jsx("path", { d: "M14.12 3.88 16 2" }), _jsx("path", { d: "M9 7.13v-1a3.003 3.003 0 1 1 6 0v1" }), _jsx("path", { d: "M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6" }), _jsx("path", { d: "M12 20v-9" }), _jsx("path", { d: "M6.53 9C4.6 8.8 3 7.1 3 5" }), _jsx("path", { d: "M6 13H2" }), _jsx("path", { d: "M3 21c0-2.1 1.7-3.9 3.8-4" }), _jsx("path", { d: "M20.97 5c0 2.1-1.6 3.8-3.5 4" }), _jsx("path", { d: "M22 13h-4" }), _jsx("path", { d: "M17.2 17c2.1.1 3.8 1.9 3.8 4" })] }));
78
78
  }
79
+ /** A speech bubble with "!" — Report a problem, the report face. */
80
+ export function ReportIcon() {
81
+ return (_jsxs("svg", { ...base, children: [_jsx("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }), _jsx("path", { d: "M12 7v2" }), _jsx("path", { d: "M12 13h.01" })] }));
82
+ }
79
83
  export function HomeIcon() {
80
84
  return (_jsxs("svg", { ...base, children: [_jsx("path", { d: "M3 10.5 12 3l9 7.5" }), _jsx("path", { d: "M5 9v11h14V9" })] }));
81
85
  }
@@ -8,6 +8,8 @@ export interface MountHudOptions {
8
8
  * Defaults to `localStorage` (`vitrinka.recorder.*`), memory where that is unavailable.
9
9
  */
10
10
  storage?: RecorderStorage;
11
+ /** Adds "Report a problem" to the idle ⋯ menu, which calls this (the report face's way back); absent = no row. */
12
+ onReportFace?: () => void;
11
13
  }
12
14
  /** Mount the HUD; returns the unmount (removes the host). */
13
15
  export declare function mountRecorderHud(controller: HudController, opts?: MountHudOptions): () => void;
@@ -19,6 +19,7 @@ export function mountRecorderHud(controller, opts = {}) {
19
19
  hostMount: host.mount,
20
20
  defaultTitle: opts.title ?? (() => document.title),
21
21
  storage,
22
+ onReportFace: opts.onReportFace,
22
23
  }));
23
24
  return () => {
24
25
  root.unmount();
@@ -54,6 +54,12 @@ export declare function VitrinkaRecorderRoot(props: VitrinkaRecorderRootProps):
54
54
  export interface VitrinkaRecorderPillProps {
55
55
  /** Session title when the tester starts from the pill; defaults to `document.title`. */
56
56
  title?: string;
57
+ /**
58
+ * Adds "Report a problem" to the idle pill's ⋯ menu, which calls this —
59
+ * how `@vitrinka/web/report` swaps a member back to its report face. Read
60
+ * when the pill mounts; absent = no row.
61
+ */
62
+ onReportFace?: () => void;
57
63
  }
58
64
  /**
59
65
  * The HUD — mount it anywhere under the root (it renders into its own shadow
@@ -52,6 +52,8 @@ function RouteFeed({ route }) {
52
52
  export function VitrinkaRecorderPill(props) {
53
53
  const titleRef = useRef(props.title);
54
54
  titleRef.current = props.title;
55
+ const reportFaceRef = useRef(props.onReportFace);
56
+ reportFaceRef.current = props.onReportFace;
55
57
  useEffect(() => {
56
58
  if (!vitrinkaConfigured())
57
59
  return;
@@ -60,6 +62,7 @@ export function VitrinkaRecorderPill(props) {
60
62
  const unmount = mountRecorderHud(createPageController(), {
61
63
  title: () => titleRef.current ?? document.title,
62
64
  storage: getRecorderStorage(),
65
+ onReportFace: reportFaceRef.current ? () => reportFaceRef.current?.() : undefined,
63
66
  });
64
67
  return () => {
65
68
  unmount();
@@ -29,6 +29,8 @@ let stopping = null;
29
29
  let face = 'none';
30
30
  let remoteStop = null;
31
31
  let pingTimer = null;
32
+ /** The claim holder `refresh` last announced. */
33
+ let claimBy = null;
32
34
  // -- what this document knows --------------------------------------------------
33
35
  function heldClaim() {
34
36
  if (!env)
@@ -133,15 +135,22 @@ function armPing() {
133
135
  pingTimer = null;
134
136
  }
135
137
  }
136
- /** Re-derive the claim and who leads; announce a change of leader to the lanes and the HUD. */
138
+ /**
139
+ * Re-derive the claim and who leads; announce a change of leader or of the
140
+ * claim's holder to the lanes and the HUD. The HUD's remote face reads the
141
+ * holder (`followingElsewhere`), and the extension's hello can land before
142
+ * its claim: a holder arriving under an unchanged leader announces too.
143
+ */
137
144
  function refresh() {
138
145
  if (!env)
139
146
  return;
140
147
  syncClaim();
141
148
  const next = computeFollowing();
142
- if (next === leadState.following)
149
+ const by = readClaim(env)?.by ?? null;
150
+ if (next === leadState.following && by === claimBy)
143
151
  return;
144
152
  leadState.following = next;
153
+ claimBy = by;
145
154
  armPing();
146
155
  notify();
147
156
  }
@@ -297,6 +306,7 @@ function resetLead() {
297
306
  if (pingTimer)
298
307
  clearInterval(pingTimer);
299
308
  pingTimer = null;
309
+ claimBy = null;
300
310
  if (leadState.following !== null) {
301
311
  leadState.following = null;
302
312
  notify();
@@ -22,7 +22,7 @@ export async function linkDevice() {
22
22
  const start = await startLink(url, { label: defaultLinkLabel(), workspace });
23
23
  const ac = new AbortController();
24
24
  const linked = pollLink(url, start.device_code, { interval: start.interval, expiresIn: start.expires_in, workspace, signal: ac.signal }).then((l) => {
25
- storeLink(l);
25
+ storeLink({ ...l, base: url });
26
26
  return l;
27
27
  });
28
28
  return { start, linked, cancel: () => ac.abort() };
@@ -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.7.1";
3
- export declare const RECORDER_ID = "web/0.7.1";
2
+ export declare const RECORDER_VERSION = "0.8.0";
3
+ export declare const RECORDER_ID = "web/0.8.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.7.1';
2
+ export const RECORDER_VERSION = '0.8.0';
3
3
  export const RECORDER_ID = `web/${RECORDER_VERSION}`;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Files the reporter attaches (vt-8020 D9): picked with 📎, pasted or dropped
3
+ * onto the card, and checked against the project's caps BEFORE anything is
4
+ * sent — a file the server would refuse is refused at once, with a reason
5
+ * that names the cap. The caps come from `GET /api/v1/report-config`
6
+ * `attachments: {maxBytes, maxCount, types}` (the capture profile's); a
7
+ * server that names none gets the defaults below. The files ride the wire's
8
+ * attachment leg (wire.ts), never the `/shot` leg — that stays the report's
9
+ * one reviewed screenshot.
10
+ */
11
+ export interface AttachmentCaps {
12
+ /** Per file. */
13
+ maxBytes: number;
14
+ /** Per report. */
15
+ maxCount: number;
16
+ /** MIME types (`image/*` wildcards allowed) or `.ext` suffixes — the file input's `accept` vocabulary. */
17
+ types: readonly string[];
18
+ }
19
+ export declare const DEFAULT_ATTACHMENT_CAPS: AttachmentCaps;
20
+ /** What admit() reads of a file: a `File` has it all. */
21
+ export type AttachableFile = Pick<File, 'name' | 'type' | 'size' | 'lastModified'>;
22
+ export type Refusal = {
23
+ kind: 'type';
24
+ name: string;
25
+ } | {
26
+ kind: 'size';
27
+ name: string;
28
+ cap: number;
29
+ } | {
30
+ kind: 'count';
31
+ cap: number;
32
+ };
33
+ /** The server's `attachments`, field by field; anything missing or malformed takes its default. */
34
+ export declare function parseAttachmentCaps(raw: unknown): AttachmentCaps;
35
+ /** Does `types` let this file in — by its MIME type (wildcards too) or its name's suffix? */
36
+ export declare function typeAllowed(file: Pick<AttachableFile, 'name' | 'type'>, types: readonly string[]): boolean;
37
+ /**
38
+ * The incoming files that may join `current`, in order: a file already there
39
+ * is skipped quietly; a wrong type, an over-size file or one past the count
40
+ * is refused — `refusal` is the first such reason (one line on the card).
41
+ */
42
+ export declare function admit<F extends AttachableFile>(current: readonly F[], incoming: readonly F[], caps: AttachmentCaps): {
43
+ files: F[];
44
+ refusal: Refusal | null;
45
+ };
46
+ /** 2 kB, 1.4 MB, 10 MB — in the widget's language (binary units, as file dialogs count them). */
47
+ export declare function formatBytes(n: number, locale: string): string;
48
+ /** The caps' types as a person reads them: "images, PDF and text files". */
49
+ export declare function typesLabel(types: readonly string[], names: {
50
+ image: string;
51
+ pdf: string;
52
+ text: string;
53
+ office: string;
54
+ }, locale: string): string;
55
+ /** A clipboard image arrives as "image.png" every time: number it, so two pastes read as two chips. */
56
+ export declare function pastedName(name: string, n: number): string;
@@ -0,0 +1,91 @@
1
+ export const DEFAULT_ATTACHMENT_CAPS = {
2
+ maxBytes: 10 * 1024 * 1024,
3
+ maxCount: 5,
4
+ types: ['image/*', 'application/pdf', 'text/*'],
5
+ };
6
+ function positiveInt(v, fallback) {
7
+ return typeof v === 'number' && Number.isInteger(v) && v > 0 ? v : fallback;
8
+ }
9
+ /** The server's `attachments`, field by field; anything missing or malformed takes its default. */
10
+ export function parseAttachmentCaps(raw) {
11
+ if (typeof raw !== 'object' || raw === null)
12
+ return DEFAULT_ATTACHMENT_CAPS;
13
+ const caps = { ...raw };
14
+ const types = Array.isArray(caps.types) ? caps.types.filter((t) => typeof t === 'string' && t.trim() !== '').map((t) => t.trim().toLowerCase()) : [];
15
+ return {
16
+ maxBytes: positiveInt(caps.maxBytes, DEFAULT_ATTACHMENT_CAPS.maxBytes),
17
+ // 0 is a real answer: the project switched attaching off.
18
+ maxCount: typeof caps.maxCount === 'number' && Number.isInteger(caps.maxCount) && caps.maxCount >= 0 ? caps.maxCount : DEFAULT_ATTACHMENT_CAPS.maxCount,
19
+ types: types.length ? types : DEFAULT_ATTACHMENT_CAPS.types,
20
+ };
21
+ }
22
+ /** Does `types` let this file in — by its MIME type (wildcards too) or its name's suffix? */
23
+ export function typeAllowed(file, types) {
24
+ const mime = file.type.toLowerCase();
25
+ const name = file.name.toLowerCase();
26
+ return types.some((t) => {
27
+ if (t === '*' || t === '*/*')
28
+ return true;
29
+ if (t.startsWith('.'))
30
+ return name.endsWith(t);
31
+ if (t.endsWith('/*'))
32
+ return mime.startsWith(t.slice(0, -1));
33
+ return mime === t;
34
+ });
35
+ }
36
+ function same(a, b) {
37
+ return a.name === b.name && a.size === b.size && a.lastModified === b.lastModified;
38
+ }
39
+ /**
40
+ * The incoming files that may join `current`, in order: a file already there
41
+ * is skipped quietly; a wrong type, an over-size file or one past the count
42
+ * is refused — `refusal` is the first such reason (one line on the card).
43
+ */
44
+ export function admit(current, incoming, caps) {
45
+ const files = [];
46
+ let refusal = null;
47
+ for (const f of incoming) {
48
+ if ([...current, ...files].some((c) => same(c, f)))
49
+ continue;
50
+ if (!typeAllowed(f, caps.types))
51
+ refusal ??= { kind: 'type', name: f.name };
52
+ else if (f.size > caps.maxBytes)
53
+ refusal ??= { kind: 'size', name: f.name, cap: caps.maxBytes };
54
+ else if (current.length + files.length >= caps.maxCount)
55
+ refusal ??= { kind: 'count', cap: caps.maxCount };
56
+ else
57
+ files.push(f);
58
+ }
59
+ return { files, refusal };
60
+ }
61
+ /** 2 kB, 1.4 MB, 10 MB — in the widget's language (binary units, as file dialogs count them). */
62
+ export function formatBytes(n, locale) {
63
+ const fmt = (v, unit, digits) => `${new Intl.NumberFormat(locale, { maximumFractionDigits: digits }).format(v)} ${unit}`;
64
+ if (n < 1024)
65
+ return fmt(n, 'B', 0);
66
+ if (n < 1024 * 1024)
67
+ return fmt(n / 1024, 'kB', 0);
68
+ return fmt(n / (1024 * 1024), 'MB', n < 10 * 1024 * 1024 ? 1 : 0);
69
+ }
70
+ /** The caps' types as a person reads them: "images, PDF and text files". */
71
+ export function typesLabel(types, names, locale) {
72
+ // The server lists exact types (image/png, the office formats): a person reads them as a few groups.
73
+ const group = (t) => {
74
+ if (t.startsWith('image/'))
75
+ return names.image;
76
+ if (t === 'application/pdf' || t === '.pdf')
77
+ return names.pdf;
78
+ if (t.startsWith('text/'))
79
+ return names.text;
80
+ if (/officedocument|msword|ms-excel|ms-powerpoint|opendocument/.test(t))
81
+ return names.office;
82
+ return t.startsWith('.') ? t : (t.split('/')[1] ?? t);
83
+ };
84
+ const named = types.map(group);
85
+ return new Intl.ListFormat(locale, { type: 'conjunction' }).format([...new Set(named)]);
86
+ }
87
+ /** A clipboard image arrives as "image.png" every time: number it, so two pastes read as two chips. */
88
+ export function pastedName(name, n) {
89
+ const generic = /^image\.(\w+)$/i.exec(name);
90
+ return generic ? `pasted-${n}.${generic[1]}` : name;
91
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Where the floating button docks (vt-8020 D9): any of the four corners,
3
+ * dragged there (it snaps to the nearest on release) or moved with Alt+arrow
4
+ * keys from the focused button; remembered per origin in localStorage. The
5
+ * card's resting place follows the button's corner — above it at the bottom,
6
+ * below it at the top — and marking parks it from there (place.ts).
7
+ */
8
+ import type { Point } from './markers';
9
+ import type { Corner } from './place';
10
+ export declare const DOCK_KEY = "vitrinka.report.dock";
11
+ /** A press that travels less than this is a click, never a drag. */
12
+ export declare const DRAG_THRESHOLD = 6;
13
+ export declare function readDock(): Corner;
14
+ export declare function saveDock(c: Corner): void;
15
+ /** The corner whose quarter of the viewport holds `p` (the dragged button's centre). */
16
+ export declare function nearestCorner(p: Point, vw: number, vh: number): Corner;
17
+ /** Alt+arrow: the corner in that direction (the same one at the edge); null for any other key. */
18
+ export declare function cornerToward(c: Corner, key: string): Corner | null;
@@ -0,0 +1,34 @@
1
+ import { readPref, writePref } from './settings';
2
+ export const DOCK_KEY = 'vitrinka.report.dock';
3
+ /** A press that travels less than this is a click, never a drag. */
4
+ export const DRAG_THRESHOLD = 6;
5
+ const CORNERS = {
6
+ t: { l: 'tl', r: 'tr' },
7
+ b: { l: 'bl', r: 'br' },
8
+ };
9
+ const ALL = ['br', 'bl', 'tr', 'tl'];
10
+ function vertical(c) {
11
+ return c === 'tl' || c === 'tr' ? 't' : 'b';
12
+ }
13
+ function horizontal(c) {
14
+ return c === 'tl' || c === 'bl' ? 'l' : 'r';
15
+ }
16
+ export function readDock() {
17
+ const v = readPref(DOCK_KEY);
18
+ return ALL.find((c) => c === v) ?? 'br';
19
+ }
20
+ export function saveDock(c) {
21
+ writePref(DOCK_KEY, c);
22
+ }
23
+ /** The corner whose quarter of the viewport holds `p` (the dragged button's centre). */
24
+ export function nearestCorner(p, vw, vh) {
25
+ return CORNERS[p.y < vh / 2 ? 't' : 'b'][p.x < vw / 2 ? 'l' : 'r'];
26
+ }
27
+ /** Alt+arrow: the corner in that direction (the same one at the edge); null for any other key. */
28
+ export function cornerToward(c, key) {
29
+ if (key === 'ArrowLeft' || key === 'ArrowRight')
30
+ return CORNERS[vertical(c)][key === 'ArrowLeft' ? 'l' : 'r'];
31
+ if (key === 'ArrowUp' || key === 'ArrowDown')
32
+ return CORNERS[key === 'ArrowUp' ? 't' : 'b'][horizontal(c)];
33
+ return null;
34
+ }
@@ -12,7 +12,10 @@
12
12
  * hides the floating button, `open-selector` rebinds; a changed `key` or
13
13
  * `base` remounts. The face is config (QA Studio D6): `face: 'recorder'`
14
14
  * mounts the recorder pill instead (npm entry only — it needs React and a
15
- * `vkr_` key or a device link).
15
+ * `vkr_` key or a device link). A linked vitrinka member also switches faces
16
+ * in place (vt-8020 D8, face.ts): the report menu's Record swaps in the pill
17
+ * on the device link, the pill's "Report a problem" swaps back, and the pick
18
+ * survives a reload (npm entry only, like `face: 'recorder'`).
16
19
  */
17
20
  import type { RecordLoader } from './engine';
18
21
  import { type Locale } from './i18n';
@@ -47,6 +50,7 @@ export interface ReportOptions extends ReportScriptOptions {
47
50
  parent?: Element;
48
51
  }
49
52
  export interface ReportHandle {
53
+ /** The face on screen — a linked member's Record switch turns a `report` mount into `recorder`. */
50
54
  readonly face: ReportFace;
51
55
  open(): void;
52
56
  close(): void;
@@ -58,6 +62,8 @@ export interface ReportHandle {
58
62
  export interface VitrinkaReportElement extends HTMLElement {
59
63
  /** Set before the element connects (mountReport does). */
60
64
  options: ReportScriptOptions;
65
+ /** The face on screen: `recorder` while a linked member has switched to the pill. */
66
+ readonly face: ReportFace;
61
67
  open(): void;
62
68
  close(): void;
63
69
  identify(who: IdentifyInput): void;
@@ -70,9 +76,12 @@ declare global {
70
76
  }
71
77
  export interface RecorderFaceOptions {
72
78
  base: string;
73
- key: string;
79
+ /** A `vkr_` key; absent or empty = the stored device link (never a baked env key). */
80
+ key?: string;
74
81
  appVersion?: string;
75
82
  sanitizeUrl?: (url: string) => string;
83
+ /** The pill's menu offers "Report a problem", which calls this; absent = no row. */
84
+ onReportFace?: () => void;
76
85
  }
77
86
  /** What each build brings: how rrweb loads, the recorder face (npm only), the default base. */
78
87
  export interface Faces {