makethisbetter 1.5.4 → 1.7.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/README.md +10 -10
- package/dist/annotate/draw-note-bar.d.ts +29 -0
- package/dist/annotate/draw-note-bar.d.ts.map +1 -0
- package/dist/annotate/draw-note-bar.test.d.ts +2 -0
- package/dist/annotate/draw-note-bar.test.d.ts.map +1 -0
- package/dist/annotate/draw.d.ts +15 -9
- package/dist/annotate/draw.d.ts.map +1 -1
- package/dist/annotate/highlighter.d.ts +2 -0
- package/dist/annotate/highlighter.d.ts.map +1 -1
- package/dist/annotate/session.d.ts +16 -2
- package/dist/annotate/session.d.ts.map +1 -1
- package/dist/api/client.d.ts +8 -5
- package/dist/api/client.d.ts.map +1 -1
- package/dist/context/breadcrumbs.d.ts +26 -0
- package/dist/context/breadcrumbs.d.ts.map +1 -0
- package/dist/context/breadcrumbs.test.d.ts +2 -0
- package/dist/context/breadcrumbs.test.d.ts.map +1 -0
- package/dist/context/dom-utils.d.ts +3 -0
- package/dist/context/dom-utils.d.ts.map +1 -0
- package/dist/context/frustration.d.ts +0 -1
- package/dist/context/frustration.d.ts.map +1 -1
- package/dist/i18n/de.d.ts +24 -0
- package/dist/i18n/de.d.ts.map +1 -1
- package/dist/i18n/en.d.ts +24 -0
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/es.d.ts +24 -0
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/fr.d.ts +24 -0
- package/dist/i18n/fr.d.ts.map +1 -1
- package/dist/i18n/ja.d.ts +24 -0
- package/dist/i18n/ja.d.ts.map +1 -1
- package/dist/i18n/ko.d.ts +24 -0
- package/dist/i18n/ko.d.ts.map +1 -1
- package/dist/i18n/zh-CN.d.ts +24 -0
- package/dist/i18n/zh-CN.d.ts.map +1 -1
- package/dist/makethisbetter.cjs +50 -25
- package/dist/makethisbetter.cjs.map +1 -1
- package/dist/makethisbetter.esm.js +1132 -590
- package/dist/makethisbetter.esm.js.map +1 -1
- package/dist/makethisbetter.js +49 -24
- package/dist/makethisbetter.js.map +1 -1
- package/dist/popup/clarify.d.ts +28 -7
- package/dist/popup/clarify.d.ts.map +1 -1
- package/dist/popup/comment.d.ts +1 -0
- package/dist/popup/comment.d.ts.map +1 -1
- package/dist/record/replay.d.ts +7 -0
- package/dist/record/replay.d.ts.map +1 -0
- package/dist/screenshot/capture.d.ts +1 -0
- package/dist/screenshot/capture.d.ts.map +1 -1
- package/dist/styles.d.ts +1 -0
- package/dist/styles.d.ts.map +1 -1
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/widget/controller.d.ts +18 -0
- package/dist/widget/controller.d.ts.map +1 -1
- package/dist/widget/dim-overlay.d.ts +8 -0
- package/dist/widget/dim-overlay.d.ts.map +1 -0
- package/dist/widget/dim-overlay.test.d.ts +2 -0
- package/dist/widget/dim-overlay.test.d.ts.map +1 -0
- package/dist/widget/payload.d.ts +2 -2
- package/dist/widget/payload.d.ts.map +1 -1
- package/dist/widget/tab.d.ts +3 -0
- package/dist/widget/tab.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/annotate/draw-note-bar.test.ts +90 -0
- package/src/annotate/draw-note-bar.ts +105 -0
- package/src/annotate/draw.test.ts +74 -84
- package/src/annotate/draw.ts +108 -65
- package/src/annotate/highlighter.test.ts +24 -1
- package/src/annotate/highlighter.ts +16 -2
- package/src/annotate/session.test.ts +112 -96
- package/src/annotate/session.ts +54 -10
- package/src/api/client.test.ts +69 -30
- package/src/api/client.ts +68 -20
- package/src/context/breadcrumbs.test.ts +154 -0
- package/src/context/breadcrumbs.ts +157 -0
- package/src/context/dom-utils.ts +16 -0
- package/src/context/frustration.ts +4 -8
- package/src/i18n/de.ts +34 -11
- package/src/i18n/en.ts +33 -10
- package/src/i18n/es.ts +34 -11
- package/src/i18n/fr.ts +33 -10
- package/src/i18n/index.test.ts +12 -0
- package/src/i18n/ja.ts +32 -9
- package/src/i18n/ko.ts +34 -11
- package/src/i18n/zh-CN.ts +35 -12
- package/src/popup/clarify.test.ts +132 -40
- package/src/popup/clarify.ts +154 -42
- package/src/popup/comment.test.ts +57 -0
- package/src/popup/comment.ts +15 -9
- package/src/record/replay.ts +115 -0
- package/src/record/session.test.ts +8 -1
- package/src/record/session.ts +1 -1
- package/src/screenshot/capture.test.ts +51 -23
- package/src/screenshot/capture.ts +101 -55
- package/src/styles/widget.css +347 -1
- package/src/styles.ts +2 -0
- package/src/types.ts +15 -0
- package/src/widget/controller.test.ts +476 -65
- package/src/widget/controller.ts +222 -40
- package/src/widget/dim-overlay.test.ts +27 -0
- package/src/widget/dim-overlay.ts +20 -0
- package/src/widget/payload.test.ts +26 -1
- package/src/widget/payload.ts +3 -1
- package/src/widget/pet.test.ts +2 -2
- package/src/widget/tab.test.ts +15 -0
- package/src/widget/tab.ts +11 -3
package/src/widget/controller.ts
CHANGED
|
@@ -1,25 +1,36 @@
|
|
|
1
1
|
import { ShadowContainer } from './shadow'
|
|
2
2
|
import { FeedbackTab } from './tab'
|
|
3
3
|
import { FrustrationPromptCard } from './frustration-prompt'
|
|
4
|
+
import { DimOverlay } from './dim-overlay'
|
|
4
5
|
import { AnnotationToolbar } from '../annotate/toolbar'
|
|
5
6
|
import type { ToolbarMode } from '../annotate/toolbar'
|
|
6
7
|
import { AnnotationSession } from '../annotate/session'
|
|
8
|
+
import { DrawNoteBar } from '../annotate/draw-note-bar'
|
|
7
9
|
import { CommentPopup } from '../popup/comment'
|
|
8
10
|
import { ClarifyCard } from '../popup/clarify'
|
|
11
|
+
import type { ClarifySummaryContext } from '../popup/clarify'
|
|
9
12
|
import { SuccessCard } from '../popup/success'
|
|
10
13
|
import type { SuccessCardOptions } from '../popup/success'
|
|
11
14
|
import { captureScreenshot } from '../screenshot/capture'
|
|
12
15
|
import { ConsoleErrorCollector } from '../context/console'
|
|
16
|
+
import { BreadcrumbCollector } from '../context/breadcrumbs'
|
|
13
17
|
import { FrustrationDetector } from '../context/frustration'
|
|
14
18
|
import { collectPageContext } from '../context/collector'
|
|
19
|
+
import type { PageContext } from '../context/collector'
|
|
15
20
|
import { ApiClient } from '../api/client'
|
|
16
21
|
import { buildPayload } from './payload'
|
|
17
22
|
import { cacheBoardUrl, getAnonId, getCachedBoardUrl, getStoredReporterEmail, rememberReporterEmail } from './anon-id'
|
|
18
23
|
import { getMessages } from '../i18n'
|
|
19
24
|
import { RecordingManager } from './recording-manager'
|
|
20
|
-
import type { MakeThisBetterConfig, Annotation } from '../types'
|
|
25
|
+
import type { MakeThisBetterConfig, Annotation, SubmissionSessionResponse } from '../types'
|
|
21
26
|
|
|
22
|
-
type Mode = 'idle' | 'annotating' | 'recording' | 'popup' | 'clarifying'
|
|
27
|
+
type Mode = 'idle' | 'annotating' | 'recording' | 'drawing' | 'popup' | 'clarifying'
|
|
28
|
+
type Via = 'pin' | 'draw' | 'record'
|
|
29
|
+
|
|
30
|
+
interface SubmittingUi {
|
|
31
|
+
setLoading: (loading: boolean) => void
|
|
32
|
+
setError: (message: string) => void
|
|
33
|
+
}
|
|
23
34
|
|
|
24
35
|
export class WidgetController {
|
|
25
36
|
private config: MakeThisBetterConfig
|
|
@@ -27,18 +38,25 @@ export class WidgetController {
|
|
|
27
38
|
private tab: FeedbackTab | null = null
|
|
28
39
|
private toolbar: AnnotationToolbar | null = null
|
|
29
40
|
private session: AnnotationSession | null = null
|
|
41
|
+
private drawBar: DrawNoteBar | null = null
|
|
42
|
+
private dim: DimOverlay | null = null
|
|
30
43
|
private popup: CommentPopup | null = null
|
|
31
44
|
private clarify: ClarifyCard | null = null
|
|
32
45
|
private success: SuccessCard | null = null
|
|
33
46
|
private frustrationPrompt: FrustrationPromptCard | null = null
|
|
34
47
|
private apiClient: ApiClient
|
|
35
48
|
private consoleCollector: ConsoleErrorCollector
|
|
49
|
+
private breadcrumbCollector: BreadcrumbCollector
|
|
36
50
|
private frustrationDetector: FrustrationDetector | null = null
|
|
37
51
|
private messages: ReturnType<typeof getMessages>
|
|
38
52
|
private mode: Mode = 'idle'
|
|
53
|
+
private via: Via = 'pin'
|
|
39
54
|
private currentAnnotation: Annotation | null = null
|
|
55
|
+
private submittingUi: SubmittingUi | null = null
|
|
40
56
|
private lastPopupPos: { x: number; y: number } | null = null
|
|
41
57
|
private recordingManager: RecordingManager | null = null
|
|
58
|
+
private activeSubmission: SubmissionSessionResponse | null = null
|
|
59
|
+
private submissionAttempt = 0
|
|
42
60
|
private lastHandoff: { feedbackId?: string; boardUrl?: string; identityToken?: string } = {}
|
|
43
61
|
|
|
44
62
|
constructor(config: MakeThisBetterConfig) {
|
|
@@ -47,12 +65,43 @@ export class WidgetController {
|
|
|
47
65
|
this.apiClient = new ApiClient(config.projectKey, config.apiUrl, undefined, config.userToken, config.userTokenFn)
|
|
48
66
|
this.consoleCollector = new ConsoleErrorCollector()
|
|
49
67
|
this.consoleCollector.start()
|
|
68
|
+
this.breadcrumbCollector = new BreadcrumbCollector()
|
|
69
|
+
this.breadcrumbCollector.start()
|
|
50
70
|
this.buildUI()
|
|
51
71
|
|
|
52
72
|
if (config.frustrationDetection !== false) {
|
|
53
73
|
this.frustrationDetector = new FrustrationDetector(() => this.handleFrustration())
|
|
54
74
|
this.frustrationDetector.start()
|
|
55
75
|
}
|
|
76
|
+
|
|
77
|
+
document.addEventListener('keydown', this.handleKeydown, true)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Escape only acts while the widget is in an active state; idle/clarifying
|
|
81
|
+
// fall through untouched so the host page's own Escape handling still works.
|
|
82
|
+
private handleKeydown = (event: KeyboardEvent): void => {
|
|
83
|
+
if (event.key !== 'Escape') return
|
|
84
|
+
|
|
85
|
+
switch (this.mode) {
|
|
86
|
+
case 'annotating':
|
|
87
|
+
case 'popup':
|
|
88
|
+
event.preventDefault()
|
|
89
|
+
event.stopPropagation()
|
|
90
|
+
this.exitAll()
|
|
91
|
+
break
|
|
92
|
+
case 'drawing':
|
|
93
|
+
event.preventDefault()
|
|
94
|
+
event.stopPropagation()
|
|
95
|
+
this.cancelDraw()
|
|
96
|
+
break
|
|
97
|
+
case 'recording':
|
|
98
|
+
event.preventDefault()
|
|
99
|
+
event.stopPropagation()
|
|
100
|
+
this.handleRecordStop()
|
|
101
|
+
break
|
|
102
|
+
default:
|
|
103
|
+
break
|
|
104
|
+
}
|
|
56
105
|
}
|
|
57
106
|
|
|
58
107
|
private buildUI(): void {
|
|
@@ -103,25 +152,38 @@ export class WidgetController {
|
|
|
103
152
|
() => this.exitAll(),
|
|
104
153
|
(mode: ToolbarMode) => this.handleToolbarModeChange(mode),
|
|
105
154
|
)
|
|
106
|
-
this.session =
|
|
107
|
-
|
|
108
|
-
|
|
155
|
+
this.session = this.createSession()
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private createSession(): AnnotationSession {
|
|
159
|
+
return new AnnotationSession(this.shadow, this.messages, {
|
|
160
|
+
onPin: (annotation, targetName) => {
|
|
161
|
+
this.currentAnnotation = annotation
|
|
162
|
+
this.via = 'pin'
|
|
163
|
+
this.showPopup(annotation.x, annotation.y, targetName)
|
|
164
|
+
},
|
|
165
|
+
onDrawStroke: () => this.handleDrawStroke(),
|
|
109
166
|
})
|
|
110
167
|
}
|
|
111
168
|
|
|
112
169
|
private handleToolbarModeChange(mode: ToolbarMode): void {
|
|
170
|
+
if (this.mode === 'clarifying') {
|
|
171
|
+
this.toolbar?.setMode(this.via === 'record' ? 'record' : 'markup')
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
|
|
113
175
|
if (mode === 'record') {
|
|
176
|
+
if (this.mode === 'recording') return
|
|
177
|
+
|
|
114
178
|
this.mode = 'recording'
|
|
179
|
+
this.currentAnnotation = null
|
|
180
|
+
this.teardownDraw()
|
|
115
181
|
this.session?.destroy()
|
|
116
182
|
this.session = null
|
|
117
183
|
this.recordingManager = new RecordingManager()
|
|
118
|
-
this.recordingManager.start(this.shadow, this.messages, () => {
|
|
119
|
-
if (!this.recordingManager) return
|
|
120
|
-
this.recordingManager.stop()
|
|
121
|
-
this.showPopup(window.innerWidth / 2, window.innerHeight / 2, this.messages.record.timer_label)
|
|
122
|
-
}).catch((error) => {
|
|
184
|
+
this.recordingManager.start(this.shadow, this.messages, this.handleRecordStop).catch((error) => {
|
|
123
185
|
// rrweb failed to load (network / SRI mismatch) — fall back to markup
|
|
124
|
-
console.warn('[MakeThisBetter]
|
|
186
|
+
console.warn('[MakeThisBetter] Interaction replay unavailable, falling back to markup:', error)
|
|
125
187
|
if (this.mode !== 'recording') return
|
|
126
188
|
this.toolbar?.setMode('markup')
|
|
127
189
|
this.handleToolbarModeChange('markup')
|
|
@@ -129,20 +191,78 @@ export class WidgetController {
|
|
|
129
191
|
} else {
|
|
130
192
|
this.recordingManager?.destroy()
|
|
131
193
|
this.recordingManager = null
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
this.currentAnnotation = annotation
|
|
135
|
-
this.showPopup(annotation.x, annotation.y, targetName)
|
|
136
|
-
})
|
|
137
|
-
}
|
|
194
|
+
this.teardownDraw()
|
|
195
|
+
if (!this.session) this.session = this.createSession()
|
|
138
196
|
this.mode = 'annotating'
|
|
139
197
|
}
|
|
140
198
|
}
|
|
141
199
|
|
|
200
|
+
private handleRecordStop = (): void => {
|
|
201
|
+
if (!this.recordingManager) return
|
|
202
|
+
this.recordingManager.stop()
|
|
203
|
+
this.via = 'record'
|
|
204
|
+
this.showPopup(window.innerWidth / 2, window.innerHeight / 2, this.messages.record.timer_label)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
private handleDrawStroke(): void {
|
|
208
|
+
if (this.mode !== 'drawing') {
|
|
209
|
+
this.mode = 'drawing'
|
|
210
|
+
this.drawBar = new DrawNoteBar(this.shadow, {
|
|
211
|
+
messages: this.messages,
|
|
212
|
+
onUndo: () => this.handleDrawUndoRedo('undo'),
|
|
213
|
+
onRedo: () => this.handleDrawUndoRedo('redo'),
|
|
214
|
+
onCancel: () => this.cancelDraw(),
|
|
215
|
+
onSubmit: (note) => this.handleDrawSubmit(note),
|
|
216
|
+
})
|
|
217
|
+
}
|
|
218
|
+
this.refreshDrawBar()
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private handleDrawUndoRedo(action: 'undo' | 'redo'): void {
|
|
222
|
+
if (action === 'undo') this.session?.undoDraw()
|
|
223
|
+
else this.session?.redoDraw()
|
|
224
|
+
this.refreshDrawBar()
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private refreshDrawBar(): void {
|
|
228
|
+
if (!this.session) return
|
|
229
|
+
this.drawBar?.setUndoRedo(this.session.canUndoDraw(), this.session.canRedoDraw())
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private cancelDraw(): void {
|
|
233
|
+
this.session?.clearDraw()
|
|
234
|
+
this.teardownDraw()
|
|
235
|
+
this.mode = 'annotating'
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private teardownDraw(): void {
|
|
239
|
+
this.drawBar?.destroy()
|
|
240
|
+
this.drawBar = null
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
private handleDrawSubmit(note: string): void {
|
|
244
|
+
const annotation = this.session?.getDrawAnnotation()
|
|
245
|
+
if (!annotation) {
|
|
246
|
+
this.cancelDraw()
|
|
247
|
+
return
|
|
248
|
+
}
|
|
249
|
+
this.currentAnnotation = annotation
|
|
250
|
+
this.via = 'draw'
|
|
251
|
+
this.session?.dismissInteraction()
|
|
252
|
+
this.submittingUi = this.drawBar
|
|
253
|
+
void this.handleSubmit(note || this.messages.annotation.drawing)
|
|
254
|
+
}
|
|
255
|
+
|
|
142
256
|
private showPopup(x: number, y: number, targetName: string): void {
|
|
143
257
|
this.mode = 'popup'
|
|
144
258
|
this.lastPopupPos = { x, y }
|
|
259
|
+
this.teardownDraw()
|
|
145
260
|
this.session?.dismissInteraction()
|
|
261
|
+
this.popup?.destroy()
|
|
262
|
+
this.popup = null
|
|
263
|
+
this.dim?.destroy()
|
|
264
|
+
this.dim = null
|
|
265
|
+
this.dim = new DimOverlay(this.shadow, () => this.exitAll())
|
|
146
266
|
|
|
147
267
|
this.popup = new CommentPopup(this.shadow, {
|
|
148
268
|
targetName,
|
|
@@ -153,6 +273,7 @@ export class WidgetController {
|
|
|
153
273
|
onClose: () => this.exitAll(),
|
|
154
274
|
onMyFeedback: this.buildMyFeedbackHandler(),
|
|
155
275
|
})
|
|
276
|
+
this.submittingUi = this.popup
|
|
156
277
|
}
|
|
157
278
|
|
|
158
279
|
private buildMyFeedbackHandler(): (() => void) | undefined {
|
|
@@ -168,9 +289,11 @@ export class WidgetController {
|
|
|
168
289
|
}
|
|
169
290
|
|
|
170
291
|
private async handleSubmit(description: string): Promise<void> {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
292
|
+
const ui = this.submittingUi
|
|
293
|
+
if (!ui) return
|
|
294
|
+
const submissionAttempt = ++this.submissionAttempt
|
|
295
|
+
ui.setLoading(true)
|
|
296
|
+
await waitForPaint()
|
|
174
297
|
const annotation = this.currentAnnotation
|
|
175
298
|
const recording = this.recordingManager?.getRecording() ?? undefined
|
|
176
299
|
|
|
@@ -188,51 +311,93 @@ export class WidgetController {
|
|
|
188
311
|
recording,
|
|
189
312
|
this.config.user ? undefined : getAnonId(),
|
|
190
313
|
this.config.user ? undefined : getStoredReporterEmail(),
|
|
314
|
+
this.breadcrumbCollector.getBreadcrumbs(),
|
|
191
315
|
)
|
|
192
316
|
|
|
193
317
|
try {
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
318
|
+
const submission = await this.apiClient.createSubmissionSession(payload, screenshot)
|
|
319
|
+
if (submissionAttempt !== this.submissionAttempt) {
|
|
320
|
+
await this.apiClient.abandonSubmissionSession(submission.id, submission.token).catch(() => {})
|
|
321
|
+
return
|
|
322
|
+
}
|
|
323
|
+
this.activeSubmission = submission
|
|
324
|
+
const summary = this.buildSummaryContext(description, pageContext, annotation)
|
|
325
|
+
this.teardownDraw()
|
|
197
326
|
this.popup?.destroy()
|
|
198
327
|
this.popup = null
|
|
328
|
+
this.dim?.destroy()
|
|
329
|
+
this.dim = null
|
|
199
330
|
this.session?.destroy()
|
|
200
331
|
this.session = null
|
|
201
|
-
this.toolbar?.destroy()
|
|
202
|
-
this.toolbar = null
|
|
203
332
|
this.recordingManager?.destroy()
|
|
204
333
|
this.recordingManager = null
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
this.showSuccess({ skipFollowup: true })
|
|
208
|
-
} else {
|
|
209
|
-
this.showClarify(feedback.id, this.lastPopupPos)
|
|
210
|
-
}
|
|
334
|
+
this.submittingUi = null
|
|
335
|
+
this.showClarify(submission, this.lastPopupPos, summary)
|
|
211
336
|
} catch {
|
|
212
|
-
this.
|
|
213
|
-
|
|
337
|
+
if (submissionAttempt !== this.submissionAttempt) return
|
|
338
|
+
ui.setLoading(false)
|
|
339
|
+
ui.setError(this.messages.error.submit)
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
private buildSummaryContext(
|
|
344
|
+
description: string,
|
|
345
|
+
pageContext: PageContext,
|
|
346
|
+
annotation: Annotation | null,
|
|
347
|
+
): ClarifySummaryContext {
|
|
348
|
+
const s = this.messages.clarify.summary
|
|
349
|
+
return {
|
|
350
|
+
originalDescription: description,
|
|
351
|
+
element: annotation?.targetName ?? this.messages.annotation.element,
|
|
352
|
+
page: pageContext.page_url,
|
|
353
|
+
browser: `${pageContext.browser} · ${pageContext.os}`,
|
|
354
|
+
captured: this.via === 'record' ? s.recording : s.screenshot,
|
|
214
355
|
}
|
|
215
356
|
}
|
|
216
357
|
|
|
217
|
-
private showClarify(
|
|
358
|
+
private showClarify(
|
|
359
|
+
submission: SubmissionSessionResponse,
|
|
360
|
+
pos: { x: number; y: number } | null,
|
|
361
|
+
summary: ClarifySummaryContext,
|
|
362
|
+
): void {
|
|
218
363
|
// 'clarifying' keeps the tab and frustration prompt from starting a second
|
|
219
364
|
// feedback while the current one is still being clarified.
|
|
220
365
|
this.mode = 'clarifying'
|
|
221
366
|
this.tab?.setActive(true)
|
|
222
367
|
this.clarify = new ClarifyCard(this.shadow, {
|
|
223
|
-
|
|
368
|
+
submissionSessionId: submission.id,
|
|
369
|
+
submissionToken: submission.token,
|
|
224
370
|
apiClient: this.apiClient,
|
|
225
371
|
messages: this.messages,
|
|
372
|
+
summary,
|
|
226
373
|
x: pos?.x,
|
|
227
374
|
y: pos?.y,
|
|
228
|
-
|
|
229
|
-
this.clarify?.destroy()
|
|
230
|
-
this.clarify = null
|
|
231
|
-
this.showSuccess()
|
|
232
|
-
},
|
|
375
|
+
onFinalize: () => this.finalizeSubmission(),
|
|
233
376
|
})
|
|
234
377
|
}
|
|
235
378
|
|
|
379
|
+
private async finalizeSubmission(): Promise<void> {
|
|
380
|
+
const submission = this.activeSubmission
|
|
381
|
+
if (!submission) throw new Error('No active submission session')
|
|
382
|
+
const submissionAttempt = this.submissionAttempt
|
|
383
|
+
|
|
384
|
+
const feedback = await this.apiClient.finalizeSubmissionSession(submission.id, submission.token)
|
|
385
|
+
if (submissionAttempt !== this.submissionAttempt || this.activeSubmission !== submission) return
|
|
386
|
+
|
|
387
|
+
this.activeSubmission = null
|
|
388
|
+
this.lastHandoff = {
|
|
389
|
+
feedbackId: feedback.id,
|
|
390
|
+
boardUrl: feedback.board_url,
|
|
391
|
+
identityToken: feedback.identity_token,
|
|
392
|
+
}
|
|
393
|
+
if (feedback.board_url) cacheBoardUrl(feedback.board_url)
|
|
394
|
+
this.clarify?.destroy()
|
|
395
|
+
this.clarify = null
|
|
396
|
+
this.toolbar?.destroy()
|
|
397
|
+
this.toolbar = null
|
|
398
|
+
this.showSuccess({ skipFollowup: submission.ai_clarify_available === false })
|
|
399
|
+
}
|
|
400
|
+
|
|
236
401
|
private showSuccess(options?: SuccessCardOptions): void {
|
|
237
402
|
this.mode = 'idle'
|
|
238
403
|
this.tab?.setActive(false)
|
|
@@ -277,24 +442,37 @@ export class WidgetController {
|
|
|
277
442
|
}
|
|
278
443
|
|
|
279
444
|
private exitAll(): void {
|
|
445
|
+
this.submissionAttempt += 1
|
|
446
|
+
const submission = this.activeSubmission
|
|
447
|
+
this.activeSubmission = null
|
|
448
|
+
if (submission) {
|
|
449
|
+
void this.apiClient.abandonSubmissionSession(submission.id, submission.token).catch(() => {})
|
|
450
|
+
}
|
|
280
451
|
this.mode = 'idle'
|
|
452
|
+
this.via = 'pin'
|
|
281
453
|
this.tab?.setActive(false)
|
|
454
|
+
this.teardownDraw()
|
|
282
455
|
this.toolbar?.destroy()
|
|
283
456
|
this.toolbar = null
|
|
284
457
|
this.session?.destroy()
|
|
285
458
|
this.session = null
|
|
459
|
+
this.dim?.destroy()
|
|
460
|
+
this.dim = null
|
|
286
461
|
this.popup?.destroy()
|
|
287
462
|
this.popup = null
|
|
288
463
|
this.clarify?.destroy()
|
|
289
464
|
this.clarify = null
|
|
290
465
|
this.currentAnnotation = null
|
|
466
|
+
this.submittingUi = null
|
|
291
467
|
this.recordingManager?.destroy()
|
|
292
468
|
this.recordingManager = null
|
|
293
469
|
}
|
|
294
470
|
|
|
295
471
|
destroy(): void {
|
|
472
|
+
document.removeEventListener('keydown', this.handleKeydown, true)
|
|
296
473
|
this.exitAll()
|
|
297
474
|
this.consoleCollector.stop()
|
|
475
|
+
this.breadcrumbCollector.stop()
|
|
298
476
|
this.frustrationDetector?.stop()
|
|
299
477
|
this.dismissFrustrationPrompt()
|
|
300
478
|
this.clarify?.destroy()
|
|
@@ -304,3 +482,7 @@ export class WidgetController {
|
|
|
304
482
|
this.shadow.destroy()
|
|
305
483
|
}
|
|
306
484
|
}
|
|
485
|
+
|
|
486
|
+
function waitForPaint(): Promise<void> {
|
|
487
|
+
return new Promise<void>((r) => requestAnimationFrame(() => setTimeout(r, 0)))
|
|
488
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { afterEach, describe, it, expect, vi } from 'vitest'
|
|
2
|
+
import { ShadowContainer } from './shadow'
|
|
3
|
+
import { DimOverlay } from './dim-overlay'
|
|
4
|
+
|
|
5
|
+
describe('DimOverlay', () => {
|
|
6
|
+
let shadow: ShadowContainer
|
|
7
|
+
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
shadow.destroy()
|
|
10
|
+
document.body.innerHTML = ''
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('renders a clickable dim scrim that invokes the reset callback on click', () => {
|
|
14
|
+
shadow = new ShadowContainer()
|
|
15
|
+
const onClick = vi.fn()
|
|
16
|
+
const dim = new DimOverlay(shadow, onClick)
|
|
17
|
+
|
|
18
|
+
const el = shadow.root.querySelector<HTMLDivElement>('.mtb-dim.mtb-dim-clickable')!
|
|
19
|
+
expect(el).toBeTruthy()
|
|
20
|
+
|
|
21
|
+
el.click()
|
|
22
|
+
expect(onClick).toHaveBeenCalledOnce()
|
|
23
|
+
|
|
24
|
+
dim.destroy()
|
|
25
|
+
expect(shadow.root.querySelector('.mtb-dim-clickable')).toBeNull()
|
|
26
|
+
})
|
|
27
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ShadowContainer } from './shadow'
|
|
2
|
+
|
|
3
|
+
// Full-screen scrim shown behind the comment popup. Clicking it resets the
|
|
4
|
+
// widget, mirroring the design's dim-to-dismiss behaviour.
|
|
5
|
+
export class DimOverlay {
|
|
6
|
+
private el: HTMLDivElement
|
|
7
|
+
private onClick: () => void
|
|
8
|
+
|
|
9
|
+
constructor(shadow: ShadowContainer, onClick: () => void) {
|
|
10
|
+
this.onClick = onClick
|
|
11
|
+
this.el = shadow.el<HTMLDivElement>('div', 'mtb-dim mtb-dim-clickable')
|
|
12
|
+
this.el.addEventListener('click', this.onClick)
|
|
13
|
+
shadow.append(this.el)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
destroy(): void {
|
|
17
|
+
this.el.removeEventListener('click', this.onClick)
|
|
18
|
+
this.el.remove()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
import { buildPayload } from './payload'
|
|
3
3
|
import type { PageContext } from '../context/collector'
|
|
4
|
-
import type { Annotation, MakeThisBetterConfig } from '../types'
|
|
4
|
+
import type { Annotation, Breadcrumb, MakeThisBetterConfig } from '../types'
|
|
5
5
|
import type { RecordingResult } from '../record/session'
|
|
6
6
|
|
|
7
7
|
const pageContext: PageContext = {
|
|
@@ -159,6 +159,24 @@ describe('buildPayload', () => {
|
|
|
159
159
|
expect(result.console_errors).toEqual([])
|
|
160
160
|
})
|
|
161
161
|
|
|
162
|
+
it('includes breadcrumbs when provided', () => {
|
|
163
|
+
const crumbs: Breadcrumb[] = [
|
|
164
|
+
{ type: 'ui', category: 'ui.click', timestamp: 1000, message: 'Save', data: { selector: '#save' } },
|
|
165
|
+
{ type: 'navigation', category: 'navigation', timestamp: 2000, data: { from: '/a', to: '/b' } },
|
|
166
|
+
]
|
|
167
|
+
|
|
168
|
+
const result = buildPayload('Feedback', pageContext, [], null, undefined, undefined, undefined, undefined, crumbs)
|
|
169
|
+
|
|
170
|
+
expect(result.breadcrumbs).toEqual(crumbs)
|
|
171
|
+
expect(result.breadcrumbs).toHaveLength(2)
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
it('omits breadcrumbs when not provided', () => {
|
|
175
|
+
const result = buildPayload('Feedback', pageContext, [], null, undefined)
|
|
176
|
+
|
|
177
|
+
expect(result.breadcrumbs).toBeUndefined()
|
|
178
|
+
})
|
|
179
|
+
|
|
162
180
|
it('combines all optional fields together', () => {
|
|
163
181
|
const annotation: Annotation = {
|
|
164
182
|
type: 'pin',
|
|
@@ -177,6 +195,9 @@ describe('buildPayload', () => {
|
|
|
177
195
|
events: [{ type: 2 }],
|
|
178
196
|
duration: 5000,
|
|
179
197
|
}
|
|
198
|
+
const crumbs: Breadcrumb[] = [
|
|
199
|
+
{ type: 'ui', category: 'ui.click', timestamp: 1000, message: 'Save', data: { selector: '#save' } },
|
|
200
|
+
]
|
|
180
201
|
|
|
181
202
|
const result = buildPayload(
|
|
182
203
|
'Save broken',
|
|
@@ -185,6 +206,9 @@ describe('buildPayload', () => {
|
|
|
185
206
|
annotation,
|
|
186
207
|
user,
|
|
187
208
|
recording,
|
|
209
|
+
undefined,
|
|
210
|
+
undefined,
|
|
211
|
+
crumbs,
|
|
188
212
|
)
|
|
189
213
|
|
|
190
214
|
expect(result.description).toBe('Save broken')
|
|
@@ -193,5 +217,6 @@ describe('buildPayload', () => {
|
|
|
193
217
|
expect(result.user_id).toBe('usr_456')
|
|
194
218
|
expect(result.recording_duration).toBe(5000)
|
|
195
219
|
expect(result.console_errors).toEqual(['Error: 500'])
|
|
220
|
+
expect(result.breadcrumbs).toEqual(crumbs)
|
|
196
221
|
})
|
|
197
222
|
})
|
package/src/widget/payload.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PageContext } from '../context/collector'
|
|
2
|
-
import type { Annotation, FeedbackPayload, MakeThisBetterConfig } from '../types'
|
|
2
|
+
import type { Annotation, Breadcrumb, FeedbackPayload, MakeThisBetterConfig } from '../types'
|
|
3
3
|
import type { RecordingResult } from '../record/session'
|
|
4
4
|
|
|
5
5
|
export function buildPayload(
|
|
@@ -11,6 +11,7 @@ export function buildPayload(
|
|
|
11
11
|
recording?: RecordingResult,
|
|
12
12
|
anonId?: string,
|
|
13
13
|
anonEmail?: string,
|
|
14
|
+
breadcrumbs?: Breadcrumb[],
|
|
14
15
|
): FeedbackPayload {
|
|
15
16
|
return {
|
|
16
17
|
description,
|
|
@@ -31,5 +32,6 @@ export function buildPayload(
|
|
|
31
32
|
reporter_email: user ? undefined : anonEmail,
|
|
32
33
|
recording_events: recording?.events,
|
|
33
34
|
recording_duration: recording?.duration,
|
|
35
|
+
breadcrumbs,
|
|
34
36
|
}
|
|
35
37
|
}
|
package/src/widget/pet.test.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { getMessages } from '../i18n'
|
|
|
5
5
|
import { MakeThisBetter } from '../index'
|
|
6
6
|
|
|
7
7
|
vi.mock('html-to-image', () => ({
|
|
8
|
-
|
|
8
|
+
toJpeg: vi.fn(async () => 'data:image/jpeg;base64,/9j/AA=='),
|
|
9
9
|
}))
|
|
10
10
|
|
|
11
11
|
// PetEntry is kept in the repo for the phase-2 pet mode but is not wired into
|
|
@@ -54,7 +54,7 @@ describe('Widget entry', () => {
|
|
|
54
54
|
|
|
55
55
|
it('renders the tab entry and never the pet', () => {
|
|
56
56
|
MakeThisBetter.init({
|
|
57
|
-
projectKey: '
|
|
57
|
+
projectKey: 'acme',
|
|
58
58
|
apiUrl: 'https://api.example.com/api/v1',
|
|
59
59
|
})
|
|
60
60
|
|
package/src/widget/tab.test.ts
CHANGED
|
@@ -69,6 +69,21 @@ describe('FeedbackTab', () => {
|
|
|
69
69
|
shadow.destroy()
|
|
70
70
|
})
|
|
71
71
|
|
|
72
|
+
it('setActive swaps label to exit text and back', () => {
|
|
73
|
+
const { shadow, tab, messages } = setupTab()
|
|
74
|
+
const btn = shadow.root.querySelector<HTMLButtonElement>('.mtb-tab')!
|
|
75
|
+
|
|
76
|
+
tab.setActive(true)
|
|
77
|
+
expect(btn.textContent).toBe(messages.toolbar.exit)
|
|
78
|
+
expect(btn.getAttribute('aria-label')).toBe(messages.toolbar.exit)
|
|
79
|
+
|
|
80
|
+
tab.setActive(false)
|
|
81
|
+
expect(btn.textContent).toBe(messages.tab)
|
|
82
|
+
|
|
83
|
+
tab.destroy()
|
|
84
|
+
shadow.destroy()
|
|
85
|
+
})
|
|
86
|
+
|
|
72
87
|
it('destroy removes element from shadow root', () => {
|
|
73
88
|
const { shadow, tab } = setupTab()
|
|
74
89
|
|
package/src/widget/tab.ts
CHANGED
|
@@ -4,6 +4,8 @@ import type { I18nMessages } from '../i18n'
|
|
|
4
4
|
export class FeedbackTab {
|
|
5
5
|
private el: HTMLButtonElement
|
|
6
6
|
private onClick: () => void
|
|
7
|
+
private idleLabel: string
|
|
8
|
+
private activeLabel: string
|
|
7
9
|
|
|
8
10
|
constructor(
|
|
9
11
|
shadow: ShadowContainer,
|
|
@@ -15,15 +17,21 @@ export class FeedbackTab {
|
|
|
15
17
|
this.onClick = onClick
|
|
16
18
|
this.el = shadow.el<HTMLButtonElement>('button', 'mtb-tab')
|
|
17
19
|
if (position === 'left') this.el.classList.add('left')
|
|
18
|
-
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
20
|
+
this.idleLabel = customText ?? messages.tab
|
|
21
|
+
this.activeLabel = messages.toolbar.exit
|
|
22
|
+
this.setLabel(this.idleLabel)
|
|
21
23
|
this.el.addEventListener('click', onClick)
|
|
22
24
|
shadow.append(this.el)
|
|
23
25
|
}
|
|
24
26
|
|
|
27
|
+
private setLabel(label: string): void {
|
|
28
|
+
this.el.textContent = label
|
|
29
|
+
this.el.setAttribute('aria-label', label)
|
|
30
|
+
}
|
|
31
|
+
|
|
25
32
|
setActive(active: boolean): void {
|
|
26
33
|
this.el.classList.toggle('active', active)
|
|
34
|
+
this.setLabel(active ? this.activeLabel : this.idleLabel)
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
destroy(): void {
|