ontrackd 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +24 -12
  2. package/dist/cli/pull.js +5 -0
  3. package/dist/cli/pull.js.map +1 -1
  4. package/dist/core/exportTaskDoc.js +43 -1
  5. package/dist/core/exportTaskDoc.js.map +1 -1
  6. package/dist/core/feedbackTypes.d.ts +37 -0
  7. package/dist/core/journey.d.ts +31 -0
  8. package/dist/core/journey.js +93 -0
  9. package/dist/core/journey.js.map +1 -0
  10. package/dist/core/untrusted.js +10 -6
  11. package/dist/core/untrusted.js.map +1 -1
  12. package/dist/mcp/search.js +3 -2
  13. package/dist/mcp/search.js.map +1 -1
  14. package/dist/mcp/server.js +13 -7
  15. package/dist/mcp/server.js.map +1 -1
  16. package/dist/overlay/anchors.d.ts +1 -0
  17. package/dist/overlay/anchors.js +3 -0
  18. package/dist/overlay/anchors.js.map +1 -1
  19. package/dist/overlay/api.d.ts +18 -1
  20. package/dist/overlay/api.js +37 -7
  21. package/dist/overlay/api.js.map +1 -1
  22. package/dist/overlay/attachments.d.ts +5 -1
  23. package/dist/overlay/attachments.js +16 -3
  24. package/dist/overlay/attachments.js.map +1 -1
  25. package/dist/overlay/connectDialog.js +1 -1
  26. package/dist/overlay/connectDialog.js.map +1 -1
  27. package/dist/overlay/directReviewer.d.ts +17 -2
  28. package/dist/overlay/directReviewer.js +37 -10
  29. package/dist/overlay/directReviewer.js.map +1 -1
  30. package/dist/overlay/journeyRecorder.d.ts +30 -0
  31. package/dist/overlay/journeyRecorder.js +238 -0
  32. package/dist/overlay/journeyRecorder.js.map +1 -0
  33. package/dist/overlay/movedAnchors.js +5 -0
  34. package/dist/overlay/movedAnchors.js.map +1 -1
  35. package/dist/overlay/recorder.d.ts +8 -4
  36. package/dist/overlay/recorder.js +163 -47
  37. package/dist/overlay/recorder.js.map +1 -1
  38. package/dist/overlay/recordingEditor.d.ts +12 -0
  39. package/dist/overlay/recordingEditor.js +130 -0
  40. package/dist/overlay/recordingEditor.js.map +1 -0
  41. package/dist/overlay/recordingPlayer.d.ts +14 -0
  42. package/dist/overlay/recordingPlayer.js +311 -0
  43. package/dist/overlay/recordingPlayer.js.map +1 -0
  44. package/dist/overlay/rrweb-replay.js +120 -0
  45. package/dist/overlay/runtime.js +748 -52
  46. package/dist/overlay/runtime.js.map +1 -1
  47. package/dist/overlay/state.js +2 -1
  48. package/dist/overlay/state.js.map +1 -1
  49. package/dist/overlay/styles.js +45 -0
  50. package/dist/overlay/styles.js.map +1 -1
  51. package/dist/remote/client.d.ts +3 -2
  52. package/dist/remote/client.js +3 -3
  53. package/dist/remote/client.js.map +1 -1
  54. package/dist/remote/content-schema.d.ts +291 -43
  55. package/dist/remote/content-schema.js +91 -0
  56. package/dist/remote/content-schema.js.map +1 -1
  57. package/dist/remote/content.js +4 -2
  58. package/dist/remote/content.js.map +1 -1
  59. package/dist/remote/store.js +3 -1
  60. package/dist/remote/store.js.map +1 -1
  61. package/dist/remote/types.d.ts +1 -0
  62. package/dist/sidecar/commentFiles.js +1 -1
  63. package/dist/sidecar/commentFiles.js.map +1 -1
  64. package/package.json +4 -2
@@ -1,6 +1,8 @@
1
1
  import { hasContractSession } from '../core/apiKind.js';
2
+ import { newId, newIdempotencyKey } from '../remote/index.js';
2
3
  import { joinReviewer, forgetReviewer, hasMagicLink } from './magicLink.js';
3
4
  import { configureDirectApi } from './api.js';
5
+ import { isRecording } from '../core/journey.js';
4
6
  import { anchorCandidatesFor, filesInsideSelection, instancesOf, locateAnchor, scopeFor, siblingInstances, belongsOnThisPage, } from './anchors.js';
5
7
  import { describeElement, summarizeDescription } from './elementDescription.js';
6
8
  import { openDialogFor, openerFor, openingDialog, rememberClick } from './dialogOpener.js';
@@ -58,6 +60,20 @@ export function mountFeedbackOverlay() {
58
60
  }
59
61
  void new FeedbackOverlay().mount();
60
62
  }
