@stefan.inc/feedback-engine 1.4.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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stefan.inc/feedback-engine",
3
- "version": "1.4.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",
@@ -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
 
@@ -8,6 +8,7 @@
8
8
  cachedProjects,
9
9
  lastProject,
10
10
  loadProjects,
11
+ namedProject,
11
12
  postTask,
12
13
  taskLink,
13
14
  type Place,
@@ -34,13 +35,20 @@
34
35
  const names = taskTitle(session.capture, session.items);
35
36
  let name = $state(names.placeholder);
36
37
  let projects = $state(cachedProjects());
37
- 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
+ });
38
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;
39
45
  let loadProblem = $state<Problem>();
40
46
  let postProblem = $state<Problem>();
41
47
  /** What the post is doing, while it runs. */
42
48
  let step = $state<string>();
43
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);
44
52
  let status = $state<HTMLElement>();
45
53
  // svelte-ignore state_referenced_locally
46
54
  const environment: Fact[] = session.capture.environment.map(entry => ({ label: entry.name, value: entry.value }));
@@ -49,6 +57,11 @@
49
57
  loadProjects(config)
50
58
  .then(loaded => {
51
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
+ }
52
65
  const project = loaded.find(candidate => candidate.id === place.projectId);
53
66
  if (!project) place = {};
54
67
  else if (!project.sections.some(section => section.id === place.sectionId)) place = { projectId: project.id };
@@ -108,7 +121,10 @@
108
121
  role="option"
109
122
  aria-selected={picked}
110
123
  disabled={posting}
111
- onclick={pick}
124
+ onclick={() => {
125
+ chosen = true;
126
+ pick();
127
+ }}
112
128
  >
113
129
  <span>{label}</span>
114
130
  {#if picked}<span class="check" aria-hidden="true">✓</span>{/if}
@@ -119,7 +135,9 @@
119
135
  {#snippet header()}
120
136
  <button type="button" class="link" disabled={posting} onclick={onclose}>Cancel</button>
121
137
  <h2>Add to ProcrastiMate</h2>
122
- <button type="submit" class="link strong" disabled={posting || !name.trim()}>{posting ? 'Adding…' : 'Add'}</button>
138
+ <button type="submit" class="link strong" disabled={posting || unresolved || !name.trim()}
139
+ >{posting ? 'Adding…' : 'Add'}</button
140
+ >
123
141
  {/snippet}
124
142
 
125
143
  <div class="status" bind:this={status}>
@@ -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) {