makethisbetter 1.1.3 → 1.2.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/LICENSE +21 -62
- package/README.md +4 -4
- package/dist/context/frustration.d.ts +1 -1
- package/dist/context/frustration.d.ts.map +1 -1
- package/dist/makethisbetter.cjs.js +13 -27
- package/dist/makethisbetter.cjs.js.map +1 -1
- package/dist/makethisbetter.esm.js +218 -248
- package/dist/makethisbetter.esm.js.map +1 -1
- package/dist/makethisbetter.js +16 -30
- package/dist/makethisbetter.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/widget/controller.d.ts +0 -1
- package/dist/widget/controller.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/context/frustration.test.ts +2 -3
- package/src/context/frustration.ts +0 -1
- package/src/types.ts +1 -1
- package/src/widget/controller.ts +7 -18
- package/src/widget/pet.test.ts +34 -32
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,QAAQ,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC3B,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;IACjC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,OAAO,CAAC,EAAE,MA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M,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,cAAc,EAAE,CAAA;IAC1B,IAAI,EAAE,OAAO,CAAA;CACd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/widget/controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/widget/controller.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,oBAAoB,EAAc,MAAM,UAAU,CAAA;AAIhE,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,GAAG,CAA2B;IACtC,OAAO,CAAC,OAAO,CAAiC;IAChD,OAAO,CAAC,OAAO,CAAiC;IAChD,OAAO,CAAC,KAAK,CAA4B;IACzC,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,iBAAiB,CAAqC;IAC9D,OAAO,CAAC,SAAS,CAAW;IAC5B,OAAO,CAAC,gBAAgB,CAAuB;IAC/C,OAAO,CAAC,mBAAmB,CAAmC;IAC9D,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,IAAI,CAAe;IAC3B,OAAO,CAAC,iBAAiB,CAA0B;IACnD,OAAO,CAAC,gBAAgB,CAAgC;gBAE5C,MAAM,EAAE,oBAAoB;IAcxC,OAAO,CAAC,OAAO;IAYf,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,wBAAwB;IAKhC,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,uBAAuB;IA6B/B,OAAO,CAAC,SAAS;YAcH,YAAY;IAuC1B,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,WAAW;IAiBnB,OAAO,CAAC,OAAO;IAgBf,OAAO,IAAI,IAAI;CAWhB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "makethisbetter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Make This Better JS Widget SDK — embed user feedback collection in any website",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/makethisbetter.cjs.js",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"type": "git",
|
|
71
71
|
"url": "https://github.com/makethisbetter/makethisbetter-js.git"
|
|
72
72
|
},
|
|
73
|
-
"license": "
|
|
73
|
+
"license": "MIT"
|
|
74
74
|
}
|
|
@@ -112,15 +112,14 @@ describe('FrustrationDetector', () => {
|
|
|
112
112
|
document.body.removeChild(host)
|
|
113
113
|
})
|
|
114
114
|
|
|
115
|
-
it('does not directly emit console errors (only counts them as
|
|
115
|
+
it('does not directly emit console errors (only counts them as dead-click input)', () => {
|
|
116
116
|
makeDetector()
|
|
117
117
|
|
|
118
118
|
if (window.onerror) {
|
|
119
119
|
;(window.onerror as Function)('Test error', 'test.js', 1, 1, new Error('Test error'))
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
expect(errorEvents.length).toBe(0)
|
|
122
|
+
expect(events.length).toBe(0)
|
|
124
123
|
})
|
|
125
124
|
|
|
126
125
|
it('stops listening after stop()', () => {
|
package/src/types.ts
CHANGED
package/src/widget/controller.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ShadowContainer } from './shadow'
|
|
2
2
|
import { FeedbackTab } from './tab'
|
|
3
|
-
import { PetEntry } from './pet'
|
|
4
3
|
import { FrustrationPromptCard } from './frustration-prompt'
|
|
5
4
|
import { AnnotationToolbar } from '../annotate/toolbar'
|
|
6
5
|
import type { ToolbarMode } from '../annotate/toolbar'
|
|
@@ -24,7 +23,6 @@ export class WidgetController {
|
|
|
24
23
|
private config: MakeThisBetterConfig
|
|
25
24
|
private shadow!: ShadowContainer
|
|
26
25
|
private tab: FeedbackTab | null = null
|
|
27
|
-
private pet: PetEntry | null = null
|
|
28
26
|
private toolbar: AnnotationToolbar | null = null
|
|
29
27
|
private session: AnnotationSession | null = null
|
|
30
28
|
private popup: CommentPopup | null = null
|
|
@@ -56,17 +54,13 @@ export class WidgetController {
|
|
|
56
54
|
private buildUI(): void {
|
|
57
55
|
this.shadow = new ShadowContainer(this.config.theme ?? 'auto')
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
this.
|
|
61
|
-
|
|
62
|
-
this.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
() => this.handleTabClick(),
|
|
67
|
-
this.config.tabText,
|
|
68
|
-
)
|
|
69
|
-
}
|
|
57
|
+
this.tab = new FeedbackTab(
|
|
58
|
+
this.shadow,
|
|
59
|
+
this.messages,
|
|
60
|
+
this.config.position ?? 'right',
|
|
61
|
+
() => this.handleTabClick(),
|
|
62
|
+
this.config.tabText,
|
|
63
|
+
)
|
|
70
64
|
}
|
|
71
65
|
|
|
72
66
|
private handleTabClick(): void {
|
|
@@ -98,7 +92,6 @@ export class WidgetController {
|
|
|
98
92
|
private enterAnnotationMode(): void {
|
|
99
93
|
this.mode = 'annotating'
|
|
100
94
|
this.tab?.setActive(true)
|
|
101
|
-
this.pet?.setActive(true)
|
|
102
95
|
|
|
103
96
|
this.toolbar = new AnnotationToolbar(
|
|
104
97
|
this.shadow,
|
|
@@ -197,7 +190,6 @@ export class WidgetController {
|
|
|
197
190
|
private showClarify(feedbackId: string, projectId: string): void {
|
|
198
191
|
this.mode = 'idle'
|
|
199
192
|
this.tab?.setActive(false)
|
|
200
|
-
this.pet?.setActive(false)
|
|
201
193
|
this.clarify = new ClarifyCard(this.shadow, {
|
|
202
194
|
feedbackId,
|
|
203
195
|
apiClient: this.apiClient,
|
|
@@ -213,7 +205,6 @@ export class WidgetController {
|
|
|
213
205
|
private showSuccess(projectId: string): void {
|
|
214
206
|
this.mode = 'idle'
|
|
215
207
|
this.tab?.setActive(false)
|
|
216
|
-
this.pet?.setActive(false)
|
|
217
208
|
const baseUrl = this.config.apiUrl
|
|
218
209
|
? this.config.apiUrl.replace(/\/api\/v1\/?$/, '')
|
|
219
210
|
: 'https://makethisbetter.dev'
|
|
@@ -231,7 +222,6 @@ export class WidgetController {
|
|
|
231
222
|
private exitAll(): void {
|
|
232
223
|
this.mode = 'idle'
|
|
233
224
|
this.tab?.setActive(false)
|
|
234
|
-
this.pet?.setActive(false)
|
|
235
225
|
this.toolbar?.destroy()
|
|
236
226
|
this.toolbar = null
|
|
237
227
|
this.session?.destroy()
|
|
@@ -253,7 +243,6 @@ export class WidgetController {
|
|
|
253
243
|
this.clarify?.destroy()
|
|
254
244
|
this.success?.destroy()
|
|
255
245
|
this.tab?.destroy()
|
|
256
|
-
this.pet?.destroy()
|
|
257
246
|
this.recordingManager?.destroy()
|
|
258
247
|
this.shadow.destroy()
|
|
259
248
|
}
|
package/src/widget/pet.test.ts
CHANGED
|
@@ -1,56 +1,58 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { PetEntry } from './pet'
|
|
3
|
+
import { ShadowContainer } from './shadow'
|
|
4
|
+
import { getMessages } from '../i18n'
|
|
2
5
|
import { MakeThisBetter } from '../index'
|
|
3
6
|
|
|
4
7
|
vi.mock('html-to-image', () => ({
|
|
5
8
|
toPng: vi.fn(async () => 'data:image/png;base64,AA=='),
|
|
6
9
|
}))
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
// PetEntry is kept in the repo for the phase-2 pet mode but is not wired into
|
|
12
|
+
// the widget build, so it is unit-tested directly instead of via init().
|
|
13
|
+
describe('PetEntry', () => {
|
|
14
|
+
let shadow: ShadowContainer
|
|
15
|
+
|
|
9
16
|
afterEach(() => {
|
|
10
|
-
|
|
11
|
-
vi.restoreAllMocks()
|
|
17
|
+
shadow?.destroy()
|
|
12
18
|
document.body.innerHTML = ''
|
|
13
19
|
})
|
|
14
20
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
apiUrl: 'https://api.example.com/api/v1',
|
|
20
|
-
})
|
|
21
|
+
function makePet(onClick: () => void = () => {}) {
|
|
22
|
+
shadow = new ShadowContainer('light')
|
|
23
|
+
return new PetEntry(shadow, getMessages('en'), onClick)
|
|
24
|
+
}
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})
|
|
26
|
+
function shadowRoot() {
|
|
27
|
+
return document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
28
|
+
}
|
|
26
29
|
|
|
27
|
-
it('
|
|
28
|
-
|
|
29
|
-
projectKey: 'proj_test',
|
|
30
|
-
entryMode: 'pet',
|
|
31
|
-
apiUrl: 'https://api.example.com/api/v1',
|
|
32
|
-
})
|
|
30
|
+
it('renders the pet element with a speech bubble', () => {
|
|
31
|
+
makePet()
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
const bubble =
|
|
33
|
+
expect(shadowRoot().querySelector('.mtb-pet')).toBeTruthy()
|
|
34
|
+
const bubble = shadowRoot().querySelector('.mtb-pet-bubble')
|
|
36
35
|
expect(bubble).toBeTruthy()
|
|
37
36
|
expect(bubble!.textContent).toBe('Need help?')
|
|
38
37
|
})
|
|
39
38
|
|
|
40
|
-
it('
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
entryMode: 'pet',
|
|
44
|
-
apiUrl: 'https://api.example.com/api/v1',
|
|
45
|
-
})
|
|
39
|
+
it('invokes the click callback on click', () => {
|
|
40
|
+
const onClick = vi.fn()
|
|
41
|
+
makePet(onClick)
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
shadowRoot().querySelector<HTMLDivElement>('.mtb-pet')!.click()
|
|
44
|
+
expect(onClick).toHaveBeenCalledOnce()
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
describe('Widget entry', () => {
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
MakeThisBetter.destroy()
|
|
51
|
+
vi.restoreAllMocks()
|
|
52
|
+
document.body.innerHTML = ''
|
|
51
53
|
})
|
|
52
54
|
|
|
53
|
-
it('renders tab
|
|
55
|
+
it('renders the tab entry and never the pet', () => {
|
|
54
56
|
MakeThisBetter.init({
|
|
55
57
|
projectKey: 'proj_test',
|
|
56
58
|
apiUrl: 'https://api.example.com/api/v1',
|