@antone-io/render-picker 0.0.0-stage → 0.3.2

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 Antone Barbaud
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 CHANGED
@@ -1,3 +1,301 @@
1
- # Temporary Holding Version
1
+ # render-picker
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Dev-only toolkit for **Next.js + React 19** — and **PrestaShop / Smarty (`.tpl`)**: click any element
4
+ and get a clipboard-ready snippet for your AI agent — route, XPath, CSS selector, React component (or
5
+ `.tpl` template) **and its source `file:line`** — plus **Alt+click to open the source in your editor**
6
+ (VS Code, Cursor, WebStorm… — 10 supported) (and **Ctrl+click to jump to the usage site** — where a
7
+ shared component is written, not its definition).
8
+
9
+ > **PrestaShop** pages resolve the source to the Smarty `.tpl:line` — see
10
+ > [PrestaShop / Smarty](#prestashop--smarty-tpl) below.
11
+
12
+ ```
13
+ [renderPicker]
14
+ Page: /dashboard
15
+ XPath: /html/body/main/section
16
+ CSS: main > section
17
+ Text: Revenue this month
18
+ Source: src/components/dashboard-card.tsx:42
19
+ React: DashboardCard
20
+ ```
21
+
22
+ `Text:` (below `CSS:`) is the element's text content (whitespace collapsed, truncated), omitted when empty.
23
+
24
+ `React:` lists the nearest component chain (outer → inner), e.g. `List > ListItem > Button` — the
25
+ sub-components wrapping the picked element, same-file ones included. The hover tooltip shows the same chain.
26
+
27
+ The picking engine is fully self-contained (no runtime dependency): hit-test, overlay, hover
28
+ tooltip, multi-selection, XPath/CSS generation and the arming hotkey all live in `src/core/`.
29
+ React 19 removed `_debugSource`, so the source `file:line` can't be read from the picked element
30
+ alone. `render-picker` annotates the DOM with `data-component` / `data-source`, resolved at runtime
31
+ from React's `_debugStack` through the dev chunks' sourcemaps (plain and index maps, Turbopack
32
+ included), and merges that into the pick output.
33
+
34
+ ## Install
35
+
36
+ ```bash
37
+ npm install @antone-io/render-picker
38
+ ```
39
+
40
+ ## Setup (Next.js App Router)
41
+
42
+ **1. `next.config.mjs`** — exposes the absolute project root to the client, dev only:
43
+
44
+ ```js
45
+ import { withRenderPicker } from "@antone-io/render-picker/next";
46
+
47
+ export default withRenderPicker({
48
+ // your config
49
+ });
50
+ ```
51
+
52
+ **2. `src/instrumentation-client.ts`** — DOM annotation, Ctrl+click → your editor, console hush:
53
+
54
+ ```ts
55
+ import { initRenderPicker } from "@antone-io/render-picker/client";
56
+
57
+ initRenderPicker();
58
+ ```
59
+
60
+ **3. Picker button** — mount once in your root layout:
61
+
62
+ ```tsx
63
+ "use client";
64
+
65
+ import { usePathname } from "next/navigation";
66
+ import { RenderPickerButton } from "@antone-io/render-picker/react";
67
+
68
+ export function DevRenderPicker() {
69
+ const pathname = usePathname();
70
+ if (process.env.NODE_ENV === "production") return null;
71
+ return <RenderPickerButton pathname={pathname} project="my-app" />;
72
+ }
73
+ ```
74
+
75
+ ## Usage
76
+
77
+ | Gesture | Effect |
78
+ |---|---|
79
+ | Double-tap `Shift` or click the aim icon | Arm the picker |
80
+ | Click | Copy one element and close |
81
+ | `Shift`+click, then `Enter` | Copy several elements at once |
82
+ | Right-click | Context menu: copy the HTML, the rendering, the classes, the XPath, or hide the element (`display:none`, live only, not persisted — survives the host app's React re-renders, unlike removing the DOM node) |
83
+ | `Ctrl`+`F` `F` | Search elements (works even when the picker is off) |
84
+ | `Ctrl`+`I` | Open the inspection panel on the HTML tab, at the hovered element |
85
+ | `Esc` | Cancel |
86
+ | `Alt`+click (picker off) | Open the element's source in your editor (see **Editor** below) |
87
+ | `Ctrl`+click (picker **armed**) | Jump to the usage site |
88
+
89
+ ### Right-click menu — "Copier le rendu" (self-contained HTML)
90
+
91
+ Right-click a picked element (on the page or in the HTML tree) → **Copier le rendu** copies a
92
+ **self-contained** HTML snippet: every node carries its **computed styles inline** (filtered to
93
+ values ≠ the UA default, inherited props deduplicated against the parent, CSS custom props `--*`
94
+ excluded). Below each tag, a comment maps its **own** classes to their CSS; classes shared by
95
+ several tags move to a **global** block, and the `var(--x)` they reference are **resolved** at the
96
+ bottom. Element **states** (`:hover`, `:focus`, `:active`…) are emitted in a trailing `<style>`
97
+ block with their `var()` resolved and `!important` added (to beat the inline `style=`), so the
98
+ pasted snippet **reproduces interactions**. Paste it anywhere and it renders — and reacts — almost
99
+ identically, without the page's CSS.
100
+
101
+ ```html
102
+ <p class="text-lg font-medium text-white" style="color: rgb(255, 255, 255); font-size: 18px; font-weight: 500; line-height: 28px; margin: 0px">
103
+ <!-- .text-lg { font-size: var(--text-lg); line-height: var(--text-lg--line-height) } -->
104
+ Collaboration en temps réel
105
+ </p>
106
+
107
+ <!-- Classes globales (utilisées sur plusieurs balises)
108
+ .font-medium { font-weight: var(--font-weight-medium) }
109
+ .text-white { color: var(--color-white) }
110
+ -->
111
+
112
+ <!-- Variables CSS
113
+ --text-lg: 1.125rem
114
+ --font-weight-medium: 500
115
+ --color-white: #fff
116
+ -->
117
+
118
+ <style>
119
+ .btn:hover { background-color: #1e293b !important }
120
+ .btn:focus-visible { outline: 2px solid #3b82f6 !important }
121
+ </style>
122
+ ```
123
+
124
+ ## API
125
+
126
+ ### `initRenderPicker(options?) => dispose`
127
+
128
+ | Option | Type | Default | |
129
+ |---|---|---|---|
130
+ | `enabled` | `boolean` | `NODE_ENV !== "production"` | Master switch |
131
+ | `projectRoot` | `string` | `process.env.NEXT_PUBLIC_PROJECT_ROOT`, then `<meta name="render-picker-root">` | Absolute root used to build the editor URI (`vscode://file/…`, `webstorm://open?file=…`) |
132
+ | `source` | `"react" \| "prestashop"` | `"react"` | `"prestashop"` resolves `data-source` from Smarty `rp@file:line` comments instead of React fibers |
133
+ | `clickToSource` | `boolean` | `true` | Alt/Ctrl+click → your editor |
134
+ | `annotate` | `boolean \| { delayMs }` | `true`, `2000` ms | Annotation starts after hydration to avoid attribute mismatches (ignored for `source: "prestashop"`) |
135
+ | `hushConsole` | `boolean \| RegExp[]` | `true` | Drops "Download the React DevTools", `[HMR] connected`, `[Fast Refresh]` logs |
136
+
137
+ Returns a function that removes every listener, observer and console patch.
138
+
139
+ ### `<RenderPickerButton>`
140
+
141
+ Props: `pathname` (copied route; the page query string `location.search` is appended when it has no `?`, the hash is dropped), `color`, `hotkey` (default `"shift shift"` — double-tap Shift), `multi`
142
+ (default `true`), `onPick`, `onPickMany`. Custom `onPick` / `onPickMany` receive the
143
+ already-enriched results and the formatted text. The copied text and the button tooltip use the
144
+ `[renderPicker]` prefix; `formatResult` / `formatResults` (and the `useRenderPicker` hook) are
145
+ exported from `@antone-io/render-picker/react` to build the same text or wire your own trigger.
146
+
147
+ ### `withRenderPicker(nextConfig)`
148
+
149
+ Adds `env.NEXT_PUBLIC_PROJECT_ROOT = process.cwd()` outside production. Accepts a config object or
150
+ function. If a `render-picker.config.json` exists at the project root, it is also injected as
151
+ `NEXT_PUBLIC_RENDER_PICKER_CONFIG` (dev only).
152
+
153
+ ### Settings — remappable commands
154
+
155
+ Layout overlays (padding / gap / margin) are **always on** when hovering while armed — no toggle.
156
+
157
+ The settings dropdown (gear) holds a **Commands** accordion to remap every shortcut: the arm hotkey
158
+ (default double `Shift`), the mouse gestures — **Copy** (default click), **Multi-select**
159
+ (default `Shift`+click), **Open source** (default `Alt`+click), **Open usage** (default
160
+ `Ctrl`+click), each a *modifier* + *click type* (click / right-click / double-click) — and the
161
+ keyboard keys **Confirm** (default `Enter`) and **Cancel** (default `Esc`), plus **Search**
162
+ (default `Ctrl` + double-tap `F`, global — works even when the picker is off) and **Inspector**
163
+ (default `Ctrl`+`I`). The right-click context menu (`copyHtml` gesture) is no longer listed in
164
+ the dropdown; it stays configurable in `render-picker.config.json`. Search opens an element finder: type a tag (`div`), a class (`.card`), a
165
+ CSS selector or a React component name (`Button`, only where the npm annotator runs); partial
166
+ typing autocompletes (`div.` lists the divs, `div.car` matches classes starting with `car`) and
167
+ `Ctrl+Z`/`Ctrl+Y` walk the query history. Results
168
+ group into suggestions (selector + occurrence count); hovering a suggestion (mouse) shows ONLY
169
+ its occurrences as net rects, while keyboard selection keeps every match visible with the
170
+ current occurrence highlighted — the ‹ › arrows (or ↑/↓) cycle WITHIN the active suggestion's
171
+ elements on the page (scroll at each step), the suggestion line itself only changes by mouse
172
+ hover — live rects (follows scroll/resize); the
173
+ inspector's own hover rect is paused while searching. Hovering a search rect then shows the element
174
+ tooltip (component, metrics, dimensions), clicking one copies the enriched snippet (pick),
175
+ right-clicking one opens the context menu; the ‹ › arrow buttons (or ↑/↓, or hovering a row) switch the
176
+ active element, clicking a row refines the query (tag + classes back into the input), `Enter`
177
+ scrolls to it. The
178
+ SettingsBar also hosts a magnifier icon next to the gear (npm package and Chrome extension).
179
+ `Esc` always disarms as a safety net.
180
+
181
+ Choices are saved to `localStorage` by default. To persist them to a committable
182
+ **`render-picker.config.json`** at the project root, add a dev API route (one line) — changes then
183
+ write the file (GET reads it back). Settings are read **live**: UI remaps apply immediately, and
184
+ manual edits to `render-picker.config.json` are picked up on window focus — no `next dev` restart
185
+ needed (the dev route reads the file from disk).
186
+
187
+ ```ts
188
+ // app/api/render-picker/route.ts
189
+ export { GET, POST } from "@antone-io/render-picker/next";
190
+ ```
191
+
192
+ ```json
193
+ // render-picker.config.json (written/read by the route)
194
+ {
195
+ "commands": {
196
+ "arm": "shift shift",
197
+ "copy": { "modifier": "none", "trigger": "click" },
198
+ "copyHtml": { "modifier": "none", "trigger": "rightclick" }, // opens the context menu
199
+ "multi": { "modifier": "shift", "trigger": "click" },
200
+ "confirm": "enter",
201
+ "cancel": "escape",
202
+ "inspect": { "modifier": "ctrl", "key": "i", "double": false },
203
+ "search": { "modifier": "ctrl", "key": "f", "double": true },
204
+ "source": { "modifier": "alt", "trigger": "click" },
205
+ "usage": { "modifier": "ctrl", "trigger": "click" },
206
+ "editor": "vscode" // vscode | vscode-insiders | cursor | windsurf | vscodium | zed | webstorm | phpstorm | idea | pycharm
207
+ },
208
+ "panel": { "width": 420, "height": 320 }
209
+ }
210
+ ```
211
+
212
+ Without the route, changes stay in `localStorage` (no crash). The handlers are no-ops in production.
213
+
214
+ ### Editor — where Alt/Ctrl+click opens the source
215
+
216
+ The settings dropdown has an **Éditeur** select (saved as `commands.editor`, default `vscode`).
217
+
218
+ **No system setup needed** (no URL scheme to register, no JetBrains Toolbox): with the dev route
219
+ installed (`app/api/render-picker/route.ts`, see above), Alt/Ctrl+click asks the `next dev` server
220
+ to launch the IDE itself — on Windows it reuses the executable of the IDE **already open**
221
+ (`Code.exe`, `webstorm64.exe`, `phpstorm64.exe`…), on macOS JetBrains IDEs go through
222
+ `open -na "<App>.app"`, elsewhere the IDE CLI on the `PATH` (`code`, `cursor`, `zed`, `webstorm`…).
223
+ No shell is involved and only files inside the project can be opened.
224
+
225
+ Without the route (or if the IDE isn't found), it falls back to the editor's URL scheme:
226
+
227
+ | `editor` | Editor | Fallback URI |
228
+ |---|---|---|
229
+ | `vscode` | VS Code | `vscode://file/<abs>:<line>` |
230
+ | `vscode-insiders` | VS Code Insiders | `vscode-insiders://file/…` |
231
+ | `cursor` | Cursor | `cursor://file/…` |
232
+ | `windsurf` | Windsurf | `windsurf://file/…` |
233
+ | `vscodium` | VSCodium | `vscodium://file/…` |
234
+ | `zed` | Zed | `zed://file/<abs>:<line>:<col>` |
235
+ | `webstorm` | WebStorm | `webstorm://open?file=<abs>&line=<line>` |
236
+ | `phpstorm` | PhpStorm | `phpstorm://open?file=…` |
237
+ | `idea` | IntelliJ IDEA | `idea://open?file=…` |
238
+ | `pycharm` | PyCharm | `pycharm://open?file=…` |
239
+
240
+ The fallback URI only works if the OS knows the scheme (VS Code / Cursor installers register it;
241
+ JetBrains needs Toolbox) — the route avoids that. An unknown value in `render-picker.config.json`
242
+ falls back to VS Code.
243
+
244
+ ### Lower-level exports (`@antone-io/render-picker/client`)
245
+
246
+ `enrichResult`, `findPickedElement`, `annotate`, `annotateTree`, `componentInfo`,
247
+ `initComponentAnnotator`, `initClickToSource`, `buildVscodeUri`, `buildEditorUri`, `EDITORS`, `hushConsoleNoise`,
248
+ `resolvePosition`, `normalizeSourcePath`, `loadSettings`, `saveSettings`.
249
+
250
+ ## PrestaShop / Smarty (`.tpl`)
251
+
252
+ A ready-to-use dev module ships in [`integrations/prestashop/renderpicker/`](integrations/prestashop/renderpicker/)
253
+ (bundled JS included — **nothing to build**). Install in 3 steps:
254
+
255
+ 1. **Copy** the `renderpicker/` folder into your shop's `modules/`:
256
+ ```
257
+ integrations/prestashop/renderpicker/ → <your-shop>/modules/renderpicker/
258
+ ```
259
+ 2. **Enable** it: back-office → *Modules* → search "render-picker" → *Install*.
260
+ 3. **Turn on dev mode**: `_PS_MODE_DEV_ = true;` in `config/defines.inc.php`, then clear the cache
261
+ (back-office → *Advanced Parameters → Performance → Clear cache*).
262
+
263
+ That's it — open any front-office page, arm the picker (double-tap **Shift**), pick an element, and
264
+ **Ctrl+click** opens its `.tpl` at the right line in your editor. The module auto-injects the script,
265
+ the project root and `RenderPicker.init()`; it is fully inert when `_PS_MODE_DEV_` is off.
266
+
267
+ Settings menu also has a **"Rectangles modules PrestaShop"** toggle: permanent rectangles over each
268
+ root module (name + render duration), right-click → **Modules** submenu to copy its name, relative/
269
+ absolute folder path, back-office config URL, or the whole page's module tree as Markdown. Details
270
+ (incl. the extra `PS_ADMIN_DIRNAME` env var for the config-URL link) in
271
+ [`integrations/prestashop/renderpicker/README.md`](integrations/prestashop/renderpicker/README.md#rectangles-permanents-modules-prestashop).
272
+
273
+ **Docker / remote server:** the server reports its own root (e.g. a container path
274
+ `/var/www/html`), which doesn't exist on the host where your editor runs. Set the host path once, in
275
+ the browser console, and reload:
276
+
277
+ ```js
278
+ localStorage.renderPickerRoot = "C:/Users/you/path/to/public_html"
279
+ ```
280
+
281
+ It overrides the server-reported root (the per-file paths are identical, only the root prefix differs).
282
+
283
+ <details>
284
+ <summary>How it works / rebuild the bundle</summary>
285
+
286
+ The module registers a Smarty prefilter that emits per-element markers (`<!-- rp@themes/.../x.tpl:42 -->`),
287
+ read client-side to set `data-source`. Ctrl+click opens `vscode://file/<root>/<relpath>:<line>` (no server
288
+ needed). To rebuild the bundled JS from source: `npm run build:standalone && npm run sync:prestashop`.
289
+ </details>
290
+
291
+ ## Limitations
292
+
293
+ - Next.js dev builds only: source resolution reads the React `_debugStack` — **Turbopack** frames
294
+ (`/_next/static/chunks/*._.js` + their sourcemaps) and **Webpack** dev frames
295
+ (`webpack-internal:///…/src/….tsx:line`, source path read directly).
296
+ - Never ships the project path to production: both `withRenderPicker` and `initRenderPicker` are
297
+ no-ops when `NODE_ENV === "production"`.
298
+
299
+ ## License
300
+
301
+ MIT