@stefan.inc/feedback-engine 1.4.0 → 1.6.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
@@ -8,7 +8,7 @@ Alt+Meta+click anything in the browser, click any component on the frozen screen
8
8
 
9
9
  | The editor in the browser | The `feedback.png` it exports |
10
10
  | :---: | :---: |
11
- | <img src="https://raw.githubusercontent.com/smirea/feedback-engine/master/docs/web-editor.png" alt="The Feedback editor in Google Chrome over the React example: the page's screenshot on the left with four notes numbered 1 to 4 and an @5 tag on the New List button, and the panel on the right with the Groceries row, a ListRow, selected and its note, Show a progress bar here." width="320"> | <img src="https://raw.githubusercontent.com/smirea/feedback-engine/master/docs/web-export.png" alt="The feedback.png exported from the browser: the page with four numbered boxes and the New List button tagged @5. One column on the left holds the app's details as Name: value lines, a References line naming @5 with its file:line, and a card per note, each joined to its box by a curve with a dot at each end that crosses no other box. Each card has its note, the component or element, and its file:line. The note on Settings reads Move this next to @5_Button. A faint GitHub mark and the repository's URL sit in the top left corner, above the details." width="520"> |
11
+ | <img src="https://raw.githubusercontent.com/smirea/feedback-engine/master/docs/web-editor.png" alt="The Feedback editor in Google Chrome over the React example: the page's screenshot on the left with four notes numbered 1 to 4 and an @5 tag on the New List button, and the panel on the right with the Groceries row, a ListRow, selected and its note, Show a progress bar here, and under the field all four notes, each with its number, target, and text." width="320"> | <img src="https://raw.githubusercontent.com/smirea/feedback-engine/master/docs/web-export.png" alt="The feedback.png exported from the browser: the page with four numbered boxes and the New List button tagged @5. One column on the left holds the app's details as Name: value lines, a References line naming @5 with its file:line, and a card per note, each joined to its box by a curve with a dot at each end that crosses no other box. Each card has its note, the component or element, and its file:line. The note on Settings reads Move this next to @5_Button. A faint GitHub mark and the repository's URL sit in the top left corner, above the details." width="520"> |
12
12
 
13
13
  Four notes on the React example in Google Chrome. The last one points at a second element. Type `@`, click the element, and the note reads `Move this next to @5_Button`. The export draws that element's box and highlights the token in the same color, so an agent knows which button you meant. Each card names its component or element and the `file:line` it comes from, such as `src/components/ListRow.tsx:4`.
14
14
 
