@vitrinka/web 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +60 -0
- package/README.md +59 -5
- package/build/hud.d.ts +1 -1
- package/build/hud.iife.js +46 -9
- package/build/protocol/index.d.ts +55 -4
- package/build/protocol/index.js +4 -2
- package/build/recorder/api.d.ts +25 -5
- package/build/recorder/api.js +21 -9
- package/build/recorder/attachments.d.ts +19 -0
- package/build/recorder/attachments.js +31 -0
- package/build/recorder/hud/Hud.d.ts +1 -1
- package/build/recorder/hud/Hud.js +43 -10
- package/build/recorder/hud/Sheet.d.ts +40 -5
- package/build/recorder/hud/Sheet.js +134 -8
- package/build/recorder/hud/attach.d.ts +26 -0
- package/build/recorder/hud/attach.js +136 -0
- package/build/recorder/hud/controller.d.ts +31 -3
- package/build/recorder/hud/controller.js +1 -1
- package/build/recorder/hud/host.js +2 -0
- package/build/recorder/hud/icons.d.ts +3 -0
- package/build/recorder/hud/icons.js +7 -0
- package/build/recorder/hud/layer.d.ts +4 -1
- package/build/recorder/hud/layer.js +11 -3
- package/build/recorder/hud/resize.d.ts +83 -0
- package/build/recorder/hud/resize.js +236 -0
- package/build/recorder/hud/styles.d.ts +1 -1
- package/build/recorder/hud/styles.js +38 -1
- package/build/recorder/link.d.ts +4 -1
- package/build/recorder/link.js +6 -2
- package/build/recorder/me.d.ts +7 -0
- package/build/recorder/me.js +62 -12
- package/build/recorder/page-controller.js +4 -3
- package/build/recorder/queue.d.ts +33 -3
- package/build/recorder/queue.js +404 -24
- package/build/recorder/report.d.ts +9 -0
- package/build/recorder/report.js +46 -4
- package/build/recorder/session.d.ts +13 -5
- package/build/recorder/session.js +42 -12
- package/build/recorder/storage/blobs.d.ts +32 -0
- package/build/recorder/storage/blobs.js +83 -0
- package/build/recorder/storage/index.js +3 -2
- package/package.json +1 -1
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
*
|
|
12
12
|
* POST /api/v1/sessions SessionCreateRequest → SessionCreateResponse
|
|
13
13
|
* POST /api/v1/sessions/:id/events { events: RecorderEvent[] }
|
|
14
|
-
* POST /api/v1/sessions/:id/shot?seq=N (image body
|
|
15
|
-
*
|
|
14
|
+
* POST /api/v1/sessions/:id/shot?seq=N (image body, its own Content-Type;
|
|
15
|
+
* the event stream carries a
|
|
16
|
+
* matching 'shot' or 'attachment'
|
|
17
|
+
* event under the same seq)
|
|
16
18
|
* PATCH /api/v1/sessions/:id { status: SessionStatus }
|
|
17
19
|
*
|
|
18
20
|
* This module is types-only and dependency-free on purpose: the vitrinka
|
|
@@ -29,12 +31,50 @@ export interface RecorderEvent {
|
|
|
29
31
|
tabId: string;
|
|
30
32
|
/** Full pathname/host context the event happened on. */
|
|
31
33
|
tabHost: string;
|
|
32
|
-
/** Event kind: 'nav' | 'click' | 'shot' | 'note' | 'net' | 'console' | … */
|
|
34
|
+
/** Event kind: 'nav' | 'click' | 'shot' | 'note' | 'attachment' | 'net' | 'console' | … */
|
|
33
35
|
kind: string;
|
|
34
36
|
payload?: Record<string, unknown>;
|
|
35
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Server blob reference for 'shot' and 'attachment' events: the `blobKey`
|
|
39
|
+
* the `/shot?seq=N` upload of this event's bytes answered (set after upload).
|
|
40
|
+
*/
|
|
36
41
|
blobKey?: string;
|
|
37
42
|
}
|
|
43
|
+
/** The image types `/shot` accepts. */
|
|
44
|
+
export type ImageMime = 'image/png' | 'image/webp' | 'image/jpeg';
|
|
45
|
+
/**
|
|
46
|
+
* Payload of an 'attachment' event — one image a tester attached to a note.
|
|
47
|
+
* Its bytes are uploaded FIRST through `/shot?seq=<this event's seq>` (≤ 12
|
|
48
|
+
* MiB, the blob's own Content-Type) and the answer's `blobKey` rides the
|
|
49
|
+
* event, exactly like a 'shot'. Same `tabId`/`tabHost` as its note.
|
|
50
|
+
*/
|
|
51
|
+
export interface AttachmentPayload {
|
|
52
|
+
/** The original file name ("pasted image.png" for a paste). */
|
|
53
|
+
name: string;
|
|
54
|
+
mime: ImageMime;
|
|
55
|
+
/** The uploaded size in bytes. */
|
|
56
|
+
bytes: number;
|
|
57
|
+
/** Pixel size. */
|
|
58
|
+
w?: number;
|
|
59
|
+
h?: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Payload of a 'note' event. An annotation adds `rect`/`selector`/`annotate`
|
|
63
|
+
* (+ `task`); a note with `attachments` may have empty `text` (an image can
|
|
64
|
+
* BE the note), a bug report still needs its description.
|
|
65
|
+
*/
|
|
66
|
+
export interface NotePayload {
|
|
67
|
+
text: string;
|
|
68
|
+
route?: string;
|
|
69
|
+
/**
|
|
70
|
+
* The seqs of the 'attachment' events this note carries, allocated BEFORE
|
|
71
|
+
* the note's (strictly lower) so a stream replays in order. The server
|
|
72
|
+
* takes at most 10 per note, tolerates one that arrives after its note and
|
|
73
|
+
* one that never arrives (the note lands without it).
|
|
74
|
+
*/
|
|
75
|
+
attachments?: number[];
|
|
76
|
+
[key: string]: unknown;
|
|
77
|
+
}
|
|
38
78
|
export interface SessionCreateRequest {
|
|
39
79
|
/** App id the server resolves project+environment from. */
|
|
40
80
|
app: string;
|
|
@@ -65,6 +105,17 @@ export interface SessionReconcileResponse {
|
|
|
65
105
|
status?: string;
|
|
66
106
|
deletedAt?: string | null;
|
|
67
107
|
}
|
|
108
|
+
/** GET /api/v1/recorder/policy — read at session start. */
|
|
109
|
+
export interface RecorderPolicyResponse {
|
|
110
|
+
/** The workspace redaction policy (`@vitrinka/redact`); null = the engine's defaults. */
|
|
111
|
+
policy?: Record<string, unknown> | null;
|
|
112
|
+
fullFidelityAllowed?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Recorders offer image attachments only on `true`: absent on a server
|
|
115
|
+
* before them, `false` when the workspace switched them off.
|
|
116
|
+
*/
|
|
117
|
+
attachments?: boolean;
|
|
118
|
+
}
|
|
68
119
|
/**
|
|
69
120
|
* PATCH response when a session completes. The board is projected AFTER the
|
|
70
121
|
* stop, so `boardUrl` is usually absent here: `projection` says how far it
|
package/build/protocol/index.js
CHANGED
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
*
|
|
12
12
|
* POST /api/v1/sessions SessionCreateRequest → SessionCreateResponse
|
|
13
13
|
* POST /api/v1/sessions/:id/events { events: RecorderEvent[] }
|
|
14
|
-
* POST /api/v1/sessions/:id/shot?seq=N (image body
|
|
15
|
-
*
|
|
14
|
+
* POST /api/v1/sessions/:id/shot?seq=N (image body, its own Content-Type;
|
|
15
|
+
* the event stream carries a
|
|
16
|
+
* matching 'shot' or 'attachment'
|
|
17
|
+
* event under the same seq)
|
|
16
18
|
* PATCH /api/v1/sessions/:id { status: SessionStatus }
|
|
17
19
|
*
|
|
18
20
|
* This module is types-only and dependency-free on purpose: the vitrinka
|
package/build/recorder/api.d.ts
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
* Vitrinka API client for the web journey recorder.
|
|
3
3
|
*
|
|
4
4
|
* Ingest contract, shared with the Expo recorder and the browser extension:
|
|
5
|
-
* GET /api/v1/recorder/policy workspace redaction policy
|
|
5
|
+
* GET /api/v1/recorder/policy workspace redaction policy + `attachments`
|
|
6
6
|
* GET /api/v1/recorder/me who the token is + HUD prefs (me.ts)
|
|
7
7
|
* PATCH /api/v1/recorder/me {prefs} (me.ts)
|
|
8
8
|
* POST /api/v1/sessions {host, title, environment?, meta} → session
|
|
9
9
|
* POST /api/v1/sessions/:id/events {events: [...]}
|
|
10
10
|
* POST /api/v1/sessions/:id/chunk?seq=N (rrweb batch body, application/json)
|
|
11
|
+
* POST /api/v1/sessions/:id/shot?seq=N (an attached image, its own Content-Type)
|
|
11
12
|
* POST /api/v1/sessions/:id/tags {tags} (non-fatal)
|
|
12
13
|
* GET /api/v1/sessions/:id reconcile
|
|
13
14
|
* PATCH /api/v1/sessions/:id {status: recording|paused|done}
|
|
@@ -18,12 +19,22 @@
|
|
|
18
19
|
import type { RedactionPolicy } from '@vitrinka/redact';
|
|
19
20
|
export { permanentStatus, VitrinkaApiError } from './api-status';
|
|
20
21
|
export declare function onUnauthorized(fn: () => void): () => void;
|
|
22
|
+
/** What the policy read decides for a session (or the idle flight recorder). */
|
|
23
|
+
export interface RecorderPolicy {
|
|
24
|
+
/** null = the engine's safe defaults. */
|
|
25
|
+
policy: RedactionPolicy | null;
|
|
26
|
+
/**
|
|
27
|
+
* The sheets take images: the server answered `attachments: true`. Absent
|
|
28
|
+
* (a server before attachments) and `false` (switched off) both read false.
|
|
29
|
+
*/
|
|
30
|
+
attachments: boolean;
|
|
31
|
+
}
|
|
21
32
|
/**
|
|
22
|
-
* Fetch the workspace redaction policy at session start. NEVER rejects:
|
|
23
|
-
* (server too old, network down, 4xx) means the engine's safe
|
|
24
|
-
* closed, never capture-everything.
|
|
33
|
+
* Fetch the workspace redaction policy at session start. NEVER rejects: a
|
|
34
|
+
* null policy (server too old, network down, 4xx) means the engine's safe
|
|
35
|
+
* defaults — fail closed, never capture-everything — and no attachments.
|
|
25
36
|
*/
|
|
26
|
-
export declare function fetchPolicy(): Promise<
|
|
37
|
+
export declare function fetchPolicy(): Promise<RecorderPolicy>;
|
|
27
38
|
export interface ApiOptions {
|
|
28
39
|
/**
|
|
29
40
|
* Survive page unload (the pagehide flush). Browsers cap keepalive bodies at
|
|
@@ -40,3 +51,12 @@ export declare function api<T = Record<string, unknown>>(method: string, path: s
|
|
|
40
51
|
export declare function uploadChunk(sessionId: string, seq: number, body: string): Promise<{
|
|
41
52
|
blobKey?: string;
|
|
42
53
|
}>;
|
|
54
|
+
/**
|
|
55
|
+
* Upload one attached image (png, webp or jpeg; ≤ 12 MiB) under its
|
|
56
|
+
* `attachment` event's pre-allocated seq through the screenshot leaf, with
|
|
57
|
+
* the blob's own Content-Type. Returns the server's blobKey — the event
|
|
58
|
+
* carries it, exactly like a `shot`.
|
|
59
|
+
*/
|
|
60
|
+
export declare function uploadImage(sessionId: string, seq: number, blob: Blob): Promise<{
|
|
61
|
+
blobKey?: string;
|
|
62
|
+
}>;
|
package/build/recorder/api.js
CHANGED
|
@@ -20,18 +20,18 @@ function reportStatus(status) {
|
|
|
20
20
|
unauthorizedHandler?.();
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
* Fetch the workspace redaction policy at session start. NEVER rejects:
|
|
24
|
-
* (server too old, network down, 4xx) means the engine's safe
|
|
25
|
-
* closed, never capture-everything.
|
|
23
|
+
* Fetch the workspace redaction policy at session start. NEVER rejects: a
|
|
24
|
+
* null policy (server too old, network down, 4xx) means the engine's safe
|
|
25
|
+
* defaults — fail closed, never capture-everything — and no attachments.
|
|
26
26
|
*/
|
|
27
27
|
export async function fetchPolicy() {
|
|
28
28
|
try {
|
|
29
29
|
const res = await api('GET', '/api/v1/recorder/policy');
|
|
30
|
-
return res.policy ?? null;
|
|
30
|
+
return { policy: res.policy ?? null, attachments: res.attachments === true };
|
|
31
31
|
}
|
|
32
32
|
catch (e) {
|
|
33
33
|
console.warn('vitrinka: redaction policy fetch failed — using safe defaults', e);
|
|
34
|
-
return null;
|
|
34
|
+
return { policy: null, attachments: false };
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
export async function api(method, path, body, opts = {}) {
|
|
@@ -60,20 +60,32 @@ export async function api(method, path, body, opts = {}) {
|
|
|
60
60
|
* under a pre-allocated seq. Returns the server's blobKey — the matching
|
|
61
61
|
* `rrweb` event row carries it.
|
|
62
62
|
*/
|
|
63
|
-
export
|
|
63
|
+
export function uploadChunk(sessionId, seq, body) {
|
|
64
|
+
return upload(sessionId, 'chunk', seq, 'application/json', body);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Upload one attached image (png, webp or jpeg; ≤ 12 MiB) under its
|
|
68
|
+
* `attachment` event's pre-allocated seq through the screenshot leaf, with
|
|
69
|
+
* the blob's own Content-Type. Returns the server's blobKey — the event
|
|
70
|
+
* carries it, exactly like a `shot`.
|
|
71
|
+
*/
|
|
72
|
+
export function uploadImage(sessionId, seq, blob) {
|
|
73
|
+
return upload(sessionId, 'shot', seq, blob.type, blob);
|
|
74
|
+
}
|
|
75
|
+
async function upload(sessionId, leaf, seq, contentType, body) {
|
|
64
76
|
const { url } = recorderConfig();
|
|
65
77
|
const key = bearerToken();
|
|
66
|
-
const res = await fetch(`${url}/api/v1/sessions/${sessionId}
|
|
78
|
+
const res = await fetch(`${url}/api/v1/sessions/${sessionId}/${leaf}?seq=${seq}`, {
|
|
67
79
|
method: 'POST',
|
|
68
80
|
mode: 'cors',
|
|
69
81
|
credentials: 'omit',
|
|
70
|
-
headers: { authorization: `Bearer ${key}`, 'content-type':
|
|
82
|
+
headers: { authorization: `Bearer ${key}`, 'content-type': contentType },
|
|
71
83
|
body,
|
|
72
84
|
});
|
|
73
85
|
const text = await res.text();
|
|
74
86
|
if (!res.ok) {
|
|
75
87
|
reportStatus(res.status);
|
|
76
|
-
throw new VitrinkaApiError(`POST
|
|
88
|
+
throw new VitrinkaApiError(`POST ${leaf} seq ${seq} → ${res.status}: ${text}`, res.status);
|
|
77
89
|
}
|
|
78
90
|
try {
|
|
79
91
|
return JSON.parse(text);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host half of recorder attachments: what an image must be to ride the
|
|
3
|
+
* wire — png, webp or jpeg, ≤ 12 MiB, what `/shot` accepts — and how many one
|
|
4
|
+
* note carries (the server takes 10 and ignores the rest). The HUD already
|
|
5
|
+
* normalizes what it hands over (hud/attach.ts); this gate stands for any
|
|
6
|
+
* other caller of the controller, dropping what the server would refuse
|
|
7
|
+
* instead of uploading it.
|
|
8
|
+
*/
|
|
9
|
+
import type { AttachmentPayload } from '../protocol';
|
|
10
|
+
import type { HudAttachment } from './hud/controller';
|
|
11
|
+
/** What the server keeps of one note; the rest is never uploaded. */
|
|
12
|
+
export declare const NOTE_ATTACHMENT_CAP = 10;
|
|
13
|
+
/** One image ready for the queue: its event payload and its bytes. */
|
|
14
|
+
export interface StagedImage {
|
|
15
|
+
payload: AttachmentPayload;
|
|
16
|
+
blob: Blob;
|
|
17
|
+
}
|
|
18
|
+
/** The images of one note that can ride, in order; each one left out is said once. */
|
|
19
|
+
export declare function stageAttachments(list: readonly HudAttachment[] | undefined): StagedImage[];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MAX_ATTACHMENT_BYTES } from './hud/attach';
|
|
2
|
+
/** What the server keeps of one note; the rest is never uploaded. */
|
|
3
|
+
export const NOTE_ATTACHMENT_CAP = 10;
|
|
4
|
+
const MIMES = ['image/png', 'image/webp', 'image/jpeg'];
|
|
5
|
+
/** The images of one note that can ride, in order; each one left out is said once. */
|
|
6
|
+
export function stageAttachments(list) {
|
|
7
|
+
const out = [];
|
|
8
|
+
for (const a of list ?? []) {
|
|
9
|
+
if (out.length >= NOTE_ATTACHMENT_CAP) {
|
|
10
|
+
console.warn(`vitrinka: a note carries at most ${NOTE_ATTACHMENT_CAP} images — the rest are left out`);
|
|
11
|
+
break;
|
|
12
|
+
}
|
|
13
|
+
const mime = MIMES.find((m) => m === a.blob.type);
|
|
14
|
+
if (!mime || a.blob.size === 0 || a.blob.size > MAX_ATTACHMENT_BYTES) {
|
|
15
|
+
const why = !mime ? `${a.blob.type || 'an untyped blob'} is not png, webp or jpeg` : a.blob.size ? 'over 12 MiB' : 'empty';
|
|
16
|
+
console.warn(`vitrinka: attachment ${a.name} left out — ${why}`);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
out.push({
|
|
20
|
+
blob: a.blob,
|
|
21
|
+
payload: {
|
|
22
|
+
name: a.name,
|
|
23
|
+
mime,
|
|
24
|
+
bytes: a.blob.size,
|
|
25
|
+
...(a.w > 0 ? { w: Math.round(a.w) } : {}),
|
|
26
|
+
...(a.h > 0 ? { h: Math.round(a.h) } : {}),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* driven ONLY through a `HudController` (controller.ts) — the in-page
|
|
4
4
|
* recorder's, or another host's. Owns the dock (where the HUD rests), the
|
|
5
5
|
* pill's inline flows (flow.ts), the sheet (open/title/ctx/pick + the
|
|
6
|
-
* surviving draft) and where it opens, the ⋯ menu, the tooltip and details
|
|
6
|
+
* surviving draft and its images) and where it opens, the ⋯ menu, the tooltip and details
|
|
7
7
|
* floats, annotate mode, the bug report (its sheet, "Mark on screen" through
|
|
8
8
|
* annotate mode, its send flow), the keyboard shortcuts, the Esc-anywhere /
|
|
9
9
|
* click-outside close and the status line a screen reader hears while the
|
|
@@ -4,7 +4,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
4
4
|
* driven ONLY through a `HudController` (controller.ts) — the in-page
|
|
5
5
|
* recorder's, or another host's. Owns the dock (where the HUD rests), the
|
|
6
6
|
* pill's inline flows (flow.ts), the sheet (open/title/ctx/pick + the
|
|
7
|
-
* surviving draft) and where it opens, the ⋯ menu, the tooltip and details
|
|
7
|
+
* surviving draft and its images) and where it opens, the ⋯ menu, the tooltip and details
|
|
8
8
|
* floats, annotate mode, the bug report (its sheet, "Mark on screen" through
|
|
9
9
|
* annotate mode, its send flow), the keyboard shortcuts, the Esc-anywhere /
|
|
10
10
|
* click-outside close and the status line a screen reader hears while the
|
|
@@ -21,6 +21,7 @@ import { listen } from './listen';
|
|
|
21
21
|
import { Menu } from './Menu';
|
|
22
22
|
import { alignFor, towardCentre } from './place';
|
|
23
23
|
import { RecorderPill } from './RecorderPill';
|
|
24
|
+
import { gripFor } from './resize';
|
|
24
25
|
import { Sheet } from './Sheet';
|
|
25
26
|
import { colOf, rowOf } from './spots';
|
|
26
27
|
import { fmtAgo, healthLine } from './status';
|
|
@@ -65,6 +66,12 @@ export function Hud({ controller, hostMount, defaultTitle, storage }) {
|
|
|
65
66
|
const [sheet, setSheet] = useState(null);
|
|
66
67
|
const [draft, setDraft] = useState('');
|
|
67
68
|
const [reportDraft, setReportDraft] = useState('');
|
|
69
|
+
// The drafts' images survive a cancel like their text (canAttach only).
|
|
70
|
+
const [images, setImages] = useState([]);
|
|
71
|
+
const [reportImages, setReportImages] = useState([]);
|
|
72
|
+
// Images still preparing belong to the draft too: a sheet reopened mid-way waits for them.
|
|
73
|
+
const [preparing, setPreparing] = useState(0);
|
|
74
|
+
const [reportPreparing, setReportPreparing] = useState(0);
|
|
68
75
|
// Annotate mode is picking the report's mark (it returns to the report sheet).
|
|
69
76
|
const [marking, setMarking] = useState(false);
|
|
70
77
|
const markRef = useRef(null);
|
|
@@ -201,6 +208,7 @@ export function Hud({ controller, hostMount, defaultTitle, storage }) {
|
|
|
201
208
|
return;
|
|
202
209
|
sent.then((res) => {
|
|
203
210
|
setReportDraft('');
|
|
211
|
+
setReportImages([]);
|
|
204
212
|
settle({ type: 'saved', ...res });
|
|
205
213
|
}, (e) => {
|
|
206
214
|
console.warn('vitrinka: report —', errorText(e));
|
|
@@ -212,6 +220,7 @@ export function Hud({ controller, hostMount, defaultTitle, storage }) {
|
|
|
212
220
|
if (controller.getSnapshot().recording) {
|
|
213
221
|
controller.report?.(r).then(() => {
|
|
214
222
|
setReportDraft('');
|
|
223
|
+
setReportImages([]);
|
|
215
224
|
saidSaved();
|
|
216
225
|
}, (e) => console.warn('vitrinka: report —', errorText(e)));
|
|
217
226
|
return;
|
|
@@ -225,21 +234,30 @@ export function Hud({ controller, hostMount, defaultTitle, storage }) {
|
|
|
225
234
|
setSheet(null);
|
|
226
235
|
if (!s)
|
|
227
236
|
return;
|
|
237
|
+
// Images ride only while the host takes them (a policy switched off mid-draft drops them).
|
|
238
|
+
const held = controller.getSnapshot().canAttach === true ? (s.report ? reportImages : images) : [];
|
|
239
|
+
const attachments = held.length ? { attachments: held } : {};
|
|
228
240
|
if (s.report) {
|
|
229
|
-
fileReport({ text, rect: s.pick?.rect ?? null, selector: s.pick?.selector ?? '' });
|
|
241
|
+
fileReport({ text, rect: s.pick?.rect ?? null, selector: s.pick?.selector ?? '', ...attachments });
|
|
230
242
|
return;
|
|
231
243
|
}
|
|
232
244
|
if (s.pick) {
|
|
233
|
-
controller.annotate({ text, rect: s.pick.rect, selector: s.pick.selector, task });
|
|
245
|
+
controller.annotate({ text, rect: s.pick.rect, selector: s.pick.selector, task, ...attachments });
|
|
234
246
|
setDraft('');
|
|
247
|
+
setImages([]);
|
|
235
248
|
saidSaved();
|
|
236
249
|
}
|
|
237
|
-
else if (text) {
|
|
238
|
-
|
|
250
|
+
else if (text || held.length) {
|
|
251
|
+
// An image can BE the note: text may be empty when it carries one.
|
|
252
|
+
if (held.length)
|
|
253
|
+
controller.note(text, held);
|
|
254
|
+
else
|
|
255
|
+
controller.note(text);
|
|
239
256
|
setDraft('');
|
|
257
|
+
setImages([]);
|
|
240
258
|
saidSaved();
|
|
241
259
|
}
|
|
242
|
-
}, [sheet, controller, saidSaved, fileReport]);
|
|
260
|
+
}, [sheet, controller, saidSaved, fileReport, images, reportImages]);
|
|
243
261
|
const onStart = useCallback(() => {
|
|
244
262
|
if (!controller.getSnapshot().linked) {
|
|
245
263
|
beginLink();
|
|
@@ -440,8 +458,10 @@ export function Hud({ controller, hostMount, defaultTitle, storage }) {
|
|
|
440
458
|
const layerOpen = sheet !== null || link !== null;
|
|
441
459
|
const vvTick = useViewportTick(layerOpen && phone);
|
|
442
460
|
// On desktop the placement is measured, so a viewport resize or a grown
|
|
443
|
-
// sheet (the textarea resizes) must place it again
|
|
461
|
+
// sheet (the textarea grows, the grip resizes) must place it again — the
|
|
462
|
+
// sheet's own report (onLayout) does it before that frame paints.
|
|
444
463
|
const [sizeTick, setSizeTick] = useState(0);
|
|
464
|
+
const placeAgain = useCallback(() => setSizeTick((n) => n + 1), []);
|
|
445
465
|
useEffect(() => {
|
|
446
466
|
if (!layerOpen || phone)
|
|
447
467
|
return;
|
|
@@ -456,14 +476,19 @@ export function Hud({ controller, hostMount, defaultTitle, storage }) {
|
|
|
456
476
|
removeEventListener('resize', bump);
|
|
457
477
|
};
|
|
458
478
|
}, [layerOpen, phone, sheetP.mounted, linkP.mounted]);
|
|
459
|
-
const [layer, setLayer] = useState({
|
|
479
|
+
const [layer, setLayer] = useState({
|
|
480
|
+
style: {},
|
|
481
|
+
origin: 'bottom right',
|
|
482
|
+
side: 'top',
|
|
483
|
+
room: 0,
|
|
484
|
+
});
|
|
460
485
|
useLayoutEffect(() => {
|
|
461
486
|
const el = dock.ref.current;
|
|
462
487
|
if (!layerOpen || !el)
|
|
463
488
|
return;
|
|
464
489
|
const o = hostOrigin(sheet && portal ? portal.mount : hostMount);
|
|
465
490
|
if (phone) {
|
|
466
|
-
setLayer({ style: phoneLayer(o), origin: 'bottom center' });
|
|
491
|
+
setLayer({ style: phoneLayer(o), origin: 'bottom center', side: 'top', room: 0 });
|
|
467
492
|
return;
|
|
468
493
|
}
|
|
469
494
|
const pop = layerRef.current?.firstElementChild;
|
|
@@ -489,8 +514,16 @@ export function Hud({ controller, hostMount, defaultTitle, storage }) {
|
|
|
489
514
|
if (rec)
|
|
490
515
|
lastRec.current = rec;
|
|
491
516
|
const detailRec = rec ?? lastRec.current;
|
|
492
|
-
const sheetEl = shownSheet && portal ? (_jsxs("div", { className: "hud", "data-size": snap.prefs.size, children: [portal.own ? _jsx("style", { children: HUD_CSS }) : null, _jsx("div", { ref: layerRef, className: layerCls, style: layer.style, children: _jsx(Sheet, { className: `${motionCls} ${sheetP.cls}`, origin: layer.origin, title: shownSheet.title, ctx: shownSheet.ctx, pick: shownSheet.pick !== null && !shownSheet.report, draft: shownSheet.report ? reportDraft : draft, onDraft: shownSheet.report ? setReportDraft : setDraft, onSend: onSend, onClose: closeSheet,
|
|
517
|
+
const sheetEl = shownSheet && portal ? (_jsxs("div", { className: "hud", "data-size": snap.prefs.size, children: [portal.own ? _jsx("style", { children: HUD_CSS }) : null, _jsx("div", { ref: layerRef, className: layerCls, style: layer.style, children: _jsx(Sheet, { className: `${motionCls} ${sheetP.cls}`, origin: layer.origin, title: shownSheet.title, ctx: shownSheet.ctx, pick: shownSheet.pick !== null && !shownSheet.report, draft: shownSheet.report ? reportDraft : draft, onDraft: shownSheet.report ? setReportDraft : setDraft, onSend: onSend, onClose: closeSheet, kind: shownSheet.report ? 'report' : shownSheet.pick ? 'annotation' : 'note',
|
|
518
|
+
// `|| 0`: a host's snapshot from before the sheet size lacks the fields.
|
|
519
|
+
sheetW: snap.prefs.sheetW || 0, sheetH: snap.prefs.sheetH || 0, room: layer.room,
|
|
520
|
+
// A phone's bottom sheet spans the viewport: its grip sizes the cap alone.
|
|
521
|
+
grip: gripFor(layer.side, align, phone ? 'y' : 'xy'), onResize: (sheetW, sheetH) => void controller.setPrefs({ sheetW, sheetH }), onLayout: placeAgain, ...(shownSheet.report
|
|
493
522
|
? { placeholder: 'What went wrong?', required: true, onMark: markOnScreen, marked: shownSheet.pick !== null }
|
|
523
|
+
: {}), ...(snap.canAttach === true
|
|
524
|
+
? shownSheet.report
|
|
525
|
+
? { images: reportImages, onImages: setReportImages, preparing: reportPreparing, onPreparing: setReportPreparing }
|
|
526
|
+
: { images, onImages: setImages, preparing, onPreparing: setPreparing }
|
|
494
527
|
: {}) }, shownSheet.report ? 'report' : 'note') })] })) : null;
|
|
495
528
|
// Stable phrases only: a live region re-announces on every text change.
|
|
496
529
|
const hs = rec?.sync.state ?? null;
|
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The composer sheet — the extension's hud.html, as a component:
|
|
3
|
-
* anchored to the dock (a bottom sheet on phones), a 14px textarea
|
|
4
|
-
* touch, so iOS never zooms)
|
|
2
|
+
* The composer sheet — the extension's hud.html, as a component: 440px wide
|
|
3
|
+
* by default, anchored to the dock (a bottom sheet on phones), a 14px textarea
|
|
4
|
+
* (16px on touch, so iOS never zooms) that grows with the draft up to a cap
|
|
5
|
+
* and then scrolls, a resize grip on the corner away from the dock (width
|
|
6
|
+
* and cap are HUD prefs — resize.ts), ✕ in the title row, a three-column footer
|
|
5
7
|
* (board|task · context · ↑ Send) and the hint line (hidden on touch). Enter sends, ⇧Enter newlines, Esc
|
|
6
8
|
* cancels. The DRAFT is owned by the caller so a cancel keeps it until the
|
|
7
9
|
* next send (recorder-hud-polish D3); the board|task choice resets on every
|
|
8
10
|
* open — a destination is per observation, not a mode. The bug report is the
|
|
9
11
|
* same sheet: a required description and "Mark on screen" in the board|task
|
|
10
12
|
* slot.
|
|
13
|
+
*
|
|
14
|
+
* Images (recorder attachments), only when the caller passes `images`: the
|
|
15
|
+
* paperclip beside Send picks them, an image paste on the textarea and a
|
|
16
|
+
* drop onto the sheet add them (attach.ts normalizes each), a strip of
|
|
17
|
+
* thumbnails above the footer removes them, at most `MAX_ATTACHMENTS`. Like
|
|
18
|
+
* the text, the caller owns them — and the count still preparing — so a
|
|
19
|
+
* cancel keeps them and a reopened sheet still waits. A refusal (not an
|
|
20
|
+
* image, the cap) shows in the footer's context slot — one line, so the
|
|
21
|
+
* footer never moves.
|
|
11
22
|
*/
|
|
12
|
-
import { type ReactElement } from 'react';
|
|
23
|
+
import { type Dispatch, type ReactElement, type SetStateAction } from 'react';
|
|
24
|
+
import type { HudAttachment } from './controller';
|
|
25
|
+
import { type Grip } from './resize';
|
|
13
26
|
export interface SheetProps {
|
|
14
27
|
/** Presence classes (`grow`/`rise` + `is-open`/`is-closing`). */
|
|
15
28
|
className: string;
|
|
@@ -30,5 +43,27 @@ export interface SheetProps {
|
|
|
30
43
|
onMark?: () => void;
|
|
31
44
|
/** Something is marked (the button reads pressed). */
|
|
32
45
|
marked?: boolean;
|
|
46
|
+
/** The draft's images; absent = the host takes none (no paperclip, paste or drop). */
|
|
47
|
+
images?: readonly HudAttachment[];
|
|
48
|
+
onImages?: Dispatch<SetStateAction<readonly HudAttachment[]>>;
|
|
49
|
+
/**
|
|
50
|
+
* The draft's files still being normalized; Send waits for them. Owned
|
|
51
|
+
* with the images, so a sheet closed and reopened mid-way still waits.
|
|
52
|
+
*/
|
|
53
|
+
preparing?: number;
|
|
54
|
+
onPreparing?: Dispatch<SetStateAction<number>>;
|
|
55
|
+
/** What it composes — names the grip ("Resize note"). */
|
|
56
|
+
kind?: 'note' | 'annotation' | 'report';
|
|
57
|
+
/** The size prefs, CSS px (0 = the default): the width, and the cap the text box grows to. */
|
|
58
|
+
sheetW?: number;
|
|
59
|
+
sheetH?: number;
|
|
60
|
+
/** The tallest the sheet may stand where it opens (viewport px); 0 = the viewport. */
|
|
61
|
+
room?: number;
|
|
62
|
+
/** The corner the resize grip sits on and what it sizes; absent = no grip. */
|
|
63
|
+
grip?: Grip | null;
|
|
64
|
+
/** A resize ended (once per drag or key-up): persist the new size; 0, 0 = the default. */
|
|
65
|
+
onResize?: (sheetW: number, sheetH: number) => void;
|
|
66
|
+
/** The sheet's box changed size: place it again before it paints. */
|
|
67
|
+
onLayout?: () => void;
|
|
33
68
|
}
|
|
34
|
-
export declare function Sheet({ className, origin, title, ctx, pick, draft, onDraft, onSend, onClose, placeholder, required, onMark, marked, }: SheetProps): ReactElement;
|
|
69
|
+
export declare function Sheet({ className, origin, title, ctx, pick, draft, onDraft, onSend, onClose, placeholder, required, onMark, marked, images, onImages, preparing: busy, onPreparing, kind, sheetW, sheetH, room, grip, onResize, onLayout, }: SheetProps): ReactElement;
|