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
|
@@ -8,7 +8,8 @@ const SVG_SEL = 'svg[class="mtb-draw-svg"]'
|
|
|
8
8
|
describe('AnnotationSession', () => {
|
|
9
9
|
let shadow: ShadowContainer
|
|
10
10
|
let session: AnnotationSession
|
|
11
|
-
let
|
|
11
|
+
let onPin: ReturnType<typeof vi.fn>
|
|
12
|
+
let onDrawStroke: ReturnType<typeof vi.fn>
|
|
12
13
|
const messages = getMessages('en')
|
|
13
14
|
|
|
14
15
|
let rafQueue: FrameRequestCallback[]
|
|
@@ -25,8 +26,17 @@ describe('AnnotationSession', () => {
|
|
|
25
26
|
|
|
26
27
|
function setup() {
|
|
27
28
|
shadow = new ShadowContainer()
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
onPin = vi.fn()
|
|
30
|
+
onDrawStroke = vi.fn()
|
|
31
|
+
session = new AnnotationSession(shadow, messages, { onPin, onDrawStroke })
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function drag(overlayEl: Element, points: number): void {
|
|
35
|
+
overlayEl.dispatchEvent(new MouseEvent('mousedown', { clientX: 0, clientY: 0, bubbles: true }))
|
|
36
|
+
for (let i = 1; i < points; i++) {
|
|
37
|
+
overlayEl.dispatchEvent(new MouseEvent('mousemove', { clientX: i * 10, clientY: i * 10, bubbles: true }))
|
|
38
|
+
}
|
|
39
|
+
overlayEl.dispatchEvent(new MouseEvent('mouseup', { clientX: (points - 1) * 10, clientY: (points - 1) * 10, bubbles: true }))
|
|
30
40
|
}
|
|
31
41
|
|
|
32
42
|
function flushFrame() {
|
|
@@ -57,15 +67,12 @@ describe('AnnotationSession', () => {
|
|
|
57
67
|
setup()
|
|
58
68
|
const overlayEl = shadow.root.querySelector('.mtb-overlay')!
|
|
59
69
|
|
|
60
|
-
overlayEl.dispatchEvent(
|
|
61
|
-
|
|
62
|
-
)
|
|
63
|
-
overlayEl.dispatchEvent(
|
|
64
|
-
new MouseEvent('mouseup', { clientX: 100, clientY: 200, bubbles: true }),
|
|
65
|
-
)
|
|
70
|
+
overlayEl.dispatchEvent(new MouseEvent('mousedown', { clientX: 100, clientY: 200, bubbles: true }))
|
|
71
|
+
overlayEl.dispatchEvent(new MouseEvent('mouseup', { clientX: 100, clientY: 200, bubbles: true }))
|
|
66
72
|
|
|
67
|
-
expect(
|
|
68
|
-
|
|
73
|
+
expect(onPin).toHaveBeenCalledOnce()
|
|
74
|
+
expect(onDrawStroke).not.toHaveBeenCalled()
|
|
75
|
+
const [annotation] = onPin.mock.calls[0]
|
|
69
76
|
expect(annotation.type).toBe('pin')
|
|
70
77
|
expect(annotation.x).toBe(100)
|
|
71
78
|
expect(annotation.y).toBe(200)
|
|
@@ -76,12 +83,8 @@ describe('AnnotationSession', () => {
|
|
|
76
83
|
setup()
|
|
77
84
|
const overlayEl = shadow.root.querySelector('.mtb-overlay')!
|
|
78
85
|
|
|
79
|
-
overlayEl.dispatchEvent(
|
|
80
|
-
|
|
81
|
-
)
|
|
82
|
-
overlayEl.dispatchEvent(
|
|
83
|
-
new MouseEvent('mouseup', { clientX: 50, clientY: 50, bubbles: true }),
|
|
84
|
-
)
|
|
86
|
+
overlayEl.dispatchEvent(new MouseEvent('mousedown', { clientX: 50, clientY: 50, bubbles: true }))
|
|
87
|
+
overlayEl.dispatchEvent(new MouseEvent('mouseup', { clientX: 50, clientY: 50, bubbles: true }))
|
|
85
88
|
|
|
86
89
|
const pin = shadow.root.querySelector('.mtb-pin')
|
|
87
90
|
expect(pin).toBeInstanceOf(HTMLDivElement)
|
|
@@ -94,18 +97,13 @@ describe('AnnotationSession', () => {
|
|
|
94
97
|
const overlayEl = shadow.root.querySelector('.mtb-overlay')!
|
|
95
98
|
|
|
96
99
|
for (let i = 0; i < 3; i++) {
|
|
97
|
-
overlayEl.dispatchEvent(
|
|
98
|
-
|
|
99
|
-
)
|
|
100
|
-
overlayEl.dispatchEvent(
|
|
101
|
-
new MouseEvent('mouseup', { clientX: 10 * i, clientY: 10 * i, bubbles: true }),
|
|
102
|
-
)
|
|
100
|
+
overlayEl.dispatchEvent(new MouseEvent('mousedown', { clientX: 10 * i, clientY: 10 * i, bubbles: true }))
|
|
101
|
+
overlayEl.dispatchEvent(new MouseEvent('mouseup', { clientX: 10 * i, clientY: 10 * i, bubbles: true }))
|
|
103
102
|
}
|
|
104
103
|
|
|
105
104
|
const pins = shadow.root.querySelectorAll('.mtb-pin')
|
|
106
105
|
expect(pins.length).toBe(3)
|
|
107
106
|
expect(pins[0].textContent).toBe('1')
|
|
108
|
-
expect(pins[1].textContent).toBe('2')
|
|
109
107
|
expect(pins[2].textContent).toBe('3')
|
|
110
108
|
session.destroy()
|
|
111
109
|
})
|
|
@@ -117,14 +115,10 @@ describe('AnnotationSession', () => {
|
|
|
117
115
|
;(document.elementsFromPoint as ReturnType<typeof vi.fn>).mockReturnValue([btn])
|
|
118
116
|
|
|
119
117
|
const overlayEl = shadow.root.querySelector('.mtb-overlay')!
|
|
120
|
-
overlayEl.dispatchEvent(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
new MouseEvent('mouseup', { clientX: 50, clientY: 50, bubbles: true }),
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
const [annotation, targetName] = onReady.mock.calls[0]
|
|
118
|
+
overlayEl.dispatchEvent(new MouseEvent('mousedown', { clientX: 50, clientY: 50, bubbles: true }))
|
|
119
|
+
overlayEl.dispatchEvent(new MouseEvent('mouseup', { clientX: 50, clientY: 50, bubbles: true }))
|
|
120
|
+
|
|
121
|
+
const [annotation, targetName] = onPin.mock.calls[0]
|
|
128
122
|
expect(targetName).toBe('Save')
|
|
129
123
|
expect(annotation.targetName).toBe('Save')
|
|
130
124
|
session.destroy()
|
|
@@ -135,61 +129,84 @@ describe('AnnotationSession', () => {
|
|
|
135
129
|
;(document.elementsFromPoint as ReturnType<typeof vi.fn>).mockReturnValue([])
|
|
136
130
|
|
|
137
131
|
const overlayEl = shadow.root.querySelector('.mtb-overlay')!
|
|
138
|
-
overlayEl.dispatchEvent(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
new MouseEvent('mouseup', { clientX: 50, clientY: 50, bubbles: true }),
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
const [, targetName] = onReady.mock.calls[0]
|
|
132
|
+
overlayEl.dispatchEvent(new MouseEvent('mousedown', { clientX: 50, clientY: 50, bubbles: true }))
|
|
133
|
+
overlayEl.dispatchEvent(new MouseEvent('mouseup', { clientX: 50, clientY: 50, bubbles: true }))
|
|
134
|
+
|
|
135
|
+
const [, targetName] = onPin.mock.calls[0]
|
|
146
136
|
expect(targetName).toBe(messages.annotation.element)
|
|
147
137
|
session.destroy()
|
|
148
138
|
})
|
|
149
139
|
})
|
|
150
140
|
|
|
151
141
|
describe('draw annotation via drag', () => {
|
|
152
|
-
it('
|
|
142
|
+
it('commits a stroke and notifies onDrawStroke when enough points are collected', () => {
|
|
153
143
|
setup()
|
|
154
144
|
const overlayEl = shadow.root.querySelector('.mtb-overlay')!
|
|
145
|
+
drag(overlayEl, 6)
|
|
146
|
+
|
|
147
|
+
expect(onDrawStroke).toHaveBeenCalledOnce()
|
|
148
|
+
expect(onPin).not.toHaveBeenCalled()
|
|
149
|
+
expect(session.hasDrawStrokes()).toBe(true)
|
|
150
|
+
const annotation = session.getDrawAnnotation()
|
|
151
|
+
expect(annotation?.type).toBe('draw')
|
|
152
|
+
expect(annotation?.drawPath).toBeDefined()
|
|
153
|
+
session.destroy()
|
|
154
|
+
})
|
|
155
155
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
156
|
+
it('supports undo and redo of committed strokes', () => {
|
|
157
|
+
setup()
|
|
158
|
+
const overlayEl = shadow.root.querySelector('.mtb-overlay')!
|
|
159
|
+
drag(overlayEl, 6)
|
|
160
|
+
|
|
161
|
+
expect(session.canUndoDraw()).toBe(true)
|
|
162
|
+
expect(session.canRedoDraw()).toBe(false)
|
|
163
|
+
|
|
164
|
+
session.undoDraw()
|
|
165
|
+
expect(session.hasDrawStrokes()).toBe(false)
|
|
166
|
+
expect(session.canRedoDraw()).toBe(true)
|
|
167
|
+
|
|
168
|
+
session.redoDraw()
|
|
169
|
+
expect(session.hasDrawStrokes()).toBe(true)
|
|
170
|
+
session.destroy()
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
it('ignores stray short clicks once strokes exist (no pin)', () => {
|
|
174
|
+
setup()
|
|
175
|
+
const overlayEl = shadow.root.querySelector('.mtb-overlay')!
|
|
176
|
+
drag(overlayEl, 6)
|
|
177
|
+
onDrawStroke.mockClear()
|
|
178
|
+
|
|
179
|
+
overlayEl.dispatchEvent(new MouseEvent('mousedown', { clientX: 200, clientY: 200, bubbles: true }))
|
|
180
|
+
overlayEl.dispatchEvent(new MouseEvent('mouseup', { clientX: 200, clientY: 200, bubbles: true }))
|
|
181
|
+
|
|
182
|
+
expect(onPin).not.toHaveBeenCalled()
|
|
183
|
+
expect(onDrawStroke).not.toHaveBeenCalled()
|
|
184
|
+
session.destroy()
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it('clearDraw removes all committed strokes', () => {
|
|
188
|
+
setup()
|
|
189
|
+
const overlayEl = shadow.root.querySelector('.mtb-overlay')!
|
|
190
|
+
drag(overlayEl, 6)
|
|
191
|
+
session.clearDraw()
|
|
192
|
+
expect(session.hasDrawStrokes()).toBe(false)
|
|
193
|
+
expect(session.getDrawAnnotation()).toBeNull()
|
|
173
194
|
session.destroy()
|
|
174
195
|
})
|
|
175
196
|
})
|
|
176
197
|
|
|
177
198
|
describe('mouseleave', () => {
|
|
178
|
-
it('
|
|
199
|
+
it('commits an in-progress stroke when the mouse leaves the overlay', () => {
|
|
179
200
|
setup()
|
|
180
201
|
const overlayEl = shadow.root.querySelector('.mtb-overlay')!
|
|
181
202
|
|
|
182
|
-
overlayEl.dispatchEvent(
|
|
183
|
-
new MouseEvent('mousedown', { clientX: 0, clientY: 0, bubbles: true }),
|
|
184
|
-
)
|
|
203
|
+
overlayEl.dispatchEvent(new MouseEvent('mousedown', { clientX: 0, clientY: 0, bubbles: true }))
|
|
185
204
|
for (let i = 1; i <= 5; i++) {
|
|
186
|
-
overlayEl.dispatchEvent(
|
|
187
|
-
new MouseEvent('mousemove', { clientX: i * 10, clientY: i * 10, bubbles: true }),
|
|
188
|
-
)
|
|
205
|
+
overlayEl.dispatchEvent(new MouseEvent('mousemove', { clientX: i * 10, clientY: i * 10, bubbles: true }))
|
|
189
206
|
}
|
|
190
207
|
overlayEl.dispatchEvent(new MouseEvent('mouseleave', { bubbles: true }))
|
|
191
208
|
|
|
192
|
-
expect(
|
|
209
|
+
expect(onDrawStroke).toHaveBeenCalledOnce()
|
|
193
210
|
session.destroy()
|
|
194
211
|
})
|
|
195
212
|
})
|
|
@@ -200,9 +217,7 @@ describe('AnnotationSession', () => {
|
|
|
200
217
|
const overlayEl = shadow.root.querySelector('.mtb-overlay')!
|
|
201
218
|
|
|
202
219
|
for (let i = 1; i <= 5; i++) {
|
|
203
|
-
overlayEl.dispatchEvent(
|
|
204
|
-
new MouseEvent('mousemove', { clientX: i * 10, clientY: i * 10, bubbles: true }),
|
|
205
|
-
)
|
|
220
|
+
overlayEl.dispatchEvent(new MouseEvent('mousemove', { clientX: i * 10, clientY: i * 10, bubbles: true }))
|
|
206
221
|
}
|
|
207
222
|
|
|
208
223
|
expect(document.elementsFromPoint).not.toHaveBeenCalled()
|
|
@@ -219,9 +234,7 @@ describe('AnnotationSession', () => {
|
|
|
219
234
|
;(document.elementsFromPoint as ReturnType<typeof vi.fn>).mockReturnValue([btn])
|
|
220
235
|
const overlayEl = shadow.root.querySelector('.mtb-overlay')!
|
|
221
236
|
|
|
222
|
-
overlayEl.dispatchEvent(
|
|
223
|
-
new MouseEvent('mousemove', { clientX: 10, clientY: 10, bubbles: true }),
|
|
224
|
-
)
|
|
237
|
+
overlayEl.dispatchEvent(new MouseEvent('mousemove', { clientX: 10, clientY: 10, bubbles: true }))
|
|
225
238
|
flushFrame()
|
|
226
239
|
|
|
227
240
|
const highlightEl = shadow.root.querySelector<HTMLDivElement>('.mtb-highlight')!
|
|
@@ -229,37 +242,44 @@ describe('AnnotationSession', () => {
|
|
|
229
242
|
session.destroy()
|
|
230
243
|
})
|
|
231
244
|
|
|
232
|
-
it('
|
|
245
|
+
it('suppresses hover highlight while a draw session is active, resumes after clearDraw', () => {
|
|
233
246
|
setup()
|
|
234
|
-
const hostEl = document.getElementById('mtb-widget-host')!
|
|
235
247
|
const btn = document.createElement('button')
|
|
236
|
-
|
|
237
|
-
;(document.elementsFromPoint as ReturnType<typeof vi.fn>).mockReturnValue([
|
|
248
|
+
document.body.appendChild(btn)
|
|
249
|
+
;(document.elementsFromPoint as ReturnType<typeof vi.fn>).mockReturnValue([btn])
|
|
238
250
|
const overlayEl = shadow.root.querySelector('.mtb-overlay')!
|
|
251
|
+
const highlightEl = shadow.root.querySelector<HTMLDivElement>('.mtb-highlight')!
|
|
252
|
+
|
|
253
|
+
drag(overlayEl, 8)
|
|
254
|
+
overlayEl.dispatchEvent(new MouseEvent('mousemove', { clientX: 10, clientY: 10, bubbles: true }))
|
|
255
|
+
flushFrame()
|
|
256
|
+
expect(highlightEl.style.display).not.toBe('block')
|
|
239
257
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
)
|
|
243
|
-
|
|
244
|
-
new MouseEvent('mouseup', { clientX: 50, clientY: 50, bubbles: true }),
|
|
245
|
-
)
|
|
258
|
+
session.undoDraw()
|
|
259
|
+
overlayEl.dispatchEvent(new MouseEvent('mousemove', { clientX: 12, clientY: 12, bubbles: true }))
|
|
260
|
+
flushFrame()
|
|
261
|
+
expect(highlightEl.style.display).not.toBe('block')
|
|
246
262
|
|
|
247
|
-
|
|
248
|
-
|
|
263
|
+
session.clearDraw()
|
|
264
|
+
overlayEl.dispatchEvent(new MouseEvent('mousemove', { clientX: 14, clientY: 14, bubbles: true }))
|
|
265
|
+
flushFrame()
|
|
266
|
+
expect(highlightEl.style.display).toBe('block')
|
|
249
267
|
session.destroy()
|
|
250
268
|
})
|
|
251
269
|
|
|
252
|
-
it('
|
|
270
|
+
it('ignores the widget host when resolving the element under the cursor', () => {
|
|
253
271
|
setup()
|
|
254
272
|
const hostEl = document.getElementById('mtb-widget-host')!
|
|
273
|
+
const btn = document.createElement('button')
|
|
274
|
+
btn.setAttribute('aria-label', 'Save')
|
|
275
|
+
;(document.elementsFromPoint as ReturnType<typeof vi.fn>).mockReturnValue([hostEl, btn])
|
|
255
276
|
const overlayEl = shadow.root.querySelector('.mtb-overlay')!
|
|
256
277
|
|
|
257
|
-
overlayEl.dispatchEvent(
|
|
258
|
-
|
|
259
|
-
)
|
|
260
|
-
flushFrame()
|
|
278
|
+
overlayEl.dispatchEvent(new MouseEvent('mousedown', { clientX: 50, clientY: 50, bubbles: true }))
|
|
279
|
+
overlayEl.dispatchEvent(new MouseEvent('mouseup', { clientX: 50, clientY: 50, bubbles: true }))
|
|
261
280
|
|
|
262
|
-
|
|
281
|
+
const [, targetName] = onPin.mock.calls[0]
|
|
282
|
+
expect(targetName).toBe('Save')
|
|
263
283
|
session.destroy()
|
|
264
284
|
})
|
|
265
285
|
|
|
@@ -267,9 +287,7 @@ describe('AnnotationSession', () => {
|
|
|
267
287
|
setup()
|
|
268
288
|
const overlayEl = shadow.root.querySelector('.mtb-overlay')!
|
|
269
289
|
|
|
270
|
-
overlayEl.dispatchEvent(
|
|
271
|
-
new MouseEvent('mousemove', { clientX: 10, clientY: 10, bubbles: true }),
|
|
272
|
-
)
|
|
290
|
+
overlayEl.dispatchEvent(new MouseEvent('mousemove', { clientX: 10, clientY: 10, bubbles: true }))
|
|
273
291
|
overlayEl.dispatchEvent(new MouseEvent('mouseleave', { bubbles: true }))
|
|
274
292
|
flushFrame()
|
|
275
293
|
|
|
@@ -281,9 +299,7 @@ describe('AnnotationSession', () => {
|
|
|
281
299
|
setup()
|
|
282
300
|
const overlayEl = shadow.root.querySelector('.mtb-overlay')!
|
|
283
301
|
|
|
284
|
-
overlayEl.dispatchEvent(
|
|
285
|
-
new MouseEvent('mousemove', { clientX: 10, clientY: 10, bubbles: true }),
|
|
286
|
-
)
|
|
302
|
+
overlayEl.dispatchEvent(new MouseEvent('mousemove', { clientX: 10, clientY: 10, bubbles: true }))
|
|
287
303
|
session.dismissInteraction()
|
|
288
304
|
flushFrame()
|
|
289
305
|
|
package/src/annotate/session.ts
CHANGED
|
@@ -8,6 +8,11 @@ import { DrawLayer } from './draw'
|
|
|
8
8
|
|
|
9
9
|
const DRAW_MIN_POINTS = 5
|
|
10
10
|
|
|
11
|
+
interface SessionHandlers {
|
|
12
|
+
onPin: (annotation: Annotation, targetName: string) => void
|
|
13
|
+
onDrawStroke: () => void
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
export class AnnotationSession {
|
|
12
17
|
private overlay: AnnotationOverlay
|
|
13
18
|
private highlighter: ElementHighlighter
|
|
@@ -22,19 +27,17 @@ export class AnnotationSession {
|
|
|
22
27
|
constructor(
|
|
23
28
|
shadow: ShadowContainer,
|
|
24
29
|
private messages: I18nMessages,
|
|
25
|
-
private
|
|
30
|
+
private handlers: SessionHandlers,
|
|
26
31
|
) {
|
|
27
32
|
this.highlighter = new ElementHighlighter(shadow)
|
|
28
33
|
this.pinMarker = new PinMarker(shadow)
|
|
29
|
-
this.drawLayer = new DrawLayer(shadow
|
|
30
|
-
this.onReady(annotation, this.messages.annotation.drawing)
|
|
31
|
-
})
|
|
34
|
+
this.drawLayer = new DrawLayer(shadow)
|
|
32
35
|
this.overlay = new AnnotationOverlay(shadow, {
|
|
33
36
|
onMouseDown: (e) => this.handleMouseDown(e),
|
|
34
37
|
onMouseMove: (e) => this.handleMouseMove(e),
|
|
35
38
|
onMouseUp: (e) => this.handleMouseUp(e),
|
|
36
39
|
onMouseLeave: () => {
|
|
37
|
-
if (this.drawLayer.isCurrentlyDrawing()) this.
|
|
40
|
+
if (this.drawLayer.isCurrentlyDrawing()) this.finishStroke()
|
|
38
41
|
this.cancelPendingHighlight()
|
|
39
42
|
this.highlighter.hide()
|
|
40
43
|
},
|
|
@@ -64,7 +67,7 @@ export class AnnotationSession {
|
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
private updateHighlight(): void {
|
|
67
|
-
if (!this.interactionActive || this.drawLayer.isCurrentlyDrawing()) return
|
|
70
|
+
if (!this.interactionActive || this.drawLayer.isCurrentlyDrawing() || this.drawSessionActive()) return
|
|
68
71
|
const underEl = getElementUnder(this.lastMoveX, this.lastMoveY)
|
|
69
72
|
if (underEl) this.highlighter.highlight(underEl)
|
|
70
73
|
else this.highlighter.hide()
|
|
@@ -78,13 +81,23 @@ export class AnnotationSession {
|
|
|
78
81
|
|
|
79
82
|
private handleMouseUp(e: MouseEvent): void {
|
|
80
83
|
if (!this.drawLayer.isCurrentlyDrawing()) return
|
|
84
|
+
this.finishStroke(e)
|
|
85
|
+
}
|
|
81
86
|
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
// A drag past the point threshold becomes a freehand stroke and opens the
|
|
88
|
+
// draw note bar; a tap on an element becomes a pin. Stray taps while a
|
|
89
|
+
// drawing already exists are ignored so they don't hijack the draw flow.
|
|
90
|
+
private finishStroke(e?: MouseEvent): void {
|
|
91
|
+
if (this.drawLayer.getCurrentPointCount() >= DRAW_MIN_POINTS) {
|
|
92
|
+
this.drawLayer.commitStroke()
|
|
93
|
+
this.highlighter.hide()
|
|
94
|
+
this.handlers.onDrawStroke()
|
|
84
95
|
return
|
|
85
96
|
}
|
|
86
97
|
|
|
87
98
|
this.drawLayer.cancelCurrentDraw()
|
|
99
|
+
if (this.drawLayer.hasStrokes() || !e) return
|
|
100
|
+
|
|
88
101
|
const underEl = getElementUnder(e.clientX, e.clientY)
|
|
89
102
|
const targetName = underEl ? getElementName(underEl) : this.messages.annotation.element
|
|
90
103
|
const annotation: Annotation = {
|
|
@@ -96,9 +109,40 @@ export class AnnotationSession {
|
|
|
96
109
|
targetName,
|
|
97
110
|
}
|
|
98
111
|
this.pinMarker.addPin(e.clientX, e.clientY, ++this.pinCount)
|
|
99
|
-
this.drawLayer.clearAll()
|
|
100
112
|
this.highlighter.hide()
|
|
101
|
-
this.
|
|
113
|
+
this.handlers.onPin(annotation, targetName)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
undoDraw(): void {
|
|
117
|
+
this.drawLayer.undo()
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
redoDraw(): void {
|
|
121
|
+
this.drawLayer.redo()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
canUndoDraw(): boolean {
|
|
125
|
+
return this.drawLayer.canUndo()
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
canRedoDraw(): boolean {
|
|
129
|
+
return this.drawLayer.canRedo()
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
hasDrawStrokes(): boolean {
|
|
133
|
+
return this.drawLayer.hasStrokes()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private drawSessionActive(): boolean {
|
|
137
|
+
return this.drawLayer.hasStrokes() || this.drawLayer.canRedo()
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
getDrawAnnotation(): Annotation | null {
|
|
141
|
+
return this.drawLayer.getAnnotation()
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
clearDraw(): void {
|
|
145
|
+
this.drawLayer.clearAll()
|
|
102
146
|
}
|
|
103
147
|
|
|
104
148
|
dismissInteraction(): void {
|