@vitrinka/web 0.8.0 → 0.8.2
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 +58 -0
- package/README.md +19 -6
- 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/lead.d.ts +2 -0
- package/build/recorder/lead.js +4 -0
- 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/element.d.ts +2 -19
- package/build/report/element.js +76 -4
- package/build/report/engine.d.ts +8 -0
- package/build/report/engine.js +24 -3
- package/build/report/face.d.ts +7 -0
- package/build/report/face.js +11 -0
- package/build/report/i18n.d.ts +2 -0
- package/build/report/i18n.js +2 -0
- package/build/report/styles.d.ts +1 -1
- package/build/report/styles.js +9 -3
- package/build/report/widget.d.ts +17 -2
- package/build/report/widget.js +94 -39
- package/build/report/wire.d.ts +40 -1
- package/build/report/wire.js +74 -9
- package/build/report-widget.mjs +18 -12
- package/package.json +1 -1
package/build/one.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var{defineProperty:
|
|
1
|
+
(()=>{var{defineProperty:H,getOwnPropertyNames:w,getOwnPropertyDescriptor:d}=Object,p=Object.prototype.hasOwnProperty;function E(k){return this[k]}var f=(k)=>{var j=(x??=new WeakMap).get(k),q;if(j)return j;if(j=H({},"__esModule",{value:!0}),k&&typeof k==="object"||typeof k==="function"){for(var F of w(k))if(!p.call(j,F))H(j,F,{get:E.bind(k,F),enumerable:!(q=d(k,F))||q.enumerable})}return x.set(k,j),j},x;var c=(k)=>k;function b(k,j){this[k]=c.bind(null,j)}var l=(k,j)=>{for(var q in j)H(k,q,{get:j[q],enumerable:!0,configurable:!0,set:b.bind(j,q)})};var Yj={};var g={};l(g,{watchClaim:()=>qj,updateClaim:()=>jj,unmarkPage:()=>Jj,takeClaim:()=>e,serveHello:()=>Uj,serveCommands:()=>Xj,serializeClaim:()=>o,sendCommand:()=>Wj,releaseClaim:()=>kj,readClaim:()=>P,parseHello:()=>S,parseCommand:()=>i,parseClaim:()=>y,parseAck:()=>N,pageMarked:()=>Qj,nonce:()=>L,markPage:()=>Fj,isLive:()=>I,holderAnswers:()=>h,documentEnv:()=>s,ask:()=>_,answeredBy:()=>A,announce:()=>T,PAGE_ATTR:()=>Z,ONE_VERSION:()=>X,LEAD_ATTR:()=>Y,HELLO_EVENT:()=>$,COMMAND_EVENT:()=>u,ACK_EVENT:()=>C});function O(k,j,q,F={}){let J=k,Q=J.__zone_symbol__addEventListener??k.addEventListener,W=J.__zone_symbol__removeEventListener??k.removeEventListener,z=F.capture??!1;return Q.call(k,j,q,{capture:z,passive:!1}),()=>W.call(k,j,q,z)}var X=1,Z="data-vitrinka-page",Y="data-vitrinka-lead",$="vitrinka:hello",u="vitrinka:command",C="vitrinka:ack";function s(){let j=globalThis.document?.documentElement;if(!j||typeof globalThis.dispatchEvent!=="function")return null;return{root:j,bus:globalThis}}function L(k){return`${k}.${Math.random().toString(36).slice(2,10)}`}var t=["page","extension"],a=["starting","recording","paused","stopping","saved"],n=["pause","stop","note"],v=["not_recording","stopping","not_here","bad_command"];function K(k){if(typeof k!=="string")return null;try{let j=JSON.parse(k);return j!==null&&typeof j==="object"&&!Array.isArray(j)?j:null}catch{return null}}var U=(k)=>typeof k==="string",B=(k)=>U(k)&&t.includes(k),R=(k)=>U(k)&&a.includes(k),M=(k)=>typeof k==="number"&&Number.isInteger(k)&&k>=1;function y(k){let j=K(k);if(!j||!M(j.v)||!B(j.by)||!U(j.id)||!j.id||!R(j.state))return null;return{v:j.v,by:j.by,id:j.id,state:j.state,sessionId:U(j.sessionId)?j.sessionId:Number.isFinite(j.sessionId)?String(j.sessionId):"",since:typeof j.since==="number"?j.since:0}}function o(k){return JSON.stringify({v:k.v,by:k.by,id:k.id,state:k.state,sessionId:k.sessionId,since:k.since})}function I(k){return k!==void 0&&k!==null&&k!=="saved"}function r(k){if(k===null||typeof k!=="object"||Array.isArray(k))return null;let j=k;if(!B(j.by)||!R(j.state))return null;return{by:j.by,state:j.state,here:j.here===!0,...U(j.id)&&j.id?{id:j.id}:{}}}function S(k){let j=K(k);if(!j||!M(j.v)||!B(j.from)||!U(j.inst)||!j.inst)return null;let q=r(j.live);return{v:j.v,from:j.from,inst:j.inst,...j.ask===!0?{ask:!0}:{},...j.live!==void 0?{live:q}:{},...j.gone===!0?{gone:!0}:{}}}function i(k){let j=K(k);if(!j||!M(j.v)||!B(j.from)||!U(j.inst)||!j.inst||!U(j.id)||!j.id)return null;if(!U(j.op)||!n.includes(j.op))return null;return{v:j.v,from:j.from,inst:j.inst,id:j.id,op:j.op,...U(j.text)?{text:j.text}:{}}}function N(k){let j=K(k);if(!j||!M(j.v)||!B(j.from)||!U(j.inst)||!U(j.id)||typeof j.ok!=="boolean")return null;return{v:j.v,from:j.from,inst:j.inst,id:j.id,ok:j.ok,...U(j.code)&&v.includes(j.code)?{code:j.code}:{},...U(j.error)?{error:j.error}:{}}}function P(k){return y(k.root.getAttribute(Y))}function m(k,j){let q=o(j);if(k.root.getAttribute(Y)!==q)k.root.setAttribute(Y,q)}function e(k,j,q){let F=P(k);if(F&&F.id!==q.id&&I(F.state)&&h(k,j,F))return{ok:!1,holder:F};let J={v:X,by:j.from,id:q.id,state:q.state,sessionId:q.sessionId??"",since:F?.id===q.id&&I(F.state)?F.since:Date.now()};return m(k,J),{ok:!0,claim:J}}function jj(k,j,q){let F=P(k);if(F?.id!==j)return!1;return m(k,{...F,v:X,state:q.state,sessionId:q.sessionId??F.sessionId}),!0}function kj(k,j){if(P(k)?.id!==j)return!1;return k.root.removeAttribute(Y),!0}function qj(k,j){if(k.watch)return k.watch(j);if(typeof MutationObserver!=="function"||typeof Node>"u"||!(k.root instanceof Node))return()=>{return};let q=new MutationObserver(j);return q.observe(k.root,{attributes:!0,attributeFilter:[Y]}),()=>q.disconnect()}function Fj(k,j){if(k.root.getAttribute(Z)!==j)k.root.setAttribute(Z,j)}function Jj(k){k.root.removeAttribute(Z)}function Qj(k){return k.root.getAttribute(Z)!==null}function V(k,j,q){k.bus.dispatchEvent(new CustomEvent(j,{detail:JSON.stringify(q)}))}function D(k,j,q){return O(k.bus,j,(F)=>q(F.detail))}function _(k,j){let q=[],F=D(k,$,(J)=>{let Q=S(J);if(Q&&!Q.ask&&Q.inst!==j.inst)q.push(Q)});try{V(k,$,{v:X,from:j.from,inst:j.inst,ask:!0})}finally{F()}return q}function T(k,j,q,F={}){V(k,$,{v:X,from:j.from,inst:j.inst,live:q,...F.gone?{gone:!0}:{}})}function Uj(k,j,q,F,J={}){return D(k,$,(Q)=>{let W=S(Q);if(!W||W.inst===j.inst)return;if(!W.ask)F?.(W);else if(J.answerIf?.()??!0)T(k,j,q())})}function A(k,j){return k.some((q)=>q.live?.here===!0&&(q.live.id?q.live.id===j.id:q.from===j.by))}function h(k,j,q){return A(_(k,j),q)}function Wj(k,j,q,F){let J=L("c"),Q=null,W=D(k,C,(z)=>{let G=N(z);if(G&&G.id===J&&G.inst!==j.inst&&!Q)Q=G});try{V(k,u,{v:X,from:j.from,inst:j.inst,id:J,op:q,...F!==void 0?{text:F}:{}})}finally{W()}return Q}function Xj(k,j,q){return D(k,u,(F)=>{let J=i(F);if(!J||J.inst===j.inst)return;let Q=q(J);if(!Q)return;V(k,C,{v:X,from:j.from,inst:j.inst,id:J.id,...Q})})}globalThis.VitrinkaOne=Object.freeze({...g});})();
|
package/build/recorder/api.d.ts
CHANGED
|
@@ -52,6 +52,8 @@ export interface ApiOptions {
|
|
|
52
52
|
* Its 401 never touches the recorder's device link.
|
|
53
53
|
*/
|
|
54
54
|
target?: ApiTarget;
|
|
55
|
+
/** Cancels the request, its answer's body included — the report face's leg deadline (report/wire.ts). */
|
|
56
|
+
signal?: AbortSignal;
|
|
55
57
|
}
|
|
56
58
|
export declare function api<T = Record<string, unknown>>(method: string, path: string, body?: unknown, opts?: ApiOptions): Promise<T>;
|
|
57
59
|
/**
|
|
@@ -74,9 +76,9 @@ export declare function uploadImage(sessionId: string, seq: number, blob: Blob):
|
|
|
74
76
|
/**
|
|
75
77
|
* POST raw bytes (an rrweb chunk, an image) to a blob leaf under the
|
|
76
78
|
* configured bearer: the session doors above and the report face's
|
|
77
|
-
* `/api/v1/reports/{id}/chunk?seq=N` (with its own `target`
|
|
78
|
-
* server's `blobKey`.
|
|
79
|
+
* `/api/v1/reports/{id}/chunk?seq=N` (with its own `target` and leg
|
|
80
|
+
* deadline `signal`). Returns the server's `blobKey`.
|
|
79
81
|
*/
|
|
80
|
-
export declare function uploadTo(path: string, contentType: string, body: string | Blob, target?: ApiTarget): Promise<{
|
|
82
|
+
export declare function uploadTo(path: string, contentType: string, body: string | Blob, target?: ApiTarget, signal?: AbortSignal): Promise<{
|
|
81
83
|
blobKey?: string;
|
|
82
84
|
}>;
|
package/build/recorder/api.js
CHANGED
|
@@ -44,6 +44,7 @@ export async function api(method, path, body, opts = {}) {
|
|
|
44
44
|
mode: 'cors',
|
|
45
45
|
credentials: 'omit',
|
|
46
46
|
keepalive: opts.keepalive ?? false,
|
|
47
|
+
...(opts.signal ? { signal: opts.signal } : {}),
|
|
47
48
|
headers: {
|
|
48
49
|
authorization: `Bearer ${key}`,
|
|
49
50
|
...(body !== undefined ? { 'content-type': 'application/json' } : {}),
|
|
@@ -81,15 +82,16 @@ function upload(sessionId, leaf, seq, contentType, body) {
|
|
|
81
82
|
/**
|
|
82
83
|
* POST raw bytes (an rrweb chunk, an image) to a blob leaf under the
|
|
83
84
|
* configured bearer: the session doors above and the report face's
|
|
84
|
-
* `/api/v1/reports/{id}/chunk?seq=N` (with its own `target`
|
|
85
|
-
* server's `blobKey`.
|
|
85
|
+
* `/api/v1/reports/{id}/chunk?seq=N` (with its own `target` and leg
|
|
86
|
+
* deadline `signal`). Returns the server's `blobKey`.
|
|
86
87
|
*/
|
|
87
|
-
export async function uploadTo(path, contentType, body, target) {
|
|
88
|
+
export async function uploadTo(path, contentType, body, target, signal) {
|
|
88
89
|
const { url, key } = resolveTarget(target);
|
|
89
90
|
const res = await fetch(url + path, {
|
|
90
91
|
method: 'POST',
|
|
91
92
|
mode: 'cors',
|
|
92
93
|
credentials: 'omit',
|
|
94
|
+
...(signal ? { signal } : {}),
|
|
93
95
|
headers: { authorization: `Bearer ${key}`, 'content-type': contentType },
|
|
94
96
|
body,
|
|
95
97
|
});
|
package/build/recorder/lead.d.ts
CHANGED
|
@@ -67,6 +67,8 @@ export declare function startLead(h: LeadHandlers, at?: OneEnv | null): () => vo
|
|
|
67
67
|
export declare function claimForStart(): void;
|
|
68
68
|
/** The Start settled: created (the claim moves on with the session) or not (it goes). */
|
|
69
69
|
export declare function settleStart(created: boolean): void;
|
|
70
|
+
/** A Start claimed this document and waits on its session: no session record yet, but one is on its way. */
|
|
71
|
+
export declare function startInFlight(): boolean;
|
|
70
72
|
/** This document's Stop is draining `sessionId` (null: it settled). */
|
|
71
73
|
export declare function setLeadStopping(sessionId: string | null): void;
|
|
72
74
|
/** The HUD's flow face (D7). */
|
package/build/recorder/lead.js
CHANGED
|
@@ -369,6 +369,10 @@ export function settleStart(created) {
|
|
|
369
369
|
releaseClaim(env, self.inst);
|
|
370
370
|
refresh();
|
|
371
371
|
}
|
|
372
|
+
/** A Start claimed this document and waits on its session: no session record yet, but one is on its way. */
|
|
373
|
+
export function startInFlight() {
|
|
374
|
+
return starting;
|
|
375
|
+
}
|
|
372
376
|
/** This document's Stop is draining `sessionId` (null: it settled). */
|
|
373
377
|
export function setLeadStopping(sessionId) {
|
|
374
378
|
stopping = sessionId;
|
|
@@ -11,7 +11,7 @@ export interface RecorderStorage {
|
|
|
11
11
|
* shares (memory) has nothing to hear.
|
|
12
12
|
*/
|
|
13
13
|
watch?(key: string, onChange: (value: string | null) => void): () => void;
|
|
14
|
-
/** Run synchronously inside an exclusive cross-document lock. Required when shared across tabs. */
|
|
14
|
+
/** Run synchronously inside an exclusive cross-document lock that sees every earlier holder's writes. Required when shared across tabs. */
|
|
15
15
|
withLock?(name: string, run: () => void): Promise<void>;
|
|
16
16
|
/** Enumerate this driver's namespaced keys (cross-tab Stop participants). */
|
|
17
17
|
keys?(): string[];
|
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { withRecorderLock } from './lock';
|
|
14
14
|
// Keys land as `vitrinka.recorder.<key>`: rec · buffer · chunks · images ·
|
|
15
|
-
// blobs · link (the recorder)
|
|
16
|
-
// attached image's bytes live in
|
|
15
|
+
// blobs · link (the recorder), lock.seq (the seq lock's fence, ./lock) and
|
|
16
|
+
// dock · prefs · me · recents (the HUD). An attached image's bytes live in
|
|
17
|
+
// the blob journal (./blobs, IndexedDB).
|
|
17
18
|
const PREFIX = 'vitrinka.recorder.';
|
|
18
19
|
let current = null;
|
|
19
20
|
let used = false;
|
|
@@ -5,22 +5,104 @@ export async function withRecorderLock(name, run) {
|
|
|
5
5
|
await navigator.locks.request(key, { signal: AbortSignal.timeout(5000) }, run);
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
|
+
const fence = { area: localArea(), key: `vitrinka.recorder.lock.${name}` };
|
|
8
9
|
// Web Locks requires a secure context. IndexedDB readwrite transactions
|
|
9
10
|
// also serialize across tabs, including ordinary HTTP development hosts.
|
|
10
11
|
const db = await lockDatabase();
|
|
11
|
-
|
|
12
|
+
const unheard = { fence: undefined, since: 0 };
|
|
13
|
+
while (!(await holdOnce(db, key, fence, run, unheard)))
|
|
14
|
+
await pause();
|
|
15
|
+
}
|
|
16
|
+
/** One fence this tab never hears (its storage cleared, a write lost) holds it back this long; then it runs anyway. */
|
|
17
|
+
const HAND_OVER_MS = 1000;
|
|
18
|
+
const HEAR_POLL_MS = 5;
|
|
19
|
+
const pause = () => new Promise((resolve) => setTimeout(resolve, HEAR_POLL_MS));
|
|
20
|
+
function localArea() {
|
|
21
|
+
try {
|
|
22
|
+
return globalThis.localStorage ?? null;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null; // refused (a sandboxed frame): exclusion alone
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Has this document's localStorage heard the last holder's fence (none yet: nothing to hear)? */
|
|
29
|
+
function heard(fence, last) {
|
|
30
|
+
return typeof last !== 'string' || !fence.area || fence.area.getItem(fence.key) === last;
|
|
31
|
+
}
|
|
32
|
+
/** A new fence, written after this holder's own writes; null when the store refused it. */
|
|
33
|
+
function publishFence(fence) {
|
|
34
|
+
if (!fence.area)
|
|
35
|
+
return null;
|
|
36
|
+
const next = `${Date.now().toString(36)}.${Math.random().toString(36).slice(2)}`;
|
|
37
|
+
try {
|
|
38
|
+
fence.area.setItem(fence.key, next);
|
|
39
|
+
return next;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.warn('vitrinka: recorder lock fence not stored — the next tab may not see this allocation', error);
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Has this tab waited out `last`? The clock starts when a transaction first
|
|
48
|
+
* shows that fence, and again for a newer one: time spent queued for the
|
|
49
|
+
* lock, or suspended, never counts as time spent hearing its holder.
|
|
50
|
+
*/
|
|
51
|
+
function waitedOut(unheard, last) {
|
|
52
|
+
const now = Date.now();
|
|
53
|
+
if (unheard.fence !== last) {
|
|
54
|
+
unheard.fence = last;
|
|
55
|
+
unheard.since = now;
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (now - unheard.since < HAND_OVER_MS)
|
|
59
|
+
return false;
|
|
60
|
+
warnUnheard();
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
let unheardWarned = false;
|
|
64
|
+
function warnUnheard() {
|
|
65
|
+
if (unheardWarned)
|
|
66
|
+
return;
|
|
67
|
+
unheardWarned = true;
|
|
68
|
+
console.warn(`vitrinka: this tab did not hear the last recorder lock holder within ${HAND_OVER_MS} ms — numbering anyway`);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* One IndexedDB hold. A readwrite transaction excludes the other tabs but
|
|
72
|
+
* does not show them the holder's localStorage writes: Chromium keeps a copy
|
|
73
|
+
* of localStorage per renderer and delivers another tab's writes to it
|
|
74
|
+
* later, unordered with the transaction hand-over, so the next holder could
|
|
75
|
+
* read the seq watermark from before the last allocation and number a
|
|
76
|
+
* capture twice. Each holder therefore leaves a fresh fence in localStorage,
|
|
77
|
+
* after its own writes (they reach every tab in order), and in this
|
|
78
|
+
* transaction's record, which every tab reads coherently. A tab whose
|
|
79
|
+
* localStorage does not show the record's fence yet lets go and retries
|
|
80
|
+
* (the transaction would commit across a timer) until it hears it or waited
|
|
81
|
+
* it out.
|
|
82
|
+
*/
|
|
83
|
+
function holdOnce(db, key, fence, run, unheard) {
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
12
85
|
const tx = db.transaction('locks', 'readwrite');
|
|
13
|
-
|
|
86
|
+
const store = tx.objectStore('locks');
|
|
87
|
+
let ran = false;
|
|
88
|
+
tx.oncomplete = () => resolve(ran);
|
|
14
89
|
tx.onabort = () => reject(tx.error ?? new Error('vitrinka: recorder lock transaction aborted'));
|
|
15
|
-
const request =
|
|
90
|
+
const request = store.get(key);
|
|
16
91
|
request.onsuccess = () => {
|
|
92
|
+
if (!heard(fence, request.result) && !waitedOut(unheard, request.result))
|
|
93
|
+
return;
|
|
17
94
|
try {
|
|
18
95
|
run();
|
|
19
96
|
}
|
|
20
97
|
catch (error) {
|
|
21
98
|
reject(error);
|
|
22
99
|
tx.abort();
|
|
100
|
+
return;
|
|
23
101
|
}
|
|
102
|
+
ran = true;
|
|
103
|
+
const next = publishFence(fence);
|
|
104
|
+
if (next)
|
|
105
|
+
store.put(next, key);
|
|
24
106
|
};
|
|
25
107
|
});
|
|
26
108
|
}
|
|
@@ -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.8.
|
|
3
|
-
export declare const RECORDER_ID = "web/0.8.
|
|
2
|
+
export declare const RECORDER_VERSION = "0.8.2";
|
|
3
|
+
export declare const RECORDER_ID = "web/0.8.2";
|
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The two ways in, shared by the npm entry (`@vitrinka/web/report`) and the
|
|
3
|
-
* single-file widget (`build/report-widget.mjs`): the `<vitrinka-report>`
|
|
4
|
-
* custom element and `mountReport(opts)`, which creates one.
|
|
5
|
-
*
|
|
6
|
-
* <vitrinka-report key="vkb_…" base="https://vitrinka.example"
|
|
7
|
-
* locale="cs" button="false" open-selector="#help-report">
|
|
8
|
-
*
|
|
9
|
-
* The element is a configuration holder that renders nothing itself: the
|
|
10
|
-
* widget paints into the shared HUD host on `<html>` (top layer, shadow
|
|
11
|
-
* root). Attributes are live — `locale` repaints in place, `button` shows or
|
|
12
|
-
* hides the floating button, `open-selector` rebinds; a changed `key` or
|
|
13
|
-
* `base` remounts. The face is config (QA Studio D6): `face: 'recorder'`
|
|
14
|
-
* mounts the recorder pill instead (npm entry only — it needs React and a
|
|
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'`).
|
|
19
|
-
*/
|
|
20
1
|
import type { RecordLoader } from './engine';
|
|
21
2
|
import { type Locale } from './i18n';
|
|
22
3
|
import type { IdentifyInput } from './identity';
|
|
@@ -52,6 +33,7 @@ export interface ReportOptions extends ReportScriptOptions {
|
|
|
52
33
|
export interface ReportHandle {
|
|
53
34
|
/** The face on screen — a linked member's Record switch turns a `report` mount into `recorder`. */
|
|
54
35
|
readonly face: ReportFace;
|
|
36
|
+
/** Opens the card; on a member's switched pill it swaps back first (never while the pill records or starts to). */
|
|
55
37
|
open(): void;
|
|
56
38
|
close(): void;
|
|
57
39
|
identify(who: IdentifyInput): void;
|
|
@@ -64,6 +46,7 @@ export interface VitrinkaReportElement extends HTMLElement {
|
|
|
64
46
|
options: ReportScriptOptions;
|
|
65
47
|
/** The face on screen: `recorder` while a linked member has switched to the pill. */
|
|
66
48
|
readonly face: ReportFace;
|
|
49
|
+
/** Opens the card; on the pill it swaps back first (never while the pill records or starts to). */
|
|
67
50
|
open(): void;
|
|
68
51
|
close(): void;
|
|
69
52
|
identify(who: IdentifyInput): void;
|
package/build/report/element.js
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The two ways in, shared by the npm entry (`@vitrinka/web/report`) and the
|
|
3
|
+
* single-file widget (`build/report-widget.mjs`): the `<vitrinka-report>`
|
|
4
|
+
* custom element and `mountReport(opts)`, which creates one.
|
|
5
|
+
*
|
|
6
|
+
* <vitrinka-report key="vkb_…" base="https://vitrinka.example"
|
|
7
|
+
* locale="cs" button="false" open-selector="#help-report">
|
|
8
|
+
*
|
|
9
|
+
* The element is a configuration holder that renders nothing itself: the
|
|
10
|
+
* widget paints into the shared HUD host on `<html>` (top layer, shadow
|
|
11
|
+
* root). Attributes are live — `locale` repaints in place, `button` shows or
|
|
12
|
+
* hides the floating button, `open-selector` rebinds; a changed `key` or
|
|
13
|
+
* `base` remounts. The face is config (QA Studio D6): `face: 'recorder'`
|
|
14
|
+
* mounts the recorder pill instead (npm entry only — it needs React and a
|
|
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'`). The host's
|
|
19
|
+
* openers — `open()` and `open-selector` — swap back too and open the card,
|
|
20
|
+
* except while the pill records or starts to.
|
|
21
|
+
*/
|
|
22
|
+
import { listen } from '../recorder/hud/listen';
|
|
23
|
+
import { memberLinked, pillRecording, rememberFace, startFace, watchMemberLink } from './face';
|
|
2
24
|
import { parseLocale } from './i18n';
|
|
3
|
-
import { ReportWidget } from './widget';
|
|
25
|
+
import { hitsOpener, ReportWidget } from './widget';
|
|
4
26
|
export const REPORT_TAG = 'vitrinka-report';
|
|
5
27
|
const ATTRS = ['key', 'base', 'open-selector', 'locale', 'button'];
|
|
6
28
|
function trimBase(raw) {
|
|
@@ -26,6 +48,10 @@ export function defineReportElement(faces) {
|
|
|
26
48
|
gen = 0;
|
|
27
49
|
/** The report widget currently offers Record. */
|
|
28
50
|
recordOffered = false;
|
|
51
|
+
/** The host's `open-selector` control while the pill shows (the report widget binds it otherwise). */
|
|
52
|
+
offPillOpener = null;
|
|
53
|
+
/** An open() refused on a recording pill has said why. */
|
|
54
|
+
warnedRecording = false;
|
|
29
55
|
offLink = null;
|
|
30
56
|
pendingIdentity = undefined;
|
|
31
57
|
get face() {
|
|
@@ -52,7 +78,7 @@ export function defineReportElement(faces) {
|
|
|
52
78
|
this.mount();
|
|
53
79
|
return;
|
|
54
80
|
}
|
|
55
|
-
// The rest are the report face's: the pill reads
|
|
81
|
+
// The rest are the report face's: the pill's opener reads `open-selector` per click, and a switch back reads them afresh.
|
|
56
82
|
if (!this.widget)
|
|
57
83
|
return;
|
|
58
84
|
if (name === 'locale')
|
|
@@ -63,7 +89,10 @@ export function defineReportElement(faces) {
|
|
|
63
89
|
this.widget.setOpenSelector(value);
|
|
64
90
|
}
|
|
65
91
|
open() {
|
|
66
|
-
this.
|
|
92
|
+
if (this.shown === 'recorder')
|
|
93
|
+
this.openFromPill();
|
|
94
|
+
else
|
|
95
|
+
this.widget?.open();
|
|
67
96
|
}
|
|
68
97
|
close() {
|
|
69
98
|
this.widget?.close();
|
|
@@ -105,6 +134,8 @@ export function defineReportElement(faces) {
|
|
|
105
134
|
this.widget?.unmount();
|
|
106
135
|
this.widget = null;
|
|
107
136
|
this.recordOffered = false;
|
|
137
|
+
this.offPillOpener?.();
|
|
138
|
+
this.offPillOpener = null;
|
|
108
139
|
this.pill?.();
|
|
109
140
|
this.pill = null;
|
|
110
141
|
}
|
|
@@ -116,6 +147,13 @@ export function defineReportElement(faces) {
|
|
|
116
147
|
const loadPill = faces.recorderFace;
|
|
117
148
|
if (face === 'recorder' && loadPill) {
|
|
118
149
|
this.shown = 'recorder';
|
|
150
|
+
// The widget that binds the host's control is down while the pill shows: the control still reaches the card.
|
|
151
|
+
this.offPillOpener = listen(document, 'click', (ev) => {
|
|
152
|
+
if (!hitsOpener(ev, this.getAttribute('open-selector')))
|
|
153
|
+
return;
|
|
154
|
+
ev.preventDefault();
|
|
155
|
+
this.open();
|
|
156
|
+
});
|
|
119
157
|
const gen = this.gen;
|
|
120
158
|
loadPill()
|
|
121
159
|
.then((mountPill) => {
|
|
@@ -161,6 +199,40 @@ export function defineReportElement(faces) {
|
|
|
161
199
|
this.recordOffered = offer;
|
|
162
200
|
this.widget.setRecordSwitch(offer ? () => this.switchTo('recorder') : null);
|
|
163
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* A host opener on the pill: back to Report a problem — remembered as the
|
|
204
|
+
* pill's own row does — and the card opens there. Deferred like switchTo,
|
|
205
|
+
* then decided on the face this mount shows by then (a remount — a new
|
|
206
|
+
* key or base, a reconnect — drops it), asked again right before the
|
|
207
|
+
* pill comes down: never while it records or a Start waits on its
|
|
208
|
+
* session, as leaving strands it.
|
|
209
|
+
*/
|
|
210
|
+
openFromPill() {
|
|
211
|
+
if (this.keepsPill())
|
|
212
|
+
return;
|
|
213
|
+
const at = this.at;
|
|
214
|
+
setTimeout(() => {
|
|
215
|
+
if (!at || this.at !== at)
|
|
216
|
+
return;
|
|
217
|
+
if (this.shown === 'recorder') {
|
|
218
|
+
if (this.keepsPill())
|
|
219
|
+
return;
|
|
220
|
+
rememberFace('report');
|
|
221
|
+
this.show('report');
|
|
222
|
+
}
|
|
223
|
+
this.widget?.open();
|
|
224
|
+
}, 0);
|
|
225
|
+
}
|
|
226
|
+
/** The pill is recording (or starting to): it stays, and the first refusal says why. */
|
|
227
|
+
keepsPill() {
|
|
228
|
+
if (!pillRecording())
|
|
229
|
+
return false;
|
|
230
|
+
if (!this.warnedRecording) {
|
|
231
|
+
console.warn('vitrinka: Report a problem stays closed while the recorder pill records — leaving would strand the session; stop the recording first');
|
|
232
|
+
}
|
|
233
|
+
this.warnedRecording = true;
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
164
236
|
/** The member's pick, remembered for this browser; applied once the menu that asked has let go of its click. */
|
|
165
237
|
switchTo(face) {
|
|
166
238
|
rememberFace(face);
|
package/build/report/engine.d.ts
CHANGED
|
@@ -125,6 +125,14 @@ export declare class CaptureEngine {
|
|
|
125
125
|
private standDown;
|
|
126
126
|
/** Freeze the capture now (the card opened); the buffer rolls on. */
|
|
127
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;
|
|
128
136
|
/**
|
|
129
137
|
* The rrweb ids of the page nodes under a hide right now — taken when the
|
|
130
138
|
* hide is drawn (the page sits frozen under the marking layer); null when
|
package/build/report/engine.js
CHANGED
|
@@ -288,6 +288,26 @@ export class CaptureEngine {
|
|
|
288
288
|
stored.catch(() => undefined); // build reports a failed read
|
|
289
289
|
return { clip, stored };
|
|
290
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
|
+
}
|
|
291
311
|
/**
|
|
292
312
|
* The rrweb ids of the page nodes under a hide right now — taken when the
|
|
293
313
|
* hide is drawn (the page sits frozen under the marking layer); null when
|
|
@@ -317,12 +337,13 @@ export class CaptureEngine {
|
|
|
317
337
|
for (const id of hiddenNodeIds(hides, mirror))
|
|
318
338
|
hiddenIds.add(id);
|
|
319
339
|
const events = [];
|
|
320
|
-
|
|
340
|
+
const clip = this.withScreen(frozen.clip);
|
|
341
|
+
let truncated = clip?.truncated ?? false;
|
|
321
342
|
const pinned = await frozen.stored.catch((e) => {
|
|
322
343
|
console.warn('vitrinka: the stored part of the capture could not be read — the replay starts later', e);
|
|
323
344
|
return null;
|
|
324
345
|
});
|
|
325
|
-
for (const w of
|
|
346
|
+
for (const w of clip?.windows ?? []) {
|
|
326
347
|
if (!w.stored) {
|
|
327
348
|
events.push(...w.events);
|
|
328
349
|
continue;
|
|
@@ -335,7 +356,7 @@ export class CaptureEngine {
|
|
|
335
356
|
events.push(...read.events);
|
|
336
357
|
}
|
|
337
358
|
// The console and network entries, earlier loads' included (priorLanes).
|
|
338
|
-
const lanes =
|
|
359
|
+
const lanes = clip?.lanes ?? [];
|
|
339
360
|
const whole = withheld ? { events: [], dropped: false } : wholeWindows(applyHides(events, hides, hiddenIds), CHUNK_HARD_BYTES);
|
|
340
361
|
if (whole.dropped)
|
|
341
362
|
truncated = true;
|
package/build/report/face.d.ts
CHANGED
|
@@ -15,6 +15,13 @@ export declare const MODE_KEY = "vitrinka.report.mode";
|
|
|
15
15
|
export declare function rememberDisplayMode(mode: string | undefined): void;
|
|
16
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
17
|
export declare function startFace(base: string): ReportFace;
|
|
18
|
+
/**
|
|
19
|
+
* The pill holds a recording — the session record its ⋯ menu reads, which
|
|
20
|
+
* offers "Report a problem" only while there is none (Menu.tsx) — or a Start
|
|
21
|
+
* still waiting on its session. Leaving the pill then would strand the
|
|
22
|
+
* session, so a host opener never switches away.
|
|
23
|
+
*/
|
|
24
|
+
export declare function pillRecording(): boolean;
|
|
18
25
|
/**
|
|
19
26
|
* Hear the stored link change: another tab's link or unlink (the storage
|
|
20
27
|
* event), or this document's (`storeLink` / `clearLink` notify). Returns the
|
package/build/report/face.js
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { linkWorkspace } from '@vitrinka/link';
|
|
14
14
|
import { LINK_KEY, readLink } from '../recorder/config';
|
|
15
|
+
import { startInFlight } from '../recorder/lead';
|
|
16
|
+
import { getState } from '../recorder/queue';
|
|
15
17
|
import { subscribe } from '../recorder/state';
|
|
16
18
|
import { getRecorderStorage } from '../recorder/storage';
|
|
17
19
|
/** localStorage key of the face this browser last picked on this origin. */
|
|
@@ -77,6 +79,15 @@ export function startFace(base) {
|
|
|
77
79
|
return picked;
|
|
78
80
|
return store()?.getItem(MODE_KEY) === 'dev' ? 'recorder' : 'report';
|
|
79
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* The pill holds a recording — the session record its ⋯ menu reads, which
|
|
84
|
+
* offers "Report a problem" only while there is none (Menu.tsx) — or a Start
|
|
85
|
+
* still waiting on its session. Leaving the pill then would strand the
|
|
86
|
+
* session, so a host opener never switches away.
|
|
87
|
+
*/
|
|
88
|
+
export function pillRecording() {
|
|
89
|
+
return getState() !== null || startInFlight();
|
|
90
|
+
}
|
|
80
91
|
/**
|
|
81
92
|
* Hear the stored link change: another tab's link or unlink (the storage
|
|
82
93
|
* event), or this document's (`storeLink` / `clearLink` notify). Returns the
|
package/build/report/i18n.d.ts
CHANGED
|
@@ -92,6 +92,8 @@ export interface Strings {
|
|
|
92
92
|
myReports: string;
|
|
93
93
|
recentRecordings: string;
|
|
94
94
|
record: string;
|
|
95
|
+
/** Why Record waits: the switch to the pill would lose the unsent report. */
|
|
96
|
+
recordHasDraft: string;
|
|
95
97
|
openVitrinka: string;
|
|
96
98
|
openPortal: string;
|
|
97
99
|
loading: string;
|
package/build/report/i18n.js
CHANGED
|
@@ -82,6 +82,7 @@ const en = {
|
|
|
82
82
|
myReports: 'My reports',
|
|
83
83
|
recentRecordings: 'Recent recordings',
|
|
84
84
|
record: 'Record',
|
|
85
|
+
recordHasDraft: 'Send or clear the report you started first',
|
|
85
86
|
openVitrinka: 'Open vitrinka',
|
|
86
87
|
openPortal: 'Open the report portal',
|
|
87
88
|
loading: 'Loading…',
|
|
@@ -202,6 +203,7 @@ const cs = {
|
|
|
202
203
|
myReports: 'Moje hlášení',
|
|
203
204
|
recentRecordings: 'Nedávné nahrávky',
|
|
204
205
|
record: 'Nahrávat',
|
|
206
|
+
recordHasDraft: 'Odešlete nebo smažte rozepsané hlášení',
|
|
205
207
|
openVitrinka: 'Otevřít vitrinku',
|
|
206
208
|
openPortal: 'Otevřít portál hlášení',
|
|
207
209
|
loading: 'Načítám…',
|