@david-xpn/llm-ui-feedback 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 david-xpn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,177 @@
1
+ # @david-xpn/llm-ui-feedback
2
+
3
+ Drop-in React feedback widget that captures component context for LLM consumption.
4
+
5
+ Users click on any element in your app, leave a comment, and the widget captures a rich context bundle — React component tree, props, screenshot with marker, and a pre-formatted LLM prompt — ready to paste into Claude, ChatGPT, or any LLM chat.
6
+
7
+ ## Features
8
+
9
+ - **One-line integration** — add `<FeedbackWidget />` to your root, done
10
+ - **React component tree capture** — walks the fiber tree to extract component names and props
11
+ - **Screenshot with X marker** — captures the viewport and marks the clicked element
12
+ - **LLM-ready prompt** — generates a structured prompt with page URL, component path, props, element text, and user comment
13
+ - **Copy & download** — copy the prompt to clipboard and download the screenshot
14
+ - **localStorage persistence** — no backend needed, all data stays client-side
15
+ - **Feedback list panel** — view, copy, and manage all saved feedback entries
16
+ - **Configurable** — position, color, and keyboard shortcut
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ npm install @david-xpn/llm-ui-feedback
22
+ ```
23
+
24
+ ## Quick Start
25
+
26
+ ```tsx
27
+ import { FeedbackWidget } from '@david-xpn/llm-ui-feedback';
28
+
29
+ function App() {
30
+ return (
31
+ <>
32
+ <YourApp />
33
+ <FeedbackWidget />
34
+ </>
35
+ );
36
+ }
37
+ ```
38
+
39
+ That's it. A floating `+` button appears in the bottom-right corner. Click it to enter pick mode, click any element, leave a comment, and get an LLM-ready prompt.
40
+
41
+ ## Props
42
+
43
+ | Prop | Type | Default | Description |
44
+ | --- | --- | --- | --- |
45
+ | `position` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | `'bottom-right'` | Corner position for the floating button |
46
+ | `buttonColor` | `string` | `'#3b82f6'` | Hex color for the FAB button |
47
+ | `hotkey` | `string` | `undefined` | Keyboard shortcut to toggle pick mode (e.g. `'Alt+F'`) |
48
+
49
+ ### Example with all props
50
+
51
+ ```tsx
52
+ <FeedbackWidget
53
+ position="bottom-left"
54
+ buttonColor="#10b981"
55
+ hotkey="Alt+F"
56
+ />
57
+ ```
58
+
59
+ ## How It Works
60
+
61
+ 1. User clicks the `+` floating button to enter **pick mode**
62
+ 2. User clicks any element on the page
63
+ 3. The widget captures:
64
+ - **Component path** — React fiber tree walk (e.g. `App > Layout > Dashboard > MetricCard`)
65
+ - **Props** — scalar props (strings, numbers, booleans) from each component
66
+ - **Element text** — innerText of the clicked element (truncated to 100 chars)
67
+ - **Page URL** — current `window.location.href`
68
+ - **Screenshot** — viewport capture via `html2canvas-pro` with a red X at the click position
69
+ 4. User types a comment and saves
70
+ 5. The entry is stored in `localStorage` with a pre-formatted LLM prompt
71
+ 6. User can **copy the prompt** and **download the screenshot** to paste into any LLM
72
+
73
+ ### Example prompt output
74
+
75
+ ```
76
+ Page: https://myapp.com/dashboard/metrics
77
+ Component: App > Layout > Dashboard > MetricCard
78
+ Props:
79
+ MetricCard: {"metricId":"revenue","period":"Q4"}
80
+ Element text: "Revenue: $1.2M"
81
+
82
+ User feedback: "This number looks wrong, should be $1.4M"
83
+
84
+ Screenshot attached with red X marking the clicked element.
85
+ ```
86
+
87
+ ## Exported API
88
+
89
+ ```ts
90
+ // Components
91
+ import { FeedbackWidget } from '@david-xpn/llm-ui-feedback';
92
+
93
+ // Types
94
+ import type {
95
+ FeedbackWidgetProps,
96
+ FeedbackEntry,
97
+ CapturedContext,
98
+ ComponentInfo,
99
+ WidgetPosition,
100
+ } from '@david-xpn/llm-ui-feedback';
101
+
102
+ // Storage utilities (for programmatic access)
103
+ import {
104
+ loadEntries,
105
+ deleteEntry,
106
+ clearEntries,
107
+ } from '@david-xpn/llm-ui-feedback';
108
+ ```
109
+
110
+ ### Storage utilities
111
+
112
+ | Function | Description |
113
+ | --- | --- |
114
+ | `loadEntries()` | Returns all saved `FeedbackEntry[]` from localStorage |
115
+ | `deleteEntry(id)` | Deletes a single entry by ID |
116
+ | `clearEntries()` | Removes all feedback entries |
117
+
118
+ ## Production Setup
119
+
120
+ In production builds, minifiers rename component functions (`MetricCard` becomes `t`), which makes the component path useless. Configure your bundler to preserve function names:
121
+
122
+ ### Vite
123
+
124
+ ```ts
125
+ // vite.config.ts
126
+ export default defineConfig({
127
+ esbuild: {
128
+ keepNames: true,
129
+ },
130
+ });
131
+ ```
132
+
133
+ ### webpack (Terser)
134
+
135
+ ```js
136
+ // webpack.config.js
137
+ module.exports = {
138
+ optimization: {
139
+ minimizer: [
140
+ new TerserPlugin({
141
+ terserOptions: { keep_fnames: true },
142
+ }),
143
+ ],
144
+ },
145
+ };
146
+ ```
147
+
148
+ ### Next.js
149
+
150
+ ```js
151
+ // next.config.js
152
+ module.exports = {
153
+ webpack: (config) => {
154
+ const terser = config.optimization?.minimizer?.find(
155
+ (p) => p.constructor.name === 'TerserPlugin'
156
+ );
157
+ if (terser) {
158
+ terser.options.terserOptions = {
159
+ ...terser.options.terserOptions,
160
+ keep_fnames: true,
161
+ };
162
+ }
163
+ return config;
164
+ },
165
+ };
166
+ ```
167
+
168
+ See [docs/production-setup.md](docs/production-setup.md) for more bundler configurations.
169
+
170
+ ## Requirements
171
+
172
+ - React 18+
173
+ - Browser environment (uses `localStorage`, `document`, `html2canvas-pro`)
174
+
175
+ ## License
176
+
177
+ MIT
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+
3
+ type WidgetPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
4
+ interface ComponentInfo {
5
+ name: string;
6
+ props: Record<string, unknown>;
7
+ }
8
+ interface FeedbackEntry {
9
+ id: string;
10
+ timestamp: string;
11
+ url: string;
12
+ componentPath: string;
13
+ components: ComponentInfo[];
14
+ elementText: string;
15
+ comment: string;
16
+ screenshot: string | null;
17
+ prompt: string;
18
+ }
19
+ interface CapturedContext {
20
+ url: string;
21
+ componentPath: string;
22
+ components: ComponentInfo[];
23
+ elementText: string;
24
+ clickX: number;
25
+ clickY: number;
26
+ }
27
+
28
+ interface FeedbackWidgetProps {
29
+ /** Corner position for the floating buttons. Default: 'bottom-right' */
30
+ position?: WidgetPosition;
31
+ /** Hex color for the FAB and badge accent. Default: '#3b82f6' */
32
+ buttonColor?: string;
33
+ /** Keyboard shortcut to toggle pick mode, e.g. 'Alt+F'. No default (opt-in only). */
34
+ hotkey?: string;
35
+ }
36
+ declare function FeedbackWidget({ position, buttonColor, hotkey, }?: FeedbackWidgetProps): React.ReactPortal;
37
+
38
+ declare function loadEntries(): FeedbackEntry[];
39
+ declare function deleteEntry(id: string): void;
40
+ declare function clearEntries(): void;
41
+
42
+ export { type CapturedContext, type ComponentInfo, type FeedbackEntry, FeedbackWidget, type FeedbackWidgetProps, type WidgetPosition, clearEntries, deleteEntry, loadEntries };
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+
3
+ type WidgetPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
4
+ interface ComponentInfo {
5
+ name: string;
6
+ props: Record<string, unknown>;
7
+ }
8
+ interface FeedbackEntry {
9
+ id: string;
10
+ timestamp: string;
11
+ url: string;
12
+ componentPath: string;
13
+ components: ComponentInfo[];
14
+ elementText: string;
15
+ comment: string;
16
+ screenshot: string | null;
17
+ prompt: string;
18
+ }
19
+ interface CapturedContext {
20
+ url: string;
21
+ componentPath: string;
22
+ components: ComponentInfo[];
23
+ elementText: string;
24
+ clickX: number;
25
+ clickY: number;
26
+ }
27
+
28
+ interface FeedbackWidgetProps {
29
+ /** Corner position for the floating buttons. Default: 'bottom-right' */
30
+ position?: WidgetPosition;
31
+ /** Hex color for the FAB and badge accent. Default: '#3b82f6' */
32
+ buttonColor?: string;
33
+ /** Keyboard shortcut to toggle pick mode, e.g. 'Alt+F'. No default (opt-in only). */
34
+ hotkey?: string;
35
+ }
36
+ declare function FeedbackWidget({ position, buttonColor, hotkey, }?: FeedbackWidgetProps): React.ReactPortal;
37
+
38
+ declare function loadEntries(): FeedbackEntry[];
39
+ declare function deleteEntry(id: string): void;
40
+ declare function clearEntries(): void;
41
+
42
+ export { type CapturedContext, type ComponentInfo, type FeedbackEntry, FeedbackWidget, type FeedbackWidgetProps, type WidgetPosition, clearEntries, deleteEntry, loadEntries };