@antone-io/render-picker 0.0.0-stage → 0.3.3
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 +21 -0
- package/README.md +324 -2
- package/dist/chunk-FM3HLV7V.js +105 -0
- package/dist/chunk-FM3HLV7V.js.map +1 -0
- package/dist/chunk-RT6TNNKG.js +6281 -0
- package/dist/chunk-RT6TNNKG.js.map +1 -0
- package/dist/chunk-XUPSSH7J.js +2676 -0
- package/dist/chunk-XUPSSH7J.js.map +1 -0
- package/dist/client.cjs +2498 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +165 -0
- package/dist/client.d.ts +165 -0
- package/dist/client.js +78 -0
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +8885 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +92 -0
- package/dist/index.js.map +1 -0
- package/dist/next.cjs +261 -0
- package/dist/next.cjs.map +1 -0
- package/dist/next.d.cts +19 -0
- package/dist/next.d.ts +19 -0
- package/dist/next.js +234 -0
- package/dist/next.js.map +1 -0
- package/dist/react.cjs +8103 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +94 -0
- package/dist/react.d.ts +94 -0
- package/dist/react.js +20 -0
- package/dist/react.js.map +1 -0
- package/dist/types-DrSxB-xa.d.cts +207 -0
- package/dist/types-DrSxB-xa.d.ts +207 -0
- package/package.json +114 -4
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,325 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/antone-io/render-picker/master/.github/logo.svg" alt="render-picker" width="96" height="96">
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
# render-picker
|
|
6
|
+
|
|
7
|
+
Dev-only toolkit for **Next.js + React 19** — and **PrestaShop / Smarty (`.tpl`)**: click any element
|
|
8
|
+
and get a clipboard-ready snippet for your AI agent — route, XPath, CSS selector, React component (or
|
|
9
|
+
`.tpl` template) **and its source `file:line`** — plus **Alt+click to open the source in your editor**
|
|
10
|
+
(VS Code, Cursor, WebStorm… — 10 supported) (and **Ctrl+click to jump to the usage site** — where a
|
|
11
|
+
shared component is written, not its definition).
|
|
12
|
+
|
|
13
|
+
> **PrestaShop** pages resolve the source to the Smarty `.tpl:line` — see
|
|
14
|
+
> [PrestaShop / Smarty](#prestashop--smarty-tpl) below.
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
[renderPicker]
|
|
18
|
+
Page: /dashboard
|
|
19
|
+
XPath: /html/body/main/section
|
|
20
|
+
CSS: main > section
|
|
21
|
+
Text: Revenue this month
|
|
22
|
+
Source: src/components/dashboard-card.tsx:42
|
|
23
|
+
React: DashboardCard
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`Text:` (below `CSS:`) is the element's text content (whitespace collapsed, truncated), omitted when empty.
|
|
27
|
+
|
|
28
|
+
`React:` lists the nearest component chain (outer → inner), e.g. `List > ListItem > Button` — the
|
|
29
|
+
sub-components wrapping the picked element, same-file ones included. The hover tooltip shows the same chain.
|
|
30
|
+
|
|
31
|
+
The picking engine is fully self-contained (no runtime dependency): hit-test, overlay, hover
|
|
32
|
+
tooltip, multi-selection, XPath/CSS generation and the arming hotkey all live in `src/core/`.
|
|
33
|
+
React 19 removed `_debugSource`, so the source `file:line` can't be read from the picked element
|
|
34
|
+
alone. `render-picker` annotates the DOM with `data-component` / `data-source`, resolved at runtime
|
|
35
|
+
from React's `_debugStack` through the dev chunks' sourcemaps (plain and index maps, Turbopack
|
|
36
|
+
included), and merges that into the pick output.
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install @antone-io/render-picker
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Setup (Next.js App Router)
|
|
45
|
+
|
|
46
|
+
**1. `next.config.mjs`** — exposes the absolute project root to the client, dev only:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
import { withRenderPicker } from "@antone-io/render-picker/next";
|
|
50
|
+
|
|
51
|
+
export default withRenderPicker({
|
|
52
|
+
// your config
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**2. `src/instrumentation-client.ts`** — DOM annotation, Ctrl+click → your editor, console hush:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { initRenderPicker } from "@antone-io/render-picker/client";
|
|
60
|
+
|
|
61
|
+
initRenderPicker();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**3. Picker button** — mount once in your root layout:
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
"use client";
|
|
68
|
+
|
|
69
|
+
import { usePathname } from "next/navigation";
|
|
70
|
+
import { RenderPickerButton } from "@antone-io/render-picker/react";
|
|
71
|
+
|
|
72
|
+
export function DevRenderPicker() {
|
|
73
|
+
const pathname = usePathname();
|
|
74
|
+
if (process.env.NODE_ENV === "production") return null;
|
|
75
|
+
return <RenderPickerButton pathname={pathname} project="my-app" />;
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Usage
|
|
80
|
+
|
|
81
|
+
| Gesture | Effect |
|
|
82
|
+
|---|---|
|
|
83
|
+
| Double-tap `Shift` or click the aim icon | Arm the picker |
|
|
84
|
+
| Click | Copy one element and close |
|
|
85
|
+
| `Shift`+click, then `Enter` | Copy several elements at once |
|
|
86
|
+
| 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) |
|
|
87
|
+
| `Ctrl`+`F` `F` | Search elements (works even when the picker is off) |
|
|
88
|
+
| `Ctrl`+`I` | Open the inspection panel on the HTML tab, at the hovered element |
|
|
89
|
+
| `Esc` | Cancel |
|
|
90
|
+
| `Alt`+click (picker off) | Open the element's source in your editor (see **Editor** below) |
|
|
91
|
+
| `Ctrl`+click (picker **armed**) | Jump to the usage site |
|
|
92
|
+
| Drag a grip (six dots) | Move a floating surface: the aim button, the bottom bar, the search box. A dashed outline shows the original spot: drop the surface on it to send it back. The inspection panel moves freely by its header (no dashed outline, no snap back). Each position is saved in `localStorage` (`renderPicker.pos.<id>`) and kept inside the window |
|
|
93
|
+
|
|
94
|
+
### Right-click menu — "Copier le rendu" (self-contained HTML)
|
|
95
|
+
|
|
96
|
+
Right-click a picked element (on the page or in the HTML tree) → **Copier le rendu** copies a
|
|
97
|
+
**self-contained** HTML snippet: every node carries its **computed styles inline** (filtered to
|
|
98
|
+
values ≠ the UA default, inherited props deduplicated against the parent, CSS custom props `--*`
|
|
99
|
+
excluded). Below each tag, a comment maps its **own** classes to their CSS; classes shared by
|
|
100
|
+
several tags move to a **global** block, and the `var(--x)` they reference are **resolved** at the
|
|
101
|
+
bottom. Element **states** (`:hover`, `:focus`, `:active`…) are emitted in a trailing `<style>`
|
|
102
|
+
block with their `var()` resolved and `!important` added (to beat the inline `style=`), so the
|
|
103
|
+
pasted snippet **reproduces interactions**. Paste it anywhere and it renders — and reacts — almost
|
|
104
|
+
identically, without the page's CSS.
|
|
105
|
+
|
|
106
|
+
```html
|
|
107
|
+
<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">
|
|
108
|
+
<!-- .text-lg { font-size: var(--text-lg); line-height: var(--text-lg--line-height) } -->
|
|
109
|
+
Collaboration en temps réel
|
|
110
|
+
</p>
|
|
111
|
+
|
|
112
|
+
<!-- Classes globales (utilisées sur plusieurs balises)
|
|
113
|
+
.font-medium { font-weight: var(--font-weight-medium) }
|
|
114
|
+
.text-white { color: var(--color-white) }
|
|
115
|
+
-->
|
|
116
|
+
|
|
117
|
+
<!-- Variables CSS
|
|
118
|
+
--text-lg: 1.125rem
|
|
119
|
+
--font-weight-medium: 500
|
|
120
|
+
--color-white: #fff
|
|
121
|
+
-->
|
|
122
|
+
|
|
123
|
+
<style>
|
|
124
|
+
.btn:hover { background-color: #1e293b !important }
|
|
125
|
+
.btn:focus-visible { outline: 2px solid #3b82f6 !important }
|
|
126
|
+
</style>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## API
|
|
130
|
+
|
|
131
|
+
### `initRenderPicker(options?) => dispose`
|
|
132
|
+
|
|
133
|
+
| Option | Type | Default | |
|
|
134
|
+
|---|---|---|---|
|
|
135
|
+
| `enabled` | `boolean` | `NODE_ENV !== "production"` | Master switch |
|
|
136
|
+
| `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=…`) |
|
|
137
|
+
| `source` | `"react" \| "prestashop"` | `"react"` | `"prestashop"` resolves `data-source` from Smarty `rp@file:line` comments instead of React fibers |
|
|
138
|
+
| `clickToSource` | `boolean` | `true` | Alt/Ctrl+click → your editor |
|
|
139
|
+
| `annotate` | `boolean \| { delayMs }` | `true`, `2000` ms | Annotation starts after hydration to avoid attribute mismatches (ignored for `source: "prestashop"`) |
|
|
140
|
+
| `hushConsole` | `boolean \| RegExp[]` | `true` | Drops "Download the React DevTools", `[HMR] connected`, `[Fast Refresh]` logs |
|
|
141
|
+
|
|
142
|
+
Returns a function that removes every listener, observer and console patch.
|
|
143
|
+
|
|
144
|
+
### `<RenderPickerButton>`
|
|
145
|
+
|
|
146
|
+
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`
|
|
147
|
+
(default `true`), `onPick`, `onPickMany`. Custom `onPick` / `onPickMany` receive the
|
|
148
|
+
already-enriched results and the formatted text. The copied text and the button tooltip use the
|
|
149
|
+
`[renderPicker]` prefix; `formatResult` / `formatResults` (and the `useRenderPicker` hook) are
|
|
150
|
+
exported from `@antone-io/render-picker/react` to build the same text or wire your own trigger.
|
|
151
|
+
|
|
152
|
+
### `withRenderPicker(nextConfig)`
|
|
153
|
+
|
|
154
|
+
Adds `env.NEXT_PUBLIC_PROJECT_ROOT = process.cwd()` outside production. Accepts a config object or
|
|
155
|
+
function. If a `render-picker.config.json` exists at the project root, it is also injected as
|
|
156
|
+
`NEXT_PUBLIC_RENDER_PICKER_CONFIG` (dev only).
|
|
157
|
+
|
|
158
|
+
### Settings — remappable commands
|
|
159
|
+
|
|
160
|
+
Layout overlays (padding / gap / margin) are **always on** when hovering while armed — no toggle.
|
|
161
|
+
|
|
162
|
+
The settings dropdown (gear) holds a **Commands** accordion to remap every shortcut: the arm hotkey
|
|
163
|
+
(default double `Shift`), the mouse gestures — **Copy** (default click), **Multi-select**
|
|
164
|
+
(default `Shift`+click), **Open source** (default `Alt`+click), **Open usage** (default
|
|
165
|
+
`Ctrl`+click), each a *modifier* + *click type* (click / right-click / double-click) — and the
|
|
166
|
+
keyboard keys **Confirm** (default `Enter`) and **Cancel** (default `Esc`), plus **Search**
|
|
167
|
+
(default `Ctrl` + double-tap `F`, global — works even when the picker is off) and **Inspector**
|
|
168
|
+
(default `Ctrl`+`I`). The right-click context menu (`copyHtml` gesture) is no longer listed in
|
|
169
|
+
the dropdown; it stays configurable in `render-picker.config.json`. Search opens an element finder: type a tag (`div`), a class (`.card`), a
|
|
170
|
+
CSS selector or a React component name (`Button`, only where the npm annotator runs); partial
|
|
171
|
+
typing autocompletes (`div.` lists the divs, `div.car` matches classes starting with `car`) and
|
|
172
|
+
`Ctrl+Z`/`Ctrl+Y` walk the query history. Search is one compact box: the input row holds the
|
|
173
|
+
counter (`3/12`, `0` when nothing matches) and the ‹ › arrows; below it, results group into
|
|
174
|
+
suggestions (selector + occurrence count), shown only when the query matches. `↑`/`↓` move
|
|
175
|
+
from one suggestion to the next (the list scrolls to keep it visible); the counter shows the
|
|
176
|
+
current element of the active suggestion (`1/2` = first of its 2 elements). The ‹ › arrows cycle
|
|
177
|
+
through those elements; `Enter` scrolls to the current one, and each further `Enter` goes to the
|
|
178
|
+
next one (`Shift+Enter`: previous). Only the active suggestion's occurrences are highlighted
|
|
179
|
+
(hovered row with the mouse, otherwise the keyboard selection), the current one net (live
|
|
180
|
+
rects, follows scroll/resize). The inspector's hover rect stays live while searching: it glides to
|
|
181
|
+
the deepest element under the pointer, through the search rects, with its tooltip (component,
|
|
182
|
+
metrics, dimensions). Every click targets that same element. Right-clicking a search rect opens
|
|
183
|
+
the context menu. While search is open, a plain left click on a page element (or on a search
|
|
184
|
+
rect) puts its classes in the query as a selector (`.card.b`, Tailwind tokens escaped; the tag
|
|
185
|
+
name when it has no class): the link or button does not fire, search stays open and `Ctrl+Z`
|
|
186
|
+
restores the previous query. A right click or a click with a modifier outside the search box
|
|
187
|
+
closes it; `Ctrl`/`Alt`+click on a rect still opens the editor. Clicking a suggestion row
|
|
188
|
+
scrolls the page to its element without touching the query; each further click goes to the
|
|
189
|
+
next element of that suggestion. Each row has a `⋯` button on the right (shown on the hovered
|
|
190
|
+
or active row, reachable with `Tab`); it opens an actions menu, and so does a right click on
|
|
191
|
+
the row (at the cursor). The menu targets the current element of that suggestion (its first
|
|
192
|
+
one if the row was not active), makes the row active and highlights the element without
|
|
193
|
+
scrolling: *Copy context* (same block as a pick: route, XPath, CSS, text, source, React
|
|
194
|
+
component), *Copy context of all (N)* (only when the suggestion has several elements, multi
|
|
195
|
+
selection format), *Copy text*, *Copy selector* (the suggestion selector, e.g. `div.card.b`),
|
|
196
|
+
*Copy HTML*, *Copy render*, *Copy classes*, *Copy XPath*, and *Open in editor* (only when the
|
|
197
|
+
element has a source and the npm click-to-source is active; not in the extension). Labels are in
|
|
198
|
+
French in the UI. A copy shows the toast, closes the menu and keeps search open. `Esc` closes
|
|
199
|
+
the menu first, a second `Esc` closes search. The
|
|
200
|
+
SettingsBar also hosts a magnifier icon next to the gear (npm package and browser extension, Chrome and Firefox).
|
|
201
|
+
`Esc` always disarms as a safety net (after closing an open context menu).
|
|
202
|
+
|
|
203
|
+
Choices are saved to `localStorage` by default. To persist them to a committable
|
|
204
|
+
**`render-picker.config.json`** at the project root, add a dev API route (one line) — changes then
|
|
205
|
+
write the file (GET reads it back). Settings are read **live**: UI remaps apply immediately, and
|
|
206
|
+
manual edits to `render-picker.config.json` are picked up on window focus — no `next dev` restart
|
|
207
|
+
needed (the dev route reads the file from disk).
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
// app/api/render-picker/route.ts
|
|
211
|
+
export { GET, POST } from "@antone-io/render-picker/next";
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
```json
|
|
215
|
+
// render-picker.config.json (written/read by the route)
|
|
216
|
+
{
|
|
217
|
+
"commands": {
|
|
218
|
+
"arm": "shift shift",
|
|
219
|
+
"copy": { "modifier": "none", "trigger": "click" },
|
|
220
|
+
"copyHtml": { "modifier": "none", "trigger": "rightclick" }, // opens the context menu
|
|
221
|
+
"multi": { "modifier": "shift", "trigger": "click" },
|
|
222
|
+
"confirm": "enter",
|
|
223
|
+
"cancel": "escape",
|
|
224
|
+
"inspect": { "modifier": "ctrl", "key": "i", "double": false },
|
|
225
|
+
"search": { "modifier": "ctrl", "key": "f", "double": true },
|
|
226
|
+
"source": { "modifier": "alt", "trigger": "click" },
|
|
227
|
+
"usage": { "modifier": "ctrl", "trigger": "click" },
|
|
228
|
+
"editor": "vscode" // vscode | vscode-insiders | cursor | windsurf | vscodium | zed | webstorm | phpstorm | idea | pycharm
|
|
229
|
+
},
|
|
230
|
+
"panel": { "width": 420, "height": 320 }
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Without the route, changes stay in `localStorage` (no crash). The handlers are no-ops in production.
|
|
235
|
+
|
|
236
|
+
### Editor — where Alt/Ctrl+click opens the source
|
|
237
|
+
|
|
238
|
+
The settings dropdown has an **Éditeur** select (saved as `commands.editor`, default `vscode`).
|
|
239
|
+
|
|
240
|
+
**No system setup needed** (no URL scheme to register, no JetBrains Toolbox): with the dev route
|
|
241
|
+
installed (`app/api/render-picker/route.ts`, see above), Alt/Ctrl+click asks the `next dev` server
|
|
242
|
+
to launch the IDE itself — on Windows it reuses the executable of the IDE **already open**
|
|
243
|
+
(`Code.exe`, `webstorm64.exe`, `phpstorm64.exe`…), on macOS JetBrains IDEs go through
|
|
244
|
+
`open -na "<App>.app"`, elsewhere the IDE CLI on the `PATH` (`code`, `cursor`, `zed`, `webstorm`…).
|
|
245
|
+
No shell is involved and only files inside the project can be opened.
|
|
246
|
+
|
|
247
|
+
Without the route (or if the IDE isn't found), it falls back to the editor's URL scheme:
|
|
248
|
+
|
|
249
|
+
| `editor` | Editor | Fallback URI |
|
|
250
|
+
|---|---|---|
|
|
251
|
+
| `vscode` | VS Code | `vscode://file/<abs>:<line>` |
|
|
252
|
+
| `vscode-insiders` | VS Code Insiders | `vscode-insiders://file/…` |
|
|
253
|
+
| `cursor` | Cursor | `cursor://file/…` |
|
|
254
|
+
| `windsurf` | Windsurf | `windsurf://file/…` |
|
|
255
|
+
| `vscodium` | VSCodium | `vscodium://file/…` |
|
|
256
|
+
| `zed` | Zed | `zed://file/<abs>:<line>:<col>` |
|
|
257
|
+
| `webstorm` | WebStorm | `webstorm://open?file=<abs>&line=<line>` |
|
|
258
|
+
| `phpstorm` | PhpStorm | `phpstorm://open?file=…` |
|
|
259
|
+
| `idea` | IntelliJ IDEA | `idea://open?file=…` |
|
|
260
|
+
| `pycharm` | PyCharm | `pycharm://open?file=…` |
|
|
261
|
+
|
|
262
|
+
The fallback URI only works if the OS knows the scheme (VS Code / Cursor installers register it;
|
|
263
|
+
JetBrains needs Toolbox) — the route avoids that. An unknown value in `render-picker.config.json`
|
|
264
|
+
falls back to VS Code.
|
|
265
|
+
|
|
266
|
+
### Lower-level exports (`@antone-io/render-picker/client`)
|
|
267
|
+
|
|
268
|
+
`enrichResult`, `findPickedElement`, `annotate`, `annotateTree`, `componentInfo`,
|
|
269
|
+
`initComponentAnnotator`, `initClickToSource`, `buildVscodeUri`, `buildEditorUri`, `EDITORS`, `hushConsoleNoise`,
|
|
270
|
+
`resolvePosition`, `normalizeSourcePath`, `loadSettings`, `saveSettings`.
|
|
271
|
+
|
|
272
|
+
## PrestaShop / Smarty (`.tpl`)
|
|
273
|
+
|
|
274
|
+
A ready-to-use dev module ships in [`integrations/prestashop/renderpicker/`](integrations/prestashop/renderpicker/)
|
|
275
|
+
(bundled JS included — **nothing to build**). Install in 3 steps:
|
|
276
|
+
|
|
277
|
+
1. **Copy** the `renderpicker/` folder into your shop's `modules/`:
|
|
278
|
+
```
|
|
279
|
+
integrations/prestashop/renderpicker/ → <your-shop>/modules/renderpicker/
|
|
280
|
+
```
|
|
281
|
+
2. **Enable** it: back-office → *Modules* → search "render-picker" → *Install*.
|
|
282
|
+
3. **Turn on dev mode**: `_PS_MODE_DEV_ = true;` in `config/defines.inc.php`, then clear the cache
|
|
283
|
+
(back-office → *Advanced Parameters → Performance → Clear cache*).
|
|
284
|
+
|
|
285
|
+
That's it — open any front-office page, arm the picker (double-tap **Shift**), pick an element, and
|
|
286
|
+
**Ctrl+click** opens its `.tpl` at the right line in your editor. The module auto-injects the script,
|
|
287
|
+
the project root and `RenderPicker.init()`; it is fully inert when `_PS_MODE_DEV_` is off.
|
|
288
|
+
|
|
289
|
+
On a PrestaShop page only (detected from the theme's `window.prestashop` object, the module's
|
|
290
|
+
`window.renderPickerAdminDir` or its `rp-module` / `rp@` markers), the settings menu also has a
|
|
291
|
+
**"Rectangles modules PrestaShop"** toggle: permanent rectangles over each
|
|
292
|
+
root module (name + render duration), right-click → **Modules** submenu to copy its name, relative/
|
|
293
|
+
absolute folder path, back-office config URL, or the whole page's module tree as Markdown. Details
|
|
294
|
+
(incl. the extra `PS_ADMIN_DIRNAME` env var for the config-URL link) in
|
|
295
|
+
[`integrations/prestashop/renderpicker/README.md`](integrations/prestashop/renderpicker/README.md#rectangles-permanents-modules-prestashop).
|
|
296
|
+
|
|
297
|
+
**Docker / remote server:** the server reports its own root (e.g. a container path
|
|
298
|
+
`/var/www/html`), which doesn't exist on the host where your editor runs. Set the host path once, in
|
|
299
|
+
the browser console, and reload:
|
|
300
|
+
|
|
301
|
+
```js
|
|
302
|
+
localStorage.renderPickerRoot = "C:/Users/you/path/to/public_html"
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
It overrides the server-reported root (the per-file paths are identical, only the root prefix differs).
|
|
306
|
+
|
|
307
|
+
<details>
|
|
308
|
+
<summary>How it works / rebuild the bundle</summary>
|
|
309
|
+
|
|
310
|
+
The module registers a Smarty prefilter that emits per-element markers (`<!-- rp@themes/.../x.tpl:42 -->`),
|
|
311
|
+
read client-side to set `data-source`. Ctrl+click opens `vscode://file/<root>/<relpath>:<line>` (no server
|
|
312
|
+
needed). To rebuild the bundled JS from source: `npm run build:standalone && npm run sync:prestashop`.
|
|
313
|
+
</details>
|
|
314
|
+
|
|
315
|
+
## Limitations
|
|
316
|
+
|
|
317
|
+
- Next.js dev builds only: source resolution reads the React `_debugStack` — **Turbopack** frames
|
|
318
|
+
(`/_next/static/chunks/*._.js` + their sourcemaps) and **Webpack** dev frames
|
|
319
|
+
(`webpack-internal:///…/src/….tsx:line`, source path read directly).
|
|
320
|
+
- Never ships the project path to production: both `withRenderPicker` and `initRenderPicker` are
|
|
321
|
+
no-ops when `NODE_ENV === "production"`.
|
|
322
|
+
|
|
323
|
+
## License
|
|
324
|
+
|
|
325
|
+
MIT
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
NPM_MARKER_ATTR,
|
|
4
|
+
initClickToSource,
|
|
5
|
+
initComponentAnnotator,
|
|
6
|
+
initSettingsRefresh,
|
|
7
|
+
initTplAnnotator,
|
|
8
|
+
startCapture
|
|
9
|
+
} from "./chunk-XUPSSH7J.js";
|
|
10
|
+
|
|
11
|
+
// src/core/dev/console-hush.ts
|
|
12
|
+
var DEFAULT_HUSH_RULES = [
|
|
13
|
+
/Download the React DevTools/,
|
|
14
|
+
/^\[HMR\] connected$/,
|
|
15
|
+
/^\[Fast Refresh\]/
|
|
16
|
+
];
|
|
17
|
+
var METHODS = ["log", "info", "debug"];
|
|
18
|
+
function hushConsoleNoise(rules = DEFAULT_HUSH_RULES) {
|
|
19
|
+
const originals = /* @__PURE__ */ new Map();
|
|
20
|
+
for (const name of METHODS) {
|
|
21
|
+
const original = console[name];
|
|
22
|
+
originals.set(name, original);
|
|
23
|
+
console[name] = (...args) => {
|
|
24
|
+
const first = args[0];
|
|
25
|
+
if (typeof first === "string" && rules.some((r) => r.test(first))) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
original.apply(console, args);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return () => {
|
|
32
|
+
for (const [name, original] of originals) {
|
|
33
|
+
console[name] = original;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/client.ts
|
|
39
|
+
var DEFAULT_ANNOTATE_DELAY_MS = 2e3;
|
|
40
|
+
function defaultEnabled() {
|
|
41
|
+
try {
|
|
42
|
+
return process.env.NODE_ENV !== "production";
|
|
43
|
+
} catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function defaultProjectRoot() {
|
|
48
|
+
try {
|
|
49
|
+
if (process.env.NEXT_PUBLIC_PROJECT_ROOT) return process.env.NEXT_PUBLIC_PROJECT_ROOT;
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
if (typeof document !== "undefined") {
|
|
53
|
+
const meta = document.querySelector('meta[name="render-picker-root"]');
|
|
54
|
+
return meta?.getAttribute("content") ?? void 0;
|
|
55
|
+
}
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
58
|
+
function initRenderPicker(options = {}) {
|
|
59
|
+
const {
|
|
60
|
+
enabled = defaultEnabled(),
|
|
61
|
+
projectRoot = defaultProjectRoot(),
|
|
62
|
+
source = "react",
|
|
63
|
+
clickToSource = true,
|
|
64
|
+
annotate: annotate2 = true,
|
|
65
|
+
hushConsole = true
|
|
66
|
+
} = options;
|
|
67
|
+
if (!enabled || typeof window === "undefined") return () => {
|
|
68
|
+
};
|
|
69
|
+
const cleanups = [];
|
|
70
|
+
document.documentElement.setAttribute(NPM_MARKER_ATTR, "npm");
|
|
71
|
+
cleanups.push(() => document.documentElement.removeAttribute(NPM_MARKER_ATTR));
|
|
72
|
+
cleanups.push(startCapture());
|
|
73
|
+
cleanups.push(initSettingsRefresh());
|
|
74
|
+
if (hushConsole) {
|
|
75
|
+
cleanups.push(
|
|
76
|
+
hushConsoleNoise(hushConsole === true ? DEFAULT_HUSH_RULES : hushConsole)
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
if (clickToSource) cleanups.push(initClickToSource(projectRoot));
|
|
80
|
+
if (annotate2) {
|
|
81
|
+
if (source === "prestashop") {
|
|
82
|
+
cleanups.push(initTplAnnotator());
|
|
83
|
+
} else {
|
|
84
|
+
const delayMs = typeof annotate2 === "object" && annotate2.delayMs !== void 0 ? annotate2.delayMs : DEFAULT_ANNOTATE_DELAY_MS;
|
|
85
|
+
let stopAnnotator = null;
|
|
86
|
+
const timer = setTimeout(() => {
|
|
87
|
+
stopAnnotator = initComponentAnnotator();
|
|
88
|
+
}, delayMs);
|
|
89
|
+
cleanups.push(() => {
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
stopAnnotator?.();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return () => {
|
|
96
|
+
for (const cleanup of cleanups.reverse()) cleanup();
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export {
|
|
101
|
+
DEFAULT_HUSH_RULES,
|
|
102
|
+
hushConsoleNoise,
|
|
103
|
+
initRenderPicker
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=chunk-FM3HLV7V.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/dev/console-hush.ts","../src/client.ts"],"sourcesContent":["/**\n * Masque les logs \"Download the React DevTools\" / \"[HMR] connected\" /\n * \"[Fast Refresh]\" en dev. Simple filtre de console.\n */\n\nexport const DEFAULT_HUSH_RULES: readonly RegExp[] = [\n /Download the React DevTools/,\n /^\\[HMR\\] connected$/,\n /^\\[Fast Refresh\\]/,\n];\n\ntype ConsoleMethod = \"log\" | \"info\" | \"debug\";\nconst METHODS: ConsoleMethod[] = [\"log\", \"info\", \"debug\"];\n\n/** Patch console.log/info/debug. Retourne une fonction qui restaure l'original. */\nexport function hushConsoleNoise(\n rules: readonly RegExp[] = DEFAULT_HUSH_RULES,\n): () => void {\n const originals = new Map<ConsoleMethod, (...args: unknown[]) => void>();\n for (const name of METHODS) {\n // eslint-disable-next-line no-console\n const original = console[name] as (...args: unknown[]) => void;\n originals.set(name, original);\n // eslint-disable-next-line no-console\n console[name] = (...args: unknown[]) => {\n const first = args[0];\n if (typeof first === \"string\" && rules.some((r) => r.test(first))) {\n return;\n }\n original.apply(console, args);\n };\n }\n return () => {\n for (const [name, original] of originals) {\n // eslint-disable-next-line no-console\n console[name] = original;\n }\n };\n}\n","import { startCapture } from \"./core/devpanel/capture\";\nimport { NPM_MARKER_ATTR } from \"./core/inspector/constants/behavior\";\nimport { initClickToSource } from \"./core/dev/click-to-source\";\nimport { initComponentAnnotator } from \"./core/source/component-annotate\";\nimport { initTplAnnotator } from \"./core/source/tpl-annotate\";\nimport { DEFAULT_HUSH_RULES, hushConsoleNoise } from \"./core/dev/console-hush\";\nimport { initSettingsRefresh } from \"./core/settings\";\n\nexport interface RenderPickerOptions {\n /** Active l'outillage. Défaut : `process.env.NODE_ENV !== \"production\"`. */\n enabled?: boolean;\n /**\n * Racine absolue du projet. Défaut : `process.env.NEXT_PUBLIC_PROJECT_ROOT`,\n * sinon le contenu de `<meta name=\"render-picker-root\">` (pages sans bundler,\n * ex. PrestaShop).\n */\n projectRoot?: string | null;\n /**\n * Source de la résolution `data-source` :\n * - `\"react\"` (défaut) : fibers React (`initComponentAnnotator`, sourcemaps) ;\n * - `\"prestashop\"` : commentaires Smarty `rp@file:line` (`initTplAnnotator`,\n * sans attente d'hydratation).\n */\n source?: \"react\" | \"prestashop\";\n /** Alt+clic → VS Code. Défaut : true. */\n clickToSource?: boolean;\n /**\n * Annotation `data-component` / `data-source`. Défaut : true, après 2000 ms —\n * injecter des attributs avant la fin de l'hydratation provoque\n * \"tree hydrated but some attributes didn't match\". Ignoré si `source: \"prestashop\"`\n * (annotation immédiate, pas d'hydratation React).\n */\n annotate?: boolean | { delayMs?: number };\n /** Filtre console dev. `true` = règles par défaut, ou liste de RegExp. Défaut : true. */\n hushConsole?: boolean | readonly RegExp[];\n}\n\nconst DEFAULT_ANNOTATE_DELAY_MS = 2000;\n\n// Accès littéraux : Next/webpack/Turbopack remplacent `process.env.X` à la build,\n// y compris dans node_modules. Le try couvre les runtimes sans `process`.\nfunction defaultEnabled(): boolean {\n try {\n return process.env.NODE_ENV !== \"production\";\n } catch {\n return false;\n }\n}\n\nfunction defaultProjectRoot(): string | undefined {\n try {\n if (process.env.NEXT_PUBLIC_PROJECT_ROOT) return process.env.NEXT_PUBLIC_PROJECT_ROOT;\n } catch {\n // pas de `process` (navigateur sans bundler) → repli sur le <meta>\n }\n if (typeof document !== \"undefined\") {\n const meta = document.querySelector('meta[name=\"render-picker-root\"]');\n return meta?.getAttribute(\"content\") ?? undefined;\n }\n return undefined;\n}\n\n/**\n * Point d'entrée à appeler dans `instrumentation-client.ts`.\n * Retourne une fonction qui démonte tout (listeners, observer, console).\n */\nexport function initRenderPicker(options: RenderPickerOptions = {}): () => void {\n const {\n enabled = defaultEnabled(),\n projectRoot = defaultProjectRoot(),\n source = \"react\",\n clickToSource = true,\n annotate = true,\n hushConsole = true,\n } = options;\n\n if (!enabled || typeof window === \"undefined\") return () => {};\n\n const cleanups: (() => void)[] = [];\n\n // Marqueur lu par l'extension Chrome pour se désactiver (évite le double picker).\n document.documentElement.setAttribute(NPM_MARKER_ATTR, \"npm\");\n cleanups.push(() => document.documentElement.removeAttribute(NPM_MARKER_ATTR));\n\n // Capture console + network pour le panneau d'inspection.\n cleanups.push(startCapture());\n\n // Config.json relu sur le disque (route dev) au focus — remap à chaud.\n cleanups.push(initSettingsRefresh());\n\n if (hushConsole) {\n cleanups.push(\n hushConsoleNoise(hushConsole === true ? DEFAULT_HUSH_RULES : hushConsole),\n );\n }\n\n // Enregistré immédiatement (avant tout effet React) pour être premier en\n // capture. Lit data-source au moment du clic → pas besoin d'attendre l'annotation.\n if (clickToSource) cleanups.push(initClickToSource(projectRoot));\n\n if (annotate) {\n if (source === \"prestashop\") {\n // Commentaires Smarty déjà dans le HTML serveur → annotation immédiate,\n // pas d'hydratation React à attendre.\n cleanups.push(initTplAnnotator());\n } else {\n const delayMs =\n typeof annotate === \"object\" && annotate.delayMs !== undefined\n ? annotate.delayMs\n : DEFAULT_ANNOTATE_DELAY_MS;\n let stopAnnotator: (() => void) | null = null;\n const timer = setTimeout(() => {\n stopAnnotator = initComponentAnnotator();\n }, delayMs);\n cleanups.push(() => {\n clearTimeout(timer);\n stopAnnotator?.();\n });\n }\n }\n\n return () => {\n for (const cleanup of cleanups.reverse()) cleanup();\n };\n}\n\nexport { buildVscodeUri, initClickToSource } from \"./core/dev/click-to-source\";\nexport { buildEditorUri, EDITORS, type EditorId, type EditorInfo } from \"./core/dev/editors\";\nexport {\n pickResultFromElement,\n searchElements,\n toSelector,\n} from \"./core/search/element-search\";\nexport {\n annotate,\n annotateTree,\n componentInfo,\n initComponentAnnotator,\n type AnnotateResult,\n} from \"./core/source/component-annotate\";\nexport {\n annotateFromComments,\n initTplAnnotator,\n parseTplMarker,\n} from \"./core/source/tpl-annotate\";\nexport { DEFAULT_HUSH_RULES, hushConsoleNoise } from \"./core/dev/console-hush\";\nexport { enrichResult, findPickedElement } from \"./core/source/enrich\";\nexport { createInspector } from \"./core/inspector/inspector\";\nexport { ACCENT } from \"./core/inspector/constants/picker\";\nexport {\n PANEL_BORDER,\n SOLID_BG,\n TOOLTIP_SHADOW,\n} from \"./core/inspector/constants/theme\";\nexport { getCssSelector } from \"./core/inspector/css-selector\";\nexport { getXPath } from \"./core/inspector/xpath\";\nexport {\n normalizeSourcePath,\n resolvePosition,\n} from \"./core/source/source-map-resolver\";\nexport {\n DEFAULT_SETTINGS,\n fetchSettings,\n initSettingsRefresh,\n loadSettings,\n refreshSettings,\n saveSettings,\n settingsDelta,\n type RenderPickerSettings,\n} from \"./core/settings\";\nexport type {\n InspectorCallbacks,\n LayoutOverlays,\n PickResult,\n ResolvedPosition,\n} from \"./core/types\";\n"],"mappings":";;;;;;;;;;;AAKO,IAAM,qBAAwC;AAAA,EACnD;AAAA,EACA;AAAA,EACA;AACF;AAGA,IAAM,UAA2B,CAAC,OAAO,QAAQ,OAAO;AAGjD,SAAS,iBACd,QAA2B,oBACf;AACZ,QAAM,YAAY,oBAAI,IAAiD;AACvE,aAAW,QAAQ,SAAS;AAE1B,UAAM,WAAW,QAAQ,IAAI;AAC7B,cAAU,IAAI,MAAM,QAAQ;AAE5B,YAAQ,IAAI,IAAI,IAAI,SAAoB;AACtC,YAAM,QAAQ,KAAK,CAAC;AACpB,UAAI,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,MAAM,EAAE,KAAK,KAAK,CAAC,GAAG;AACjE;AAAA,MACF;AACA,eAAS,MAAM,SAAS,IAAI;AAAA,IAC9B;AAAA,EACF;AACA,SAAO,MAAM;AACX,eAAW,CAAC,MAAM,QAAQ,KAAK,WAAW;AAExC,cAAQ,IAAI,IAAI;AAAA,IAClB;AAAA,EACF;AACF;;;ACDA,IAAM,4BAA4B;AAIlC,SAAS,iBAA0B;AACjC,MAAI;AACF,WAAO,QAAQ,IAAI,aAAa;AAAA,EAClC,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,qBAAyC;AAChD,MAAI;AACF,QAAI,QAAQ,IAAI,yBAA0B,QAAO,QAAQ,IAAI;AAAA,EAC/D,QAAQ;AAAA,EAER;AACA,MAAI,OAAO,aAAa,aAAa;AACnC,UAAM,OAAO,SAAS,cAAc,iCAAiC;AACrE,WAAO,MAAM,aAAa,SAAS,KAAK;AAAA,EAC1C;AACA,SAAO;AACT;AAMO,SAAS,iBAAiB,UAA+B,CAAC,GAAe;AAC9E,QAAM;AAAA,IACJ,UAAU,eAAe;AAAA,IACzB,cAAc,mBAAmB;AAAA,IACjC,SAAS;AAAA,IACT,gBAAgB;AAAA,IAChB,UAAAA,YAAW;AAAA,IACX,cAAc;AAAA,EAChB,IAAI;AAEJ,MAAI,CAAC,WAAW,OAAO,WAAW,YAAa,QAAO,MAAM;AAAA,EAAC;AAE7D,QAAM,WAA2B,CAAC;AAGlC,WAAS,gBAAgB,aAAa,iBAAiB,KAAK;AAC5D,WAAS,KAAK,MAAM,SAAS,gBAAgB,gBAAgB,eAAe,CAAC;AAG7E,WAAS,KAAK,aAAa,CAAC;AAG5B,WAAS,KAAK,oBAAoB,CAAC;AAEnC,MAAI,aAAa;AACf,aAAS;AAAA,MACP,iBAAiB,gBAAgB,OAAO,qBAAqB,WAAW;AAAA,IAC1E;AAAA,EACF;AAIA,MAAI,cAAe,UAAS,KAAK,kBAAkB,WAAW,CAAC;AAE/D,MAAIA,WAAU;AACZ,QAAI,WAAW,cAAc;AAG3B,eAAS,KAAK,iBAAiB,CAAC;AAAA,IAClC,OAAO;AACL,YAAM,UACJ,OAAOA,cAAa,YAAYA,UAAS,YAAY,SACjDA,UAAS,UACT;AACN,UAAI,gBAAqC;AACzC,YAAM,QAAQ,WAAW,MAAM;AAC7B,wBAAgB,uBAAuB;AAAA,MACzC,GAAG,OAAO;AACV,eAAS,KAAK,MAAM;AAClB,qBAAa,KAAK;AAClB,wBAAgB;AAAA,MAClB,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO,MAAM;AACX,eAAW,WAAW,SAAS,QAAQ,EAAG,SAAQ;AAAA,EACpD;AACF;","names":["annotate"]}
|