@stefan.inc/feedback-engine 1.3.0 → 1.4.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 +1 -1
- package/package.json +1 -1
- package/src/core/index.ts +1 -0
- package/src/core/savedWebhooks.ts +118 -0
- package/src/dom/savedWebhooks.ts +18 -0
- package/src/dom/share.ts +15 -8
- package/src/dom/webhook.ts +51 -6
- package/src/editor/Editor.svelte +67 -10
- package/src/editor/ProcrastimateSheet.svelte +39 -140
- package/src/editor/Sheet.svelte +120 -0
- package/src/editor/WebhookDialog.svelte +247 -0
- package/src/editor/WebhookSheet.svelte +8 -12
- package/src/editor/destinations.ts +20 -5
package/README.md
CHANGED
|
@@ -266,7 +266,7 @@ The token is the switch. With `PROCRASTIMATE_TOKEN` set, **ProcrastiMate** shows
|
|
|
266
266
|
|
|
267
267
|
## Webhooks
|
|
268
268
|
|
|
269
|
-
A webhook is a Share entry of your own. Choosing it posts the image export and the JSON export to your server in one request, with nothing to fill in, and a toast links to whatever the server made. List any number of them when you set Feedback up:
|
|
269
|
+
A webhook is a Share entry of your own. Choosing it posts the image export and the JSON export to your server in one request, with nothing to fill in, and a toast links to whatever the server made. Someone using the page can also add one from **New Webhook**, last in the Share menu, and the browser keeps it for the site ([docs/webhooks.md](https://github.com/smirea/feedback-engine/blob/master/docs/webhooks.md#add-one-in-the-editor)). List any number of them when you set Feedback up:
|
|
270
270
|
|
|
271
271
|
```ts
|
|
272
272
|
import { githubIcon, setupFeedbackEngine } from '@stefan.inc/feedback-engine/svelte'; // or '/react'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stefan.inc/feedback-engine",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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/index.ts
CHANGED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { ContextEntry } from './model.ts';
|
|
2
|
+
|
|
3
|
+
export type Compression = 'low' | 'medium' | 'high';
|
|
4
|
+
|
|
5
|
+
/** Neither a browser's canvas nor UIKit sets a PNG's compression, so only a JPEG has a level. */
|
|
6
|
+
export type ImageEncoding = { format: 'png' } | { format: 'jpeg'; compression: Compression };
|
|
7
|
+
|
|
8
|
+
/** The JPEG quality of each level, the same on iOS. */
|
|
9
|
+
export const jpegQuality: Record<Compression, number> = { low: 0.9, medium: 0.7, high: 0.5 };
|
|
10
|
+
|
|
11
|
+
/** A webhook someone added in the editor. The device keeps it, and the Share menu lists it after the app's own. */
|
|
12
|
+
export type SavedWebhook = {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
url: string;
|
|
16
|
+
header?: { name: string; value: string };
|
|
17
|
+
image?: ImageEncoding;
|
|
18
|
+
feedback: boolean;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type WebhookDraft = {
|
|
22
|
+
name: string;
|
|
23
|
+
url: string;
|
|
24
|
+
header: string;
|
|
25
|
+
image: boolean;
|
|
26
|
+
format: ImageEncoding['format'];
|
|
27
|
+
compression: Compression;
|
|
28
|
+
feedback: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type DraftErrors = Partial<Record<'name' | 'url' | 'header', string>>;
|
|
32
|
+
|
|
33
|
+
export function draftOf(webhook?: SavedWebhook): WebhookDraft {
|
|
34
|
+
return {
|
|
35
|
+
name: webhook?.name ?? '',
|
|
36
|
+
url: webhook?.url ?? '',
|
|
37
|
+
header: webhook?.header ? `${webhook.header.name}: ${webhook.header.value}` : '',
|
|
38
|
+
image: webhook ? !!webhook.image : true,
|
|
39
|
+
format: webhook?.image?.format ?? 'png',
|
|
40
|
+
compression: webhook?.image?.format === 'jpeg' ? webhook.image.compression : 'medium',
|
|
41
|
+
feedback: webhook?.feedback ?? true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const headerPattern = /^([!#$%&'*+.^_`|~0-9A-Za-z-]+)\s*:\s*(\S.*)$/;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The webhook a draft describes, or what is wrong with it. `taken` holds the names of the Share menu's other entries,
|
|
49
|
+
* since a name is what `pinned` picks an entry by.
|
|
50
|
+
*/
|
|
51
|
+
export function readDraft(
|
|
52
|
+
draft: WebhookDraft,
|
|
53
|
+
{ id, taken }: { id: string; taken: string[] },
|
|
54
|
+
): { webhook: SavedWebhook } | { errors: DraftErrors } {
|
|
55
|
+
const errors: DraftErrors = {};
|
|
56
|
+
const name = draft.name.trim();
|
|
57
|
+
if (!name) errors.name = 'Give the webhook a name.';
|
|
58
|
+
else if (taken.some(other => other.toLowerCase() === name.toLowerCase()))
|
|
59
|
+
errors.name = `The Share menu already has ${name}.`;
|
|
60
|
+
const url = draft.url.trim();
|
|
61
|
+
if (!URL.canParse(url) || !/^https?:$/.test(new URL(url).protocol))
|
|
62
|
+
errors.url = 'Enter an address that starts with http:// or https://.';
|
|
63
|
+
const header = draft.header.trim();
|
|
64
|
+
const match = headerPattern.exec(header);
|
|
65
|
+
if (header && !match) errors.header = 'Write the header as Name: value, such as Authorization: Bearer key.';
|
|
66
|
+
if (Object.keys(errors).length) return { errors };
|
|
67
|
+
return {
|
|
68
|
+
webhook: {
|
|
69
|
+
id,
|
|
70
|
+
name,
|
|
71
|
+
url,
|
|
72
|
+
...(match ? { header: { name: match[1]!, value: match[2]!.trim() } } : {}),
|
|
73
|
+
...(draft.image
|
|
74
|
+
? {
|
|
75
|
+
image:
|
|
76
|
+
draft.format === 'jpeg'
|
|
77
|
+
? { format: 'jpeg' as const, compression: draft.compression }
|
|
78
|
+
: { format: 'png' as const },
|
|
79
|
+
}
|
|
80
|
+
: {}),
|
|
81
|
+
feedback: draft.feedback,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The saved webhooks in what the device kept. An entry it cannot read is left out, so one bad entry hides no other. */
|
|
87
|
+
export function parseSavedWebhooks(text: string | null): SavedWebhook[] {
|
|
88
|
+
let parsed: unknown;
|
|
89
|
+
try {
|
|
90
|
+
parsed = JSON.parse(text ?? '[]');
|
|
91
|
+
} catch {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
if (!Array.isArray(parsed)) return [];
|
|
95
|
+
return parsed.flatMap((entry: Partial<SavedWebhook>) => {
|
|
96
|
+
if (typeof entry?.id !== 'string' || typeof entry.feedback !== 'boolean') return [];
|
|
97
|
+
const image = entry.image;
|
|
98
|
+
const read = readDraft(
|
|
99
|
+
{
|
|
100
|
+
name: String(entry.name ?? ''),
|
|
101
|
+
url: String(entry.url ?? ''),
|
|
102
|
+
header: entry.header ? `${entry.header.name}: ${entry.header.value}` : '',
|
|
103
|
+
image: !!image,
|
|
104
|
+
format: image?.format === 'jpeg' ? 'jpeg' : 'png',
|
|
105
|
+
compression: image?.format === 'jpeg' && image.compression in jpegQuality ? image.compression : 'medium',
|
|
106
|
+
feedback: entry.feedback,
|
|
107
|
+
},
|
|
108
|
+
{ id: entry.id, taken: [] },
|
|
109
|
+
);
|
|
110
|
+
return 'webhook' in read ? [read.webhook] : [];
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The `device` part of a saved webhook's post: the environment as one object, with sorted keys as on iOS. */
|
|
115
|
+
export function deviceJSON(environment: ContextEntry[]) {
|
|
116
|
+
const sorted = environment.toSorted((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
117
|
+
return JSON.stringify(Object.fromEntries(sorted.map(entry => [entry.name, entry.value])));
|
|
118
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { parseSavedWebhooks, type SavedWebhook } from '../core/savedWebhooks.ts';
|
|
2
|
+
|
|
3
|
+
/** The page's origin keeps them, so every page of the app lists them, and another app on another origin does not. */
|
|
4
|
+
const key = 'feedback-engine.webhooks';
|
|
5
|
+
|
|
6
|
+
/** A browser that blocks storage, such as one with cookies off, lists none. */
|
|
7
|
+
export function loadSavedWebhooks(): SavedWebhook[] {
|
|
8
|
+
try {
|
|
9
|
+
return parseSavedWebhooks(localStorage.getItem(key));
|
|
10
|
+
} catch {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Throws where the browser keeps nothing, so the dialog can say so. */
|
|
16
|
+
export function storeSavedWebhooks(webhooks: SavedWebhook[]) {
|
|
17
|
+
localStorage.setItem(key, JSON.stringify(webhooks));
|
|
18
|
+
}
|
package/src/dom/share.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Annotations } from '../core/index.ts';
|
|
2
|
-
import { reportJSON } from '../core/index.ts';
|
|
1
|
+
import type { Annotations, ImageEncoding } from '../core/index.ts';
|
|
2
|
+
import { jpegQuality, reportJSON } from '../core/index.ts';
|
|
3
3
|
import type { Screen } from './capture.ts';
|
|
4
4
|
import { annotatedImage } from './image.ts';
|
|
5
5
|
import { zip } from './zip.ts';
|
|
@@ -15,16 +15,23 @@ export const exportTitles: Record<ExportFormat, string> = {
|
|
|
15
15
|
/** One export: the file to save or share, and the parts the clipboard takes. */
|
|
16
16
|
export type Export = { file: File; image?: Blob; json?: string };
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
'image/
|
|
18
|
+
export function encodeImage(screen: Screen, annotations: Annotations, encoding: ImageEncoding) {
|
|
19
|
+
const [type, name, quality] =
|
|
20
|
+
encoding.format === 'png'
|
|
21
|
+
? ['image/png', 'feedback.png', undefined]
|
|
22
|
+
: ['image/jpeg', 'feedback.jpg', jpegQuality[encoding.compression]];
|
|
23
|
+
return new Promise<File>((resolve, reject) =>
|
|
24
|
+
annotatedImage(screen, annotations).toBlob(
|
|
25
|
+
blob =>
|
|
26
|
+
blob ? resolve(new File([blob], name, { type })) : reject(new Error('The browser could not encode the image')),
|
|
27
|
+
type,
|
|
28
|
+
quality,
|
|
23
29
|
),
|
|
24
30
|
);
|
|
31
|
+
}
|
|
25
32
|
|
|
26
33
|
export async function buildExport(screen: Screen, annotations: Annotations, format: ExportFormat): Promise<Export> {
|
|
27
|
-
const image = format === 'json' ? undefined : await
|
|
34
|
+
const image = format === 'json' ? undefined : await encodeImage(screen, annotations, { format: 'png' });
|
|
28
35
|
const json = format === 'image' ? undefined : reportJSON(screen.capture, annotations);
|
|
29
36
|
if (format === 'image') return { file: new File([image!], 'feedback.png', { type: 'image/png' }), image };
|
|
30
37
|
if (format === 'json') return { file: new File([json!], 'feedback.json', { type: 'application/json' }), json };
|
package/src/dom/webhook.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import type { Annotations } from '../core/annotations.ts';
|
|
1
2
|
import { Problem } from '../core/problem.ts';
|
|
3
|
+
import { reportJSON } from '../core/report.ts';
|
|
4
|
+
import { deviceJSON, type ImageEncoding, type SavedWebhook } from '../core/savedWebhooks.ts';
|
|
5
|
+
import type { Screen } from './capture.ts';
|
|
6
|
+
import { encodeImage } from './share.ts';
|
|
2
7
|
|
|
3
8
|
/** One entry of the Share menu that posts the feedback to a server of the app's own. `docs/webhooks.md` has the request. */
|
|
4
9
|
export type Webhook = {
|
|
@@ -24,12 +29,53 @@ export type WebhookPost = {
|
|
|
24
29
|
/** Made once per post and sent again on a retry, so a server can tell a retry from a second post. */
|
|
25
30
|
id: string;
|
|
26
31
|
title: string;
|
|
27
|
-
|
|
28
|
-
image: Blob;
|
|
29
|
-
/** The JSON export. */
|
|
30
|
-
report: string;
|
|
32
|
+
files: { name: string; file: File }[];
|
|
31
33
|
};
|
|
32
34
|
|
|
35
|
+
/**
|
|
36
|
+
* What a post carries beside its `id` and `title`. An app's webhook sends the image export as PNG and the JSON export,
|
|
37
|
+
* as `image` and `report`. A saved webhook sends the image and the JSON export if it was saved with them, as `image`
|
|
38
|
+
* and `feedback`, and the environment as `device`.
|
|
39
|
+
*/
|
|
40
|
+
export type WebhookContents = { kind: 'report' } | { kind: 'saved'; image?: ImageEncoding; feedback: boolean };
|
|
41
|
+
|
|
42
|
+
/** A webhook with what its posts carry. */
|
|
43
|
+
export type Delivery = { webhook: Webhook; contents: WebhookContents };
|
|
44
|
+
|
|
45
|
+
export function savedDelivery(saved: SavedWebhook): Delivery {
|
|
46
|
+
return {
|
|
47
|
+
webhook: {
|
|
48
|
+
name: saved.name,
|
|
49
|
+
url: saved.url,
|
|
50
|
+
...(saved.header ? { headers: { [saved.header.name]: saved.header.value } } : {}),
|
|
51
|
+
},
|
|
52
|
+
contents: { kind: 'saved', image: saved.image, feedback: saved.feedback },
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const json = (name: string, text: string) => new File([text], name, { type: 'application/json' });
|
|
57
|
+
|
|
58
|
+
/** The file parts of a post, drawn from the editor's capture and annotations. */
|
|
59
|
+
export async function postFiles(
|
|
60
|
+
contents: WebhookContents,
|
|
61
|
+
screen: Screen,
|
|
62
|
+
annotations: Annotations,
|
|
63
|
+
): Promise<WebhookPost['files']> {
|
|
64
|
+
const report = () => reportJSON(screen.capture, annotations, false);
|
|
65
|
+
if (contents.kind === 'report') {
|
|
66
|
+
const image = await encodeImage(screen, annotations, { format: 'png' });
|
|
67
|
+
return [
|
|
68
|
+
{ name: 'image', file: image },
|
|
69
|
+
{ name: 'report', file: json('feedback.json', report()) },
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
return [
|
|
73
|
+
...(contents.image ? [{ name: 'image', file: await encodeImage(screen, annotations, contents.image) }] : []),
|
|
74
|
+
...(contents.feedback ? [{ name: 'feedback', file: json('feedback.json', report()) }] : []),
|
|
75
|
+
{ name: 'device', file: json('device.json', deviceJSON(screen.capture.environment)) },
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
|
|
33
79
|
/**
|
|
34
80
|
* GitHub's mark, 16 points square. The iOS package draws the same path (`GitHubIcon.swift`), which has only absolute
|
|
35
81
|
* `M`, `L`, `C`, and `Z` commands so that a few lines can read it.
|
|
@@ -65,8 +111,7 @@ export async function postWebhook(webhook: Webhook, post: WebhookPost): Promise<
|
|
|
65
111
|
const form = new FormData();
|
|
66
112
|
form.set('id', post.id);
|
|
67
113
|
form.set('title', post.title);
|
|
68
|
-
|
|
69
|
-
form.set('report', new File([post.report], 'feedback.json', { type: 'application/json' }));
|
|
114
|
+
for (const { name, file } of post.files) form.set(name, file);
|
|
70
115
|
let response: Response;
|
|
71
116
|
try {
|
|
72
117
|
response = await fetch(url, { method: 'POST', headers, body: form });
|
package/src/editor/Editor.svelte
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
tag,
|
|
11
11
|
title,
|
|
12
12
|
type Frame,
|
|
13
|
+
type SavedWebhook,
|
|
13
14
|
} from '../core/index.ts';
|
|
14
15
|
import type { Screen } from '../dom/capture.ts';
|
|
15
16
|
import {
|
|
@@ -22,10 +23,12 @@
|
|
|
22
23
|
type Export,
|
|
23
24
|
type ExportFormat,
|
|
24
25
|
} from '../dom/share.ts';
|
|
25
|
-
import
|
|
26
|
+
import { loadSavedWebhooks, storeSavedWebhooks } from '../dom/savedWebhooks.ts';
|
|
27
|
+
import { savedDelivery, type Delivery } from '../dom/webhook.ts';
|
|
26
28
|
import { destinations, pinnedDestinations, type Destination } from './destinations.ts';
|
|
27
29
|
import type { Engine } from './engine.ts';
|
|
28
30
|
import ProcrastimateSheet from './ProcrastimateSheet.svelte';
|
|
31
|
+
import WebhookDialog from './WebhookDialog.svelte';
|
|
29
32
|
import WebhookSheet from './WebhookSheet.svelte';
|
|
30
33
|
|
|
31
34
|
let { engine, screen }: { engine: Engine; screen: Screen } = $props();
|
|
@@ -89,11 +92,12 @@
|
|
|
89
92
|
let showsInfo = $state(false);
|
|
90
93
|
let showsShare = $state(false);
|
|
91
94
|
let showsProcrastimate = $state(false);
|
|
92
|
-
let posting = $state<
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
95
|
+
let posting = $state<Delivery>();
|
|
96
|
+
let saved = $state(loadSavedWebhooks());
|
|
97
|
+
/** The dialog for a saved webhook, `webhook` unset for a new one. */
|
|
98
|
+
let editing = $state<{ webhook?: SavedWebhook }>();
|
|
99
|
+
const targets = $derived(destinations({ ...engine.options, saved }));
|
|
100
|
+
const pinned = $derived(pinnedDestinations(targets, engine.options.pinned));
|
|
97
101
|
let confirmsClose = $state(false);
|
|
98
102
|
let pending = $state<{ format: ExportFormat; ready: Export }>();
|
|
99
103
|
let busy = $state(false);
|
|
@@ -202,9 +206,9 @@
|
|
|
202
206
|
}
|
|
203
207
|
|
|
204
208
|
function requestClose() {
|
|
205
|
-
if (showsInfo || showsShare || showsProcrastimate || posting || pending) {
|
|
209
|
+
if (showsInfo || showsShare || showsProcrastimate || posting || pending || editing) {
|
|
206
210
|
showsInfo = showsShare = showsProcrastimate = false;
|
|
207
|
-
posting = pending = undefined;
|
|
211
|
+
posting = pending = editing = undefined;
|
|
208
212
|
} else if (session.isTyping || session.unshared.length) {
|
|
209
213
|
confirmsClose = true;
|
|
210
214
|
} else {
|
|
@@ -215,7 +219,32 @@
|
|
|
215
219
|
function send(destination: Destination) {
|
|
216
220
|
showsShare = false;
|
|
217
221
|
if (destination.kind === 'procrastimate') showsProcrastimate = true;
|
|
218
|
-
else
|
|
222
|
+
else if (destination.kind === 'saved') edit(destination.saved);
|
|
223
|
+
else posting = destination.delivery;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function edit(webhook?: SavedWebhook) {
|
|
227
|
+
showsShare = false;
|
|
228
|
+
editing = { webhook };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Stores the list and returns why it could not, for the dialog to show. */
|
|
232
|
+
function keep(list: SavedWebhook[]) {
|
|
233
|
+
try {
|
|
234
|
+
storeSavedWebhooks(list);
|
|
235
|
+
} catch (error) {
|
|
236
|
+
return `This browser did not keep the webhook: ${(error as Error).message}`;
|
|
237
|
+
}
|
|
238
|
+
saved = list;
|
|
239
|
+
editing = undefined;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** A new webhook is only saved. An edited one is saved and the feedback goes to it, since choosing it opened the form. */
|
|
243
|
+
function submitWebhook(webhook: SavedWebhook) {
|
|
244
|
+
const isNew = !saved.some(other => other.id === webhook.id);
|
|
245
|
+
const failure = keep(isNew ? [...saved, webhook] : saved.map(other => (other.id === webhook.id ? webhook : other)));
|
|
246
|
+
if (!failure && !isNew) posting = savedDelivery(webhook);
|
|
247
|
+
return failure;
|
|
219
248
|
}
|
|
220
249
|
|
|
221
250
|
async function choose(format: ExportFormat) {
|
|
@@ -294,6 +323,10 @@
|
|
|
294
323
|
{destination.name}
|
|
295
324
|
</button>
|
|
296
325
|
{/each}
|
|
326
|
+
<button type="button" role="menuitem" class="destination" onclick={() => edit()}>
|
|
327
|
+
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M5 12h14" /></svg>
|
|
328
|
+
New Webhook
|
|
329
|
+
</button>
|
|
297
330
|
</div>
|
|
298
331
|
{/if}
|
|
299
332
|
</div>
|
|
@@ -507,11 +540,24 @@
|
|
|
507
540
|
/>
|
|
508
541
|
{/if}
|
|
509
542
|
|
|
543
|
+
{#if editing}
|
|
544
|
+
{@const webhook = editing.webhook}
|
|
545
|
+
<WebhookDialog
|
|
546
|
+
{webhook}
|
|
547
|
+
taken={targets
|
|
548
|
+
.filter(target => target.kind !== 'saved' || target.saved.id !== webhook?.id)
|
|
549
|
+
.map(target => target.name)}
|
|
550
|
+
onsubmit={submitWebhook}
|
|
551
|
+
ondelete={() => keep(saved.filter(other => other.id !== webhook?.id))}
|
|
552
|
+
onclose={() => (editing = undefined)}
|
|
553
|
+
/>
|
|
554
|
+
{/if}
|
|
555
|
+
|
|
510
556
|
{#if posting}
|
|
511
557
|
<WebhookSheet
|
|
512
558
|
{screen}
|
|
513
559
|
{session}
|
|
514
|
-
|
|
560
|
+
delivery={posting}
|
|
515
561
|
onclose={() => (posting = undefined)}
|
|
516
562
|
onposted={(items, toast) => {
|
|
517
563
|
posting = undefined;
|
|
@@ -713,6 +759,17 @@
|
|
|
713
759
|
object-fit: contain;
|
|
714
760
|
}
|
|
715
761
|
|
|
762
|
+
.popup svg {
|
|
763
|
+
flex: none;
|
|
764
|
+
width: 18px;
|
|
765
|
+
height: 18px;
|
|
766
|
+
fill: none;
|
|
767
|
+
stroke: currentColor;
|
|
768
|
+
stroke-width: 2;
|
|
769
|
+
stroke-linecap: round;
|
|
770
|
+
stroke-linejoin: round;
|
|
771
|
+
}
|
|
772
|
+
|
|
716
773
|
.body {
|
|
717
774
|
display: flex;
|
|
718
775
|
flex: 1;
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
type ProcrastimateConfig,
|
|
15
15
|
} from '../dom/procrastimate.ts';
|
|
16
16
|
import ProblemCard from './ProblemCard.svelte';
|
|
17
|
+
import Sheet from './Sheet.svelte';
|
|
17
18
|
|
|
18
19
|
let {
|
|
19
20
|
screen,
|
|
@@ -114,145 +115,53 @@
|
|
|
114
115
|
</button>
|
|
115
116
|
{/snippet}
|
|
116
117
|
|
|
117
|
-
<
|
|
118
|
-
|
|
119
|
-
class="
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
<
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
{
|
|
146
|
-
|
|
118
|
+
<Sheet label="Add to ProcrastiMate" onsubmit={() => void post()}>
|
|
119
|
+
{#snippet header()}
|
|
120
|
+
<button type="button" class="link" disabled={posting} onclick={onclose}>Cancel</button>
|
|
121
|
+
<h2>Add to ProcrastiMate</h2>
|
|
122
|
+
<button type="submit" class="link strong" disabled={posting || !name.trim()}>{posting ? 'Adding…' : 'Add'}</button>
|
|
123
|
+
{/snippet}
|
|
124
|
+
|
|
125
|
+
<div class="status" bind:this={status}>
|
|
126
|
+
{#if step}<p class="step" role="status">{step}…</p>{/if}
|
|
127
|
+
{#if postProblem}<ProblemCard problem={postProblem} />{/if}
|
|
128
|
+
{#if loadProblem}<ProblemCard problem={loadProblem} />{/if}
|
|
129
|
+
</div>
|
|
130
|
+
<label>
|
|
131
|
+
<span class="caption">Name</span>
|
|
132
|
+
<input bind:value={name} aria-label="Task name" disabled={posting} />
|
|
133
|
+
</label>
|
|
134
|
+
<span class="caption">Project{loading ? ' · loading…' : ''}</span>
|
|
135
|
+
<div class="list" role="listbox" aria-label="Project">
|
|
136
|
+
{@render row('Inbox', !place.projectId, false, () => (place = {}))}
|
|
137
|
+
{#each projects as project (project.id)}
|
|
138
|
+
{@const open = project.id === place.projectId && project.sections.length > 0}
|
|
139
|
+
{@render row(
|
|
140
|
+
project.name,
|
|
141
|
+
project.id === place.projectId && !open,
|
|
142
|
+
false,
|
|
143
|
+
() => (place = { projectId: project.id }),
|
|
144
|
+
)}
|
|
145
|
+
{#if open}
|
|
146
|
+
{@render row('No section', !place.sectionId, true, () => (place = { projectId: project.id }))}
|
|
147
|
+
{#each project.sections as section (section.id)}
|
|
147
148
|
{@render row(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
() => (place = { projectId: project.id }),
|
|
149
|
+
section.name,
|
|
150
|
+
place.sectionId === section.id,
|
|
151
|
+
true,
|
|
152
|
+
() => (place = { projectId: project.id, sectionId: section.id }),
|
|
152
153
|
)}
|
|
153
|
-
{#if open}
|
|
154
|
-
{@render row('No section', !place.sectionId, true, () => (place = { projectId: project.id }))}
|
|
155
|
-
{#each project.sections as section (section.id)}
|
|
156
|
-
{@render row(
|
|
157
|
-
section.name,
|
|
158
|
-
place.sectionId === section.id,
|
|
159
|
-
true,
|
|
160
|
-
() => (place = { projectId: project.id, sectionId: section.id }),
|
|
161
|
-
)}
|
|
162
|
-
{/each}
|
|
163
|
-
{/if}
|
|
164
154
|
{/each}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
</
|
|
168
|
-
</
|
|
155
|
+
{/if}
|
|
156
|
+
{/each}
|
|
157
|
+
</div>
|
|
158
|
+
</Sheet>
|
|
169
159
|
|
|
170
160
|
<style>
|
|
171
|
-
.scrim {
|
|
172
|
-
position: absolute;
|
|
173
|
-
inset: 0;
|
|
174
|
-
z-index: 5;
|
|
175
|
-
display: grid;
|
|
176
|
-
place-items: end center;
|
|
177
|
-
background: rgb(0 0 0 / 0.5);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
.sheet {
|
|
181
|
-
display: flex;
|
|
182
|
-
flex-direction: column;
|
|
183
|
-
width: min(100%, 480px);
|
|
184
|
-
max-height: 85%;
|
|
185
|
-
border-radius: 16px 16px 0 0;
|
|
186
|
-
box-sizing: border-box;
|
|
187
|
-
background: #1f1f1f;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
header {
|
|
191
|
-
display: flex;
|
|
192
|
-
align-items: center;
|
|
193
|
-
gap: 8px;
|
|
194
|
-
padding: 14px 16px 8px;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
h2 {
|
|
198
|
-
flex: 1;
|
|
199
|
-
margin: 0;
|
|
200
|
-
font-size: 16px;
|
|
201
|
-
text-align: center;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
button,
|
|
205
|
-
input {
|
|
206
|
-
color: inherit;
|
|
207
|
-
font: inherit;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
button {
|
|
211
|
-
border: 0;
|
|
212
|
-
background: none;
|
|
213
|
-
cursor: pointer;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
button:disabled {
|
|
217
|
-
cursor: default;
|
|
218
|
-
opacity: 0.5;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
.link {
|
|
222
|
-
color: #0a84ff;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
161
|
.strong {
|
|
226
162
|
font-weight: 600;
|
|
227
163
|
}
|
|
228
164
|
|
|
229
|
-
.scroll {
|
|
230
|
-
display: grid;
|
|
231
|
-
gap: 8px;
|
|
232
|
-
padding: 8px 16px 16px;
|
|
233
|
-
overflow: auto;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
.caption {
|
|
237
|
-
color: #aeaeb2;
|
|
238
|
-
font-size: 12px;
|
|
239
|
-
font-weight: 600;
|
|
240
|
-
text-transform: uppercase;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
label {
|
|
244
|
-
display: grid;
|
|
245
|
-
gap: 6px;
|
|
246
|
-
margin-bottom: 8px;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
input {
|
|
250
|
-
border: 0;
|
|
251
|
-
border-radius: 10px;
|
|
252
|
-
padding: 10px 12px;
|
|
253
|
-
background: #2e2e30;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
165
|
.list {
|
|
257
166
|
display: grid;
|
|
258
167
|
border-radius: 10px;
|
|
@@ -291,14 +200,4 @@
|
|
|
291
200
|
margin: 0;
|
|
292
201
|
color: #aeaeb2;
|
|
293
202
|
}
|
|
294
|
-
|
|
295
|
-
@media (min-width: 900px) {
|
|
296
|
-
.scrim {
|
|
297
|
-
place-items: center;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
.sheet {
|
|
301
|
-
border-radius: 16px;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
203
|
</style>
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
<svelte:options css="injected" />
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import type { Snippet } from 'svelte';
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
label,
|
|
8
|
+
onsubmit,
|
|
9
|
+
header,
|
|
10
|
+
children,
|
|
11
|
+
}: { label: string; onsubmit: () => void; header: Snippet; children: Snippet } = $props();
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<div class="scrim" role="presentation">
|
|
15
|
+
<form
|
|
16
|
+
class="sheet"
|
|
17
|
+
aria-label={label}
|
|
18
|
+
novalidate
|
|
19
|
+
onsubmit={event => {
|
|
20
|
+
event.preventDefault();
|
|
21
|
+
onsubmit();
|
|
22
|
+
}}
|
|
23
|
+
>
|
|
24
|
+
<header>{@render header()}</header>
|
|
25
|
+
<div class="scroll">{@render children()}</div>
|
|
26
|
+
</form>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<!-- The shared styles reach into content another component scopes, and `:where` keeps them below that component's own. -->
|
|
30
|
+
<style>
|
|
31
|
+
.scrim {
|
|
32
|
+
position: absolute;
|
|
33
|
+
inset: 0;
|
|
34
|
+
z-index: 5;
|
|
35
|
+
display: grid;
|
|
36
|
+
place-items: end center;
|
|
37
|
+
background: rgb(0 0 0 / 0.5);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.sheet {
|
|
41
|
+
display: flex;
|
|
42
|
+
flex-direction: column;
|
|
43
|
+
width: min(100%, 480px);
|
|
44
|
+
max-height: 85%;
|
|
45
|
+
border-radius: 16px 16px 0 0;
|
|
46
|
+
box-sizing: border-box;
|
|
47
|
+
background: #1f1f1f;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
header {
|
|
51
|
+
display: flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
gap: 8px;
|
|
54
|
+
padding: 14px 16px 8px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
header :global(h2) {
|
|
58
|
+
flex: 1;
|
|
59
|
+
margin: 0;
|
|
60
|
+
font-size: 16px;
|
|
61
|
+
text-align: center;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.scroll {
|
|
65
|
+
display: grid;
|
|
66
|
+
gap: 8px;
|
|
67
|
+
padding: 8px 16px 16px;
|
|
68
|
+
overflow: auto;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
:where(.sheet) :global(:is(button, input)) {
|
|
72
|
+
color: inherit;
|
|
73
|
+
font: inherit;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
:where(.sheet) :global(button) {
|
|
77
|
+
border: 0;
|
|
78
|
+
background: none;
|
|
79
|
+
cursor: pointer;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
:where(.sheet) :global(button:disabled) {
|
|
83
|
+
cursor: default;
|
|
84
|
+
opacity: 0.5;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
:where(.sheet) :global(.link) {
|
|
88
|
+
color: #0a84ff;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
:where(.sheet) :global(.caption) {
|
|
92
|
+
color: #aeaeb2;
|
|
93
|
+
font-size: 12px;
|
|
94
|
+
font-weight: 600;
|
|
95
|
+
text-transform: uppercase;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
:where(.sheet) :global(label:has(> .caption)) {
|
|
99
|
+
display: grid;
|
|
100
|
+
gap: 6px;
|
|
101
|
+
margin-bottom: 8px;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
:where(.sheet) :global(:is(input:not([type]), input[type='url'])) {
|
|
105
|
+
border: 0;
|
|
106
|
+
border-radius: 10px;
|
|
107
|
+
padding: 10px 12px;
|
|
108
|
+
background: #2e2e30;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@media (min-width: 900px) {
|
|
112
|
+
.scrim {
|
|
113
|
+
place-items: center;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.sheet {
|
|
117
|
+
border-radius: 16px;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
</style>
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
<svelte:options css="injected" />
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import {
|
|
5
|
+
draftOf,
|
|
6
|
+
readDraft,
|
|
7
|
+
type Compression,
|
|
8
|
+
type DraftErrors,
|
|
9
|
+
type SavedWebhook,
|
|
10
|
+
type WebhookDraft,
|
|
11
|
+
} from '../core/index.ts';
|
|
12
|
+
import { postId } from '../dom/webhook.ts';
|
|
13
|
+
import Sheet from './Sheet.svelte';
|
|
14
|
+
|
|
15
|
+
let {
|
|
16
|
+
webhook,
|
|
17
|
+
taken,
|
|
18
|
+
onsubmit,
|
|
19
|
+
ondelete,
|
|
20
|
+
onclose,
|
|
21
|
+
}: {
|
|
22
|
+
/** The webhook to edit, or none for a new one. */
|
|
23
|
+
webhook?: SavedWebhook;
|
|
24
|
+
/** The names of the Share menu's other entries. */
|
|
25
|
+
taken: string[];
|
|
26
|
+
/** Saves a new webhook, or saves an edited one and sends the feedback to it. Returns why it could not save. */
|
|
27
|
+
onsubmit: (webhook: SavedWebhook) => string | undefined;
|
|
28
|
+
ondelete: () => string | undefined;
|
|
29
|
+
onclose: () => void;
|
|
30
|
+
} = $props();
|
|
31
|
+
|
|
32
|
+
// The editor makes a new dialog each time it opens one, so the first value is the only one.
|
|
33
|
+
// svelte-ignore state_referenced_locally
|
|
34
|
+
let draft = $state<WebhookDraft>(draftOf(webhook));
|
|
35
|
+
let errors = $state<DraftErrors>({});
|
|
36
|
+
let failure = $state<string>();
|
|
37
|
+
// svelte-ignore state_referenced_locally
|
|
38
|
+
const id = webhook?.id ?? postId();
|
|
39
|
+
const compressions: Compression[] = ['low', 'medium', 'high'];
|
|
40
|
+
const list = new Intl.ListFormat('en', { type: 'conjunction' });
|
|
41
|
+
|
|
42
|
+
function submit() {
|
|
43
|
+
const read = readDraft(draft, { id, taken });
|
|
44
|
+
errors = 'errors' in read ? read.errors : {};
|
|
45
|
+
if ('webhook' in read) failure = onsubmit(read.webhook);
|
|
46
|
+
}
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
{#snippet field(key: keyof DraftErrors, caption: string, placeholder: string, type?: 'url')}
|
|
50
|
+
<label>
|
|
51
|
+
<span class="caption">{caption}</span>
|
|
52
|
+
<input
|
|
53
|
+
bind:value={draft[key]}
|
|
54
|
+
{type}
|
|
55
|
+
{placeholder}
|
|
56
|
+
autocapitalize={key === 'name' ? undefined : 'off'}
|
|
57
|
+
autocomplete="off"
|
|
58
|
+
spellcheck={key === 'name'}
|
|
59
|
+
aria-invalid={!!errors[key]}
|
|
60
|
+
aria-describedby={errors[key] ? `webhook-${key}-error` : undefined}
|
|
61
|
+
/>
|
|
62
|
+
{#if errors[key]}<span class="error" id="webhook-{key}-error">{errors[key]}</span>{/if}
|
|
63
|
+
</label>
|
|
64
|
+
{/snippet}
|
|
65
|
+
|
|
66
|
+
{#snippet segments(name: string, options: [string, string][], value: string, pick: (value: string) => void)}
|
|
67
|
+
<div class="choice" role="radiogroup" aria-label={name}>
|
|
68
|
+
<span>{name}</span>
|
|
69
|
+
<div class="segments">
|
|
70
|
+
{#each options as [option, label] (option)}
|
|
71
|
+
<label class:picked={value === option}>
|
|
72
|
+
<input type="radio" {name} value={option} checked={value === option} onchange={() => pick(option)} />{label}
|
|
73
|
+
</label>
|
|
74
|
+
{/each}
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
{/snippet}
|
|
78
|
+
|
|
79
|
+
<Sheet label={webhook ? 'Edit Webhook' : 'New Webhook'} onsubmit={submit}>
|
|
80
|
+
{#snippet header()}
|
|
81
|
+
{#if webhook}
|
|
82
|
+
<button type="button" class="icon danger" aria-label="Delete Webhook" onclick={() => (failure = ondelete())}>
|
|
83
|
+
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3" /></svg
|
|
84
|
+
>
|
|
85
|
+
</button>
|
|
86
|
+
{:else}
|
|
87
|
+
<span class="icon"></span>
|
|
88
|
+
{/if}
|
|
89
|
+
<h2>{webhook ? webhook.name : 'New Webhook'}</h2>
|
|
90
|
+
<button type="button" class="icon" aria-label="Close" onclick={onclose}>
|
|
91
|
+
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18" /></svg>
|
|
92
|
+
</button>
|
|
93
|
+
{/snippet}
|
|
94
|
+
|
|
95
|
+
{#if failure}<p class="error" role="alert">{failure}</p>{/if}
|
|
96
|
+
{@render field('name', 'Name', 'Agent')}
|
|
97
|
+
{@render field('url', 'URL', 'https://hooks.example.com/feedback', 'url')}
|
|
98
|
+
{@render field('header', 'Header (optional)', 'Authorization: Bearer key')}
|
|
99
|
+
|
|
100
|
+
<div class="list">
|
|
101
|
+
<label class="toggle">
|
|
102
|
+
<span>Attach JSON</span>
|
|
103
|
+
<input type="checkbox" bind:checked={draft.feedback} />
|
|
104
|
+
</label>
|
|
105
|
+
<label class="toggle">
|
|
106
|
+
<span>Attach image</span>
|
|
107
|
+
<input type="checkbox" bind:checked={draft.image} />
|
|
108
|
+
</label>
|
|
109
|
+
{#if draft.image}
|
|
110
|
+
{@render segments(
|
|
111
|
+
'Image format',
|
|
112
|
+
[
|
|
113
|
+
['png', 'PNG'],
|
|
114
|
+
['jpeg', 'JPEG'],
|
|
115
|
+
],
|
|
116
|
+
draft.format,
|
|
117
|
+
value => (draft.format = value as WebhookDraft['format']),
|
|
118
|
+
)}
|
|
119
|
+
{#if draft.format === 'jpeg'}
|
|
120
|
+
{@render segments(
|
|
121
|
+
'Compression',
|
|
122
|
+
compressions.map(level => [level, level[0]!.toUpperCase() + level.slice(1)]),
|
|
123
|
+
draft.compression,
|
|
124
|
+
value => (draft.compression = value as Compression),
|
|
125
|
+
)}
|
|
126
|
+
{/if}
|
|
127
|
+
{/if}
|
|
128
|
+
</div>
|
|
129
|
+
<p class="note">
|
|
130
|
+
Each post sends {list.format(
|
|
131
|
+
['the title', draft.feedback && 'the feedback JSON', draft.image && 'the image', 'the device JSON'].filter(
|
|
132
|
+
part => typeof part === 'string',
|
|
133
|
+
),
|
|
134
|
+
)}. This browser keeps the webhook, header included, for this site.
|
|
135
|
+
</p>
|
|
136
|
+
<div class="actions">
|
|
137
|
+
<button type="submit" class="primary">{webhook ? 'Send' : 'Save'}</button>
|
|
138
|
+
</div>
|
|
139
|
+
</Sheet>
|
|
140
|
+
|
|
141
|
+
<style>
|
|
142
|
+
.icon {
|
|
143
|
+
display: grid;
|
|
144
|
+
place-items: center;
|
|
145
|
+
width: 32px;
|
|
146
|
+
height: 32px;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.icon svg {
|
|
150
|
+
width: 20px;
|
|
151
|
+
height: 20px;
|
|
152
|
+
fill: none;
|
|
153
|
+
stroke: currentColor;
|
|
154
|
+
stroke-width: 2;
|
|
155
|
+
stroke-linecap: round;
|
|
156
|
+
stroke-linejoin: round;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.danger {
|
|
160
|
+
color: #ff453a;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
input[aria-invalid='true'] {
|
|
164
|
+
outline: 1px solid #ff453a;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.error {
|
|
168
|
+
margin: 0;
|
|
169
|
+
color: #ff6961;
|
|
170
|
+
font-size: 13px;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.list {
|
|
174
|
+
display: grid;
|
|
175
|
+
border-radius: 10px;
|
|
176
|
+
background: #2c2c2e;
|
|
177
|
+
overflow: hidden;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.toggle,
|
|
181
|
+
.choice {
|
|
182
|
+
display: flex;
|
|
183
|
+
align-items: center;
|
|
184
|
+
justify-content: space-between;
|
|
185
|
+
gap: 12px;
|
|
186
|
+
border-bottom: 1px solid rgb(255 255 255 / 0.08);
|
|
187
|
+
padding: 11px 12px;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.list > :last-child {
|
|
191
|
+
border-bottom: 0;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.toggle input {
|
|
195
|
+
width: 20px;
|
|
196
|
+
height: 20px;
|
|
197
|
+
margin: 0;
|
|
198
|
+
accent-color: #0a84ff;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.segments {
|
|
202
|
+
display: flex;
|
|
203
|
+
border-radius: 8px;
|
|
204
|
+
padding: 2px;
|
|
205
|
+
background: #1c1c1e;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.segments label {
|
|
209
|
+
border-radius: 6px;
|
|
210
|
+
padding: 4px 10px;
|
|
211
|
+
font-size: 14px;
|
|
212
|
+
cursor: pointer;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.segments label.picked {
|
|
216
|
+
background: #636366;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.segments label:has(:focus-visible) {
|
|
220
|
+
outline: 2px solid #0a84ff;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.segments input {
|
|
224
|
+
position: absolute;
|
|
225
|
+
opacity: 0;
|
|
226
|
+
pointer-events: none;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.note {
|
|
230
|
+
margin: 0;
|
|
231
|
+
color: #aeaeb2;
|
|
232
|
+
font-size: 13px;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.actions {
|
|
236
|
+
display: flex;
|
|
237
|
+
justify-content: flex-end;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.primary {
|
|
241
|
+
min-width: 96px;
|
|
242
|
+
border-radius: 12px;
|
|
243
|
+
padding: 10px 20px;
|
|
244
|
+
background: #0a84ff;
|
|
245
|
+
font-weight: 600;
|
|
246
|
+
}
|
|
247
|
+
</style>
|
|
@@ -3,20 +3,19 @@
|
|
|
3
3
|
<script lang="ts">
|
|
4
4
|
import { Problem, taskTitle, type Fact, type FeedbackItem, type Session, type Toast } from '../core/index.ts';
|
|
5
5
|
import type { Screen } from '../dom/capture.ts';
|
|
6
|
-
import {
|
|
7
|
-
import { postId, postWebhook, type Webhook } from '../dom/webhook.ts';
|
|
6
|
+
import { postFiles, postId, postWebhook, type Delivery } from '../dom/webhook.ts';
|
|
8
7
|
import ProblemCard from './ProblemCard.svelte';
|
|
9
8
|
|
|
10
9
|
let {
|
|
11
10
|
screen,
|
|
12
11
|
session,
|
|
13
|
-
|
|
12
|
+
delivery,
|
|
14
13
|
onclose,
|
|
15
14
|
onposted,
|
|
16
15
|
}: {
|
|
17
16
|
screen: Screen;
|
|
18
17
|
session: Session;
|
|
19
|
-
|
|
18
|
+
delivery: Delivery;
|
|
20
19
|
onclose: () => void;
|
|
21
20
|
onposted: (items: FeedbackItem[], toast: Toast) => void;
|
|
22
21
|
} = $props();
|
|
@@ -27,7 +26,7 @@
|
|
|
27
26
|
// svelte-ignore state_referenced_locally
|
|
28
27
|
const title = taskTitle(session.capture, items).placeholder;
|
|
29
28
|
// svelte-ignore state_referenced_locally
|
|
30
|
-
const
|
|
29
|
+
const { webhook, contents } = delivery;
|
|
31
30
|
const id = postId();
|
|
32
31
|
let step = $state('Drawing the image');
|
|
33
32
|
let problem = $state<Problem>();
|
|
@@ -36,15 +35,12 @@
|
|
|
36
35
|
problem = undefined;
|
|
37
36
|
step = 'Drawing the image';
|
|
38
37
|
const started = performance.now();
|
|
39
|
-
const facts: Fact[] = [
|
|
40
|
-
{ label: 'Post', value: id },
|
|
41
|
-
{ label: 'Report', value: `${new TextEncoder().encode(report).length} bytes` },
|
|
42
|
-
];
|
|
38
|
+
const facts: Fact[] = [{ label: 'Post', value: id }];
|
|
43
39
|
try {
|
|
44
|
-
const
|
|
45
|
-
facts.push({ label:
|
|
40
|
+
const files = await postFiles(contents, screen, session.annotations);
|
|
41
|
+
for (const { file } of files) facts.push({ label: file.name, value: `${file.size} bytes` });
|
|
46
42
|
step = `Sending to ${webhook.name}`;
|
|
47
|
-
const link = await postWebhook(webhook, { id, title,
|
|
43
|
+
const link = await postWebhook(webhook, { id, title, files });
|
|
48
44
|
onposted(items, { text: `Sent to ${webhook.name}`, link });
|
|
49
45
|
} catch (error) {
|
|
50
46
|
const elapsed = { label: 'Elapsed', value: `${((performance.now() - started) / 1000).toFixed(1)} s` };
|
|
@@ -1,15 +1,24 @@
|
|
|
1
|
+
import type { SavedWebhook } from '../core/savedWebhooks.ts';
|
|
1
2
|
import type { ProcrastimateConfig } from '../dom/procrastimate.ts';
|
|
2
3
|
import { procrastimateIcon } from '../dom/procrastimate-icon.ts';
|
|
3
|
-
import { githubIcon, type Webhook } from '../dom/webhook.ts';
|
|
4
|
+
import { githubIcon, type Delivery, type Webhook } from '../dom/webhook.ts';
|
|
4
5
|
|
|
5
6
|
/** A server the feedback can be posted to, as the Share menu lists it after the exports. */
|
|
6
7
|
export type Destination = { name: string; image?: string } & (
|
|
7
8
|
| { kind: 'procrastimate' }
|
|
8
|
-
| { kind: 'webhook';
|
|
9
|
+
| { kind: 'webhook'; delivery: Delivery }
|
|
10
|
+
| { kind: 'saved'; saved: SavedWebhook }
|
|
9
11
|
);
|
|
10
12
|
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
+
/**
|
|
14
|
+
* ProcrastiMate first, then the webhooks with GitHub's icon, then the app's other webhooks in its order, then the ones
|
|
15
|
+
* saved in the editor in the order they were added.
|
|
16
|
+
*/
|
|
17
|
+
export function destinations(options: {
|
|
18
|
+
procrastimate?: ProcrastimateConfig;
|
|
19
|
+
webhooks?: Webhook[];
|
|
20
|
+
saved?: SavedWebhook[];
|
|
21
|
+
}): Destination[] {
|
|
13
22
|
const webhooks = [...(options.webhooks ?? [])].sort(
|
|
14
23
|
(a, b) => Number(b.image === githubIcon) - Number(a.image === githubIcon),
|
|
15
24
|
);
|
|
@@ -17,7 +26,13 @@ export function destinations(options: { procrastimate?: ProcrastimateConfig; web
|
|
|
17
26
|
...(options.procrastimate
|
|
18
27
|
? [{ kind: 'procrastimate' as const, name: 'ProcrastiMate', image: procrastimateIcon }]
|
|
19
28
|
: []),
|
|
20
|
-
...webhooks.map(webhook => ({
|
|
29
|
+
...webhooks.map(webhook => ({
|
|
30
|
+
kind: 'webhook' as const,
|
|
31
|
+
name: webhook.name,
|
|
32
|
+
image: webhook.image,
|
|
33
|
+
delivery: { webhook, contents: { kind: 'report' as const } },
|
|
34
|
+
})),
|
|
35
|
+
...(options.saved ?? []).map(saved => ({ kind: 'saved' as const, name: saved.name, saved })),
|
|
21
36
|
];
|
|
22
37
|
}
|
|
23
38
|
|