@stefan.inc/feedback-engine 1.3.0 → 1.5.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 CHANGED
@@ -239,6 +239,7 @@ export default defineConfig({
239
239
  The token is the switch. With `PROCRASTIMATE_TOKEN` set, **ProcrastiMate** shows in the Share menu, with the same picker and task as on iOS. Without it, the entry is not there, and nothing else changes. `setupFeedbackEngine()` needs no option for either case.
240
240
 
241
241
  - The token is a ProcrastiMate API token. `feedbackProcrastimate({ url })` names another ProcrastiMate server.
242
+ - `feedbackProcrastimate({ project })` names the project the picker opens on, by name (ignoring case) or id, so an app's feedback lands in its own project. Without it, the picker opens on the last project posted to. A name ProcrastiMate does not have shows as an error above the list.
242
243
  - The proxy runs in `vite dev` and `vite preview`. A build reads the token too. Build a site you deploy without it, because a static host has no proxy.
243
244
  - For a proxy of your own, pass its address to the page instead: `setupFeedbackEngine({ procrastimate: { url: '/my-proxy' } })`.
244
245
 
@@ -266,7 +267,7 @@ The token is the switch. With `PROCRASTIMATE_TOKEN` set, **ProcrastiMate** shows
266
267
 
267
268
  ## Webhooks
268
269
 
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:
270
+ 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
271
 
271
272
  ```ts
272
273
  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.0",
3
+ "version": "1.5.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
@@ -4,6 +4,7 @@ export * from './describe.ts';
4
4
  export * from './model.ts';
5
5
  export * from './problem.ts';
6
6
  export * from './report.ts';
7
+ export * from './savedWebhooks.ts';
7
8
  export * from './session.ts';
8
9
  export * from './taskTitle.ts';
9
10
  export * from './tree.ts';
@@ -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
+ }
@@ -7,6 +7,8 @@ export type ProcrastimateConfig = {
7
7
  token?: string;
8
8
  /** The ProcrastiMate web app, for the link to a posted task. */
9
9
  app?: string;
10
+ /** The project the picker opens on, by name (ignoring case) or id, in place of the last one posted to. */
11
+ project?: string;
10
12
  };
11
13
 
12
14
  export type Section = { id: string; name: string };
@@ -45,6 +47,11 @@ export const cachedProjects = () => stored<Project[]>(projectsKey) ?? [];
45
47
  /** The project of the last post. Its section is not kept, so a new post starts at the project's top. */
46
48
  export const lastProject = () => stored<string>(lastProjectKey);
47
49
 
50
+ /** The project `config.project` names, by id or by name ignoring case. */
51
+ export const namedProject = (projects: Project[], name: string) =>
52
+ projects.find(project => project.id === name) ??
53
+ projects.find(project => project.name.toLowerCase() === name.toLowerCase());
54
+
48
55
  export const taskLink = (config: ProcrastimateConfig, id: string) =>
49
56
  `${(config.app ?? defaultApp).replace(/\/$/, '')}/inbox?task=${encodeURIComponent(id)}`;
50
57
 
@@ -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
- const toBlob = (canvas: HTMLCanvasElement) =>
19
- new Promise<Blob>((resolve, reject) =>
20
- canvas.toBlob(
21
- blob => (blob ? resolve(blob) : reject(new Error('The browser could not encode the image'))),
22
- 'image/png',
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 toBlob(annotatedImage(screen, annotations));
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 };
@@ -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
- /** The image export, as PNG. */
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
- form.set('image', new File([post.image], 'feedback.png', { type: 'image/png' }));
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 });
@@ -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 type { Webhook } from '../dom/webhook.ts';
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<Webhook>();
93
- // svelte-ignore state_referenced_locally
94
- const targets = destinations(engine.options);
95
- // svelte-ignore state_referenced_locally
96
- const pinned = pinnedDestinations(targets, engine.options.pinned);
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 posting = destination.webhook;
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
- webhook={posting}
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;
@@ -8,12 +8,14 @@
8
8
  cachedProjects,
9
9
  lastProject,
10
10
  loadProjects,
11
+ namedProject,
11
12
  postTask,
12
13
  taskLink,
13
14
  type Place,
14
15
  type ProcrastimateConfig,
15
16
  } from '../dom/procrastimate.ts';
16
17
  import ProblemCard from './ProblemCard.svelte';
18
+ import Sheet from './Sheet.svelte';
17
19
 
18
20
  let {
19
21
  screen,
@@ -33,13 +35,20 @@
33
35
  const names = taskTitle(session.capture, session.items);
34
36
  let name = $state(names.placeholder);
35
37
  let projects = $state(cachedProjects());
36
- let place = $state<Place>({ projectId: lastProject() });
38
+ // svelte-ignore state_referenced_locally
39
+ let place = $state<Place>({
40
+ projectId: config.project ? namedProject(projects, config.project)?.id : lastProject(),
41
+ });
37
42
  let loading = $state(true);
43
+ /** Whether the user chose a place, which a project list that finishes loading must not undo. */
44
+ let chosen = false;
38
45
  let loadProblem = $state<Problem>();
39
46
  let postProblem = $state<Problem>();
40
47
  /** What the post is doing, while it runs. */
41
48
  let step = $state<string>();
42
49
  const posting = $derived(step !== undefined);
50
+ /** Until the projects load, a post would land in the Inbox instead of the project the app named. */
51
+ const unresolved = $derived(loading && !!config.project && !place.projectId);
43
52
  let status = $state<HTMLElement>();
44
53
  // svelte-ignore state_referenced_locally
45
54
  const environment: Fact[] = session.capture.environment.map(entry => ({ label: entry.name, value: entry.value }));
@@ -48,6 +57,11 @@
48
57
  loadProjects(config)
49
58
  .then(loaded => {
50
59
  projects = loaded;
60
+ if (config.project) {
61
+ const named = namedProject(loaded, config.project);
62
+ if (!named) throw new Error(`ProcrastiMate has no project named "${config.project}"`);
63
+ if (!chosen) place = { projectId: named.id };
64
+ }
51
65
  const project = loaded.find(candidate => candidate.id === place.projectId);
52
66
  if (!project) place = {};
53
67
  else if (!project.sections.some(section => section.id === place.sectionId)) place = { projectId: project.id };
@@ -107,152 +121,65 @@
107
121
  role="option"
108
122
  aria-selected={picked}
109
123
  disabled={posting}
110
- onclick={pick}
124
+ onclick={() => {
125
+ chosen = true;
126
+ pick();
127
+ }}
111
128
  >
112
129
  <span>{label}</span>
113
130
  {#if picked}<span class="check" aria-hidden="true">✓</span>{/if}
114
131
  </button>
115
132
  {/snippet}
116
133
 
117
- <div class="scrim" role="presentation">
118
- <form
119
- class="sheet"
120
- aria-label="Add to ProcrastiMate"
121
- onsubmit={event => {
122
- event.preventDefault();
123
- void post();
124
- }}
125
- >
126
- <header>
127
- <button type="button" class="link" disabled={posting} onclick={onclose}>Cancel</button>
128
- <h2>Add to ProcrastiMate</h2>
129
- <button type="submit" class="link strong" disabled={posting || !name.trim()}>{posting ? 'Adding…' : 'Add'}</button
130
- >
131
- </header>
132
- <div class="scroll">
133
- <div class="status" bind:this={status}>
134
- {#if step}<p class="step" role="status">{step}…</p>{/if}
135
- {#if postProblem}<ProblemCard problem={postProblem} />{/if}
136
- {#if loadProblem}<ProblemCard problem={loadProblem} />{/if}
137
- </div>
138
- <label>
139
- <span class="caption">Name</span>
140
- <input bind:value={name} aria-label="Task name" disabled={posting} />
141
- </label>
142
- <span class="caption">Project{loading ? ' · loading…' : ''}</span>
143
- <div class="list" role="listbox" aria-label="Project">
144
- {@render row('Inbox', !place.projectId, false, () => (place = {}))}
145
- {#each projects as project (project.id)}
146
- {@const open = project.id === place.projectId && project.sections.length > 0}
134
+ <Sheet label="Add to ProcrastiMate" onsubmit={() => void post()}>
135
+ {#snippet header()}
136
+ <button type="button" class="link" disabled={posting} onclick={onclose}>Cancel</button>
137
+ <h2>Add to ProcrastiMate</h2>
138
+ <button type="submit" class="link strong" disabled={posting || unresolved || !name.trim()}
139
+ >{posting ? 'Adding…' : 'Add'}</button
140
+ >
141
+ {/snippet}
142
+
143
+ <div class="status" bind:this={status}>
144
+ {#if step}<p class="step" role="status">{step}…</p>{/if}
145
+ {#if postProblem}<ProblemCard problem={postProblem} />{/if}
146
+ {#if loadProblem}<ProblemCard problem={loadProblem} />{/if}
147
+ </div>
148
+ <label>
149
+ <span class="caption">Name</span>
150
+ <input bind:value={name} aria-label="Task name" disabled={posting} />
151
+ </label>
152
+ <span class="caption">Project{loading ? ' · loading…' : ''}</span>
153
+ <div class="list" role="listbox" aria-label="Project">
154
+ {@render row('Inbox', !place.projectId, false, () => (place = {}))}
155
+ {#each projects as project (project.id)}
156
+ {@const open = project.id === place.projectId && project.sections.length > 0}
157
+ {@render row(
158
+ project.name,
159
+ project.id === place.projectId && !open,
160
+ false,
161
+ () => (place = { projectId: project.id }),
162
+ )}
163
+ {#if open}
164
+ {@render row('No section', !place.sectionId, true, () => (place = { projectId: project.id }))}
165
+ {#each project.sections as section (section.id)}
147
166
  {@render row(
148
- project.name,
149
- project.id === place.projectId && !open,
150
- false,
151
- () => (place = { projectId: project.id }),
167
+ section.name,
168
+ place.sectionId === section.id,
169
+ true,
170
+ () => (place = { projectId: project.id, sectionId: section.id }),
152
171
  )}
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
172
  {/each}
165
- </div>
166
- </div>
167
- </form>
168
- </div>
173
+ {/if}
174
+ {/each}
175
+ </div>
176
+ </Sheet>
169
177
 
170
178
  <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
179
  .strong {
226
180
  font-weight: 600;
227
181
  }
228
182
 
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
183
  .list {
257
184
  display: grid;
258
185
  border-radius: 10px;
@@ -291,14 +218,4 @@
291
218
  margin: 0;
292
219
  color: #aeaeb2;
293
220
  }
294
-
295
- @media (min-width: 900px) {
296
- .scrim {
297
- place-items: center;
298
- }
299
-
300
- .sheet {
301
- border-radius: 16px;
302
- }
303
- }
304
221
  </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 { buildExport } from '../dom/share.ts';
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
- webhook,
12
+ delivery,
14
13
  onclose,
15
14
  onposted,
16
15
  }: {
17
16
  screen: Screen;
18
17
  session: Session;
19
- webhook: Webhook;
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 report = session.compactJSON;
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 { image } = await buildExport(screen, session.annotations, 'image');
45
- facts.push({ label: 'Image', value: `${image!.size} bytes` });
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, image: image!, report });
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'; webhook: Webhook }
9
+ | { kind: 'webhook'; delivery: Delivery }
10
+ | { kind: 'saved'; saved: SavedWebhook }
9
11
  );
10
12
 
11
- /** ProcrastiMate first, then the webhooks with GitHub's icon, then the other webhooks in the app's order. */
12
- export function destinations(options: { procrastimate?: ProcrastimateConfig; webhooks?: Webhook[] }): Destination[] {
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 => ({ kind: 'webhook' as const, name: webhook.name, image: webhook.image, 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
 
@@ -45,9 +45,10 @@ export function setupFeedbackEngine(options: FeedbackOptions = {}): FeedbackEngi
45
45
  // one piece. Webpack has no `import.meta.env`. The cast needs no `import.meta.env` type from the app.
46
46
  type Meta = { env?: Record<string, string | undefined> };
47
47
  const proxy = (import.meta as Meta).env && (import.meta as Meta).env!.FEEDBACK_PROCRASTIMATE;
48
+ const project = (import.meta as Meta).env && (import.meta as Meta).env!.FEEDBACK_PROCRASTIMATE_PROJECT;
48
49
  const engine = new Engine({
49
50
  ...options,
50
- procrastimate: options.procrastimate ?? (proxy ? { url: proxy } : undefined),
51
+ procrastimate: options.procrastimate ?? (proxy ? { url: proxy, project: project || undefined } : undefined),
51
52
  });
52
53
  const host = document.createElement('div');
53
54
  host.setAttribute(hostAttribute, '');
@@ -34,6 +34,8 @@ export type FeedbackOptions = {
34
34
  token?: string;
35
35
  /** The ProcrastiMate web app, for the link to a posted task. */
36
36
  app?: string;
37
+ /** The project the picker opens on, by name (ignoring case) or id, in place of the last one posted to. */
38
+ project?: string;
37
39
  };
38
40
  /**
39
41
  * Adds one entry to the Share menu per webhook. Choosing it posts the image export and the JSON export to the
@@ -23,6 +23,8 @@ export function feedbackProcrastimate(options?: {
23
23
  token?: string;
24
24
  /** Defaults to `/__feedback/procrastimate`. */
25
25
  path?: string;
26
+ /** The project the picker opens on, by name (ignoring case) or id, in place of the last one posted to. */
27
+ project?: string;
26
28
  }): Plugin;
27
29
 
28
30
  /**
package/src/vite/index.js CHANGED
@@ -7,6 +7,7 @@ const entry = '@stefan.inc/feedback-engine/svelte';
7
7
 
8
8
  /** What `setupFeedbackEngine()` reads for the proxy's path. `editor/setup.ts` spells the same name. */
9
9
  const procrastimateDefine = 'import.meta.env.FEEDBACK_PROCRASTIMATE';
10
+ const procrastimateProjectDefine = 'import.meta.env.FEEDBACK_PROCRASTIMATE_PROJECT';
10
11
 
11
12
  /**
12
13
  * The name a tag gets without one: the file's, as `.feedback(self)` uses the type's on iOS. A SvelteKit route file is
@@ -155,7 +156,7 @@ export function feedbackEngine(options = {}) {
155
156
  * ProcrastiMate. Without one the page is told nothing, so the entry is not there. A page that names the path itself
156
157
  * then gets a 501 that says why.
157
158
  *
158
- * @param {{ url?: string, token?: string, path?: string }} [options]
159
+ * @param {{ url?: string, token?: string, path?: string, project?: string }} [options]
159
160
  */
160
161
  export function feedbackProcrastimate(options = {}) {
161
162
  const path = options.path ?? '/__feedback/procrastimate';
@@ -193,7 +194,12 @@ export function feedbackProcrastimate(options = {}) {
193
194
  return {
194
195
  name: 'feedback-engine-procrastimate',
195
196
  config() {
196
- return { define: { [procrastimateDefine]: JSON.stringify(options.token ? path : '') } };
197
+ return {
198
+ define: {
199
+ [procrastimateDefine]: JSON.stringify(options.token ? path : ''),
200
+ [procrastimateProjectDefine]: JSON.stringify(options.project ?? ''),
201
+ },
202
+ };
197
203
  },
198
204
  /** @param {import('vite').ViteDevServer} server */
199
205
  configureServer(server) {