@stefan.inc/feedback-engine 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/README.md +276 -3
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,13 +1,286 @@
1
1
  # @stefan.inc/feedback-engine
2
2
 
3
+ In-app feedback for Svelte and React apps. For SwiftUI, use the [iOS package](https://github.com/smirea/feedback-engine#ios) from the same repository.
4
+
3
5
  **Point at your app. Say what's wrong. Hand an agent the exact component and line of code.**
4
6
 
5
- Alt+Meta+click anything in your Svelte or React app, click any component on the frozen screenshot, and write what should change. Feedback exports one file that names every component you flagged, where it lives in the source, and the data it was showing, so an agent can act on the feedback without guessing.
7
+ Alt+Meta+click anything in the browser, click any component on the frozen screenshot, and write what should change. Feedback exports one file that names every component you flagged, where it lives in the source, and the data it was showing, so an agent can act on the feedback without guessing.
8
+
9
+ | The editor in the browser | The `feedback.png` it exports |
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, 2, 3, and 5 and an @4 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 @4. Each box links to a card with its note, the component or element, and its file:line, and the app's details sit at the top right. The note on Settings reads Move this next to @4_Button." width="520"> |
12
+
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 @4_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
+
15
+ Prefer structured data? Share JSON for the whole component tree, each component's data, and the app context you attached, or both in one ZIP. A [webhook](#webhooks) adds a Share entry that posts both to a server of yours in one click, such as one that files a GitHub issue. [The report format](https://github.com/smirea/feedback-engine/blob/master/spec/report.md) is the same on every platform.
16
+
17
+ ## Install
6
18
 
7
19
  ```sh
8
20
  bun add @stefan.inc/feedback-engine
9
21
  ```
10
22
 
11
- The package has one entry point per framework, `/svelte` and `/react`, with build plugins in `/vite` and `/next`. It ships TypeScript and Svelte source, and your app's bundler compiles it.
23
+ The package has one entry point per framework, `/svelte` and `/react`. A Svelte app builds with Vite. A React app builds with Vite or with [Next.js](#nextjs). The package ships TypeScript and Svelte source, and your app's bundler compiles it. The editor is the same in both: Svelte components in a shadow root. A React app needs no Svelte setup, because the package's Vite plugin or Next.js config compiles the editor.
24
+
25
+ ## Svelte
26
+
27
+ Requires Svelte 5.29 or later.
28
+
29
+ ### Turn it on
30
+
31
+ ```svelte
32
+ <!-- src/routes/+layout.svelte -->
33
+ <script lang="ts">
34
+ import { setupFeedbackEngine } from '@stefan.inc/feedback-engine/svelte';
35
+ import { store } from '../lib/store.svelte';
36
+
37
+ const feedback = setupFeedbackEngine({ app: 'Todo', version: '1.0' });
38
+ feedback.context('Store', () => store);
39
+ </script>
40
+ ```
41
+
42
+ - `setupFeedbackEngine()` turns on the trigger. Alt+Meta+click on anything, which is Option+Command+click on a Mac, captures the page and opens the editor with what you clicked selected. The app never gets that click, so a link does not navigate, and a disabled button can be clicked too. Pass `shortcut: 'Ctrl+Shift+Click'` for another chord, or `shortcut: false` for none. On a server the call returns an engine that does nothing, so a layout needs no guard.
43
+ - A chord that ends in a key, such as `shortcut: 'Alt+Shift+F'`, drops an **Add Feedback** pill in at the top center instead, and clicking the pill captures the page. Left alone, the pill leaves after 5 seconds, and it leaves at once when the tab goes to the background.
44
+ - `feedback.context(name, () => value)` attaches app state to every JSON export. The function runs when a capture is taken.
45
+ - `button: true` shows a round Feedback button in the bottom right corner of every screen. It is the trigger for a phone, which has no modifier keys, and for an app opened from the home screen. Tapping it captures the page. Drag it to move it up or down, or to the other side. It stays where you leave it.
46
+ - `feedback.countdown()` is the other trigger for a phone, where a shake does not work yet. Call it from an entry in one of your app's menus, such as Settings. The pill shows **Feedback in 5** and counts down, so you have 5 seconds to leave the menu and open the screen you mean. Then it captures. Tapping the pill captures at once, and `countdown(10)` gives more time.
47
+ - `feedback.present()` captures at once, with no countdown. It suits a control that is on the screen you want to capture.
48
+ - To keep Feedback out of production, call it behind `import.meta.env.DEV` with a dynamic import. The production bundle then has the tags and none of the editor.
49
+
50
+ ```ts
51
+ if (import.meta.env.DEV) {
52
+ void import('@stefan.inc/feedback-engine/svelte').then(({ setupFeedbackEngine }) => setupFeedbackEngine());
53
+ }
54
+ ```
55
+
56
+ Add the plugin to your Vite config. JavaScript has no `#fileID` and `#line`, so the plugin writes each tag's `file:line` in at build time.
57
+
58
+ ```ts
59
+ // vite.config.ts
60
+ import { feedbackEngine } from '@stefan.inc/feedback-engine/vite';
61
+
62
+ export default defineConfig({
63
+ plugins: [sveltekit({ preprocess: [feedbackEngine()] })],
64
+ });
65
+ ```
66
+
67
+ In a plain Svelte project, pass `preprocess: [feedbackEngine()]` to `svelte()` from `@sveltejs/vite-plugin-svelte`.
68
+
69
+ ### Name your components
70
+
71
+ Attach a tag to each component's root element:
72
+
73
+ ```svelte
74
+ <script lang="ts">
75
+ import { feedback } from '@stefan.inc/feedback-engine/svelte';
76
+
77
+ let { item }: { item: TodoItem } = $props();
78
+ let isExpanded = $state(false);
79
+ </script>
80
+
81
+ <li {@attach feedback()}>…</li>
82
+ ```
83
+
84
+ `feedback()` names the component after its file, so `TodoRow.svelte` is `TodoRow`, and a SvelteKit route file is named after its folders, so `routes/lists/[id]/+page.svelte` is `ListsIdPage`. It reports the component's props and its `$state` variables. To choose the name or the data yourself, use `{@attach feedback('TodoRow', () => item)}`. The data function runs when a capture is taken, never while rendering.
85
+
86
+ ## React
87
+
88
+ Requires React 18 or later and Vite 8 or later. It is tested with React 18.3 and React 19.
89
+
90
+ ### Turn it on
91
+
92
+ Add the plugin to your Vite config, before the React plugin:
93
+
94
+ ```ts
95
+ // vite.config.ts
96
+ import { feedbackEngineReact } from '@stefan.inc/feedback-engine/vite';
97
+ import react from '@vitejs/plugin-react';
98
+
99
+ export default defineConfig({
100
+ plugins: [feedbackEngineReact(), react()],
101
+ });
102
+ ```
103
+
104
+ ```tsx
105
+ // src/main.tsx
106
+ import { setupFeedbackEngine } from '@stefan.inc/feedback-engine/react';
107
+ import { store } from './store';
108
+
109
+ const feedback = setupFeedbackEngine({ app: 'Todo', version: '1.0' });
110
+ feedback.context('Store', () => store);
111
+ ```
112
+
113
+ `setupFeedbackEngine()` takes the options and returns the engine described under [Svelte](#turn-it-on). Call it before or after React renders. To keep Feedback out of production, call it behind `import.meta.env.DEV`. In a React 18 app with seven components, the production bundle then grew by 1.3 kB, for the component names, and had none of the editor.
114
+
115
+ The plugin does three things:
116
+
117
+ - It registers every component in your `.jsx` and `.tsx` files with its name and `file:line`. React knows a component only by its function's name, which a minified build replaces.
118
+ - It compiles the editor's Svelte files. Without the plugin, the build stops at the first one. Svelte is a peer dependency, which `bun add` and `npm install` add by themselves.
119
+ - On the dev server, it writes each HTML element's `file:line` into a `data-feedback-source` attribute, because React 19 no longer records it. `feedbackEngineReact({ elementSources: false })` turns that off, and test runs never get it. `elementSources: true` writes it into a production build too, for a deployed preview where people give feedback.
120
+
121
+ ### Components need no tags
122
+
123
+ React keeps its component tree at runtime, so a capture reads it. Every component of your app is in the capture under its own name, with its props as its data and the `file:line` of its declaration:
124
+
125
+ ```tsx
126
+ export function TodoRow({ item, onToggle }: { item: TodoItem; onToggle: () => void }) {
127
+ return <li>…</li>;
128
+ }
129
+ ```
130
+
131
+ A capture shows `TodoRow` with `item: {id: "…", title: "Oat milk", …}` at `src/components/TodoRow.tsx:3`.
132
+
133
+ - A component is found when it is declared at the top level of a module: a function, a class, an arrow function, or a `memo` or `forwardRef` call. A component declared inside another function is not.
134
+ - A library's components, such as a router's `Link`, stay out of the tree. The elements they draw still appear.
135
+ - `children` and functions are left out of the data, and a prop that is JSX reads as its tag, such as `<Icon>`.
136
+ - A component that renders several elements is one box around them. A component that draws through a portal sits where it draws.
137
+
138
+ ### Tag a region, or add state
139
+
140
+ `feedback(name, data)` returns a ref. Use it for a region that is drawn inline, without a component of its own:
141
+
142
+ ```tsx
143
+ import { feedback } from '@stefan.inc/feedback-engine/react';
144
+
145
+ <figure ref={feedback('Chart', () => plot)}>…</figure>;
146
+ ```
147
+
148
+ React keeps hook state without names, so a capture cannot read it. To report state, tag the component's root element under the component's own name. The tag's data then replaces the props:
149
+
150
+ ```tsx
151
+ export function TodoDetailDialog({ item }: { item: TodoItem }) {
152
+ const [draft, setDraft] = useState({ ...item });
153
+ return <dialog ref={feedback('TodoDetailDialog', () => ({ item: draft }))}>…</dialog>;
154
+ }
155
+ ```
156
+
157
+ The data function runs when a capture is taken, never while rendering. On an element that already has a ref, call both from one ref function.
158
+
159
+ ## Next.js
160
+
161
+ Requires Next.js 16 and React 19. Turbopack, the default, and webpack (`--webpack`) both work. Wrap your config:
162
+
163
+ ```ts
164
+ // next.config.ts
165
+ import { withFeedbackEngine } from '@stefan.inc/feedback-engine/next';
166
+
167
+ export default withFeedbackEngine({
168
+ // your config
169
+ });
170
+ ```
171
+
172
+ `withFeedbackEngine()` does what the [React plugin](#react) does: it registers your components, compiles the editor, and writes each HTML element's `file:line` into `data-feedback-source` in `next dev`. It also adds the package to `transpilePackages`, and keeps your own `turbopack.rules` and `webpack` function.
173
+
174
+ Turn Feedback on from a client component in your root layout:
175
+
176
+ ```tsx
177
+ // app/Feedback.tsx
178
+ 'use client';
179
+
180
+ import { setupFeedbackEngine } from '@stefan.inc/feedback-engine/react';
181
+ import { useEffect } from 'react';
182
+
183
+ export function Feedback() {
184
+ useEffect(() => setupFeedbackEngine({ app: 'My App', button: true }).destroy, []);
185
+ return null;
186
+ }
187
+ ```
188
+
189
+ ```tsx
190
+ // app/layout.tsx
191
+ <body>
192
+ {children}
193
+ <Feedback />
194
+ </body>
195
+ ```
196
+
197
+ - Client components are in the capture under their own names, as in a Vite app. A server component leaves no component in the page, so it is not a node. The elements it draws are, each with its own `file:line`.
198
+ - On a deployed preview, such as a Vercel preview link, pass `withFeedbackEngine(config, { elementSources: true })` so a production build keeps every element's `file:line`. Components keep theirs in every build without it. The attribute puts your file paths in the page's HTML, so leave it off a public production deploy, for example with `elementSources: process.env.VERCEL_ENV === 'preview'`.
199
+ - To keep Feedback off a production deploy, render `<Feedback />` only where you want it, for example behind `process.env.NEXT_PUBLIC_VERCEL_ENV !== 'production'`.
200
+ - `feedbackProcrastimate()` is a Vite plugin, so a Next.js app has no ProcrastiMate entry unless you pass `procrastimate: { url }` for a proxy of your own.
201
+
202
+ ## Component data and untagged content
203
+
204
+ Data reads like code, with the limits of the iOS package: `{kg: 72.575, note: null}` for a plain object, `Entry(kg: 72.575, note: null)` for a class instance, 3 decimals, 3 levels, 10 elements, and 1,500 characters. Functions and DOM nodes are skipped at any depth. Give a class a `toFeedback()` method to choose how it reads.
205
+
206
+ Untagged content still appears. Buttons, links, fields, headings, images, and text come from the DOM with their ARIA role and accessible name, and each one attaches to the component around it. A button or a link is one element, such as `Link "Work 3"`, so the text inside it can't be picked by itself. A tagged component inside it still can. In a development build every element also reports its own `file:line`, so feedback on an untagged button names that button's line.
207
+
208
+ ## Set up your app's coding agents
209
+
210
+ [`skills/feedback-accessibility/SKILL.md`](https://github.com/smirea/feedback-engine/blob/master/skills/feedback-accessibility/SKILL.md) is the playbook for making screens accessible and precise to point at, with a section for Svelte and one for React: the accessibility rules, what to tag, and how to check a screen. To have your app's agents follow it, add this to the app's `AGENTS.md` (or `CLAUDE.md`), with `React` in place of `Svelte` for a React app:
211
+
212
+ ```md
213
+ - When you build or change a Svelte screen, row, card, or chart, follow Feedback's accessibility skill. Read the latest with `gh api repos/smirea/feedback-engine/contents/skills/feedback-accessibility/SKILL.md -H 'Accept: application/vnd.github.raw'`.
214
+ ```
215
+
216
+ ## Give feedback
217
+
218
+ The editor works as on iOS, with these differences:
219
+
220
+ - Hover the screenshot to see what a click would select.
221
+ - Hold Ctrl and scroll, or pinch on a trackpad, to zoom up to 4×.
222
+ - Enter adds the feedback. Shift with Enter adds a line.
223
+ - **Share** lists **Image**, **JSON**, and **Image and JSON (ZIP)**. Each one then offers **Copy Feedback**, **Save File**, and, where the browser can share files, **Share…**. A browser takes one clipboard item per copy, so copying the ZIP export puts one item on the clipboard with the image and the JSON, and the place you paste into picks the one it reads.
224
+
225
+ ## Post to ProcrastiMate
226
+
227
+ Optional, and off until the dev server has a token. [ProcrastiMate](https://github.com/smirea/procrastimate) is the task app that Feedback's author files feedback into. A page cannot call ProcrastiMate from another origin, and a token in the page would be public, so the dev server forwards the calls and adds the token:
228
+
229
+ ```ts
230
+ // vite.config.ts
231
+ import { feedbackProcrastimate } from '@stefan.inc/feedback-engine/vite';
232
+
233
+ export default defineConfig({
234
+ plugins: [feedbackProcrastimate({ token: process.env.PROCRASTIMATE_TOKEN }) /* and the plugins above */],
235
+ });
236
+ ```
237
+
238
+ 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.
239
+
240
+ - The token is a ProcrastiMate API token. `feedbackProcrastimate({ url })` names another ProcrastiMate server.
241
+ - 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.
242
+ - For a proxy of your own, pass its address to the page instead: `setupFeedbackEngine({ procrastimate: { url: '/my-proxy' } })`.
243
+
244
+ ## How capture works
245
+
246
+ - The browser gives a page no way to read its own pixels without a permission prompt, so Feedback draws the DOM again into a canvas with [modern-screenshot](https://github.com/qq15725/modern-screenshot). On the example app, a scrolled page differs from the browser's own screenshot in under 0.5% of pixels, and a page with an open dialog in about 1%.
247
+ - The whole document is drawn at its full scroll height in one pass. Nothing scrolls on screen. The window jumps to its origin and back inside one task, so a sticky bar is read where the document has it, and scroll listeners run.
248
+ - Content that stays put while the page scrolls, such as a `position: fixed` tab bar, is drawn where it was on screen, over the visible part of the capture.
249
+ - A modal `<dialog>`, an open popover, and an `aria-modal` dialog are separate layers. Clicks on a layer only select what is inside it, and whatever it hides completely is left out of the tree.
250
+ - Roles and names come from the DOM with [dom-accessibility-api](https://github.com/eps1lon/dom-accessibility-api). There is nothing to switch on first, and reading a screen takes a few milliseconds.
251
+
252
+ ## Limits
253
+
254
+ - The screenshot is a re-draw, not the screen's pixels. A `<canvas>`, an inline SVG, and an image from another origin that allows CORS are drawn. An image from an origin that does not allow CORS, a `<video>`, and an iframe can come out blank, and a field's placeholder is drawn in its text color. It is tested in Chromium, in Google Chrome, and in Playwright's WebKit, not in Safari itself.
255
+ - A very tall page is drawn at a lower scale, so the capture fits a 16 megapixel canvas.
256
+ - A scroll container inside the page shows what was on screen in it.
257
+ - A minified production build shows a class's minified name in component data, such as `a(count: 2)`.
258
+ - Element locations for untagged content exist only in development builds, unless a React app turns on `elementSources`. Components keep theirs in every build.
259
+ - React: a capture reads fields that are internal to React, the ones React's own developer tools read. If React renames them, components found without a tag are missing, and tagged regions and elements still appear. Bundlers other than Vite and Next.js are not supported.
260
+ - A shake does not trigger Feedback on phones, where `button: true` or `countdown()` from a menu stands in for it, and the task name is not summarized by an on-device model. [spec/features.md](https://github.com/smirea/feedback-engine/blob/master/spec/features.md) lists both as planned.
261
+
262
+ ## Drive it from a script
263
+
264
+ `setupFeedbackEngine()` also puts the engine on `globalThis.__feedbackEngine`. `__feedbackEngine.present()` opens the editor without the click, and `__feedbackEngine.lastExport` holds the files of the last export as `{ name, blob }`, written when a Share menu entry is chosen. `packages/web/e2e/feedback.e2e.ts` does both with Playwright, for the Svelte app and the React app.
265
+
266
+ ## Webhooks
267
+
268
+ 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
+
270
+ ```ts
271
+ import { githubIcon, setupFeedbackEngine } from '@stefan.inc/feedback-engine/svelte'; // or '/react'
272
+
273
+ setupFeedbackEngine({
274
+ webhooks: [{ name: 'GitHub Issue', url: 'https://hooks.example.com/feedback', image: githubIcon }],
275
+ });
276
+ ```
277
+
278
+ 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.
279
+
280
+ ## Releases
281
+
282
+ 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.
283
+
284
+ ## License
12
285
 
13
- Setup for Svelte, React, and Next.js, and everything else the package does, is in the [repository's README](https://github.com/smirea/feedback-engine#web). [CHANGELOG.md](https://github.com/smirea/feedback-engine/blob/master/packages/web/CHANGELOG.md) lists every release.
286
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stefan.inc/feedback-engine",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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",