@stefan.inc/feedback-engine 1.10.0 → 1.10.1
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/package.json +1 -1
- package/src/dom/procrastimatePopup.ts +68 -3
- package/src/editor/Editor.svelte +32 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stefan.inc/feedback-engine",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.1",
|
|
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",
|
|
@@ -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.
|
|
@@ -102,7 +162,7 @@ export function openProcrastimatePopup({
|
|
|
102
162
|
}
|
|
103
163
|
|
|
104
164
|
const popup = window.open(url, 'feedback-procrastimate', popupFeatures());
|
|
105
|
-
if (!popup) {
|
|
165
|
+
if (!isRealPopup(popup, expectedOrigin, location.origin)) {
|
|
106
166
|
onerror(
|
|
107
167
|
new Problem('The browser blocked ProcrastiMate’s window. Allow pop-ups for this site and try again.', [
|
|
108
168
|
{ label: 'URL', value: url },
|
|
@@ -111,6 +171,11 @@ export function openProcrastimatePopup({
|
|
|
111
171
|
);
|
|
112
172
|
return { cancel() {} };
|
|
113
173
|
}
|
|
174
|
+
try {
|
|
175
|
+
popup.focus();
|
|
176
|
+
} catch {
|
|
177
|
+
// Some browsers restrict focusing a popup window.
|
|
178
|
+
}
|
|
114
179
|
|
|
115
180
|
// Render synchronously before any await; encode JPEGs while the popup loads.
|
|
116
181
|
let prepared: Promise<{ full: Blob; thumb: Blob; width: number; height: number }>;
|
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,40 @@
|
|
|
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
|
-
|
|
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
|
+
app: engine.options.app ?? (document.title.trim() || undefined),
|
|
295
|
+
screen,
|
|
296
|
+
annotations: session.annotations,
|
|
297
|
+
report: session.compactJSON,
|
|
298
|
+
onposted: ({ destination: where, url }) => {
|
|
299
|
+
act(() => {
|
|
300
|
+
session.markShared(items);
|
|
301
|
+
session.toast = { text: `Added to ${where} in ProcrastiMate`, link: url };
|
|
302
|
+
});
|
|
303
|
+
},
|
|
304
|
+
onerror: problem => {
|
|
305
|
+
act(() => {
|
|
306
|
+
session.toast = { text: 'Couldn’t open ProcrastiMate', problem };
|
|
307
|
+
});
|
|
308
|
+
},
|
|
300
309
|
});
|
|
301
|
-
}
|
|
302
|
-
onerror: problem => {
|
|
310
|
+
} catch (error) {
|
|
303
311
|
act(() => {
|
|
304
|
-
session.toast = { text: 'Couldn’t open ProcrastiMate', problem };
|
|
312
|
+
session.toast = { text: 'Couldn’t open ProcrastiMate', problem: Problem.from(error) };
|
|
305
313
|
});
|
|
306
|
-
}
|
|
314
|
+
}
|
|
307
315
|
});
|
|
308
316
|
} else if (destination.kind === 'saved') edit(destination.saved);
|
|
309
317
|
else posting = destination.delivery;
|
|
@@ -407,7 +415,7 @@
|
|
|
407
415
|
<button type="button" role="menuitem" onclick={() => void choose(format as ExportFormat)}>{name}</button>
|
|
408
416
|
{/each}
|
|
409
417
|
{#each targets as destination, index (index)}
|
|
410
|
-
<button type="button" role="menuitem" class="destination" onclick={
|
|
418
|
+
<button type="button" role="menuitem" class="destination" onclick={event => send(destination, event)}>
|
|
411
419
|
{#if destination.image}<img src={destination.image} alt="" />{/if}
|
|
412
420
|
{destination.name}
|
|
413
421
|
</button>
|
|
@@ -426,7 +434,7 @@
|
|
|
426
434
|
aria-label={destination.name}
|
|
427
435
|
title={destination.name}
|
|
428
436
|
disabled={!view.items.length || busy}
|
|
429
|
-
onclick={
|
|
437
|
+
onclick={event => send(destination, event)}
|
|
430
438
|
>
|
|
431
439
|
{#if destination.image}
|
|
432
440
|
<img src={destination.image} alt="" />
|
|
@@ -653,8 +661,8 @@
|
|
|
653
661
|
<button
|
|
654
662
|
type="button"
|
|
655
663
|
class:failed={problem}
|
|
656
|
-
onclick={
|
|
657
|
-
if (link) open(link, '_blank', 'noopener');
|
|
664
|
+
onclick={event => {
|
|
665
|
+
if (link) runOnLightClick(event, () => open(link, '_blank', 'noopener'));
|
|
658
666
|
if (problem) failure = { title: text, problem };
|
|
659
667
|
act(() => (session.toast = undefined));
|
|
660
668
|
}}
|