@@ -238,7 +238,8 @@ export default defineConfig({
238
238
 
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
- - The token is a ProcrastiMate API token. `feedbackProcrastimate({ url })` names another ProcrastiMate server.
241
+ - The token is a ProcrastiMate personal token, from Settings › Personal token. An AI account's token lists the projects but cannot upload the image, so the post fails with `Not for AI accounts`. `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.6.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",
@@ -92,6 +92,13 @@ export class Session {
92
92
  return this.annotations.colorIndex(node);
93
93
  }
94
94
 
95
+ /** What a tap on the screenshot or on an item in the list picks while the text ends in `@`. */
96
+ pickReference(node: number) {
97
+ if (!this.isReferencing) return;
98
+ this.referencePick = node;
99
+ this.referenceLevel = 0;
100
+ }
101
+
95
102
  stepReference(level: number) {
96
103
  this.referenceLevel = level;
97
104
  }
@@ -124,8 +131,7 @@ export class Session {
124
131
  pick(point: Point) {
125
132
  const id = hitTest(this.capture, point);
126
133
  if (this.isReferencing) {
127
- this.referencePick = id;
128
- this.referenceLevel = 0;
134
+ this.pickReference(id);
129
135
  return;
130
136
  }
131
137
  const flagged = new Set(this.items.map(item => item.target));
@@ -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
 
@@ -67,6 +67,7 @@
67
67
  ...item,
68
68
  number: session.annotations.number(item.target),
69
69
  color: paletteColor(session.colorIndex(item.target)),
70
+ title: title(capture.nodes[item.target]!),
70
71
  })),
71
72
  references: session.visibleReferences.map(reference => ({
72
73
  ...reference,
@@ -90,6 +91,8 @@
90
91
  let zoom = $state(1);
91
92
  let hover = $state<number>();
92
93
  let showsInfo = $state(false);
94
+ /** The list of items starts open beside the screenshot, and closed under it on a phone, where it would cover the picture. */
95
+ let showsItems = $state(matchMedia('(min-width: 900px)').matches);
93
96
  let showsShare = $state(false);
94
97
  let showsProcrastimate = $state(false);
95
98
  let posting = $state<Delivery>();
@@ -476,7 +479,7 @@
476
479
  <strong class="picked">{title(view.referenceTarget)}</strong>
477
480
  <button type="button" class="insert" onclick={() => act(() => session.insertReference())}>Insert</button>
478
481
  {:else}
479
- <span class="picked">@ Click an element to reference it</span>
482
+ <span class="picked">@ Click an element{view.items.length ? ' or an item' : ''} to reference it</span>
480
483
  {/if}
481
484
  </div>
482
485
  {/if}
@@ -507,6 +510,48 @@
507
510
  </svg>
508
511
  </button>
509
512
  </div>
513
+ {#if view.items.length}
514
+ <div class="items">
515
+ <button
516
+ type="button"
517
+ class="toggle"
518
+ aria-expanded={showsItems}
519
+ aria-controls="feedback-items"
520
+ onclick={() => (showsItems = !showsItems)}
521
+ >
522
+ {count(view.items.length)}
523
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9l6 6 6-6" /></svg>
524
+ </button>
525
+ {#if showsItems}
526
+ <!-- A press keeps the field's focus, so Enter still inserts a reference or saves after picking an item. -->
527
+ <ol id="feedback-items" aria-label="Feedback items">
528
+ {#each view.items as item (item.id)}
529
+ <li>
530
+ <button
531
+ type="button"
532
+ class:current={item.id === view.editing?.id}
533
+ class:referenced={item.target === view.referenceTarget?.id}
534
+ aria-label={view.isReferencing
535
+ ? `Reference item ${item.number}, ${item.title}`
536
+ : `Edit item ${item.number}, ${item.title}`}
537
+ onmousedown={event => event.preventDefault()}
538
+ onclick={() =>
539
+ act(() =>
540
+ view.isReferencing ? session.pickReference(item.target) : session.select(item.target),
541
+ )}
542
+ >
543
+ <span class="number static" style="--color:{item.color}">{item.number}</span>
544
+ <span class="summary">
545
+ <strong>{item.title}</strong>
546
+ <span>{item.text}</span>
547
+ </span>
548
+ </button>
549
+ </li>
550
+ {/each}
551
+ </ol>
552
+ {/if}
553
+ </div>
554
+ {/if}
510
555
  </section>
511
556
  </div>
512
557
 
@@ -1033,6 +1078,99 @@
1033
1078
  background: #0a84ff;
1034
1079
  }
1035
1080
 
1081
+ .items {
1082
+ display: flex;
1083
+ flex-direction: column;
1084
+ gap: 6px;
1085
+ min-height: 0;
1086
+ }
1087
+
1088
+ .toggle {
1089
+ display: flex;
1090
+ align-items: center;
1091
+ gap: 4px;
1092
+ align-self: flex-start;
1093
+ border: 0;
1094
+ padding: 2px 0;
1095
+ background: none;
1096
+ color: #aeaeb2;
1097
+ font-size: 13px;
1098
+ font-weight: 600;
1099
+ }
1100
+
1101
+ .toggle svg {
1102
+ width: 14px;
1103
+ height: 14px;
1104
+ transition: rotate 0.15s;
1105
+ }
1106
+
1107
+ .toggle[aria-expanded='false'] svg {
1108
+ rotate: -90deg;
1109
+ }
1110
+
1111
+ ol {
1112
+ display: grid;
1113
+ gap: 4px;
1114
+ min-height: 0;
1115
+ max-height: 30dvh;
1116
+ margin: 0;
1117
+ padding: 0;
1118
+ list-style: none;
1119
+ overflow-y: auto;
1120
+ overscroll-behavior: contain;
1121
+ }
1122
+
1123
+ ol button {
1124
+ display: flex;
1125
+ align-items: flex-start;
1126
+ gap: 10px;
1127
+ width: 100%;
1128
+ border: 1.5px solid transparent;
1129
+ border-radius: 12px;
1130
+ padding: 8px 10px;
1131
+ box-sizing: border-box;
1132
+ background: #2a2a2c;
1133
+ text-align: left;
1134
+ }
1135
+
1136
+ ol button:hover {
1137
+ background: #323234;
1138
+ }
1139
+
1140
+ ol button.current {
1141
+ border-color: #ffd60a;
1142
+ }
1143
+
1144
+ ol button.referenced {
1145
+ border-color: #32ade6;
1146
+ background: rgb(50 173 230 / 0.12);
1147
+ }
1148
+
1149
+ ol .number.static {
1150
+ flex: none;
1151
+ margin: 0;
1152
+ }
1153
+
1154
+ .summary {
1155
+ display: grid;
1156
+ gap: 2px;
1157
+ min-width: 0;
1158
+ }
1159
+
1160
+ .summary strong {
1161
+ font-size: 13px;
1162
+ color: #aeaeb2;
1163
+ }
1164
+
1165
+ .summary span {
1166
+ display: -webkit-box;
1167
+ -webkit-box-orient: vertical;
1168
+ -webkit-line-clamp: 2;
1169
+ line-clamp: 2;
1170
+ overflow: hidden;
1171
+ white-space: pre-line;
1172
+ }
1173
+
1036
1174
  .toast {
1037
1175
  position: absolute;
1038
1176
  top: 60px;
@@ -1108,13 +1246,19 @@
1108
1246
  flex-direction: row;
1109
1247
  }
1110
1248
 
1249
+ /* A column, so the list takes the height left under the field and scrolls inside it. */
1111
1250
  .panel {
1112
- align-content: start;
1251
+ display: flex;
1252
+ flex-direction: column;
1113
1253
  width: 380px;
1114
1254
  box-sizing: border-box;
1115
1255
  border-left: 1px solid rgb(255 255 255 / 0.08);
1116
1256
  }
1117
1257
 
1258
+ ol {
1259
+ max-height: none;
1260
+ }
1261
+
1118
1262
  .info {
1119
1263
  top: calc(100% + 10px);
1120
1264
  bottom: auto;
@@ -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) {