63
+ /** Seconds counted down, on the screen, before a recording starts: time to get the page the way it should be. */
64
+ const COUNTDOWN_SECONDS = 5;
65
+ function retryableModulePath(path, attempt) {
66
+ return `${path}${path.includes('?') ? '&' : '?'}retry=${attempt}`;
67
+ }
68
+ /** A definitive create refusal: the upload claim and its idempotency result cannot be reused. */
69
+ function recordingAttachmentRefusal(error) {
70
+ if (!error || typeof error !== 'object')
71
+ return false;
72
+ const details = error.details;
73
+ if (details && typeof details === 'object' && details.reason === 'recording_attachment')
74
+ return true;
75
+ return error instanceof Error && error.message.includes('recording_attachment');
76
+ }
61
77
  class FeedbackOverlay {
62
78
  host = document.createElement('div');
63
79
  root;
@@ -85,12 +101,25 @@ class FeedbackOverlay {
85
101
  replyBody = '';
86
102
  /** How files reach the API or the sidecar, for both composers. */
87
103
  fileTransport = {
88
- send: (file, onProgress) => api.uploadAttachment(file, onProgress),
104
+ send: async (file, onProgress) => {
105
+ try {
106
+ return await api.uploadAttachment(file, onProgress);
107
+ }
108
+ catch (error) {
109
+ if (error instanceof SessionExpiredError && this.shared && !this.signIn) {
110
+ if (this.recordingSaving)
111
+ this.pendingRecordingSave = true;
112
+ this.handleSessionExpired();
113
+ }
114
+ throw error;
115
+ }
116
+ },
89
117
  discard: (id) => api.discardUpload(id),
90
118
  };
91
119
  /** Files of the comment being written, and of the reply being written (spec: Attachments). */
92
120
  draftTray = new AttachmentTray(this.fileTransport, () => this.render(), (item) => this.showProgress('draft', item));
93
121
  replyTray = new AttachmentTray(this.fileTransport, () => this.render(), (item) => this.showProgress('reply', item));
122
+ recordingTray = new AttachmentTray(this.fileTransport, () => this.render(), (item) => this.showProgress('recording', item));
94
123
  /**
95
124
  * The thread whose reply is being claimed by the server now. Its files are the request's: moving to
96
125
  * another thread meanwhile must not discard them (a removal racing the claim refuses the reply).
@@ -107,6 +136,23 @@ class FeedbackOverlay {
107
136
  /** The recording in progress: the page is the reviewer's meanwhile (the mode they were in comes back after). */
108
137
  recording = null;
109
138
  startingRecording = false;
139
+ /** A whole journey stopped but not yet saved. */
140
+ recordingDraft = null;
141
+ recordingSaving = false;
142
+ recordingError = null;
143
+ recordingDiscard = null;
144
+ recordingDiscardFocus = null;
145
+ pendingRecordingSave = false;
146
+ recordingUi = null;
147
+ recordingUiLoad = null;
148
+ recordingUiAttempt = 0;
149
+ recordingUiFailed = false;
150
+ recordingEditor = null;
151
+ recordingPlayer = null;
152
+ threadRecordingPlayer = null;
153
+ threadRecordingPlayerId = null;
154
+ threadRecordingFile = null;
155
+ threadRecordingGeneration = 0;
110
156
  /** The route a comment's recording began on, while the page is elsewhere: the draft waits there, as it does when its element is scrolled away. */
111
157
  draftHeldFor = null;
112
158
  /** Until when (performance.now) a draft's elements, gone with the route, are looked for again. */
@@ -230,6 +276,7 @@ class FeedbackOverlay {
230
276
  panelContent;
231
277
  panelToast;
232
278
  fileInput;
279
+ recordingDialog;
233
280
  lightbox;
234
281
  chip;
235
282
  /** The phone's bottom sheet (sheet.ts): every panel goes into it in compact layout. */
@@ -240,9 +287,13 @@ class FeedbackOverlay {
240
287
  sheetBack = null;
241
288
  /** On a phone: the list sheet shows only these comments, after a tap on a group of pins. */
242
289
  listFilter = null;
290
+ /** The list's message kind, independent of open/resolved. */
291
+ kindFilter = 'all';
243
292
  panelToastTimer = null;
244
293
  constructor() {
245
294
  this.host.id = rootId;
295
+ // rrweb preserves a blocked node's class (but strips its data attributes), so replay can remove its placeholder box.
296
+ this.host.classList.add('fb-overlay-blocked');
246
297
  this.host.setAttribute('data-feedback-overlay', '');
247
298
  // React Aria listens for outside presses in the capture phase, where nothing of ours can stop it;
248
299
  // this marker is the opt-out it documents for floating UI that does not belong to a dialog.
@@ -273,6 +324,7 @@ class FeedbackOverlay {
273
324
  this.panelContent = required(this.root, '[data-fb-panel-content]');
274
325
  this.panelToast = required(this.root, '[data-fb-panel-toast]');
275
326
  this.fileInput = required(this.root, '[data-fb-file-input]');
327
+ this.recordingDialog = required(this.root, '[data-fb-recording-mount]');
276
328
  this.fileInput.accept = acceptAttribute;
277
329
  // The picker's answer. Bound once, here: the composers' markup is rebuilt on every render.
278
330
  this.fileInput.addEventListener('change', () => {
@@ -365,9 +417,7 @@ class FeedbackOverlay {
365
417
  }
366
418
  // A group's filter names pins of the page left behind.
367
419
  this.listFilter = null;
368
- this.state.openThreadId = null;
369
- this.sheetBack = null;
370
- this.abandonReplyFiles();
420
+ this.closeThread();
371
421
  this.render();
372
422
  });
373
423
  this.state.subscribe(() => this.render());
@@ -853,6 +903,13 @@ class FeedbackOverlay {
853
903
  void this.bootstrapViewer();
854
904
  this.requestNotifications();
855
905
  this.render();
906
+ // The save that discovered the session was dead. Finished now, with the same local file,
907
+ // identity and words, so an ambiguous create cannot turn into a duplicate comment.
908
+ if (this.pendingRecordingSave && this.recordingDraft) {
909
+ this.pendingRecordingSave = false;
910
+ void this.saveRecording();
911
+ return;
912
+ }
856
913
  // The save that discovered the session was dead. Finished now, with the same words the
857
914
  // reviewer typed before they were interrupted.
858
915
  if (this.pendingDraftSave) {
@@ -1078,6 +1135,62 @@ class FeedbackOverlay {
1078
1135
  this.render();
1079
1136
  }
1080
1137
  handleKeydown(event) {
1138
+ if (this.recordingDiscard) {
1139
+ const confirm = this.recordingDialog.querySelector('[data-fb-recording-discard]');
1140
+ const inside = event.composedPath().includes(confirm);
1141
+ if (event.key === 'Tab' && confirm) {
1142
+ event.preventDefault();
1143
+ event.stopPropagation();
1144
+ const buttons = Array.from(confirm.querySelectorAll('button:not(:disabled)'));
1145
+ const at = buttons.indexOf(this.root.activeElement);
1146
+ buttons[(at + (event.shiftKey ? -1 : 1) + buttons.length) % buttons.length]?.focus();
1147
+ return;
1148
+ }
1149
+ if (event.key === 'Escape') {
1150
+ event.preventDefault();
1151
+ event.stopPropagation();
1152
+ this.keepRecording();
1153
+ return;
1154
+ }
1155
+ if (event.key !== 'Enter' || !inside) {
1156
+ event.preventDefault();
1157
+ event.stopPropagation();
1158
+ }
1159
+ return;
1160
+ }
1161
+ if (this.recordingDraft && event.key === 'Tab') {
1162
+ const dialog = this.recordingDialog.querySelector('[data-fb-recording-dialog]');
1163
+ const controls = dialog ? Array.from(dialog.querySelectorAll('button, input, [contenteditable="true"], [tabindex]:not([tabindex="-1"])')).filter((element) => !element.hasAttribute('disabled') && !element.closest('[inert]') && element.getClientRects().length > 0) : [];
1164
+ const active = this.root.activeElement;
1165
+ const at = controls.indexOf(active);
1166
+ if (controls.length > 0 && (at < 0 || !event.shiftKey && at === controls.length - 1 || event.shiftKey && at === 0)) {
1167
+ event.preventDefault();
1168
+ event.stopPropagation();
1169
+ controls[event.shiftKey ? controls.length - 1 : 0]?.focus();
1170
+ return;
1171
+ }
1172
+ }
1173
+ // Journey recording owns its shortcut in every state, before recording's early return.
1174
+ if (event.altKey && event.shiftKey && event.code === 'KeyR') {
1175
+ event.preventDefault();
1176
+ event.stopPropagation();
1177
+ if (this.recordingSaving)
1178
+ return;
1179
+ if (this.recording) {
1180
+ if (this.recording.countdown != null)
1181
+ this.recording.cancel?.();
1182
+ else
1183
+ this.recording.recorder.stop();
1184
+ return;
1185
+ }
1186
+ if (this.recordingDraft) {
1187
+ this.askToDiscardRecording(true);
1188
+ return;
1189
+ }
1190
+ if (this.recordOffered())
1191
+ void this.startRecording(true);
1192
+ return;
1193
+ }
1081
1194
  // The keys are the page's while recording: Escape closing something of the app must not discard the comment.
1082
1195
  if (this.recording)
1083
1196
  return;
@@ -1089,6 +1202,11 @@ class FeedbackOverlay {
1089
1202
  return;
1090
1203
  }
1091
1204
  if (event.key === 'Escape') {
1205
+ if (this.recordingDraft) {
1206
+ if (!this.recordingSaving)
1207
+ this.askToDiscardRecording(false);
1208
+ return;
1209
+ }
1092
1210
  if (this.signIn) {
1093
1211
  this.dismissSignIn();
1094
1212
  return;
@@ -1628,6 +1746,11 @@ class FeedbackOverlay {
1628
1746
  if (!target) {
1629
1747
  return;
1630
1748
  }
1749
+ if (this.recordingDraft && target === this.recordingDialog.querySelector('[data-fb-recording-dialog]')) {
1750
+ if (!this.recordingSaving)
1751
+ this.askToDiscardRecording(false);
1752
+ return;
1753
+ }
1631
1754
  // A click on the dimmed backdrop around the sign-in, not on the dialog itself. In a sheet (a phone)
1632
1755
  // the scrim is the dialog's own background: a tap there is not a backdrop tap.
1633
1756
  if (this.signIn && target === this.scrim && !this.compact) {
@@ -1651,15 +1774,50 @@ class FeedbackOverlay {
1651
1774
  return;
1652
1775
  }
1653
1776
  const { fbAction: name, fbValue: value } = action.dataset;
1777
+ // The alertdialog is the only interactive surface until its choice is made.
1778
+ if (this.recordingDiscard && name !== 'keep-recording' && name !== 'discard-recording')
1779
+ return;
1654
1780
  // The page is the reviewer's while recording: the rest of the overlay is out of the way, and inert.
1655
1781
  if (this.recording && name !== 'stop-recording')
1656
1782
  return;
1657
1783
  switch (name) {
1784
+ case 'record-journey':
1785
+ void this.startRecording(true);
1786
+ break;
1658
1787
  case 'record':
1659
- void this.startRecording();
1788
+ void this.startRecording(false);
1660
1789
  break;
1661
1790
  case 'stop-recording':
1662
- this.recording?.recorder.stop();
1791
+ // Until it starts, this is the cancel.
1792
+ if (this.recording?.countdown != null)
1793
+ this.recording.cancel?.();
1794
+ else
1795
+ this.recording?.recorder.stop();
1796
+ break;
1797
+ case 'cancel-recording':
1798
+ if (!this.recordingSaving)
1799
+ this.askToDiscardRecording(false);
1800
+ break;
1801
+ case 'save-recording':
1802
+ void this.saveRecording();
1803
+ break;
1804
+ case 'retry-recording-ui':
1805
+ if (this.recordingDraft && !this.recordingSaving) {
1806
+ this.recordingUiFailed = false;
1807
+ this.recordingError = null;
1808
+ this.renderRecordingDialog();
1809
+ void this.mountRecordingUi(this.recordingDraft);
1810
+ }
1811
+ break;
1812
+ case 'discard-recording': {
1813
+ const restart = this.recordingDiscard?.restart === true;
1814
+ this.discardRecording();
1815
+ if (restart)
1816
+ queueMicrotask(() => { void this.startRecording(true); });
1817
+ break;
1818
+ }
1819
+ case 'keep-recording':
1820
+ this.keepRecording();
1663
1821
  break;
1664
1822
  case 'join':
1665
1823
  void this.completeJoin();
@@ -1803,6 +1961,12 @@ class FeedbackOverlay {
1803
1961
  this.clearSticky();
1804
1962
  this.state.setFilter(value);
1805
1963
  break;
1964
+ case 'set-kind-filter':
1965
+ this.clearSticky();
1966
+ if (value === 'all' || value === 'pin' || value === 'recording')
1967
+ this.kindFilter = value;
1968
+ this.render();
1969
+ break;
1806
1970
  case 'cancel-draft':
1807
1971
  this.cancelDraft();
1808
1972
  break;
@@ -1855,8 +2019,8 @@ class FeedbackOverlay {
1855
2019
  void this.sendReply(String(value));
1856
2020
  break;
1857
2021
  case 'attach': {
1858
- const which = value === 'reply' ? 'reply' : 'draft';
1859
- if (!this.takesFiles(which) || this.sending === which)
2022
+ const which = value === 'reply' ? 'reply' : value === 'recording' ? 'recording' : 'draft';
2023
+ if (!this.takesFiles(which) || (which === 'recording' ? this.recordingSaving : this.sending === which))
1860
2024
  break;
1861
2025
  this.pickingFor = which;
1862
2026
  this.fileInput.click();
@@ -1864,9 +2028,9 @@ class FeedbackOverlay {
1864
2028
  }
1865
2029
  case 'remove-file': {
1866
2030
  const [which, key = ''] = String(value).split(':');
1867
- const tray = which === 'reply' ? 'reply' : 'draft';
2031
+ const tray = which === 'reply' ? 'reply' : which === 'recording' ? 'recording' : 'draft';
1868
2032
  // While that composer sends, its files are being claimed: none is taken out from under it.
1869
- if (this.sending === tray)
2033
+ if ((tray !== 'recording' && this.sending === tray) || (tray === 'recording' && this.recordingSaving))
1870
2034
  break;
1871
2035
  this.trayFor(tray).remove(key);
1872
2036
  // The button that had the focus is gone with its file.
@@ -2119,6 +2283,25 @@ class FeedbackOverlay {
2119
2283
  if (!wasThere && candidates[0]?.element.isConnected)
2120
2284
  queueMicrotask(() => this.render());
2121
2285
  }
2286
+ /**
2287
+ * Re-anchors the draft to the page the reviewer is on, at the element in the middle of it, keeping what was written.
2288
+ * False when nothing on the page can be anchored to: the draft then waits for its own page.
2289
+ */
2290
+ anchorDraftHere() {
2291
+ const x = window.innerWidth / 2, y = window.innerHeight / 2;
2292
+ for (const element of document.elementsFromPoint(x, y)) {
2293
+ if (this.host.contains(element))
2294
+ continue;
2295
+ const candidates = anchorCandidatesFor(element);
2296
+ if (!candidates.length)
2297
+ continue;
2298
+ this.draft = this.draftAt(candidates, x, y);
2299
+ this.draftRelocateUntil = 0;
2300
+ this.snapshotSelected();
2301
+ return true;
2302
+ }
2303
+ return false;
2304
+ }
2122
2305
  /** The element the draft currently points at. */
2123
2306
  selectedElement(draft = this.draft) {
2124
2307
  if (!draft)
@@ -2167,7 +2350,9 @@ class FeedbackOverlay {
2167
2350
  this.trace('screenshot-failed', { reason: error instanceof Error ? error.message.slice(0, 120) : 'unknown' });
2168
2351
  }
2169
2352
  }
2170
- trayFor(which) { return which === 'reply' ? this.replyTray : this.draftTray; }
2353
+ trayFor(which) {
2354
+ return which === 'reply' ? this.replyTray : which === 'recording' ? this.recordingTray : this.draftTray;
2355
+ }
2171
2356
  /** The reply being written is left (thread closed or another opened): its uploads go, unless a send is claiming them. */
2172
2357
  abandonReplyFiles() {
2173
2358
  if (!this.claimingReplyFor)
@@ -2178,6 +2363,8 @@ class FeedbackOverlay {
2178
2363
  * a sent message adds none). Never Standalone, and never a thread another session holds.
2179
2364
  */
2180
2365
  takesFiles(which) {
2366
+ if (which === 'recording')
2367
+ return Boolean(this.recordingDraft) && attachmentsAvailable();
2181
2368
  if (which === 'draft')
2182
2369
  return Boolean(this.draft) && attachmentsAvailable();
2183
2370
  const id = this.state.openThreadId;
@@ -2185,6 +2372,10 @@ class FeedbackOverlay {
2185
2372
  }
2186
2373
  /** Back to a composer's words, after the control that had the focus was replaced. */
2187
2374
  focusComposer(which) {
2375
+ if (which === 'recording') {
2376
+ this.recordingEditor?.element.focus();
2377
+ return;
2378
+ }
2188
2379
  const field = this.root.querySelector(which === 'reply' ? '[data-fb-reply]' : '[data-fb-body]');
2189
2380
  if (field && !field.disabled)
2190
2381
  field.focus();
@@ -2209,33 +2400,70 @@ class FeedbackOverlay {
2209
2400
  * Records the page while the reviewer reproduces the problem. The mode they were in is set aside, so the page
2210
2401
  * behaves as if the tool were absent; the draft stays. The limit is asked again: the plan may have changed.
2211
2402
  */
2212
- async startRecording() {
2213
- if (this.recording || this.startingRecording || !this.draft || this.sending === 'draft')
2403
+ async startRecording(journey) {
2404
+ if (this.recording || this.startingRecording || this.recordingSaving)
2405
+ return;
2406
+ if (journey && this.recordingDraft) {
2407
+ this.askToDiscardRecording(true);
2408
+ return;
2409
+ }
2410
+ if (!journey && (!this.draft || this.sending === 'draft'))
2214
2411
  return;
2412
+ const pinDraft = journey ? null : this.draft;
2215
2413
  this.startingRecording = true;
2216
- const refuse = (message) => { this.draftTray.notice = message; this.render(); };
2414
+ const refuse = (message) => {
2415
+ if (journey)
2416
+ this.showReviewerNotice(message);
2417
+ else {
2418
+ this.draftTray.notice = message;
2419
+ this.render();
2420
+ }
2421
+ };
2217
2422
  try {
2218
2423
  const limit = await api.recordingLimit();
2219
2424
  this.recordingLimit = limit;
2425
+ if (!journey && this.draft !== pinDraft)
2426
+ return;
2220
2427
  if (!limit?.available) {
2221
2428
  refuse('Recording is not available');
2222
2429
  return;
2223
2430
  }
2224
- const recorder = new Recorder(limit, '[data-feedback-overlay]', (elapsed) => this.showRecordingTime(elapsed));
2431
+ const recorder = new Recorder(limit, '[data-feedback-overlay]', (elapsed) => this.showRecordingTime(elapsed), api.recordingOrigin());
2225
2432
  const from = this.state.mode;
2226
- const recording = { recorder, from, limit, elapsed: 0, route: location.pathname, moved: false };
2433
+ const recording = {
2434
+ recorder, journey, from, limit, elapsed: 0, route: location.pathname,
2435
+ moved: false, countdown: COUNTDOWN_SECONDS,
2436
+ };
2227
2437
  this.recording = recording;
2228
2438
  // The page as it is without the pin cursor and the highlight: that is where the recording begins.
2229
2439
  this.state.setMode('visible');
2440
+ this.render();
2441
+ this.root.querySelector('[data-fb-action="stop-recording"]')?.focus();
2442
+ if (!await this.countDown(recording))
2443
+ return;
2444
+ if (recording.journey) {
2445
+ recording.route = location.pathname;
2446
+ recording.url = remoteFeedbackStatus ? pageUrl(window.location.href, { query: false }) ?? undefined : undefined;
2447
+ }
2230
2448
  try {
2231
2449
  await recorder.start();
2232
2450
  }
2233
2451
  catch {
2452
+ if (this.recording !== recording)
2453
+ return;
2234
2454
  this.recording = null;
2235
2455
  this.state.setMode(from);
2456
+ if (this.draft)
2457
+ this.settleDraft(recording.route);
2236
2458
  refuse('Could not start recording');
2237
2459
  return;
2238
2460
  }
2461
+ // Cancelled at zero, while it loaded: it is stopped, and what it recorded is dropped.
2462
+ if (this.recording !== recording) {
2463
+ recorder.stop();
2464
+ return;
2465
+ }
2466
+ recording.countdown = null;
2239
2467
  void recorder.ended.then((end) => this.recordingEnded(recording, end));
2240
2468
  this.render();
2241
2469
  this.root.querySelector('[data-fb-action="stop-recording"]')?.focus();
@@ -2244,18 +2472,80 @@ class FeedbackOverlay {
2244
2472
  this.startingRecording = false;
2245
2473
  }
2246
2474
  }
2475
+ /**
2476
+ * The page was the reviewer's (a recording, or the count before it): the draft is where they are. Route changes were not heard,
2477
+ * so its elements may have come back mounted again; and if it ended on another page where what the comment was about is not,
2478
+ * the comment is written here. An element on the page without a box (display: none) is not there either.
2479
+ */
2480
+ settleDraft(route) {
2481
+ if (!this.draft)
2482
+ return;
2483
+ this.relocateDraft();
2484
+ const shown = () => (this.draft?.candidates[0]?.element.getClientRects().length ?? 0) > 0 && this.draftAnchorVisible();
2485
+ if (location.pathname === route || shown())
2486
+ return;
2487
+ if (this.anchorDraftHere())
2488
+ this.showReviewerNotice('The comment is on this page now.');
2489
+ else {
2490
+ this.draftHeldFor = route;
2491
+ this.showReviewerNotice(`Go back to ${route} to finish the comment.`);
2492
+ }
2493
+ }
2494
+ /** Counts down on the screen; true when it reached zero, false when the reviewer cancelled it. */
2495
+ countDown(recording) {
2496
+ return new Promise((resolve) => {
2497
+ const timer = window.setInterval(() => {
2498
+ recording.countdown = (recording.countdown ?? 1) - 1;
2499
+ this.showCountdown();
2500
+ if (recording.countdown > 0)
2501
+ return;
2502
+ // Zero is shown while the recorder loads; cancelling then stops it as soon as it has (startRecording).
2503
+ window.clearInterval(timer);
2504
+ resolve(true);
2505
+ }, 1000);
2506
+ recording.cancel = () => {
2507
+ window.clearInterval(timer);
2508
+ this.recording = null;
2509
+ this.state.setMode(recording.from);
2510
+ if (this.draft)
2511
+ this.settleDraft(recording.route);
2512
+ this.render();
2513
+ if (this.draft)
2514
+ this.focusComposer('draft');
2515
+ resolve(false);
2516
+ };
2517
+ this.showCountdown();
2518
+ });
2519
+ }
2247
2520
  recordingEnded(recording, end) {
2248
2521
  if (this.recording !== recording)
2249
2522
  return;
2250
2523
  this.recording = null;
2251
2524
  this.state.setMode(recording.from);
2252
- if (this.draft && location.pathname !== recording.route) {
2253
- this.draftHeldFor = recording.route;
2254
- this.showReviewerNotice(`Recorded. Go back to ${recording.route} to finish the comment.`);
2255
- }
2256
- else {
2257
- // Route changes were not heard while recording: the page may have come back with its elements mounted again.
2258
- this.relocateDraft();
2525
+ if (this.draft)
2526
+ this.settleDraft(recording.route);
2527
+ if (recording.journey) {
2528
+ if (!end.ok) {
2529
+ this.showReviewerNotice(end.message);
2530
+ this.render();
2531
+ return;
2532
+ }
2533
+ this.recordingDraft = {
2534
+ ...end,
2535
+ route: recording.route,
2536
+ ...(recording.url ? { url: recording.url } : {}),
2537
+ createIdentity: { id: newId('cmt'), idempotencyKey: newIdempotencyKey() },
2538
+ };
2539
+ this.recordingError = end.reason === 'user' ? null
2540
+ : end.reason === 'limit' ? `Stopped at ${clock(recording.limit.seconds * 1000)}, the most your plan records`
2541
+ : 'Stopped: the recording got too long';
2542
+ this.recordingUiFailed = false;
2543
+ this.recordingDiscard = null;
2544
+ this.recordingTray.reset();
2545
+ this.recordingTray.addRecording(end.file, end.durationMs);
2546
+ this.render();
2547
+ void this.mountRecordingUi(this.recordingDraft);
2548
+ return;
2259
2549
  }
2260
2550
  if (this.draft && end.ok) {
2261
2551
  this.draftTray.addRecording(end.file, end.durationMs);
@@ -2272,6 +2562,282 @@ class FeedbackOverlay {
2272
2562
  this.render();
2273
2563
  this.focusComposer('draft');
2274
2564
  }
2565
+ loadRecordingUi() {
2566
+ if (this.recordingUiLoad)
2567
+ return this.recordingUiLoad;
2568
+ const attempt = ++this.recordingUiAttempt;
2569
+ const editorPath = typeof __FEEDBACK_RECORDING_EDITOR_MODULE__ === 'string'
2570
+ ? __FEEDBACK_RECORDING_EDITOR_MODULE__ : './recordingEditor.js';
2571
+ const playerPath = typeof __FEEDBACK_RECORDING_PLAYER_MODULE__ === 'string'
2572
+ ? __FEEDBACK_RECORDING_PLAYER_MODULE__ : './recordingPlayer.js';
2573
+ this.recordingUiLoad = Promise.all([
2574
+ import(/* @vite-ignore */ retryableModulePath(editorPath, attempt)),
2575
+ import(/* @vite-ignore */ retryableModulePath(playerPath, attempt)),
2576
+ ]).then(([editor, player]) => {
2577
+ const ui = { RecordingEditor: editor.RecordingEditor, RecordingPlayer: player.RecordingPlayer };
2578
+ this.recordingUi = ui;
2579
+ return ui;
2580
+ }).catch((error) => { this.recordingUiLoad = null; throw error; });
2581
+ return this.recordingUiLoad;
2582
+ }
2583
+ async mountRecordingUi(draft) {
2584
+ try {
2585
+ const ui = this.recordingUi ?? await this.loadRecordingUi();
2586
+ if (this.recordingDraft !== draft)
2587
+ return;
2588
+ const editorHost = this.recordingDialog.querySelector('[data-fb-recording-editor-host]');
2589
+ const playerHost = this.recordingDialog.querySelector('[data-fb-recording-player]');
2590
+ if (!editorHost || !playerHost)
2591
+ return;
2592
+ const focusEditor = !this.recordingEditor;
2593
+ this.recordingEditor ??= new ui.RecordingEditor(editorHost);
2594
+ this.renderRecordingDialog();
2595
+ if (focusEditor)
2596
+ this.recordingEditor.element.focus();
2597
+ if (!this.recordingPlayer) {
2598
+ const player = new ui.RecordingPlayer(playerHost, draft.file);
2599
+ this.recordingPlayer = player;
2600
+ try {
2601
+ await player.ready;
2602
+ }
2603
+ catch (error) {
2604
+ if (this.recordingPlayer === player) {
2605
+ player.destroy();
2606
+ this.recordingPlayer = null;
2607
+ }
2608
+ throw error;
2609
+ }
2610
+ }
2611
+ if (this.recordingDraft === draft) {
2612
+ this.recordingUiFailed = false;
2613
+ this.renderRecordingDialog();
2614
+ }
2615
+ }
2616
+ catch {
2617
+ if (this.recordingDraft !== draft)
2618
+ return;
2619
+ this.recordingUiFailed = true;
2620
+ this.recordingError = 'The recording could not be shown. You can try again or save it without a description.';
2621
+ this.renderRecordingDialog();
2622
+ }
2623
+ }
2624
+ askToDiscardRecording(restart) {
2625
+ if (!this.recordingDraft || this.recordingSaving)
2626
+ return;
2627
+ const active = this.root.activeElement;
2628
+ this.recordingDiscardFocus = active instanceof HTMLElement && this.recordingDialog.contains(active) ? active : null;
2629
+ this.recordingDiscard = { restart };
2630
+ this.renderRecordingDialog();
2631
+ this.recordingDialog.querySelector('[data-fb-action="keep-recording"]')?.focus();
2632
+ }
2633
+ keepRecording() {
2634
+ const restore = this.recordingDiscardFocus;
2635
+ this.recordingDiscard = null;
2636
+ this.recordingDiscardFocus = null;
2637
+ this.renderRecordingDialog();
2638
+ if (restore?.isConnected && !restore.inert)
2639
+ restore.focus();
2640
+ else
2641
+ this.recordingEditor?.element.focus();
2642
+ }
2643
+ discardRecording() {
2644
+ this.recordingPlayer?.destroy();
2645
+ this.recordingPlayer = null;
2646
+ this.recordingEditor = null;
2647
+ this.recordingTray.reset();
2648
+ this.recordingDraft = null;
2649
+ this.recordingDiscard = null;
2650
+ this.recordingDiscardFocus = null;
2651
+ this.pendingRecordingSave = false;
2652
+ this.recordingUiFailed = false;
2653
+ this.recordingError = null;
2654
+ this.render();
2655
+ }
2656
+ async saveRecording() {
2657
+ const draft = this.recordingDraft;
2658
+ if (!draft || this.recordingSaving)
2659
+ return;
2660
+ const body = this.recordingEditor?.markdown() ?? '';
2661
+ if (this.recordingTray.blocked)
2662
+ this.recordingTray.retryFailed();
2663
+ this.recordingSaving = true;
2664
+ this.recordingError = null;
2665
+ this.renderRecordingDialog();
2666
+ await this.recordingTray.settled();
2667
+ if (this.recordingDraft !== draft) {
2668
+ this.recordingSaving = false;
2669
+ return;
2670
+ }
2671
+ if (this.recordingTray.blocked) {
2672
+ this.recordingSaving = false;
2673
+ this.recordingError = 'One file did not upload. Try Save again.';
2674
+ this.renderRecordingDialog();
2675
+ return;
2676
+ }
2677
+ const attachmentIds = this.recordingTray.ids();
2678
+ const recordingUploads = this.recordingTray.items.filter((item) => item.kind === 'recording' && item.upload);
2679
+ if (recordingUploads.length !== 1) {
2680
+ this.recordingSaving = false;
2681
+ this.recordingError = 'The recording did not upload. Try Save again.';
2682
+ this.renderRecordingDialog();
2683
+ return;
2684
+ }
2685
+ let created;
2686
+ try {
2687
+ created = await api.createComment({
2688
+ kind: 'recording',
2689
+ author: this.authorName,
2690
+ authorId: this.identity?.id ?? null,
2691
+ body,
2692
+ anchor: null,
2693
+ context: {
2694
+ route: draft.route,
2695
+ viewport: { w: window.innerWidth, h: window.innerHeight },
2696
+ ...(draft.url ? { url: draft.url } : {}),
2697
+ },
2698
+ recording: { durationMs: draft.durationMs, startedAt: draft.startedAt },
2699
+ journey: draft.journey,
2700
+ ...(draft.journeyTruncated ? { journeyTruncated: true } : {}),
2701
+ attachmentIds,
2702
+ }, draft.createIdentity);
2703
+ }
2704
+ catch (error) {
2705
+ this.recordingSaving = false;
2706
+ const unavailable = unavailableFile(error);
2707
+ const refusedRecording = recordingAttachmentRefusal(error);
2708
+ if (unavailable)
2709
+ this.recordingTray.fail(unavailable, 'No longer available: remove it and add it again');
2710
+ if (refusedRecording) {
2711
+ const recordingId = recordingUploads[0]?.upload?.id;
2712
+ if (recordingId)
2713
+ this.recordingTray.fail(recordingId, 'Upload expired: Save again to retry');
2714
+ // This refusal is definitive and can be cached under the idempotency key. A new upload
2715
+ // therefore gets a new create identity; unknown/network failures keep the old one.
2716
+ draft.createIdentity = { id: newId('cmt'), idempotencyKey: newIdempotencyKey() };
2717
+ }
2718
+ this.recordingError = unavailable
2719
+ ? 'One file could not be sent. Remove it and try again.'
2720
+ : refusedRecording
2721
+ ? 'The recording upload expired. Save again to retry it.'
2722
+ : 'Not saved. Your recording is still here, try again.';
2723
+ if (error instanceof SessionExpiredError && this.shared) {
2724
+ this.pendingRecordingSave = true;
2725
+ this.handleSessionExpired();
2726
+ }
2727
+ else
2728
+ this.renderRecordingDialog();
2729
+ return;
2730
+ }
2731
+ this.recordingSaving = false;
2732
+ this.recordingPlayer?.destroy();
2733
+ this.recordingPlayer = null;
2734
+ this.recordingEditor = null;
2735
+ this.recordingTray.clear();
2736
+ this.recordingDraft = null;
2737
+ this.recordingDiscard = null;
2738
+ this.recordingDiscardFocus = null;
2739
+ this.pendingRecordingSave = false;
2740
+ this.recordingUiFailed = false;
2741
+ this.recordingError = null;
2742
+ this.stickyId = created.id;
2743
+ const [shown] = renderable([created]);
2744
+ if (shown)
2745
+ this.state.applyLocal((comments) => [shown, ...comments.filter((item) => item.id !== shown.id)]);
2746
+ this.render();
2747
+ void this.state.refresh();
2748
+ }
2749
+ renderRecordingDialog() {
2750
+ const draft = this.recordingDraft;
2751
+ this.recordingDialog.hidden = Boolean(draft && this.signIn);
2752
+ if (!draft) {
2753
+ this.recordingDialog.replaceChildren();
2754
+ return;
2755
+ }
2756
+ let dialog = this.recordingDialog.querySelector('[data-fb-recording-dialog]');
2757
+ if (!dialog) {
2758
+ this.recordingDialog.innerHTML = recordingDialogMarkup();
2759
+ dialog = this.recordingDialog.querySelector('[data-fb-recording-dialog]');
2760
+ }
2761
+ const error = dialog.querySelector('[data-fb-recording-error]');
2762
+ if (error) {
2763
+ error.textContent = this.recordingError ?? '';
2764
+ error.hidden = !this.recordingError;
2765
+ }
2766
+ const oldRetry = dialog.querySelector('[data-fb-action="retry-recording-ui"]');
2767
+ if (this.recordingUiFailed && !oldRetry) {
2768
+ error?.insertAdjacentHTML('afterend', '<button type="button" class="fb-threadblock__cancel" data-fb-action="retry-recording-ui">Try loading the editor and player again</button>');
2769
+ }
2770
+ else if (!this.recordingUiFailed)
2771
+ oldRetry?.remove();
2772
+ const tray = dialog.querySelector('[data-fb-recording-tray]');
2773
+ if (tray)
2774
+ tray.innerHTML = trayMarkup(this.recordingTray, 'recording');
2775
+ const blocked = this.recordingSaving || this.recordingDiscard !== null;
2776
+ this.recordingEditor?.setDisabled(blocked);
2777
+ const save = dialog.querySelector('[data-fb-action="save-recording"]');
2778
+ if (save) {
2779
+ save.disabled = blocked || (!this.recordingEditor && !this.recordingUiFailed);
2780
+ save.setAttribute('aria-busy', String(this.recordingSaving));
2781
+ save.textContent = this.recordingSaving ? 'Saving…' : 'Save';
2782
+ }
2783
+ const cancel = dialog.querySelector('[data-fb-action="cancel-recording"]');
2784
+ if (cancel)
2785
+ cancel.disabled = blocked;
2786
+ const attach = dialog.querySelector('[data-fb-action="attach"]');
2787
+ if (attach)
2788
+ attach.disabled = blocked;
2789
+ const card = dialog.querySelector('.fb-recording-dialog__card');
2790
+ if (card) {
2791
+ card.inert = this.recordingDiscard !== null;
2792
+ card.setAttribute('aria-hidden', String(this.recordingDiscard !== null));
2793
+ }
2794
+ const existing = dialog.querySelector('[data-fb-recording-discard]');
2795
+ if (this.recordingDiscard && !existing)
2796
+ dialog.insertAdjacentHTML('beforeend', recordingDiscardMarkup());
2797
+ else if (!this.recordingDiscard)
2798
+ existing?.remove();
2799
+ }
2800
+ async mountThreadRecording(comment, generation) {
2801
+ const attachment = comment.attachments?.find((item) => item.kind === 'recording');
2802
+ const host = this.popover.querySelector('[data-fb-recording-thread-player]');
2803
+ if (!attachment || !host)
2804
+ return;
2805
+ const key = `${comment.id}:${attachment.id}`;
2806
+ if (this.threadRecordingFile?.key !== key) {
2807
+ this.threadRecordingFile?.abort.abort();
2808
+ const abort = new AbortController();
2809
+ this.threadRecordingFile = { key, abort, promise: api.attachmentBlob(comment.id, attachment.id, abort.signal) };
2810
+ }
2811
+ const loading = this.threadRecordingFile;
2812
+ try {
2813
+ const [ui, file] = await Promise.all([this.recordingUi ?? this.loadRecordingUi(), loading.promise]);
2814
+ if (this.threadRecordingFile === loading)
2815
+ this.threadRecordingFile = null;
2816
+ if (generation !== this.threadRecordingGeneration || this.state.openThreadId !== comment.id || !host.isConnected)
2817
+ return;
2818
+ const player = new ui.RecordingPlayer(host, file);
2819
+ this.threadRecordingPlayer = player;
2820
+ this.threadRecordingPlayerId = comment.id;
2821
+ try {
2822
+ await player.ready;
2823
+ }
2824
+ catch (error) {
2825
+ if (this.threadRecordingPlayer === player) {
2826
+ this.threadRecordingPlayer = null;
2827
+ this.threadRecordingPlayerId = null;
2828
+ }
2829
+ throw error;
2830
+ }
2831
+ }
2832
+ catch {
2833
+ if (this.threadRecordingFile === loading) {
2834
+ loading.abort.abort();
2835
+ this.threadRecordingFile = null;
2836
+ }
2837
+ if (generation === this.threadRecordingGeneration && host.isConnected)
2838
+ host.textContent = 'The recording could not be played.';
2839
+ }
2840
+ }
2275
2841
  /** The indicator that says the page is being recorded: a dot, the time, and the button that stops it. */
2276
2842
  renderRecorder() {
2277
2843
  const pill = this.root.querySelector('[data-fb-recorder]');
@@ -2280,16 +2846,38 @@ class FeedbackOverlay {
2280
2846
  if (!this.recording) {
2281
2847
  pill.hidden = true;
2282
2848
  pill.innerHTML = '';
2849
+ delete pill.dataset.phase;
2850
+ this.showCountdown();
2283
2851
  return;
2284
2852
  }
2285
- if (!pill.hidden)
2853
+ const phase = this.recording.countdown === null ? 'recording' : 'countdown';
2854
+ if (!pill.hidden && pill.dataset.phase === phase)
2286
2855
  return;
2287
2856
  pill.hidden = false;
2288
- // Announced once, when it starts; the time is not read out every second.
2289
- pill.innerHTML = `<span class="fb-sr" role="status">Recording started. Stop recording is the last button on the page.</span>
2857
+ pill.dataset.phase = phase;
2858
+ // Each is announced once, when it begins; the time and the seconds are not read out as they change.
2859
+ pill.innerHTML = phase === 'countdown'
2860
+ ? `<span class="fb-sr" role="status">Recording starts in ${COUNTDOWN_SECONDS} seconds. Cancel recording is the last button on the page.</span>
2861
+ <span class="fb-recorder__dot" aria-hidden="true"></span><span class="fb-recorder__label" aria-hidden="true">Recording in <span data-fb-countdown-text>${this.recording.countdown}</span></span>
2862
+ <button type="button" class="fb-recorder__stop" data-fb-action="stop-recording" aria-label="Cancel recording">Cancel</button>`
2863
+ : `<span class="fb-sr" role="status">Recording started. Stop recording is the last button on the page.</span>
2290
2864
  <span class="fb-recorder__dot" aria-hidden="true"></span><span class="fb-recorder__label" aria-hidden="true">Recording</span>
2291
2865
  <span class="fb-recorder__time" data-fb-recorder-time aria-hidden="true">${clock(0)} / ${clock(this.recording.limit.seconds * 1000)}</span>
2292
2866
  <button type="button" class="fb-recorder__stop" data-fb-action="stop-recording" aria-label="Stop recording">Stop</button>`;
2867
+ this.showCountdown();
2868
+ }
2869
+ /** The seconds left, big on the page and in the indicator; both gone once the recording starts. */
2870
+ showCountdown() {
2871
+ const big = this.root.querySelector('[data-fb-countdown]');
2872
+ if (!big)
2873
+ return;
2874
+ const left = this.recording?.countdown;
2875
+ big.hidden = left == null;
2876
+ if (left != null)
2877
+ big.textContent = String(left);
2878
+ const text = this.root.querySelector('[data-fb-countdown-text]');
2879
+ if (text && left != null)
2880
+ text.textContent = String(left);
2293
2881
  }
2294
2882
  showRecordingTime(elapsed) {
2295
2883
  if (!this.recording)
@@ -2303,7 +2891,7 @@ class FeedbackOverlay {
2303
2891
  dropTarget(event) {
2304
2892
  const block = event.composedPath().find((node) => node instanceof HTMLElement && node.dataset.fbDrop !== undefined);
2305
2893
  const which = block?.dataset.fbDrop;
2306
- return (which === 'draft' || which === 'reply') && this.takesFiles(which) ? which : null;
2894
+ return (which === 'draft' || which === 'reply' || which === 'recording') && this.takesFiles(which) ? which : null;
2307
2895
  }
2308
2896
  /**
2309
2897
  * Files over a composer are ours: the browser does not open them in place of the page, and the
@@ -2315,7 +2903,7 @@ class FeedbackOverlay {
2315
2903
  return;
2316
2904
  event.preventDefault();
2317
2905
  event.stopPropagation();
2318
- event.dataTransfer.dropEffect = this.sending === which ? 'none' : 'copy';
2906
+ event.dataTransfer.dropEffect = (which === 'recording' ? this.recordingSaving : this.sending === which) ? 'none' : 'copy';
2319
2907
  }
2320
2908
  onComposerDrop(event) {
2321
2909
  const which = this.dropTarget(event);
@@ -2324,7 +2912,7 @@ class FeedbackOverlay {
2324
2912
  return;
2325
2913
  event.preventDefault();
2326
2914
  event.stopPropagation();
2327
- if (this.sending === which)
2915
+ if (which === 'recording' ? this.recordingSaving : this.sending === which)
2328
2916
  return;
2329
2917
  this.trayFor(which).add(files);
2330
2918
  }
@@ -2332,7 +2920,7 @@ class FeedbackOverlay {
2332
2920
  onComposerPaste(event) {
2333
2921
  const which = this.dropTarget(event);
2334
2922
  const images = Array.from(event.clipboardData?.files ?? []).filter((file) => file.type.startsWith('image/'));
2335
- if (!which || !images.length || this.sending === which)
2923
+ if (!which || !images.length || (which === 'recording' ? this.recordingSaving : this.sending === which))
2336
2924
  return;
2337
2925
  event.stopPropagation();
2338
2926
  // A pasted screenshot carries no text; a copied picture with a caption keeps its caption.
@@ -2622,6 +3210,11 @@ class FeedbackOverlay {
2622
3210
  return;
2623
3211
  this.state.panelOpen = false;
2624
3212
  this.panelView = 'feedback';
3213
+ if (isRecording(comment)) {
3214
+ this.stickyId = id;
3215
+ this.openThread(id, from);
3216
+ return;
3217
+ }
2625
3218
  const route = comment.context?.route;
2626
3219
  if (route && !belongsOnThisPage(comment)) {
2627
3220
  // Only a same-origin path: the route is stored content, and any reviewer can write it.
@@ -2665,6 +3258,12 @@ class FeedbackOverlay {
2665
3258
  openThread(id, back = null) {
2666
3259
  this.sheetBack = back;
2667
3260
  if (this.state.openThreadId !== id) {
3261
+ this.threadRecordingPlayer?.destroy();
3262
+ this.threadRecordingPlayer = null;
3263
+ this.threadRecordingPlayerId = null;
3264
+ this.threadRecordingFile?.abort.abort();
3265
+ this.threadRecordingFile = null;
3266
+ this.threadRecordingGeneration += 1;
2668
3267
  this.replyBody = '';
2669
3268
  this.abandonReplyFiles();
2670
3269
  this.clearSticky();
@@ -2677,6 +3276,12 @@ class FeedbackOverlay {
2677
3276
  this.render();
2678
3277
  }
2679
3278
  closeThread() {
3279
+ this.threadRecordingPlayer?.destroy();
3280
+ this.threadRecordingPlayer = null;
3281
+ this.threadRecordingPlayerId = null;
3282
+ this.threadRecordingFile?.abort.abort();
3283
+ this.threadRecordingFile = null;
3284
+ this.threadRecordingGeneration += 1;
2680
3285
  this.state.openThreadId = null;
2681
3286
  this.sheetBack = null;
2682
3287
  this.abandonReplyFiles();
@@ -2782,10 +3387,14 @@ class FeedbackOverlay {
2782
3387
  // Its send button is disabled until the file that failed is removed; Enter does nothing either.
2783
3388
  if (this.replyTray.blocked)
2784
3389
  return;
2785
- // SPEC 5: a reply's anchor is resolved now, not inherited from the thread.
2786
- const element = locateComment(comment);
2787
- const found = element ? anchorCandidatesFor(element)[0] : undefined;
2788
- const currentAnchor = found ? { ...found.anchor, element: describeElement(found.element) } : comment.anchor;
3390
+ // SPEC 5: a pin reply's anchor is resolved now, not inherited from the thread. Recordings have no anchor.
3391
+ const currentAnchor = isRecording(comment)
3392
+ ? { file: '', line: 0, column: 0, componentName: null, domPath: '', textSnippet: null }
3393
+ : (() => {
3394
+ const element = locateComment(comment);
3395
+ const found = element ? anchorCandidatesFor(element)[0] : undefined;
3396
+ return found ? { ...found.anchor, element: describeElement(found.element) } : comment.anchor;
3397
+ })();
2789
3398
  this.sending = 'reply';
2790
3399
  this.saveError = null;
2791
3400
  this.render();
@@ -2993,6 +3602,7 @@ class FeedbackOverlay {
2993
3602
  this.updatePinCursor();
2994
3603
  this.renderBar();
2995
3604
  this.renderJoinDialog();
3605
+ this.renderRecordingDialog();
2996
3606
  this.renderPins();
2997
3607
  this.drawnFiles = new Set();
2998
3608
  this.renderPopover();
@@ -3087,7 +3697,7 @@ class FeedbackOverlay {
3087
3697
  delete this.bar.dataset.compact;
3088
3698
  this.bar.innerHTML = closed
3089
3699
  ? closedBarMarkup()
3090
- : openBarMarkup(this.state, this.identity, this.notifications?.unread ?? 0);
3700
+ : openBarMarkup(this.state, this.identity, this.notifications?.unread ?? 0, this.recordOffered());
3091
3701
  // After the markup: the open bar is wider than the closed one, and the placement is
3092
3702
  // clamped against the size it actually has.
3093
3703
  this.placeBar();
@@ -3558,7 +4168,7 @@ class FeedbackOverlay {
3558
4168
  if (!this.state.chipsVisible && !this.draft && !this.compact) {
3559
4169
  return;
3560
4170
  }
3561
- const visible = this.visibleWithSticky().filter((comment) => belongsOnThisPage(comment));
4171
+ const visible = this.visibleWithSticky().filter((comment) => !isRecording(comment) && belongsOnThisPage(comment));
3562
4172
  if (this.draft && this.draftAnchorVisible()) {
3563
4173
  const pending = document.createElement('span');
3564
4174
  pending.className = 'fb-pin';
@@ -3759,6 +4369,33 @@ class FeedbackOverlay {
3759
4369
  this.popover.innerHTML = '';
3760
4370
  return;
3761
4371
  }
4372
+ if (isRecording(thread)) {
4373
+ const active = this.activeTextarea();
4374
+ const retainedHost = this.threadRecordingPlayer && this.threadRecordingPlayerId === thread.id
4375
+ ? this.popover.querySelector('[data-fb-recording-thread-player]')
4376
+ : null;
4377
+ if (this.threadRecordingPlayer && !retainedHost) {
4378
+ this.threadRecordingPlayer.destroy();
4379
+ this.threadRecordingPlayer = null;
4380
+ this.threadRecordingPlayerId = null;
4381
+ this.threadRecordingGeneration += 1;
4382
+ }
4383
+ const generation = retainedHost ? this.threadRecordingGeneration : ++this.threadRecordingGeneration;
4384
+ const composing = this.editingKey ? this.editingBody : this.replyBody;
4385
+ this.popover.dataset.draft = 'false';
4386
+ this.popover.dataset.resolved = String(thread.status === 'resolved');
4387
+ this.popover.innerHTML = recordingThreadMarkup(thread, this.identity, composing, this.editingKey, this.editingKey ? this.saveError : null, this.sending === (this.editingKey ? 'edit' : 'reply'), { offered: this.takesFiles('reply'), tray: this.editingKey || (this.claimingReplyFor && this.claimingReplyFor !== thread.id) ? '' : trayMarkup(this.replyTray, 'reply'),
4388
+ blocked: this.replyTray.blocked && (!this.claimingReplyFor || this.claimingReplyFor === thread.id) }, (attachment) => this.fileUrl(thread.id, attachment), this.compact && this.sheetBack !== null, mayChange(thread, this.identity, this.direct?.moderates ?? true));
4389
+ if (retainedHost) {
4390
+ this.popover.querySelector('[data-fb-recording-thread-player]')?.replaceWith(retainedHost);
4391
+ }
4392
+ this.popover.style.display = 'block';
4393
+ this.positionPopover();
4394
+ this.restoreTextarea(this.editingKey ? '[data-fb-edit-body]' : '[data-fb-reply]', composing, this.editingKey ? !this.compact || active === 'body' : active === 'reply');
4395
+ if (!retainedHost)
4396
+ void this.mountThreadRecording(thread, generation);
4397
+ return;
4398
+ }
3762
4399
  const active = this.activeTextarea();
3763
4400
  const threadPin = this.pinLayer.querySelector(`.fb-pin[data-fb-value="${thread.id}"]`);
3764
4401
  // On a phone the thread is a sheet: it does not need its pin on screen (the audit's F10, F11).
@@ -4018,6 +4655,11 @@ class FeedbackOverlay {
4018
4655
  return;
4019
4656
  }
4020
4657
  if (this.state.openThreadId) {
4658
+ const comment = this.state.comments.find((item) => item.id === this.state.openThreadId);
4659
+ if (comment && isRecording(comment)) {
4660
+ this.popover.style.display = 'block';
4661
+ return;
4662
+ }
4021
4663
  const pin = this.pinLayer.querySelector(`.fb-pin[data-fb-value="${this.state.openThreadId}"]`);
4022
4664
  this.popover.style.display = pin ? 'block' : 'none';
4023
4665
  }
@@ -4095,12 +4737,13 @@ class FeedbackOverlay {
4095
4737
  this.panel.dataset.view = this.panelView;
4096
4738
  if (this.panelView !== 'feedback')
4097
4739
  this.listFilter = null;
4098
- const shown = this.visibleWithSticky();
4740
+ const shown = this.visibleWithSticky().filter((comment) => this.kindFilter === 'all'
4741
+ || (this.kindFilter === 'recording' ? isRecording(comment) : !isRecording(comment)));
4099
4742
  const listed = this.listFilter ? shown.filter((comment) => this.listFilter.includes(comment.id)) : shown;
4100
4743
  this.panelContent.innerHTML = panelMarkup(this.state, listed, this.selection, this.shared !== null, this.notifications, this.panelView,
4101
4744
  // A script-tag install, on a live site: the reviewer needs a way back to being a visitor.
4102
4745
  // A magic-link reviewer on a build preview too: leaving is how the stored key is removed.
4103
- this.shared !== null && (!this.shared.buildId || this.direct !== null), this.shared?.devReviewLinks ?? false, this.listFilter ? listed.length : null);
4746
+ this.shared !== null && (!this.shared.buildId || this.direct !== null), this.shared?.devReviewLinks ?? false, this.listFilter ? listed.length : null, this.kindFilter);
4104
4747
  this.positionPanelToast();
4105
4748
  }
4106
4749
  isOverlayEvent(event) {
@@ -4123,12 +4766,46 @@ function shellMarkup() {
4123
4766
  <input type="file" multiple hidden data-fb-file-input tabindex="-1" aria-hidden="true">
4124
4767
  <div data-fb-toast class="fb-toast" role="status"></div>
4125
4768
  <div data-fb-recorder class="fb-recorder" hidden></div>
4769
+ <div data-fb-countdown class="fb-countdown" aria-hidden="true" hidden></div>
4126
4770
  <div data-fb-bar class="fb-bar" role="toolbar" aria-label="Feedback"></div>
4127
4771
  <div data-fb-tip class="fb-tip" role="tooltip" aria-hidden="true"></div>
4772
+ <div data-fb-recording-mount></div>
4128
4773
  <!-- Last: at the same z-index as the toolbar, the full-size image covers it. -->
4129
4774
  <div data-fb-lightbox class="fb-lightbox" role="dialog" aria-modal="true" aria-label="Image, full size" hidden></div>
4130
4775
  `;
4131
4776
  }
4777
+ function recordingDialogMarkup() {
4778
+ return `<div data-fb-recording-dialog class="fb-recording-dialog" role="dialog" aria-modal="true" aria-label="Recording">
4779
+ <section class="fb-recording-dialog__card" data-fb-drop="recording">
4780
+ <header class="fb-recording-dialog__head">
4781
+ <h2>Recording</h2>
4782
+ <button type="button" class="fb-icon-btn" data-fb-action="cancel-recording" aria-label="Cancel">${icon('close', 16)}</button>
4783
+ </header>
4784
+ <div class="fb-recording-dialog__columns">
4785
+ <div class="fb-recording-dialog__player" data-fb-recording-player><span class="fb-recording-loading">Loading recording…</span></div>
4786
+ <div class="fb-recording-dialog__compose">
4787
+ <div data-fb-recording-error class="fb-savefail" role="alert" hidden></div>
4788
+ <div data-fb-recording-editor-host><span class="fb-recording-loading">Loading editor…</span></div>
4789
+ <div data-fb-recording-tray></div>
4790
+ <div class="fb-recording-dialog__actions">
4791
+ ${attachButton('recording', false)}
4792
+ <button type="button" class="fb-threadblock__cancel" data-fb-action="cancel-recording">Cancel</button>
4793
+ <button type="button" class="fb-primary" data-fb-action="save-recording">Save</button>
4794
+ </div>
4795
+ </div>
4796
+ </div>
4797
+ </section>
4798
+ </div>`;
4799
+ }
4800
+ function recordingDiscardMarkup() {
4801
+ return `<div class="fb-recording-discard" data-fb-recording-discard role="alertdialog" aria-modal="true" aria-label="Discard this recording?">
4802
+ <div class="fb-recording-discard__card">
4803
+ <p>Discard this recording?</p>
4804
+ <div><button type="button" class="fb-threadblock__cancel" data-fb-action="keep-recording">Keep</button>
4805
+ <button type="button" class="fb-primary" data-fb-action="discard-recording">Discard</button></div>
4806
+ </div>
4807
+ </div>`;
4808
+ }
4132
4809
  /** Always draws something: an empty slot next to the input reads as a broken avatar. */
4133
4810
  function composerAvatar(identity) {
4134
4811
  return identity
@@ -4142,7 +4819,7 @@ function closedBarMarkup() {
4142
4819
  return `<button type="button" data-fb-action="close-overlay" data-tip="Show feedback" data-tip-keys="${toggleKeys}"
4143
4820
  aria-label="Show feedback" aria-keyshortcuts="Alt+Shift+F">${icon('comment', 17)}</button>`;
4144
4821
  }
4145
- function openBarMarkup(state, identity, unread = 0) {
4822
+ function openBarMarkup(state, identity, unread = 0, record = false) {
4146
4823
  const commenting = state.mode === 'commenting';
4147
4824
  const count = state.routeCount();
4148
4825
  unread += state.newRemoteComments;
@@ -4165,6 +4842,8 @@ function openBarMarkup(state, identity, unread = 0) {
4165
4842
  * the panel, where there is room to say what it is counting.
4166
4843
  */
4167
4844
  unread > 0 ? '<span class="fb-dot" aria-label="Unread feedback"></span>' : ''}</button>
4845
+ ${record ? `<button type="button" data-fb-action="record-journey" data-tip="Record" data-tip-keys="Alt+Shift+R"
4846
+ aria-label="Record" aria-keyshortcuts="Alt+Shift+R"><span class="fb-toolbar-word">Record</span></button>` : ''}
4168
4847
  ${state.remoteNotice ? `<span role="status" style="font-size:11px;max-width:180px">${escapeHtml(state.remoteNotice)}</span>` : ''}
4169
4848
  <span class="fb-sep"></span>
4170
4849
  ${identity
@@ -4498,6 +5177,13 @@ function threadMarkup(comment, identity, value, editing, editError, sending, fil
4498
5177
  ${threadComposerMarkup(comment, identity, value, editing, editError, sending, files)}
4499
5178
  `;
4500
5179
  }
5180
+ function recordingThreadMarkup(comment, identity, value, editing, editError, sending, files, fileUrl, back = false, changeable = true) {
5181
+ const markup = threadMarkup(comment, identity, value, editing, editError, sending, files, fileUrl, back, changeable);
5182
+ const duration = clock(comment.recording?.durationMs ?? 0);
5183
+ return markup.replace('<div class="fb-card-body">', `<div class="fb-recording-thread-head"><span>Recording</span><time>${escapeHtml(duration)}</time></div>
5184
+ <div data-fb-recording-thread-player class="fb-recording-thread-player"><span class="fb-recording-loading">Loading recording…</span></div>
5185
+ <div class="fb-card-body">`);
5186
+ }
4501
5187
  /**
4502
5188
  * The one place in a thread where anything is typed, and the one place the actions live.
4503
5189
  *
@@ -4617,7 +5303,7 @@ function notificationPanelMarkup(notifications) {
4617
5303
  <div class="fb-list">${body}</div>
4618
5304
  `;
4619
5305
  }
4620
- function panelMarkup(state, comments, selection, shared = false, notifications = null, view = 'feedback', scriptTag = false, devReviewLinks = false, filtered = null) {
5306
+ function panelMarkup(state, comments, selection, shared = false, notifications = null, view = 'feedback', scriptTag = false, devReviewLinks = false, filtered = null, kindFilter = 'all') {
4621
5307
  // The notification list replaces the feedback list rather than sitting beside it: the panel
4622
5308
  // is narrow, and two scrolling lists in it would each be too short to read.
4623
5309
  if (view === 'notifications' && notifications) {
@@ -4639,25 +5325,29 @@ function panelMarkup(state, comments, selection, shared = false, notifications =
4639
5325
  .map(([file, grouped]) => {
4640
5326
  const items = grouped
4641
5327
  .map((comment) => {
4642
- // On another page it is neither orphaned nor off screen: it is on its page.
4643
- const elsewhere = !belongsOnThisPage(comment);
4644
- // Found but not drawn (a closed dialog, menu or tab), or not on this page at all.
4645
- const element = elsewhere ? null : locateComment(comment);
4646
- const orphaned = !elsewhere && element === null;
5328
+ const recording = isRecording(comment);
5329
+ // A recording has a route but no anchor; it is never orphaned or hidden.
5330
+ const elsewhere = recording ? false : !belongsOnThisPage(comment);
5331
+ const element = recording || elsewhere ? null : locateComment(comment);
5332
+ const orphaned = !recording && !elsewhere && element === null;
4647
5333
  const hidden = element !== null && !shownOnPage(element);
4648
5334
  const checked = selection.has(comment.id);
4649
5335
  const latest = comment.replies.at(-1) ?? comment;
5336
+ const summary = recording
5337
+ ? `<b>Recording</b> &middot; ${escapeHtml(clock(comment.recording?.durationMs ?? 0))}${latest.body ? ` &middot; ${escapeHtml(latest.body)}` : ''}`
5338
+ : escapeHtml(latest.body);
5339
+ const anchorMeta = recording ? '' : comment.anchor.file ? `${escapeHtml(`line ${comment.anchor.line}`)} &middot; ` : '';
5340
+ const locationMeta = recording || elsewhere ? ''
5341
+ : orphaned ? (comment.anchor.file ? ' &middot; orphaned' : ' &middot; not on this page')
5342
+ : hidden ? ' &middot; hidden right now' : '';
4650
5343
  return `
4651
- <div class="fb-item" data-status="${comment.status}" data-fb-action="focus-comment" data-fb-value="${comment.id}">
5344
+ <div class="fb-item" data-status="${comment.status}" data-kind="${recording ? 'recording' : 'pin'}" data-fb-action="focus-comment" data-fb-value="${comment.id}">
4652
5345
  ${avatarMarkup(comment.author, colorForId(comment.authorId ?? comment.author), 'sm')}
4653
5346
  <span>
4654
- <p>${escapeHtml(latest.body)}</p>
4655
- <small>${
4656
- // A line is only worth showing where it is known: on a preview the browser
4657
- // never sees a path, and every comment read "line 0".
4658
- comment.anchor.file ? `${escapeHtml(`line ${comment.anchor.line}`)} &middot; ` : ''}${escapeHtml(comment.author)}${comment.authorUnverified ? ' (unverified)' : ''}${comment.replies.length > 0
5347
+ <p>${summary}</p>
5348
+ <small>${anchorMeta}${escapeHtml(comment.author)}${comment.authorUnverified ? ' (unverified)' : ''}${comment.replies.length > 0
4659
5349
  ? ` &middot; ${comment.replies.length} ${comment.replies.length === 1 ? 'reply' : 'replies'}`
4660
- : ''}${elsewhere ? '' : orphaned ? (comment.anchor.file ? ' &middot; orphaned' : ' &middot; not on this page') : hidden ? ' &middot; hidden right now' : ''}</small>
5350
+ : ''}${locationMeta}</small>
4661
5351
  </span>
4662
5352
  <button type="button" class="fb-select" data-selected="${checked}"
4663
5353
  data-fb-action="toggle-selection" data-fb-value="${comment.id}"
@@ -4696,6 +5386,10 @@ function panelMarkup(state, comments, selection, shared = false, notifications =
4696
5386
  aria-pressed="${state.filter === value}">${value[0].toUpperCase()}${value.slice(1)}</button>`)
4697
5387
  .join('')}
4698
5388
  </div>
5389
+ <div class="fb-segmented fb-segmented--kind" role="group" aria-label="Feedback kind">
5390
+ ${[['all', 'All'], ['pin', 'Comments'], ['recording', 'Recordings']].map(([value, label]) => `<button type="button" data-fb-action="set-kind-filter" data-fb-value="${value}"
5391
+ aria-pressed="${kindFilter === value}">${label}</button>`).join('')}
5392
+ </div>
4699
5393
  ${filtered !== null ? `<div class="fb-listfilter"><span>${filtered} ${filtered === 1 ? 'comment' : 'comments'} here</span>
4700
5394
  <button type="button" class="fb-link" data-fb-action="clear-list-filter">Show all</button></div>` : ''}
4701
5395
  <div class="fb-list">${list}</div>
@@ -4813,6 +5507,8 @@ function offsetWithin(element, point) {
4813
5507
  * does not (a preview, where every file is blank and they all fell into one unnamed group).
4814
5508
  */
4815
5509
  function groupOf(comment) {
5510
+ if (isRecording(comment))
5511
+ return 'Recordings';
4816
5512
  if (comment.anchor.file)
4817
5513
  return comment.anchor.file;
4818
5514
  const route = comment.context?.route ?? '';