makethisbetter 1.5.3 → 1.6.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 +51 -26
- package/dist/makethisbetter.cjs.map +1 -1
- package/dist/makethisbetter.esm.js +1124 -591
- package/dist/makethisbetter.esm.js.map +1 -1
- package/dist/makethisbetter.js +50 -25
- 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 +16 -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 +2 -2
- 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 +143 -43
- package/src/popup/clarify.ts +160 -46
- 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 +335 -65
- package/src/widget/controller.ts +187 -35
- 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/dist/index.d.cts +0 -8
- package/dist/index.d.mts +0 -8
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,6 +65,8 @@ 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) {
|
|
@@ -103,25 +123,43 @@ export class WidgetController {
|
|
|
103
123
|
() => this.exitAll(),
|
|
104
124
|
(mode: ToolbarMode) => this.handleToolbarModeChange(mode),
|
|
105
125
|
)
|
|
106
|
-
this.session =
|
|
107
|
-
|
|
108
|
-
|
|
126
|
+
this.session = this.createSession()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private createSession(): AnnotationSession {
|
|
130
|
+
return new AnnotationSession(this.shadow, this.messages, {
|
|
131
|
+
onPin: (annotation, targetName) => {
|
|
132
|
+
this.currentAnnotation = annotation
|
|
133
|
+
this.via = 'pin'
|
|
134
|
+
this.showPopup(annotation.x, annotation.y, targetName)
|
|
135
|
+
},
|
|
136
|
+
onDrawStroke: () => this.handleDrawStroke(),
|
|
109
137
|
})
|
|
110
138
|
}
|
|
111
139
|
|
|
112
140
|
private handleToolbarModeChange(mode: ToolbarMode): void {
|
|
141
|
+
if (this.mode === 'clarifying') {
|
|
142
|
+
this.toolbar?.setMode(this.via === 'record' ? 'record' : 'markup')
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
|
|
113
146
|
if (mode === 'record') {
|
|
147
|
+
if (this.mode === 'recording') return
|
|
148
|
+
|
|
114
149
|
this.mode = 'recording'
|
|
150
|
+
this.currentAnnotation = null
|
|
151
|
+
this.teardownDraw()
|
|
115
152
|
this.session?.destroy()
|
|
116
153
|
this.session = null
|
|
117
154
|
this.recordingManager = new RecordingManager()
|
|
118
155
|
this.recordingManager.start(this.shadow, this.messages, () => {
|
|
119
156
|
if (!this.recordingManager) return
|
|
120
157
|
this.recordingManager.stop()
|
|
158
|
+
this.via = 'record'
|
|
121
159
|
this.showPopup(window.innerWidth / 2, window.innerHeight / 2, this.messages.record.timer_label)
|
|
122
160
|
}).catch((error) => {
|
|
123
161
|
// rrweb failed to load (network / SRI mismatch) — fall back to markup
|
|
124
|
-
console.warn('[MakeThisBetter]
|
|
162
|
+
console.warn('[MakeThisBetter] Interaction replay unavailable, falling back to markup:', error)
|
|
125
163
|
if (this.mode !== 'recording') return
|
|
126
164
|
this.toolbar?.setMode('markup')
|
|
127
165
|
this.handleToolbarModeChange('markup')
|
|
@@ -129,30 +167,84 @@ export class WidgetController {
|
|
|
129
167
|
} else {
|
|
130
168
|
this.recordingManager?.destroy()
|
|
131
169
|
this.recordingManager = null
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
this.currentAnnotation = annotation
|
|
135
|
-
this.showPopup(annotation.x, annotation.y, targetName)
|
|
136
|
-
})
|
|
137
|
-
}
|
|
170
|
+
this.teardownDraw()
|
|
171
|
+
if (!this.session) this.session = this.createSession()
|
|
138
172
|
this.mode = 'annotating'
|
|
139
173
|
}
|
|
140
174
|
}
|
|
141
175
|
|
|
176
|
+
private handleDrawStroke(): void {
|
|
177
|
+
if (this.mode !== 'drawing') {
|
|
178
|
+
this.mode = 'drawing'
|
|
179
|
+
this.drawBar = new DrawNoteBar(this.shadow, {
|
|
180
|
+
messages: this.messages,
|
|
181
|
+
onUndo: () => this.handleDrawUndoRedo('undo'),
|
|
182
|
+
onRedo: () => this.handleDrawUndoRedo('redo'),
|
|
183
|
+
onCancel: () => this.cancelDraw(),
|
|
184
|
+
onSubmit: (note) => this.handleDrawSubmit(note),
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
this.refreshDrawBar()
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private handleDrawUndoRedo(action: 'undo' | 'redo'): void {
|
|
191
|
+
if (action === 'undo') this.session?.undoDraw()
|
|
192
|
+
else this.session?.redoDraw()
|
|
193
|
+
this.refreshDrawBar()
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private refreshDrawBar(): void {
|
|
197
|
+
if (!this.session) return
|
|
198
|
+
this.drawBar?.setUndoRedo(this.session.canUndoDraw(), this.session.canRedoDraw())
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
private cancelDraw(): void {
|
|
202
|
+
this.session?.clearDraw()
|
|
203
|
+
this.teardownDraw()
|
|
204
|
+
this.mode = 'annotating'
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
private teardownDraw(): void {
|
|
208
|
+
this.drawBar?.destroy()
|
|
209
|
+
this.drawBar = null
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private handleDrawSubmit(note: string): void {
|
|
213
|
+
const annotation = this.session?.getDrawAnnotation()
|
|
214
|
+
if (!annotation) {
|
|
215
|
+
this.cancelDraw()
|
|
216
|
+
return
|
|
217
|
+
}
|
|
218
|
+
this.currentAnnotation = annotation
|
|
219
|
+
this.via = 'draw'
|
|
220
|
+
this.session?.dismissInteraction()
|
|
221
|
+
this.submittingUi = this.drawBar
|
|
222
|
+
void this.handleSubmit(note || this.messages.annotation.drawing)
|
|
223
|
+
}
|
|
224
|
+
|
|
142
225
|
private showPopup(x: number, y: number, targetName: string): void {
|
|
143
226
|
this.mode = 'popup'
|
|
144
227
|
this.lastPopupPos = { x, y }
|
|
228
|
+
this.teardownDraw()
|
|
145
229
|
this.session?.dismissInteraction()
|
|
230
|
+
this.popup?.destroy()
|
|
231
|
+
this.popup = null
|
|
232
|
+
this.dim?.destroy()
|
|
233
|
+
this.dim = null
|
|
234
|
+
this.dim = new DimOverlay(this.shadow, () => this.exitAll())
|
|
146
235
|
|
|
236
|
+
const recording = this.via === 'record' ? this.recordingManager?.getRecording() ?? undefined : undefined
|
|
147
237
|
this.popup = new CommentPopup(this.shadow, {
|
|
148
238
|
targetName,
|
|
149
239
|
x,
|
|
150
240
|
y,
|
|
151
241
|
messages: this.messages,
|
|
242
|
+
recording: recording ? { events: recording.events, duration: recording.duration } : undefined,
|
|
152
243
|
onSubmit: (description) => this.handleSubmit(description),
|
|
153
244
|
onClose: () => this.exitAll(),
|
|
154
245
|
onMyFeedback: this.buildMyFeedbackHandler(),
|
|
155
246
|
})
|
|
247
|
+
this.submittingUi = this.popup
|
|
156
248
|
}
|
|
157
249
|
|
|
158
250
|
private buildMyFeedbackHandler(): (() => void) | undefined {
|
|
@@ -168,9 +260,11 @@ export class WidgetController {
|
|
|
168
260
|
}
|
|
169
261
|
|
|
170
262
|
private async handleSubmit(description: string): Promise<void> {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
263
|
+
const ui = this.submittingUi
|
|
264
|
+
if (!ui) return
|
|
265
|
+
const submissionAttempt = ++this.submissionAttempt
|
|
266
|
+
ui.setLoading(true)
|
|
267
|
+
await waitForPaint()
|
|
174
268
|
const annotation = this.currentAnnotation
|
|
175
269
|
const recording = this.recordingManager?.getRecording() ?? undefined
|
|
176
270
|
|
|
@@ -188,51 +282,93 @@ export class WidgetController {
|
|
|
188
282
|
recording,
|
|
189
283
|
this.config.user ? undefined : getAnonId(),
|
|
190
284
|
this.config.user ? undefined : getStoredReporterEmail(),
|
|
285
|
+
this.breadcrumbCollector.getBreadcrumbs(),
|
|
191
286
|
)
|
|
192
287
|
|
|
193
288
|
try {
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
289
|
+
const submission = await this.apiClient.createSubmissionSession(payload, screenshot)
|
|
290
|
+
if (submissionAttempt !== this.submissionAttempt) {
|
|
291
|
+
await this.apiClient.abandonSubmissionSession(submission.id, submission.token).catch(() => {})
|
|
292
|
+
return
|
|
293
|
+
}
|
|
294
|
+
this.activeSubmission = submission
|
|
295
|
+
const summary = this.buildSummaryContext(description, pageContext, annotation)
|
|
296
|
+
this.teardownDraw()
|
|
197
297
|
this.popup?.destroy()
|
|
198
298
|
this.popup = null
|
|
299
|
+
this.dim?.destroy()
|
|
300
|
+
this.dim = null
|
|
199
301
|
this.session?.destroy()
|
|
200
302
|
this.session = null
|
|
201
|
-
this.toolbar?.destroy()
|
|
202
|
-
this.toolbar = null
|
|
203
303
|
this.recordingManager?.destroy()
|
|
204
304
|
this.recordingManager = null
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
this.showSuccess({ skipFollowup: true })
|
|
208
|
-
} else {
|
|
209
|
-
this.showClarify(feedback.id, this.lastPopupPos)
|
|
210
|
-
}
|
|
305
|
+
this.submittingUi = null
|
|
306
|
+
this.showClarify(submission, this.lastPopupPos, summary)
|
|
211
307
|
} catch {
|
|
212
|
-
this.
|
|
213
|
-
|
|
308
|
+
if (submissionAttempt !== this.submissionAttempt) return
|
|
309
|
+
ui.setLoading(false)
|
|
310
|
+
ui.setError(this.messages.error.submit)
|
|
214
311
|
}
|
|
215
312
|
}
|
|
216
313
|
|
|
217
|
-
private
|
|
314
|
+
private buildSummaryContext(
|
|
315
|
+
description: string,
|
|
316
|
+
pageContext: PageContext,
|
|
317
|
+
annotation: Annotation | null,
|
|
318
|
+
): ClarifySummaryContext {
|
|
319
|
+
const s = this.messages.clarify.summary
|
|
320
|
+
return {
|
|
321
|
+
originalDescription: description,
|
|
322
|
+
element: annotation?.targetName ?? this.messages.annotation.element,
|
|
323
|
+
page: pageContext.page_url,
|
|
324
|
+
browser: `${pageContext.browser} · ${pageContext.os}`,
|
|
325
|
+
captured: this.via === 'record' ? s.recording : s.screenshot,
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
private showClarify(
|
|
330
|
+
submission: SubmissionSessionResponse,
|
|
331
|
+
pos: { x: number; y: number } | null,
|
|
332
|
+
summary: ClarifySummaryContext,
|
|
333
|
+
): void {
|
|
218
334
|
// 'clarifying' keeps the tab and frustration prompt from starting a second
|
|
219
335
|
// feedback while the current one is still being clarified.
|
|
220
336
|
this.mode = 'clarifying'
|
|
221
337
|
this.tab?.setActive(true)
|
|
222
338
|
this.clarify = new ClarifyCard(this.shadow, {
|
|
223
|
-
|
|
339
|
+
submissionSessionId: submission.id,
|
|
340
|
+
submissionToken: submission.token,
|
|
224
341
|
apiClient: this.apiClient,
|
|
225
342
|
messages: this.messages,
|
|
343
|
+
summary,
|
|
226
344
|
x: pos?.x,
|
|
227
345
|
y: pos?.y,
|
|
228
|
-
|
|
229
|
-
this.clarify?.destroy()
|
|
230
|
-
this.clarify = null
|
|
231
|
-
this.showSuccess()
|
|
232
|
-
},
|
|
346
|
+
onFinalize: () => this.finalizeSubmission(),
|
|
233
347
|
})
|
|
234
348
|
}
|
|
235
349
|
|
|
350
|
+
private async finalizeSubmission(): Promise<void> {
|
|
351
|
+
const submission = this.activeSubmission
|
|
352
|
+
if (!submission) throw new Error('No active submission session')
|
|
353
|
+
const submissionAttempt = this.submissionAttempt
|
|
354
|
+
|
|
355
|
+
const feedback = await this.apiClient.finalizeSubmissionSession(submission.id, submission.token)
|
|
356
|
+
if (submissionAttempt !== this.submissionAttempt || this.activeSubmission !== submission) return
|
|
357
|
+
|
|
358
|
+
this.activeSubmission = null
|
|
359
|
+
this.lastHandoff = {
|
|
360
|
+
feedbackId: feedback.id,
|
|
361
|
+
boardUrl: feedback.board_url,
|
|
362
|
+
identityToken: feedback.identity_token,
|
|
363
|
+
}
|
|
364
|
+
if (feedback.board_url) cacheBoardUrl(feedback.board_url)
|
|
365
|
+
this.clarify?.destroy()
|
|
366
|
+
this.clarify = null
|
|
367
|
+
this.toolbar?.destroy()
|
|
368
|
+
this.toolbar = null
|
|
369
|
+
this.showSuccess({ skipFollowup: submission.ai_clarify_available === false })
|
|
370
|
+
}
|
|
371
|
+
|
|
236
372
|
private showSuccess(options?: SuccessCardOptions): void {
|
|
237
373
|
this.mode = 'idle'
|
|
238
374
|
this.tab?.setActive(false)
|
|
@@ -277,17 +413,28 @@ export class WidgetController {
|
|
|
277
413
|
}
|
|
278
414
|
|
|
279
415
|
private exitAll(): void {
|
|
416
|
+
this.submissionAttempt += 1
|
|
417
|
+
const submission = this.activeSubmission
|
|
418
|
+
this.activeSubmission = null
|
|
419
|
+
if (submission) {
|
|
420
|
+
void this.apiClient.abandonSubmissionSession(submission.id, submission.token).catch(() => {})
|
|
421
|
+
}
|
|
280
422
|
this.mode = 'idle'
|
|
423
|
+
this.via = 'pin'
|
|
281
424
|
this.tab?.setActive(false)
|
|
425
|
+
this.teardownDraw()
|
|
282
426
|
this.toolbar?.destroy()
|
|
283
427
|
this.toolbar = null
|
|
284
428
|
this.session?.destroy()
|
|
285
429
|
this.session = null
|
|
430
|
+
this.dim?.destroy()
|
|
431
|
+
this.dim = null
|
|
286
432
|
this.popup?.destroy()
|
|
287
433
|
this.popup = null
|
|
288
434
|
this.clarify?.destroy()
|
|
289
435
|
this.clarify = null
|
|
290
436
|
this.currentAnnotation = null
|
|
437
|
+
this.submittingUi = null
|
|
291
438
|
this.recordingManager?.destroy()
|
|
292
439
|
this.recordingManager = null
|
|
293
440
|
}
|
|
@@ -295,6 +442,7 @@ export class WidgetController {
|
|
|
295
442
|
destroy(): void {
|
|
296
443
|
this.exitAll()
|
|
297
444
|
this.consoleCollector.stop()
|
|
445
|
+
this.breadcrumbCollector.stop()
|
|
298
446
|
this.frustrationDetector?.stop()
|
|
299
447
|
this.dismissFrustrationPrompt()
|
|
300
448
|
this.clarify?.destroy()
|
|
@@ -304,3 +452,7 @@ export class WidgetController {
|
|
|
304
452
|
this.shadow.destroy()
|
|
305
453
|
}
|
|
306
454
|
}
|
|
455
|
+
|
|
456
|
+
function waitForPaint(): Promise<void> {
|
|
457
|
+
return new Promise<void>((r) => requestAnimationFrame(() => setTimeout(r, 0)))
|
|
458
|
+
}
|
|
@@ -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 {
|
package/dist/index.d.cts
DELETED
package/dist/index.d.mts
DELETED