@stefan.inc/feedback-engine 1.10.0 → 1.11.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 +2 -1
- package/package.json +1 -1
- package/src/core/taskTitle.ts +17 -11
- package/src/dom/procrastimatePopup.ts +72 -3
- package/src/editor/Editor.svelte +33 -24
package/README.md
CHANGED
|
@@ -245,6 +245,7 @@ Choosing **ProcrastiMate** opens a popup on `https://procrastimate.stf.lol/feedb
|
|
|
245
245
|
- `space` names another user's ProcrastiMate user id when two spaces share the same project name; leave it out to match across the signed-in user's own and edit-shared projects.
|
|
246
246
|
- `app` points at another ProcrastiMate origin if you self-host or run locally.
|
|
247
247
|
- Each project in the picker has a ↗ link to its page in ProcrastiMate (`/projects/<id>`), which opens in a new tab.
|
|
248
|
+
- The task's name starts as the screen's name, `Feedback`, and the item count, such as `Groceries Feedback: 3 changes`. Left as it is, ProcrastiMate's server summarizes the items about a second after the post and renames the task, such as `3 Groceries Feedback: bigger titles, remove the share button`. A name typed in the popup is kept.
|
|
248
249
|
|
|
249
250
|
## How capture works
|
|
250
251
|
|
|
@@ -262,7 +263,7 @@ Choosing **ProcrastiMate** opens a popup on `https://procrastimate.stf.lol/feedb
|
|
|
262
263
|
- A minified production build shows a class's minified name in component data, such as `a(count: 2)`.
|
|
263
264
|
- Element locations for untagged content exist only in development builds, unless a React app turns on `elementSources`. Components keep theirs in every build.
|
|
264
265
|
- React: a capture reads fields that are internal to React, the ones React's own developer tools read. If React renames them, components found without a tag are missing, and tagged regions and elements still appear. Bundlers other than Vite and Next.js are not supported.
|
|
265
|
-
- A shake does not trigger Feedback on phones, where a three-finger hold, `button: true`, or `countdown()` from a menu stands in for it
|
|
266
|
+
- A shake does not trigger Feedback on phones, where a three-finger hold, `button: true`, or `countdown()` from a menu stands in for it. [spec/features.md](https://github.com/smirea/feedback-engine/blob/master/spec/features.md) lists it as planned.
|
|
266
267
|
|
|
267
268
|
## Drive it from a script
|
|
268
269
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stefan.inc/feedback-engine",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "In-app feedback for Svelte and React: point at a component, write what should change, and export its name, file:line, and data for an agent.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accessibility",
|
package/src/core/taskTitle.ts
CHANGED
|
@@ -1,31 +1,37 @@
|
|
|
1
1
|
import type { FeedbackItem } from './annotations.ts';
|
|
2
2
|
import { title, type Capture } from './model.ts';
|
|
3
3
|
|
|
4
|
+
/** @deprecated ProcrastiMate's server names the task now, from `suggestion`. Removed in the next major version. */
|
|
4
5
|
export const taskTitleInstructions =
|
|
5
6
|
'You name tasks for a developer. Given feedback items about an app screen, reply with one lowercase phrase of at ' +
|
|
6
7
|
'most 8 words that covers every item, such as "bigger titles, remove the share button". No quotes, no trailing ' +
|
|
7
8
|
'period, no preamble.';
|
|
8
9
|
|
|
9
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* A ProcrastiMate task's name, `<screen> Feedback: N changes`, and the `suggestion` a post carries while the name is
|
|
12
|
+
* untouched, from which ProcrastiMate's server renames the task `N <screen> Feedback: <summary>`.
|
|
13
|
+
*/
|
|
10
14
|
export function taskTitle(capture: Capture, items: FeedbackItem[]) {
|
|
11
15
|
const subject = [capture.screenName ?? capture.environment.find(entry => entry.name === 'App')?.value, 'Feedback']
|
|
12
16
|
.filter(Boolean)
|
|
13
17
|
.join(' ');
|
|
14
18
|
const count = items.length;
|
|
19
|
+
const prompt = items
|
|
20
|
+
.map(
|
|
21
|
+
item =>
|
|
22
|
+
`- On ${title(capture.nodes[item.target]!)}: ${item.text
|
|
23
|
+
.split(/[\r\n]+/)
|
|
24
|
+
.filter(Boolean)
|
|
25
|
+
.join(' ')}`,
|
|
26
|
+
)
|
|
27
|
+
.join('\n');
|
|
15
28
|
return {
|
|
16
29
|
subject,
|
|
17
30
|
count,
|
|
18
|
-
prompt
|
|
19
|
-
.map(
|
|
20
|
-
item =>
|
|
21
|
-
`- On ${title(capture.nodes[item.target]!)}: ${item.text
|
|
22
|
-
.split(/[\r\n]+/)
|
|
23
|
-
.filter(Boolean)
|
|
24
|
-
.join(' ')}`,
|
|
25
|
-
)
|
|
26
|
-
.join('\n'),
|
|
31
|
+
prompt,
|
|
27
32
|
placeholder: `${subject}: ${count} ${count === 1 ? 'change' : 'changes'}`,
|
|
28
|
-
|
|
33
|
+
suggestion: { subject, count, prompt },
|
|
34
|
+
/** @deprecated ProcrastiMate's server summarizes now. Removed in the next major version. */
|
|
29
35
|
summarized(reply: string) {
|
|
30
36
|
const line = reply.split(/[\r\n]+/).find(Boolean) ?? '';
|
|
31
37
|
const summary = line.replace(/^[\s"'“”‘’`*]+|[\s"'“”‘’`*]+$/g, '').replace(/^[.\s]+|[.\s]+$/g, '');
|
|
@@ -54,11 +54,71 @@ export function parsePopupReply(
|
|
|
54
54
|
function popupFeatures() {
|
|
55
55
|
const width = 460;
|
|
56
56
|
const height = 680;
|
|
57
|
-
const
|
|
58
|
-
const
|
|
57
|
+
const scr = window.screen as { availLeft?: number; availTop?: number };
|
|
58
|
+
const rawLeft = Math.round((window.screenX ?? 0) + (window.outerWidth - width) / 2);
|
|
59
|
+
const rawTop = Math.round((window.screenY ?? 0) + (window.outerHeight - height) / 2);
|
|
60
|
+
const left = scr.availLeft === undefined ? rawLeft : Math.max(scr.availLeft, rawLeft);
|
|
61
|
+
const top = scr.availTop === undefined ? rawTop : Math.max(scr.availTop, rawTop);
|
|
59
62
|
return `popup,width=${width},height=${height},left=${left},top=${top}`;
|
|
60
63
|
}
|
|
61
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Distinguishes a real browser WindowProxy from `null`, an already-closed window, or a plain JS stub returned by a
|
|
67
|
+
* popup-blocker extension (which sets `location.href` synchronously and leaves `closed: false` forever).
|
|
68
|
+
*/
|
|
69
|
+
export function isRealPopup(popup: unknown, expectedOrigin: string, currentOrigin: string): popup is Window {
|
|
70
|
+
if (!popup || (typeof popup !== 'object' && typeof popup !== 'function')) return false;
|
|
71
|
+
const candidate = popup as Window;
|
|
72
|
+
try {
|
|
73
|
+
if (candidate.closed) return false;
|
|
74
|
+
} catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
let href: string;
|
|
78
|
+
try {
|
|
79
|
+
href = candidate.location.href;
|
|
80
|
+
} catch {
|
|
81
|
+
// Reading `location.href` threw a cross-origin SecurityError: only a real browser WindowProxy enforces that.
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
if (Object.prototype.toString.call(candidate) !== '[object Window]') return false;
|
|
85
|
+
if (expectedOrigin !== currentOrigin && typeof href === 'string' && href.startsWith(expectedOrigin)) return false;
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Runs `action` on the shadow host's light-DOM click bubble when the click originated inside a shadow root.
|
|
91
|
+
* Per the DOM spec, browsers clear `window.event` while an event dispatches inside a shadow tree, which causes popup
|
|
92
|
+
* blockers that inspect `window.event.currentTarget` (such as Poper Blocker) to treat a real button click as having no
|
|
93
|
+
* user interaction. Waiting one synchronous propagation step onto `root.host` restores `window.event` within the same
|
|
94
|
+
* click gesture.
|
|
95
|
+
*/
|
|
96
|
+
export function runOnLightClick(event: MouseEvent | undefined, action: () => void) {
|
|
97
|
+
if (!event || !event.bubbles || !event.composed || event.cancelBubble) {
|
|
98
|
+
action();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const path = event.composedPath();
|
|
102
|
+
const root = (path[0] as Node | undefined)?.getRootNode?.();
|
|
103
|
+
if (!(root instanceof ShadowRoot) || !path.includes(root.host)) {
|
|
104
|
+
action();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
let ran = false;
|
|
108
|
+
const host = root.host;
|
|
109
|
+
const onHostClick = (bubbled: Event) => {
|
|
110
|
+
if (bubbled !== event || ran) return;
|
|
111
|
+
ran = true;
|
|
112
|
+
host.removeEventListener(event.type, onHostClick);
|
|
113
|
+
action();
|
|
114
|
+
};
|
|
115
|
+
host.addEventListener(event.type, onHostClick);
|
|
116
|
+
// Macrotask, not microtask: browsers drain microtasks between each listener in an event's bubble path.
|
|
117
|
+
setTimeout(() => {
|
|
118
|
+
if (!ran) host.removeEventListener(event.type, onHostClick);
|
|
119
|
+
}, 0);
|
|
120
|
+
}
|
|
121
|
+
|
|
62
122
|
/**
|
|
63
123
|
* Opens ProcrastiMate's `/feedback` popup synchronously (so the browser's click gesture allows `window.open`) while
|
|
64
124
|
* encoding the screenshot in parallel, then hands over the draft over `postMessage` once the popup signals ready.
|
|
@@ -67,6 +127,7 @@ function popupFeatures() {
|
|
|
67
127
|
export function openProcrastimatePopup({
|
|
68
128
|
config,
|
|
69
129
|
title,
|
|
130
|
+
titleSuggestion,
|
|
70
131
|
app,
|
|
71
132
|
screen,
|
|
72
133
|
annotations,
|
|
@@ -77,6 +138,8 @@ export function openProcrastimatePopup({
|
|
|
77
138
|
}: {
|
|
78
139
|
config: ProcrastimateConfig;
|
|
79
140
|
title: string;
|
|
141
|
+
/** What ProcrastiMate names the task from, if the popup keeps `title`. */
|
|
142
|
+
titleSuggestion: { subject: string; count: number; prompt: string };
|
|
80
143
|
app?: string;
|
|
81
144
|
screen: Screen;
|
|
82
145
|
annotations: Annotations;
|
|
@@ -102,7 +165,7 @@ export function openProcrastimatePopup({
|
|
|
102
165
|
}
|
|
103
166
|
|
|
104
167
|
const popup = window.open(url, 'feedback-procrastimate', popupFeatures());
|
|
105
|
-
if (!popup) {
|
|
168
|
+
if (!isRealPopup(popup, expectedOrigin, location.origin)) {
|
|
106
169
|
onerror(
|
|
107
170
|
new Problem('The browser blocked ProcrastiMate’s window. Allow pop-ups for this site and try again.', [
|
|
108
171
|
{ label: 'URL', value: url },
|
|
@@ -111,6 +174,11 @@ export function openProcrastimatePopup({
|
|
|
111
174
|
);
|
|
112
175
|
return { cancel() {} };
|
|
113
176
|
}
|
|
177
|
+
try {
|
|
178
|
+
popup.focus();
|
|
179
|
+
} catch {
|
|
180
|
+
// Some browsers restrict focusing a popup window.
|
|
181
|
+
}
|
|
114
182
|
|
|
115
183
|
// Render synchronously before any await; encode JPEGs while the popup loads.
|
|
116
184
|
let prepared: Promise<{ full: Blob; thumb: Blob; width: number; height: number }>;
|
|
@@ -148,6 +216,7 @@ export function openProcrastimatePopup({
|
|
|
148
216
|
type: FEEDBACK_DRAFT,
|
|
149
217
|
nonce,
|
|
150
218
|
title,
|
|
219
|
+
titleSuggestion,
|
|
151
220
|
app,
|
|
152
221
|
project: config.project,
|
|
153
222
|
projects: config.projects,
|
package/src/editor/Editor.svelte
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
type SavedWebhook,
|
|
16
16
|
} from '../core/index.ts';
|
|
17
17
|
import type { Screen } from '../dom/capture.ts';
|
|
18
|
-
import { openProcrastimatePopup } from '../dom/procrastimatePopup.ts';
|
|
18
|
+
import { openProcrastimatePopup, runOnLightClick } from '../dom/procrastimatePopup.ts';
|
|
19
19
|
import {
|
|
20
20
|
buildExport,
|
|
21
21
|
canShare,
|
|
@@ -278,32 +278,41 @@
|
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
function send(destination: Destination) {
|
|
281
|
+
function send(destination: Destination, event?: MouseEvent) {
|
|
282
282
|
showsShare = false;
|
|
283
283
|
if (destination.kind === 'procrastimate') {
|
|
284
284
|
const config = engine.options.procrastimate;
|
|
285
285
|
if (!config) return;
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
session.
|
|
299
|
-
|
|
286
|
+
runOnLightClick(event, () => {
|
|
287
|
+
popup.cancel();
|
|
288
|
+
const items = [...session.items];
|
|
289
|
+
const names = taskTitle(session.capture, items);
|
|
290
|
+
try {
|
|
291
|
+
popup = openProcrastimatePopup({
|
|
292
|
+
config,
|
|
293
|
+
title: names.placeholder,
|
|
294
|
+
titleSuggestion: names.suggestion,
|
|
295
|
+
app: engine.options.app ?? (document.title.trim() || undefined),
|
|
296
|
+
screen,
|
|
297
|
+
annotations: session.annotations,
|
|
298
|
+
report: session.compactJSON,
|
|
299
|
+
onposted: ({ destination: where, url }) => {
|
|
300
|
+
act(() => {
|
|
301
|
+
session.markShared(items);
|
|
302
|
+
session.toast = { text: `Added to ${where} in ProcrastiMate`, link: url };
|
|
303
|
+
});
|
|
304
|
+
},
|
|
305
|
+
onerror: problem => {
|
|
306
|
+
act(() => {
|
|
307
|
+
session.toast = { text: 'Couldn’t open ProcrastiMate', problem };
|
|
308
|
+
});
|
|
309
|
+
},
|
|
300
310
|
});
|
|
301
|
-
}
|
|
302
|
-
onerror: problem => {
|
|
311
|
+
} catch (error) {
|
|
303
312
|
act(() => {
|
|
304
|
-
session.toast = { text: 'Couldn’t open ProcrastiMate', problem };
|
|
313
|
+
session.toast = { text: 'Couldn’t open ProcrastiMate', problem: Problem.from(error) };
|
|
305
314
|
});
|
|
306
|
-
}
|
|
315
|
+
}
|
|
307
316
|
});
|
|
308
317
|
} else if (destination.kind === 'saved') edit(destination.saved);
|
|
309
318
|
else posting = destination.delivery;
|
|
@@ -407,7 +416,7 @@
|
|
|
407
416
|
<button type="button" role="menuitem" onclick={() => void choose(format as ExportFormat)}>{name}</button>
|
|
408
417
|
{/each}
|
|
409
418
|
{#each targets as destination, index (index)}
|
|
410
|
-
<button type="button" role="menuitem" class="destination" onclick={
|
|
419
|
+
<button type="button" role="menuitem" class="destination" onclick={event => send(destination, event)}>
|
|
411
420
|
{#if destination.image}<img src={destination.image} alt="" />{/if}
|
|
412
421
|
{destination.name}
|
|
413
422
|
</button>
|
|
@@ -426,7 +435,7 @@
|
|
|
426
435
|
aria-label={destination.name}
|
|
427
436
|
title={destination.name}
|
|
428
437
|
disabled={!view.items.length || busy}
|
|
429
|
-
onclick={
|
|
438
|
+
onclick={event => send(destination, event)}
|
|
430
439
|
>
|
|
431
440
|
{#if destination.image}
|
|
432
441
|
<img src={destination.image} alt="" />
|
|
@@ -653,8 +662,8 @@
|
|
|
653
662
|
<button
|
|
654
663
|
type="button"
|
|
655
664
|
class:failed={problem}
|
|
656
|
-
onclick={
|
|
657
|
-
if (link) open(link, '_blank', 'noopener');
|
|
665
|
+
onclick={event => {
|
|
666
|
+
if (link) runOnLightClick(event, () => open(link, '_blank', 'noopener'));
|
|
658
667
|
if (problem) failure = { title: text, problem };
|
|
659
668
|
act(() => (session.toast = undefined));
|
|
660
669
|
}}
|