@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
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
|
});
|
|
@@ -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
|
-
|
|
58
|
-
export
|
|
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
|
|
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 {
|
|
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;
|
|
@@ -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
|
package/build/recorder/index.js
CHANGED
|
@@ -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();
|
package/build/recorder/link.js
CHANGED
|
@@ -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() };
|
|
@@ -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.
|
|
3
|
-
export declare const RECORDER_ID = "web/0.
|
|
2
|
+
export declare const RECORDER_VERSION = "0.8.1";
|
|
3
|
+
export declare const RECORDER_ID = "web/0.8.1";
|
|
@@ -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;
|