@vitrinka/web 0.7.2 → 0.8.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.
- package/CHANGELOG.md +162 -0
- package/README.md +130 -23
- package/build/hud.iife.js +15 -15
- package/build/one.iife.js +1 -1
- package/build/recorder/api.d.ts +5 -3
- package/build/recorder/api.js +5 -3
- package/build/recorder/config.d.ts +6 -2
- package/build/recorder/hud/Hud.d.ts +3 -1
- package/build/recorder/hud/Hud.js +2 -2
- package/build/recorder/hud/Menu.d.ts +7 -1
- package/build/recorder/hud/Menu.js +2 -2
- package/build/recorder/hud/host.d.ts +13 -0
- package/build/recorder/hud/host.js +96 -1
- package/build/recorder/hud/icons.d.ts +2 -0
- package/build/recorder/hud/icons.js +4 -0
- package/build/recorder/hud/mount.d.ts +2 -0
- package/build/recorder/hud/mount.js +1 -0
- package/build/recorder/index.d.ts +6 -0
- package/build/recorder/index.js +3 -0
- package/build/recorder/link.js +1 -1
- package/build/recorder/storage/index.d.ts +1 -1
- package/build/recorder/storage/index.js +3 -2
- package/build/recorder/storage/lock.js +85 -3
- package/build/recorder/version.d.ts +2 -2
- package/build/recorder/version.js +1 -1
- package/build/report/attachments.d.ts +56 -0
- package/build/report/attachments.js +91 -0
- package/build/report/drag.d.ts +18 -0
- package/build/report/drag.js +34 -0
- package/build/report/element.d.ts +11 -2
- package/build/report/element.js +106 -15
- package/build/report/engine.d.ts +13 -1
- package/build/report/engine.js +31 -4
- package/build/report/face.d.ts +23 -0
- package/build/report/face.js +92 -0
- package/build/report/i18n.d.ts +77 -3
- package/build/report/i18n.js +127 -6
- package/build/report/place.d.ts +26 -0
- package/build/report/place.js +33 -0
- package/build/report/reader.d.ts +42 -0
- package/build/report/reader.js +39 -0
- package/build/report/recorder-face.js +6 -2
- package/build/report/sent.d.ts +16 -0
- package/build/report/sent.js +39 -0
- package/build/report/settings.d.ts +32 -0
- package/build/report/settings.js +47 -0
- package/build/report/styles.d.ts +1 -1
- package/build/report/styles.js +223 -53
- package/build/report/widget.d.ts +122 -3
- package/build/report/widget.js +1125 -107
- package/build/report/wire.d.ts +59 -9
- package/build/report/wire.js +114 -14
- package/build/report-widget.mjs +232 -62
- package/package.json +1 -1
|
@@ -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
|
|
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 {
|
package/build/report/element.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { memberLinked, rememberFace, startFace, watchMemberLink } from './face';
|
|
1
2
|
import { parseLocale } from './i18n';
|
|
2
3
|
import { ReportWidget } from './widget';
|
|
3
4
|
export const REPORT_TAG = 'vitrinka-report';
|
|
@@ -14,36 +15,52 @@ export function defineReportElement(faces) {
|
|
|
14
15
|
return ATTRS;
|
|
15
16
|
}
|
|
16
17
|
options = {};
|
|
18
|
+
/** The mounted key and base; null until both are set. */
|
|
19
|
+
at = null;
|
|
20
|
+
/** The face on screen once mounted. */
|
|
21
|
+
shown = null;
|
|
17
22
|
widget = null;
|
|
23
|
+
/** Unmounts the recorder pill once its lazy face has loaded. */
|
|
24
|
+
pill = null;
|
|
25
|
+
/** Bumped whenever a face comes down: a pill that loads after its face was left never mounts. */
|
|
26
|
+
gen = 0;
|
|
27
|
+
/** The report widget currently offers Record. */
|
|
28
|
+
recordOffered = false;
|
|
29
|
+
offLink = null;
|
|
18
30
|
pendingIdentity = undefined;
|
|
31
|
+
get face() {
|
|
32
|
+
return this.shown ?? 'report';
|
|
33
|
+
}
|
|
19
34
|
connectedCallback() {
|
|
20
35
|
this.hidden = true;
|
|
21
|
-
this.
|
|
36
|
+
this.mount();
|
|
22
37
|
}
|
|
23
38
|
disconnectedCallback() {
|
|
24
|
-
this.
|
|
25
|
-
this.widget = null;
|
|
39
|
+
this.unmount();
|
|
26
40
|
}
|
|
27
41
|
attributeChangedCallback(name, old, value) {
|
|
28
42
|
if (old === value)
|
|
29
43
|
return;
|
|
30
|
-
if (!this.
|
|
44
|
+
if (!this.at) {
|
|
31
45
|
// Connected but waiting for its key or base (a host that configures later): mount now.
|
|
32
46
|
if (this.isConnected && (name === 'key' || name === 'base'))
|
|
33
|
-
this.
|
|
47
|
+
this.mount();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (name === 'key' || name === 'base') {
|
|
51
|
+
this.unmount();
|
|
52
|
+
this.mount();
|
|
34
53
|
return;
|
|
35
54
|
}
|
|
55
|
+
// The rest are the report face's: the pill reads none, and a switch back reads them afresh.
|
|
56
|
+
if (!this.widget)
|
|
57
|
+
return;
|
|
36
58
|
if (name === 'locale')
|
|
37
59
|
this.widget.setLocale(value);
|
|
38
60
|
else if (name === 'button')
|
|
39
61
|
this.widget.setButton(value !== 'false');
|
|
40
62
|
else if (name === 'open-selector')
|
|
41
63
|
this.widget.setOpenSelector(value);
|
|
42
|
-
else {
|
|
43
|
-
this.widget.unmount();
|
|
44
|
-
this.widget = null;
|
|
45
|
-
this.mountWidget();
|
|
46
|
-
}
|
|
47
64
|
}
|
|
48
65
|
open() {
|
|
49
66
|
this.widget?.open();
|
|
@@ -60,8 +77,8 @@ export function defineReportElement(faces) {
|
|
|
60
77
|
this.setAttribute('locale', String(locale));
|
|
61
78
|
}
|
|
62
79
|
/** Idempotent: an upgrade runs attributeChangedCallback before connectedCallback, and both land here. */
|
|
63
|
-
|
|
64
|
-
if (this.
|
|
80
|
+
mount() {
|
|
81
|
+
if (this.at)
|
|
65
82
|
return;
|
|
66
83
|
const key = (this.getAttribute('key') ?? '').trim();
|
|
67
84
|
const base = trimBase(this.getAttribute('base') ?? faces.defaultBase());
|
|
@@ -69,9 +86,60 @@ export function defineReportElement(faces) {
|
|
|
69
86
|
console.warn(`vitrinka: <${REPORT_TAG}> needs a key${base ? '' : ' and a base'} — nothing mounted`);
|
|
70
87
|
return;
|
|
71
88
|
}
|
|
89
|
+
this.at = { key, base };
|
|
90
|
+
// Only a build that carries the pill can switch to it (the single-file widget does not).
|
|
91
|
+
if (faces.recorderFace)
|
|
92
|
+
this.offLink = watchMemberLink(() => this.offerRecord());
|
|
93
|
+
this.show(faces.recorderFace ? startFace(base) : 'report');
|
|
94
|
+
}
|
|
95
|
+
unmount() {
|
|
96
|
+
this.offLink?.();
|
|
97
|
+
this.offLink = null;
|
|
98
|
+
this.takeDown();
|
|
99
|
+
this.at = null;
|
|
100
|
+
this.shown = null;
|
|
101
|
+
}
|
|
102
|
+
/** Take the face on screen down; the mount (and its link watch) stays. */
|
|
103
|
+
takeDown() {
|
|
104
|
+
this.gen++;
|
|
105
|
+
this.widget?.unmount();
|
|
106
|
+
this.widget = null;
|
|
107
|
+
this.recordOffered = false;
|
|
108
|
+
this.pill?.();
|
|
109
|
+
this.pill = null;
|
|
110
|
+
}
|
|
111
|
+
show(face) {
|
|
112
|
+
const at = this.at;
|
|
113
|
+
if (!at)
|
|
114
|
+
return;
|
|
115
|
+
this.takeDown();
|
|
116
|
+
const loadPill = faces.recorderFace;
|
|
117
|
+
if (face === 'recorder' && loadPill) {
|
|
118
|
+
this.shown = 'recorder';
|
|
119
|
+
const gen = this.gen;
|
|
120
|
+
loadPill()
|
|
121
|
+
.then((mountPill) => {
|
|
122
|
+
if (gen !== this.gen)
|
|
123
|
+
return;
|
|
124
|
+
// The member's own device link, never the host's key: a `vkb_` key cannot record.
|
|
125
|
+
this.pill = mountPill({
|
|
126
|
+
base: at.base,
|
|
127
|
+
appVersion: this.options.appVersion,
|
|
128
|
+
sanitizeUrl: this.options.sanitizeUrl,
|
|
129
|
+
onReportFace: () => this.switchTo('report'),
|
|
130
|
+
});
|
|
131
|
+
})
|
|
132
|
+
.catch((e) => {
|
|
133
|
+
console.warn('vitrinka: the recorder face did not load — showing Report a problem', e);
|
|
134
|
+
if (gen === this.gen)
|
|
135
|
+
this.show('report');
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
this.shown = 'report';
|
|
72
140
|
this.widget = new ReportWidget({
|
|
73
|
-
base,
|
|
74
|
-
key,
|
|
141
|
+
base: at.base,
|
|
142
|
+
key: at.key,
|
|
75
143
|
locale: parseLocale(this.getAttribute('locale')),
|
|
76
144
|
button: this.getAttribute('button') !== 'false',
|
|
77
145
|
openSelector: this.getAttribute('open-selector'),
|
|
@@ -81,6 +149,26 @@ export function defineReportElement(faces) {
|
|
|
81
149
|
sanitizeUrl: this.options.sanitizeUrl,
|
|
82
150
|
loadRecord: faces.loadRecord,
|
|
83
151
|
});
|
|
152
|
+
this.offerRecord();
|
|
153
|
+
}
|
|
154
|
+
/** Record is on the report face's menu exactly while this browser holds a member link for this base. */
|
|
155
|
+
offerRecord() {
|
|
156
|
+
if (!this.widget || !this.at)
|
|
157
|
+
return;
|
|
158
|
+
const offer = faces.recorderFace !== null && memberLinked(this.at.base);
|
|
159
|
+
if (offer === this.recordOffered)
|
|
160
|
+
return;
|
|
161
|
+
this.recordOffered = offer;
|
|
162
|
+
this.widget.setRecordSwitch(offer ? () => this.switchTo('recorder') : null);
|
|
163
|
+
}
|
|
164
|
+
/** The member's pick, remembered for this browser; applied once the menu that asked has let go of its click. */
|
|
165
|
+
switchTo(face) {
|
|
166
|
+
rememberFace(face);
|
|
167
|
+
const gen = this.gen;
|
|
168
|
+
setTimeout(() => {
|
|
169
|
+
if (gen === this.gen && this.shown !== face)
|
|
170
|
+
this.show(face);
|
|
171
|
+
}, 0);
|
|
84
172
|
}
|
|
85
173
|
}
|
|
86
174
|
customElements.define(REPORT_TAG, ReportElement);
|
|
@@ -106,7 +194,9 @@ export function mountReport(opts, faces) {
|
|
|
106
194
|
el.identify(opts.identity);
|
|
107
195
|
(opts.parent ?? document.body).append(el);
|
|
108
196
|
return {
|
|
109
|
-
face
|
|
197
|
+
get face() {
|
|
198
|
+
return el.face;
|
|
199
|
+
},
|
|
110
200
|
open: () => el.open(),
|
|
111
201
|
close: () => el.close(),
|
|
112
202
|
identify: (who) => el.identify(who),
|
|
@@ -125,6 +215,7 @@ function mountRecorder(opts, faces) {
|
|
|
125
215
|
faces
|
|
126
216
|
.recorderFace()
|
|
127
217
|
.then((mount) => {
|
|
218
|
+
// The host picked this face: no "Report a problem" row — there is no report key to swap back to.
|
|
128
219
|
if (!gone)
|
|
129
220
|
unmount = mount({ base, key: opts.key, appVersion: opts.appVersion, sanitizeUrl: opts.sanitizeUrl });
|
|
130
221
|
})
|
package/build/report/engine.d.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* driven by the project's capture profile instead of a recording:
|
|
4
4
|
*
|
|
5
5
|
* 1. `GET /api/v1/report-config` with the `vkb_` key → the capture profile
|
|
6
|
-
* (narrowed by the host's `capture` option)
|
|
6
|
+
* (narrowed by the host's `capture` option), the masking profile and the
|
|
7
|
+
* attachment caps (attachments.ts). An
|
|
7
8
|
* unreachable or older server means the safe fallback: memory, the last
|
|
8
9
|
* minute, strict masking.
|
|
9
10
|
* 2. The redaction rules first, then the lanes — so capture runs under the
|
|
@@ -25,6 +26,7 @@ import type { eventWithTime } from '@rrweb/types';
|
|
|
25
26
|
import { type RecordFn } from '../recorder/capture/rrweb-lane';
|
|
26
27
|
import { type FlightClip, type FlightLaneEvent } from '../recorder/flight';
|
|
27
28
|
import { EVENTS_PER_POST } from '../recorder/queue';
|
|
29
|
+
import { type AttachmentCaps } from './attachments';
|
|
28
30
|
import { type Marker } from './markers';
|
|
29
31
|
import { type CaptureLanes, type CaptureNarrowing, type CaptureProfile, type MaskingProfile } from './profile';
|
|
30
32
|
export { EVENTS_PER_POST };
|
|
@@ -50,6 +52,8 @@ export interface ReportConfig {
|
|
|
50
52
|
reachable: boolean;
|
|
51
53
|
/** This widget captures (false while the recorder face runs the page's capture). */
|
|
52
54
|
capturing: boolean;
|
|
55
|
+
/** What the reporter may attach (vt-8020 D9): the server's caps, else the defaults. */
|
|
56
|
+
attachments: AttachmentCaps;
|
|
53
57
|
}
|
|
54
58
|
export interface ConsoleEntry {
|
|
55
59
|
level: string;
|
|
@@ -121,6 +125,14 @@ export declare class CaptureEngine {
|
|
|
121
125
|
private standDown;
|
|
122
126
|
/** Freeze the capture now (the card opened); the buffer rolls on. */
|
|
123
127
|
freeze(): Frozen;
|
|
128
|
+
/**
|
|
129
|
+
* The card opened before the lazily loaded recorder ran (a slow network,
|
|
130
|
+
* device or runner): the frozen clip holds no screen of this page, and the
|
|
131
|
+
* report would go without its replay. When the recorder runs by Send, take
|
|
132
|
+
* its view now, as freeze() does for one that only just started. Earlier
|
|
133
|
+
* loads' windows and the console/network entries stay the frozen ones.
|
|
134
|
+
*/
|
|
135
|
+
private withScreen;
|
|
124
136
|
/**
|
|
125
137
|
* The rrweb ids of the page nodes under a hide right now — taken when the
|
|
126
138
|
* hide is drawn (the page sits frozen under the marking layer); null when
|
package/build/report/engine.js
CHANGED
|
@@ -9,6 +9,7 @@ import { listen } from '../recorder/hud/listen';
|
|
|
9
9
|
import { EVENTS_PER_POST, splitRRWebEvents, utf8Bytes } from '../recorder/queue';
|
|
10
10
|
import { browserTabId, claimCapture, currentRoute, releaseCapture, setTabIdentity } from '../recorder/state';
|
|
11
11
|
import { deleteCaptureStore, openCaptureStore } from '../recorder/storage/capture';
|
|
12
|
+
import { DEFAULT_ATTACHMENT_CAPS, parseAttachmentCaps } from './attachments';
|
|
12
13
|
import { applyHides, hiddenNodeIds } from './markers';
|
|
13
14
|
import { lanesOf, legacyProfile, maskingOf, maskingPolicy, narrowProfile, parseProfile, UNMASK_SELECTOR, } from './profile';
|
|
14
15
|
export { EVENTS_PER_POST };
|
|
@@ -99,11 +100,15 @@ async function fetchConfig(target) {
|
|
|
99
100
|
profile: res.captureProfile == null ? legacyProfile(flight) : parseProfile(res.captureProfile, flight),
|
|
100
101
|
masking: maskingOf(res.profile),
|
|
101
102
|
reachable: true,
|
|
103
|
+
// vitrinka serves the caps inside the capture profile; a top-level `attachments` is read as a fallback.
|
|
104
|
+
attachments: parseAttachmentCaps(typeof res.captureProfile === 'object' && res.captureProfile !== null && 'attachments' in res.captureProfile
|
|
105
|
+
? res.captureProfile.attachments
|
|
106
|
+
: res.attachments),
|
|
102
107
|
};
|
|
103
108
|
}
|
|
104
109
|
catch (e) {
|
|
105
110
|
console.warn('vitrinka: report config unavailable — capturing the last minute, strictly masked', e);
|
|
106
|
-
return { project: '', profile: legacyProfile(), masking: 'strict', reachable: false };
|
|
111
|
+
return { project: '', profile: legacyProfile(), masking: 'strict', reachable: false, attachments: DEFAULT_ATTACHMENT_CAPS };
|
|
107
112
|
}
|
|
108
113
|
}
|
|
109
114
|
/** rrweb's mirror off the running recorder, when it carries one (the vendor build may not). */
|
|
@@ -149,6 +154,7 @@ export class CaptureEngine {
|
|
|
149
154
|
masking: fetched.masking,
|
|
150
155
|
reachable: fetched.reachable,
|
|
151
156
|
capturing: false,
|
|
157
|
+
attachments: fetched.attachments,
|
|
152
158
|
};
|
|
153
159
|
if (this.stopped)
|
|
154
160
|
return config;
|
|
@@ -282,6 +288,26 @@ export class CaptureEngine {
|
|
|
282
288
|
stored.catch(() => undefined); // build reports a failed read
|
|
283
289
|
return { clip, stored };
|
|
284
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* The card opened before the lazily loaded recorder ran (a slow network,
|
|
293
|
+
* device or runner): the frozen clip holds no screen of this page, and the
|
|
294
|
+
* report would go without its replay. When the recorder runs by Send, take
|
|
295
|
+
* its view now, as freeze() does for one that only just started. Earlier
|
|
296
|
+
* loads' windows and the console/network entries stay the frozen ones.
|
|
297
|
+
*/
|
|
298
|
+
withScreen(clip) {
|
|
299
|
+
if (!this.capturing || !runningRecord() || (clip && clipHasSnapshot(clip)))
|
|
300
|
+
return clip;
|
|
301
|
+
checkoutRRWeb();
|
|
302
|
+
const now = takeFlightClip();
|
|
303
|
+
if (!now)
|
|
304
|
+
return clip;
|
|
305
|
+
return {
|
|
306
|
+
windows: [...(clip?.windows.filter((w) => w.stored) ?? []), ...now.windows.filter((w) => !w.stored)],
|
|
307
|
+
lanes: clip?.lanes ?? now.lanes,
|
|
308
|
+
truncated: clip?.truncated ?? now.truncated,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
285
311
|
/**
|
|
286
312
|
* The rrweb ids of the page nodes under a hide right now — taken when the
|
|
287
313
|
* hide is drawn (the page sits frozen under the marking layer); null when
|
|
@@ -311,12 +337,13 @@ export class CaptureEngine {
|
|
|
311
337
|
for (const id of hiddenNodeIds(hides, mirror))
|
|
312
338
|
hiddenIds.add(id);
|
|
313
339
|
const events = [];
|
|
314
|
-
|
|
340
|
+
const clip = this.withScreen(frozen.clip);
|
|
341
|
+
let truncated = clip?.truncated ?? false;
|
|
315
342
|
const pinned = await frozen.stored.catch((e) => {
|
|
316
343
|
console.warn('vitrinka: the stored part of the capture could not be read — the replay starts later', e);
|
|
317
344
|
return null;
|
|
318
345
|
});
|
|
319
|
-
for (const w of
|
|
346
|
+
for (const w of clip?.windows ?? []) {
|
|
320
347
|
if (!w.stored) {
|
|
321
348
|
events.push(...w.events);
|
|
322
349
|
continue;
|
|
@@ -329,7 +356,7 @@ export class CaptureEngine {
|
|
|
329
356
|
events.push(...read.events);
|
|
330
357
|
}
|
|
331
358
|
// The console and network entries, earlier loads' included (priorLanes).
|
|
332
|
-
const lanes =
|
|
359
|
+
const lanes = clip?.lanes ?? [];
|
|
333
360
|
const whole = withheld ? { events: [], dropped: false } : wholeWindows(applyHides(events, hides, hiddenIds), CHUNK_HARD_BYTES);
|
|
334
361
|
if (whole.dropped)
|
|
335
362
|
truncated = true;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ReportFace } from './element';
|
|
2
|
+
/** localStorage key of the face this browser last picked on this origin. */
|
|
3
|
+
export declare const FACE_KEY = "vitrinka.report.face";
|
|
4
|
+
/**
|
|
5
|
+
* This browser holds a member link for `base`: one recorded as minted there,
|
|
6
|
+
* or — a link stored before links carried their base — one pinned to the
|
|
7
|
+
* workspace `base` addresses (any, for a bare origin).
|
|
8
|
+
*/
|
|
9
|
+
export declare function memberLinked(base: string): boolean;
|
|
10
|
+
/** The face this browser last picked here; null when it never picked (or storage is blocked). */
|
|
11
|
+
export declare function rememberedFace(): ReportFace | null;
|
|
12
|
+
export declare function rememberFace(face: ReportFace): void;
|
|
13
|
+
/** localStorage key of the linked member's display mode, as `/api/v1/recorder/me` last answered it. */
|
|
14
|
+
export declare const MODE_KEY = "vitrinka.report.mode";
|
|
15
|
+
export declare function rememberDisplayMode(mode: string | undefined): void;
|
|
16
|
+
/** The face a mount starts on: a member's last pick, else the pill for a dev-mode member; everyone else the report face. */
|
|
17
|
+
export declare function startFace(base: string): ReportFace;
|
|
18
|
+
/**
|
|
19
|
+
* Hear the stored link change: another tab's link or unlink (the storage
|
|
20
|
+
* event), or this document's (`storeLink` / `clearLink` notify). Returns the
|
|
21
|
+
* unsubscribe.
|
|
22
|
+
*/
|
|
23
|
+
export declare function watchMemberLink(onChange: () => void): () => void;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which face a `<vitrinka-report>` shows (vt-8020 D8): Report a problem, or —
|
|
3
|
+
* for a linked vitrinka member — the recorder pill, switched in place and
|
|
4
|
+
* remembered per browser and origin (`vitrinka.report.face` in localStorage).
|
|
5
|
+
*
|
|
6
|
+
* A member is a browser holding the device link the member link flow minted
|
|
7
|
+
* (`vitrinka.recorder.link`) on the widget's own `base`. A reporter holds
|
|
8
|
+
* none, and a `vkr_` key the host passes is a build's key, never a person:
|
|
9
|
+
* neither ever gets the switch. A member who never picked starts where their
|
|
10
|
+
* account's display mode says (D8: dev starts on the pill) — the mode
|
|
11
|
+
* `GET /api/v1/recorder/me` answers, remembered here once the widget read it.
|
|
12
|
+
*/
|
|
13
|
+
import { linkWorkspace } from '@vitrinka/link';
|
|
14
|
+
import { LINK_KEY, readLink } from '../recorder/config';
|
|
15
|
+
import { subscribe } from '../recorder/state';
|
|
16
|
+
import { getRecorderStorage } from '../recorder/storage';
|
|
17
|
+
/** localStorage key of the face this browser last picked on this origin. */
|
|
18
|
+
export const FACE_KEY = 'vitrinka.report.face';
|
|
19
|
+
const trimBase = (url) => url.trim().replace(/\/+$/, '');
|
|
20
|
+
function store() {
|
|
21
|
+
try {
|
|
22
|
+
return globalThis.localStorage ?? null;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null; // storage blocked (sandboxed frame, privacy mode): every mount starts on the report face
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* This browser holds a member link for `base`: one recorded as minted there,
|
|
30
|
+
* or — a link stored before links carried their base — one pinned to the
|
|
31
|
+
* workspace `base` addresses (any, for a bare origin).
|
|
32
|
+
*/
|
|
33
|
+
export function memberLinked(base) {
|
|
34
|
+
const link = readLink();
|
|
35
|
+
if (!link)
|
|
36
|
+
return false;
|
|
37
|
+
if (link.base)
|
|
38
|
+
return trimBase(link.base) === trimBase(base);
|
|
39
|
+
try {
|
|
40
|
+
const ws = linkWorkspace(base);
|
|
41
|
+
return ws === undefined || ws === link.workspace;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return false; // not a URL: no link can be for it
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** The face this browser last picked here; null when it never picked (or storage is blocked). */
|
|
48
|
+
export function rememberedFace() {
|
|
49
|
+
const v = store()?.getItem(FACE_KEY);
|
|
50
|
+
return v === 'recorder' || v === 'report' ? v : null;
|
|
51
|
+
}
|
|
52
|
+
export function rememberFace(face) {
|
|
53
|
+
try {
|
|
54
|
+
store()?.setItem(FACE_KEY, face);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
console.warn('vitrinka: the picked face could not be remembered — the next load starts on Report a problem', e);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** localStorage key of the linked member's display mode, as `/api/v1/recorder/me` last answered it. */
|
|
61
|
+
export const MODE_KEY = 'vitrinka.report.mode';
|
|
62
|
+
export function rememberDisplayMode(mode) {
|
|
63
|
+
try {
|
|
64
|
+
if (mode === 'dev' || mode === 'regular')
|
|
65
|
+
store()?.setItem(MODE_KEY, mode);
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
console.warn('vitrinka: the display mode could not be remembered — the next load starts on Report a problem', e);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** The face a mount starts on: a member's last pick, else the pill for a dev-mode member; everyone else the report face. */
|
|
72
|
+
export function startFace(base) {
|
|
73
|
+
if (!memberLinked(base))
|
|
74
|
+
return 'report';
|
|
75
|
+
const picked = rememberedFace();
|
|
76
|
+
if (picked)
|
|
77
|
+
return picked;
|
|
78
|
+
return store()?.getItem(MODE_KEY) === 'dev' ? 'recorder' : 'report';
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Hear the stored link change: another tab's link or unlink (the storage
|
|
82
|
+
* event), or this document's (`storeLink` / `clearLink` notify). Returns the
|
|
83
|
+
* unsubscribe.
|
|
84
|
+
*/
|
|
85
|
+
export function watchMemberLink(onChange) {
|
|
86
|
+
const offOther = getRecorderStorage().watch?.(LINK_KEY, () => onChange());
|
|
87
|
+
const offHere = subscribe(onChange);
|
|
88
|
+
return () => {
|
|
89
|
+
offOther?.();
|
|
90
|
+
offHere();
|
|
91
|
+
};
|
|
92
|
+
}
|