@stefan.inc/feedback-engine 1.2.4 → 1.3.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
@@ -278,6 +278,12 @@ setupFeedbackEngine({
278
278
 
279
279
  Each webhook also takes `headers` and `query`, as fixed values or as a function that runs when the post is made, for a token the user only has once signed in. [docs/webhooks.md](https://github.com/smirea/feedback-engine/blob/master/docs/webhooks.md) has the request, the answer a server gives, and a server that files every post as a GitHub issue.
280
280
 
281
+ The first two of ProcrastiMate and the webhooks also get a button beside Share. To choose them yourself, list their names in `pinned`, and the rest stay in the Share menu:
282
+
283
+ ```ts
284
+ setupFeedbackEngine({ webhooks, pinned: ['ProcrastiMate'] });
285
+ ```
286
+
281
287
  ## Releases
282
288
 
283
289
  Every change is a release, versioned by [semver](https://semver.org). [CHANGELOG.md](https://github.com/smirea/feedback-engine/blob/master/packages/web/CHANGELOG.md) lists them. A major version is only for a change that breaks an app that upgrades without editing its code.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stefan.inc/feedback-engine",
3
- "version": "1.2.4",
3
+ "version": "1.3.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",
@@ -23,9 +23,8 @@
23
23
  type ExportFormat,
24
24
  } from '../dom/share.ts';
25
25
  import type { Webhook } from '../dom/webhook.ts';
26
- import { destinations, shortcutCount, type Destination } from './destinations.ts';
26
+ import { destinations, pinnedDestinations, type Destination } from './destinations.ts';
27
27
  import type { Engine } from './engine.ts';
28
- import ItemsSheet from './ItemsSheet.svelte';
29
28
  import ProcrastimateSheet from './ProcrastimateSheet.svelte';
30
29
  import WebhookSheet from './WebhookSheet.svelte';
31
30
 
@@ -88,12 +87,13 @@
88
87
  let zoom = $state(1);
89
88
  let hover = $state<number>();
90
89
  let showsInfo = $state(false);
91
- let showsList = $state(false);
92
90
  let showsShare = $state(false);
93
91
  let showsProcrastimate = $state(false);
94
92
  let posting = $state<Webhook>();
95
93
  // svelte-ignore state_referenced_locally
96
94
  const targets = destinations(engine.options);
95
+ // svelte-ignore state_referenced_locally
96
+ const pinned = pinnedDestinations(targets, engine.options.pinned);
97
97
  let confirmsClose = $state(false);
98
98
  let pending = $state<{ format: ExportFormat; ready: Export }>();
99
99
  let busy = $state(false);
@@ -202,8 +202,8 @@
202
202
  }
203
203
 
204
204
  function requestClose() {
205
- if (showsInfo || showsList || showsShare || showsProcrastimate || posting || pending) {
206
- showsInfo = showsList = showsShare = showsProcrastimate = false;
205
+ if (showsInfo || showsShare || showsProcrastimate || posting || pending) {
206
+ showsInfo = showsShare = showsProcrastimate = false;
207
207
  posting = pending = undefined;
208
208
  } else if (session.isTyping || session.unshared.length) {
209
209
  confirmsClose = true;
@@ -267,39 +267,14 @@
267
267
  }}
268
268
  >
269
269
  <header>
270
- <button type="button" class="round" aria-label="Close" onclick={requestClose}>
270
+ <button type="button" class="nav" aria-label="Close" onclick={requestClose}>
271
271
  <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18" /></svg>
272
272
  </button>
273
273
  <h1>Feedback</h1>
274
- <button
275
- type="button"
276
- class="round"
277
- aria-label="Feedback list, {count(view.items.length)}"
278
- onclick={() => (showsList = true)}
279
- >
280
- <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 6h11M9 12h11M9 18h11M4 6h.01M4 12h.01M4 18h.01" /></svg>
281
- {#if view.items.length}<span class="count" aria-hidden="true">{view.items.length}</span>{/if}
282
- </button>
283
- {#each targets.slice(0, shortcutCount) as destination, index (index)}
284
- <button
285
- type="button"
286
- class="round"
287
- aria-label={destination.name}
288
- title={destination.name}
289
- disabled={!view.items.length || busy}
290
- onclick={() => send(destination)}
291
- >
292
- {#if destination.image}
293
- <img src={destination.image} alt="" />
294
- {:else}
295
- <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z" /></svg>
296
- {/if}
297
- </button>
298
- {/each}
299
274
  <div class="menu">
300
275
  <button
301
276
  type="button"
302
- class="round"
277
+ class="nav"
303
278
  aria-label="Share"
304
279
  aria-haspopup="menu"
305
280
  aria-expanded={showsShare}
@@ -322,6 +297,22 @@
322
297
  </div>
323
298
  {/if}
324
299
  </div>
300
+ {#each pinned as destination, index (index)}
301
+ <button
302
+ type="button"
303
+ class="nav"
304
+ aria-label={destination.name}
305
+ title={destination.name}
306
+ disabled={!view.items.length || busy}
307
+ onclick={() => send(destination)}
308
+ >
309
+ {#if destination.image}
310
+ <img src={destination.image} alt="" />
311
+ {:else}
312
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z" /></svg>
313
+ {/if}
314
+ </button>
315
+ {/each}
325
316
  </header>
326
317
 
327
318
  <div class="body">
@@ -500,19 +491,6 @@
500
491
  </div>
501
492
  {/if}
502
493
 
503
- {#if showsList}
504
- <ItemsSheet
505
- {session}
506
- {version}
507
- onclose={() => (showsList = false)}
508
- onselect={id => {
509
- act(() => session.select(id));
510
- showsList = false;
511
- }}
512
- onremove={id => act(() => session.remove(id))}
513
- />
514
- {/if}
515
-
516
494
  {#if showsProcrastimate && engine.options.procrastimate}
517
495
  <ProcrastimateSheet
518
496
  {screen}
@@ -626,8 +604,8 @@
626
604
  header {
627
605
  display: flex;
628
606
  align-items: center;
629
- gap: 12px;
630
- padding: 8px 16px;
607
+ gap: 4px;
608
+ padding: 4px 8px;
631
609
  }
632
610
 
633
611
  h1 {
@@ -643,7 +621,6 @@
643
621
  }
644
622
 
645
623
  .round {
646
- position: relative;
647
624
  display: grid;
648
625
  place-items: center;
649
626
  width: 36px;
@@ -653,12 +630,27 @@
653
630
  background: #2c2c2e;
654
631
  }
655
632
 
656
- .round img {
657
- width: 22px;
658
- height: 22px;
633
+ .nav {
634
+ display: grid;
635
+ place-items: center;
636
+ width: 44px;
637
+ height: 44px;
638
+ border: 0;
639
+ padding: 0;
640
+ background: none;
641
+ }
642
+
643
+ .nav img {
644
+ width: 30px;
645
+ height: 30px;
659
646
  object-fit: contain;
660
647
  }
661
648
 
649
+ .nav svg {
650
+ width: 26px;
651
+ height: 26px;
652
+ }
653
+
662
654
  .round.small {
663
655
  width: 30px;
664
656
  height: 30px;
@@ -674,19 +666,6 @@
674
666
  stroke-linejoin: round;
675
667
  }
676
668
 
677
- .count {
678
- position: absolute;
679
- top: -4px;
680
- right: -4px;
681
- min-width: 18px;
682
- border-radius: 9px;
683
- padding: 0 4px;
684
- background: #ff3b30;
685
- font-size: 11px;
686
- font-weight: 700;
687
- line-height: 18px;
688
- }
689
-
690
669
  .menu {
691
670
  position: relative;
692
671
  }
@@ -8,9 +8,6 @@ export type Destination = { name: string; image?: string } & (
8
8
  | { kind: 'webhook'; webhook: Webhook }
9
9
  );
10
10
 
11
- /** How many destinations also get a button beside Share. */
12
- export const shortcutCount = 2;
13
-
14
11
  /** ProcrastiMate first, then the webhooks with GitHub's icon, then the other webhooks in the app's order. */
15
12
  export function destinations(options: { procrastimate?: ProcrastimateConfig; webhooks?: Webhook[] }): Destination[] {
16
13
  const webhooks = [...(options.webhooks ?? [])].sort(
@@ -23,3 +20,12 @@ export function destinations(options: { procrastimate?: ProcrastimateConfig; web
23
20
  ...webhooks.map(webhook => ({ kind: 'webhook' as const, name: webhook.name, image: webhook.image, webhook })),
24
21
  ];
25
22
  }
23
+
24
+ /**
25
+ * The destinations that also get a button beside Share: the ones `pinned` names, in its order, or the first two
26
+ * without it. A name with no destination is skipped, since a webhook can join the list after setup.
27
+ */
28
+ export function pinnedDestinations(all: Destination[], pinned: string[] | undefined): Destination[] {
29
+ if (!pinned) return all.slice(0, 2);
30
+ return pinned.flatMap(name => all.filter(destination => destination.name === name));
31
+ }
@@ -33,9 +33,15 @@ export type FeedbackOptions = {
33
33
  /**
34
34
  * Adds one entry to the Share menu per webhook. Choosing it posts the image export and the JSON export to the
35
35
  * webhook's `url`, with nothing more to fill in. The menu lists ProcrastiMate, then the webhooks with `githubIcon`,
36
- * then the others, and the first two of them also get a button beside Share.
36
+ * then the others.
37
37
  */
38
38
  webhooks?: Webhook[];
39
+ /**
40
+ * The Share menu entries that also get a button beside Share, by name, in this order: `'ProcrastiMate'` or a
41
+ * webhook's `name`. A name the menu does not list is skipped. Without it, the first two of ProcrastiMate and the
42
+ * webhooks get one. `[]` gives none.
43
+ */
44
+ pinned?: string[];
39
45
  };
40
46
 
41
47
  export const defaultShortcut = 'Alt+Meta+Click';
@@ -38,9 +38,15 @@ export type FeedbackOptions = {
38
38
  /**
39
39
  * Adds one entry to the Share menu per webhook. Choosing it posts the image export and the JSON export to the
40
40
  * webhook's `url`, with nothing more to fill in. The menu lists ProcrastiMate, then the webhooks with `githubIcon`,
41
- * then the others, and the first two of them also get a button beside Share.
41
+ * then the others.
42
42
  */
43
43
  webhooks?: Webhook[];
44
+ /**
45
+ * The Share menu entries that also get a button beside Share, by name, in this order: `'ProcrastiMate'` or a
46
+ * webhook's `name`. A name the menu does not list is skipped. Without it, the first two of ProcrastiMate and the
47
+ * webhooks get one. `[]` gives none.
48
+ */
49
+ pinned?: string[];
44
50
  };
45
51
 
46
52
  /** One entry of the Share menu that posts the feedback to a server of the app's own. `docs/webhooks.md` has the request. */
@@ -1,233 +0,0 @@
1
- <svelte:options css="injected" />
2
-
3
- <script lang="ts">
4
- import { paletteColor, title, type Session } from '../core/index.ts';
5
-
6
- let {
7
- session,
8
- version,
9
- onclose,
10
- onselect,
11
- onremove,
12
- }: {
13
- session: Session;
14
- /** Changes whenever the session does, since the session is not reactive by itself. */
15
- version: number;
16
- onclose: () => void;
17
- onselect: (id: number) => void;
18
- onremove: (id: string) => void;
19
- } = $props();
20
-
21
- // svelte-ignore state_referenced_locally
22
- const { capture } = session;
23
- const items = $derived.by(() => {
24
- void version;
25
- return session.items.map(item => ({
26
- ...item,
27
- number: session.annotations.number(item.target),
28
- color: paletteColor(session.colorIndex(item.target)),
29
- segments: session.annotations.segments(item.text),
30
- }));
31
- });
32
- </script>
33
-
34
- <div class="scrim" role="presentation" onclick={event => event.target === event.currentTarget && onclose()}>
35
- <div class="sheet" role="dialog" tabindex="-1" aria-label="Feedback list">
36
- <header>
37
- <h2>Feedback</h2>
38
- <button type="button" class="done" onclick={onclose}>Done</button>
39
- </header>
40
- <div class="scroll">
41
- {#if !items.length}
42
- <p class="empty">No feedback yet. Click a component, type, and press the arrow.</p>
43
- {/if}
44
- <ul>
45
- {#each items as item (item.id)}
46
- <li>
47
- <button type="button" class="row" onclick={() => onselect(item.target)}>
48
- <span class="number" style="background:{item.color}">{item.number}</span>
49
- <span class="text">
50
- <strong>{title(capture.nodes[item.target]!)}</strong>
51
- <span>
52
- {#each item.segments as segment, index (index)}
53
- {#if segment.reference}<span
54
- class="token"
55
- style="background:{paletteColor(session.colorIndex(segment.reference.target))}"
56
- >{segment.text}</span
57
- >{:else}{segment.text}{/if}
58
- {/each}
59
- </span>
60
- </span>
61
- </button>
62
- <button
63
- type="button"
64
- class="remove"
65
- aria-label="Remove item {item.number}"
66
- onclick={() => onremove(item.id)}
67
- >
68
- <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 7h14M10 7V4h4v3M7 7l1 13h8l1-13" /></svg>
69
- </button>
70
- </li>
71
- {/each}
72
- </ul>
73
- <h3>Attached context</h3>
74
- {#each [...capture.environment, ...capture.context] as entry, index (index)}
75
- <details>
76
- <summary>{entry.name}</summary>
77
- <pre>{entry.value}</pre>
78
- </details>
79
- {/each}
80
- </div>
81
- </div>
82
- </div>
83
-
84
- <style>
85
- .scrim {
86
- position: absolute;
87
- inset: 0;
88
- z-index: 5;
89
- display: grid;
90
- place-items: end center;
91
- background: rgb(0 0 0 / 0.5);
92
- }
93
-
94
- .sheet {
95
- display: flex;
96
- flex-direction: column;
97
- width: min(100%, 560px);
98
- max-height: 80%;
99
- border-radius: 16px 16px 0 0;
100
- box-sizing: border-box;
101
- background: #1f1f1f;
102
- }
103
-
104
- header {
105
- display: flex;
106
- align-items: center;
107
- justify-content: space-between;
108
- padding: 14px 16px 8px;
109
- }
110
-
111
- h2 {
112
- margin: 0;
113
- font-size: 17px;
114
- }
115
-
116
- h3 {
117
- margin: 20px 0 6px;
118
- color: #aeaeb2;
119
- font-size: 12px;
120
- font-weight: 600;
121
- text-transform: uppercase;
122
- }
123
-
124
- button {
125
- border: 0;
126
- background: none;
127
- color: inherit;
128
- font: inherit;
129
- cursor: pointer;
130
- }
131
-
132
- .done {
133
- color: #0a84ff;
134
- font-weight: 600;
135
- }
136
-
137
- .scroll {
138
- padding: 0 16px 16px;
139
- overflow: auto;
140
- }
141
-
142
- .empty {
143
- color: #aeaeb2;
144
- }
145
-
146
- ul {
147
- margin: 0;
148
- padding: 0;
149
- list-style: none;
150
- }
151
-
152
- li {
153
- display: flex;
154
- align-items: flex-start;
155
- gap: 4px;
156
- border-bottom: 1px solid rgb(255 255 255 / 0.08);
157
- }
158
-
159
- .row {
160
- display: flex;
161
- flex: 1;
162
- gap: 10px;
163
- min-width: 0;
164
- padding: 10px 0;
165
- text-align: left;
166
- }
167
-
168
- .number {
169
- display: grid;
170
- flex: none;
171
- place-items: center;
172
- width: 22px;
173
- height: 22px;
174
- border-radius: 11px;
175
- font-size: 12px;
176
- font-weight: 700;
177
- }
178
-
179
- .text {
180
- display: grid;
181
- gap: 2px;
182
- min-width: 0;
183
- white-space: pre-wrap;
184
- }
185
-
186
- .token {
187
- border-radius: 3px;
188
- padding: 0 4px;
189
- font-weight: 600;
190
- }
191
-
192
- .remove {
193
- padding: 10px 4px;
194
- color: #ff453a;
195
- }
196
-
197
- svg {
198
- width: 18px;
199
- height: 18px;
200
- fill: none;
201
- stroke: currentColor;
202
- stroke-width: 2;
203
- stroke-linecap: round;
204
- stroke-linejoin: round;
205
- }
206
-
207
- summary {
208
- padding: 8px 0;
209
- cursor: pointer;
210
- }
211
-
212
- pre {
213
- margin: 0 0 8px;
214
- color: #aeaeb2;
215
- font:
216
- 12px/1.35 ui-monospace,
217
- 'SF Mono',
218
- Menlo,
219
- monospace;
220
- white-space: pre-wrap;
221
- overflow-wrap: anywhere;
222
- }
223
-
224
- @media (min-width: 900px) {
225
- .scrim {
226
- place-items: center;
227
- }
228
-
229
- .sheet {
230
- border-radius: 16px;
231
- }
232
- }
233
- </style>