@classic-homes/feedback-svelte 0.1.1 → 0.2.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/README.md +53 -0
- package/dist/lib/FeedbackDialog.svelte +11 -2
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @classic-homes/feedback-svelte
|
|
2
|
+
|
|
3
|
+
Svelte 5 feedback widget for chapi: an edge tab, selection comments, and screenshots. It renders the same markup as `@classic-homes/feedback-react`.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @classic-homes/feedback-svelte svelte
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Peer dependency: `svelte@^5.0.0`.
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```svelte
|
|
16
|
+
<script lang="ts">
|
|
17
|
+
import '@classic-homes/feedback-core/styles.css';
|
|
18
|
+
import { FeedbackWidget, openFeedback } from '@classic-homes/feedback-svelte';
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<FeedbackWidget apiBase="https://chapi.example.com" source="app" />
|
|
22
|
+
|
|
23
|
+
<button onclick={() => openFeedback()}>Send feedback</button>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or import the stylesheet once in a global CSS file with `@import '@classic-homes/feedback-core/styles.css';`.
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```svelte
|
|
31
|
+
<FeedbackWidget
|
|
32
|
+
apiBase="https://chapi.example.com"
|
|
33
|
+
source="app"
|
|
34
|
+
selection={{ container: '.article' }}
|
|
35
|
+
maxAttachments={3}
|
|
36
|
+
user={{ name: 'Pat Example', email: 'pat@example.com' }}
|
|
37
|
+
getContext={() => ({ route: window.location.pathname })}
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
<button onclick={() => openFeedback({ context: { card: 'schedule', error: 'E_TIMEOUT' } })}>
|
|
41
|
+
Report a problem
|
|
42
|
+
</button>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Key props (from `FeedbackConfig`): `apiBase` and `source` (required), `getToken`, `user`, `turnstileSiteKey`, `selection`, `categories`, `getContext`, `trigger` (`'tab'` or `'none'`), `tabLabel`, `maxAttachments` (default 1, max 3), `allowScreenshotCapture`, `submit`, `onSubmitted`.
|
|
46
|
+
|
|
47
|
+
## Exports
|
|
48
|
+
|
|
49
|
+
- **Component**: `FeedbackWidget`
|
|
50
|
+
- **State**: `feedbackState` (reactive widget state)
|
|
51
|
+
- **Functions**: `openFeedback`, `closeFeedback`, `submitFeedback`, `isFeedbackError`
|
|
52
|
+
- **Classes and constants**: `FeedbackError`, `DEFAULT_CATEGORIES`
|
|
53
|
+
- **Types**: `FeedbackConfig`, `FeedbackPayload`, `FeedbackCategoryOption`, `FeedbackErrorCode`, `FeedbackPageContext`, `FeedbackState`, `OpenFeedbackOptions`, `SelectionData`, `SubmitResult`
|
|
@@ -94,6 +94,9 @@
|
|
|
94
94
|
let closing = false;
|
|
95
95
|
let pointerOnBackdrop = false;
|
|
96
96
|
let wasOpen = false;
|
|
97
|
+
// Set once this dialog instance is torn down (close + reopen remounts it by
|
|
98
|
+
// nonce). Async attachment work checks it after every await (CT-022).
|
|
99
|
+
let destroyed = false;
|
|
97
100
|
|
|
98
101
|
const done = $derived(status === 'success' || status === 'queued');
|
|
99
102
|
const dirty = $derived(!done && (comment.trim().length > 0 || attachments.length > 0));
|
|
@@ -189,6 +192,7 @@
|
|
|
189
192
|
});
|
|
190
193
|
|
|
191
194
|
onDestroy(() => {
|
|
195
|
+
destroyed = true;
|
|
192
196
|
turnstile?.remove();
|
|
193
197
|
turnstile = null;
|
|
194
198
|
for (const a of attachments) URL.revokeObjectURL(a.url);
|
|
@@ -234,9 +238,13 @@
|
|
|
234
238
|
for (const file of accepted) {
|
|
235
239
|
try {
|
|
236
240
|
const blob = await prepareImage(file);
|
|
241
|
+
// Torn down while processing: drop the blob, never mint a URL for it.
|
|
242
|
+
if (destroyed) return;
|
|
237
243
|
if (attachments.length >= options.maxAttachments) break;
|
|
244
|
+
// The URL is created only for an attachment that is actually stored.
|
|
238
245
|
attachments.push({ id: createClientId(), blob, url: URL.createObjectURL(blob) });
|
|
239
246
|
} catch (err) {
|
|
247
|
+
if (destroyed) return;
|
|
240
248
|
attachError = errorMessage(err);
|
|
241
249
|
}
|
|
242
250
|
}
|
|
@@ -255,11 +263,12 @@
|
|
|
255
263
|
attachError = null;
|
|
256
264
|
try {
|
|
257
265
|
const blob = await capturePage();
|
|
266
|
+
if (destroyed) return;
|
|
258
267
|
await addFiles([blob]);
|
|
259
268
|
} catch {
|
|
260
|
-
attachError = MESSAGES.captureFailed;
|
|
269
|
+
if (!destroyed) attachError = MESSAGES.captureFailed;
|
|
261
270
|
} finally {
|
|
262
|
-
capturing = false;
|
|
271
|
+
if (!destroyed) capturing = false;
|
|
263
272
|
}
|
|
264
273
|
}
|
|
265
274
|
|
package/package.json
CHANGED