uidex 0.1.0 → 0.1.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.
- package/README.md +239 -155
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# uidex
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A framework-agnostic library for highlighting and annotating UI elements. Works with React, vanilla JS, or any framework. Includes a build-time scanner, inspect mode, Playwright integration, and Claude Code tooling.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,32 +8,61 @@ A React library for highlighting and annotating components. Perfect for building
|
|
|
8
8
|
npm install uidex
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Quick Start
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
```bash
|
|
14
|
+
# 1. Initialize config
|
|
15
|
+
npx uidex init
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
# 2. Add data-uidex attributes to your elements
|
|
18
|
+
# <button data-uidex="submit-btn">Submit</button>
|
|
19
|
+
|
|
20
|
+
# 3. Run the scanner
|
|
21
|
+
npx uidex scan
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### React
|
|
17
25
|
|
|
18
26
|
```tsx
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
import './uidex.gen';
|
|
28
|
+
import { UidexDevtools } from 'uidex';
|
|
29
|
+
|
|
30
|
+
function App() {
|
|
31
|
+
return (
|
|
32
|
+
<>
|
|
33
|
+
<button data-uidex="submit-btn">Submit</button>
|
|
34
|
+
<UidexDevtools />
|
|
35
|
+
</>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
21
39
|
|
|
22
|
-
|
|
23
|
-
npx uidex-scan
|
|
40
|
+
### Vanilla JS
|
|
24
41
|
|
|
25
|
-
|
|
42
|
+
```js
|
|
26
43
|
import './uidex.gen';
|
|
44
|
+
import { createUidexUI } from 'uidex/core';
|
|
27
45
|
|
|
28
|
-
|
|
29
|
-
|
|
46
|
+
const ui = createUidexUI();
|
|
47
|
+
ui.mount();
|
|
48
|
+
|
|
49
|
+
// Cleanup
|
|
50
|
+
ui.destroy();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Script Tag
|
|
30
54
|
|
|
31
|
-
|
|
55
|
+
```html
|
|
56
|
+
<script src="https://unpkg.com/uidex/dist/core/index.global.js"></script>
|
|
57
|
+
<script>
|
|
58
|
+
const ui = UidexCore.createUidexUI({ components: { ... } });
|
|
59
|
+
ui.mount();
|
|
60
|
+
</script>
|
|
32
61
|
```
|
|
33
62
|
|
|
34
63
|
## Configuration
|
|
35
64
|
|
|
36
|
-
|
|
65
|
+
`npx uidex init` creates a `.uidex.json` file:
|
|
37
66
|
|
|
38
67
|
```json
|
|
39
68
|
{
|
|
@@ -61,221 +90,276 @@ Create a `.uidex.json` file in your project root to customize default settings:
|
|
|
61
90
|
}
|
|
62
91
|
```
|
|
63
92
|
|
|
64
|
-
##
|
|
93
|
+
## Scanner
|
|
65
94
|
|
|
66
|
-
|
|
95
|
+
The scanner finds `data-uidex` attributes in your source files and generates a typed registry.
|
|
67
96
|
|
|
68
|
-
|
|
97
|
+
```bash
|
|
98
|
+
npx uidex scan # Generate registry
|
|
99
|
+
npx uidex scan --check # Validate UIDEX_PAGE.md coverage
|
|
100
|
+
```
|
|
69
101
|
|
|
70
|
-
|
|
71
|
-
import { UidexDevtools } from 'uidex';
|
|
102
|
+
Add it to your build:
|
|
72
103
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
);
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"scripts": {
|
|
107
|
+
"prebuild": "npx uidex scan",
|
|
108
|
+
"build": "next build"
|
|
109
|
+
}
|
|
80
110
|
}
|
|
81
111
|
```
|
|
82
112
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
| Prop | Type | Default | Description |
|
|
86
|
-
|------|------|---------|-------------|
|
|
87
|
-
| `components` | `UidexMap` | - | Optional components map (uses registry if not provided) |
|
|
88
|
-
| `config` | `UidexConfig` | - | Optional configuration for styling |
|
|
89
|
-
| `buttonPosition` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | `'bottom-right'` | Position of the floating button |
|
|
90
|
-
| `trigger` | `ReactNode` | - | Custom trigger element |
|
|
91
|
-
| `disabled` | `boolean` | `false` | Disable the devtools |
|
|
92
|
-
| `onSelect` | `(id: string) => void` | - | Callback when a component is selected |
|
|
93
|
-
|
|
94
|
-
### UidexOverlay
|
|
95
|
-
|
|
96
|
-
For manual control over overlays:
|
|
113
|
+
### Annotating Components
|
|
97
114
|
|
|
98
115
|
```tsx
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
function App() {
|
|
103
|
-
const [target, setTarget] = useState<HTMLElement | null>(null);
|
|
116
|
+
<nav data-uidex="main-nav">
|
|
117
|
+
<a href="/">Home</a>
|
|
118
|
+
</nav>
|
|
104
119
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
<button
|
|
108
|
-
ref={(el) => setTarget(el)}
|
|
109
|
-
onMouseEnter={(e) => setTarget(e.currentTarget)}
|
|
110
|
-
onMouseLeave={() => setTarget(null)}
|
|
111
|
-
>
|
|
112
|
-
Hover me
|
|
113
|
-
</button>
|
|
114
|
-
<UidexOverlay
|
|
115
|
-
target={target}
|
|
116
|
-
label="Button"
|
|
117
|
-
color="#3b82f6"
|
|
118
|
-
/>
|
|
119
|
-
</>
|
|
120
|
-
);
|
|
121
|
-
}
|
|
120
|
+
/** @uidex cta-button - Primary call-to-action button */
|
|
121
|
+
<button data-uidex="cta-button">Click Me</button>
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
| Prop | Type | Default | Description |
|
|
127
|
-
|------|------|---------|-------------|
|
|
128
|
-
| `target` | `HTMLElement \| null` | required | The element to highlight |
|
|
129
|
-
| `label` | `string` | - | Label text shown on the overlay |
|
|
130
|
-
| `color` | `string` | `#3b82f6` | Highlight color (hex or named color) |
|
|
131
|
-
| `borderStyle` | `'solid' \| 'dashed' \| 'dotted'` | `'solid'` | Border style |
|
|
132
|
-
| `borderWidth` | `number` | `2` | Border width in pixels |
|
|
133
|
-
| `showLabel` | `boolean` | `true` | Whether to show the label |
|
|
134
|
-
| `labelPosition` | `'top-left' \| 'top-right' \| 'bottom-left' \| 'bottom-right'` | `'top-left'` | Label position |
|
|
135
|
-
| `colors` | `Record<string, string>` | - | Named colors map |
|
|
136
|
-
|
|
137
|
-
## Build-Time Scanner
|
|
138
|
-
|
|
139
|
-
The `uidex-scan` CLI tool scans your source files for `data-uidex` attributes and generates a TypeScript registry file.
|
|
140
|
-
|
|
141
|
-
### Setup
|
|
124
|
+
### Generated Output
|
|
142
125
|
|
|
143
|
-
|
|
126
|
+
The scanner generates `src/uidex.gen.ts` (gitignored) with:
|
|
144
127
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
"outputPath": "src/uidex.gen.ts",
|
|
152
|
-
"rootDir": "src"
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
```
|
|
128
|
+
- `components` — map of id to file locations
|
|
129
|
+
- `componentIds` — array of all ids
|
|
130
|
+
- `ComponentId` — union type of all ids
|
|
131
|
+
- `pages` — from `UIDEX_PAGE.md` files (directory-based component association)
|
|
132
|
+
- `features` — from `UIDEX_FEATURE.md` files (explicit component association)
|
|
133
|
+
- Auto-registration calls
|
|
156
134
|
|
|
157
135
|
### Monorepo Support
|
|
158
136
|
|
|
159
|
-
|
|
137
|
+
Use `sources` for multiple scan roots:
|
|
160
138
|
|
|
161
139
|
```json
|
|
162
140
|
{
|
|
163
|
-
"$schema": "./node_modules/uidex/uidex.schema.json",
|
|
164
141
|
"scanner": {
|
|
165
142
|
"sources": [
|
|
166
|
-
{
|
|
167
|
-
|
|
168
|
-
"include": ["**/*.tsx"]
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
"rootDir": "../packages/ui/src",
|
|
172
|
-
"include": ["**/*.tsx"],
|
|
173
|
-
"prefix": "@myorg/ui"
|
|
174
|
-
}
|
|
143
|
+
{ "rootDir": "src", "include": ["**/*.tsx"] },
|
|
144
|
+
{ "rootDir": "../packages/ui/src", "include": ["**/*.tsx"], "prefix": "@myorg/ui" }
|
|
175
145
|
],
|
|
176
|
-
"exclude": ["**/*.test.*"
|
|
146
|
+
"exclude": ["**/*.test.*"],
|
|
177
147
|
"outputPath": "src/uidex.gen.ts"
|
|
178
148
|
}
|
|
179
149
|
}
|
|
180
150
|
```
|
|
181
151
|
|
|
182
|
-
|
|
152
|
+
## Components
|
|
183
153
|
|
|
184
|
-
|
|
154
|
+
### UidexDevtools (React)
|
|
185
155
|
|
|
186
|
-
|
|
187
|
-
{
|
|
188
|
-
"scripts": {
|
|
189
|
-
"prebuild": "npx uidex-scan",
|
|
190
|
-
"build": "next build"
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
```
|
|
156
|
+
Floating devtools panel with component list, pages, features, and inspect mode.
|
|
194
157
|
|
|
195
|
-
|
|
158
|
+
```tsx
|
|
159
|
+
import { UidexDevtools } from 'uidex';
|
|
196
160
|
|
|
197
|
-
|
|
198
|
-
|
|
161
|
+
<UidexDevtools
|
|
162
|
+
buttonPosition="bottom-right"
|
|
163
|
+
onSelect={(id) => console.log(id)}
|
|
164
|
+
/>
|
|
199
165
|
```
|
|
200
166
|
|
|
201
|
-
|
|
167
|
+
| Prop | Type | Default | Description |
|
|
168
|
+
|------|------|---------|-------------|
|
|
169
|
+
| `components` | `UidexMap` | registry | Components map |
|
|
170
|
+
| `config` | `UidexConfig` | - | Styling configuration |
|
|
171
|
+
| `buttonPosition` | `ButtonPosition` | `'bottom-right'` | Initial button position |
|
|
172
|
+
| `disabled` | `boolean` | `false` | Disable devtools |
|
|
173
|
+
| `onSelect` | `(id: string) => void` | - | Selection callback |
|
|
174
|
+
| `inspectShortcut` | `KeyboardShortcut \| false` | `Shift+Cmd+U` | Inspect mode shortcut |
|
|
202
175
|
|
|
203
|
-
|
|
176
|
+
### UidexOverlay (React)
|
|
177
|
+
|
|
178
|
+
Standalone overlay for highlighting a single element.
|
|
204
179
|
|
|
205
180
|
```tsx
|
|
206
|
-
|
|
207
|
-
<a href="/">Home</a>
|
|
208
|
-
</nav>
|
|
181
|
+
import { UidexOverlay } from 'uidex';
|
|
209
182
|
|
|
210
|
-
<
|
|
183
|
+
<UidexOverlay
|
|
184
|
+
target={element}
|
|
185
|
+
label="Button"
|
|
186
|
+
color="#3b82f6"
|
|
187
|
+
/>
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
| Prop | Type | Default | Description |
|
|
191
|
+
|------|------|---------|-------------|
|
|
192
|
+
| `target` | `HTMLElement \| null` | required | Element to highlight |
|
|
193
|
+
| `label` | `string` | - | Label text |
|
|
194
|
+
| `color` | `string` | - | Border color (hex or named) |
|
|
195
|
+
| `borderStyle` | `BorderStyle` | `'solid'` | `solid`, `dashed`, or `dotted` |
|
|
196
|
+
| `borderWidth` | `number` | `2` | Border width in px |
|
|
197
|
+
| `showLabel` | `boolean` | `true` | Show label |
|
|
198
|
+
| `labelPosition` | `LabelPosition` | `'top-left'` | Label position |
|
|
199
|
+
| `colors` | `Record<string, string>` | - | Named colors map |
|
|
200
|
+
|
|
201
|
+
### createUidexUI (Vanilla JS)
|
|
202
|
+
|
|
203
|
+
```js
|
|
204
|
+
import { createUidexUI } from 'uidex/core';
|
|
205
|
+
|
|
206
|
+
const ui = createUidexUI({
|
|
207
|
+
components: { ... },
|
|
208
|
+
pages: [ ... ],
|
|
209
|
+
features: [ ... ],
|
|
210
|
+
config: { defaults: { color: '#3b82f6' } },
|
|
211
|
+
buttonPosition: 'bottom-right',
|
|
212
|
+
inspectShortcut: { key: 'u', shiftKey: true, metaKey: true },
|
|
213
|
+
onSelect: (id) => console.log(id),
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
ui.mount();
|
|
217
|
+
ui.destroy();
|
|
211
218
|
```
|
|
212
219
|
|
|
213
|
-
|
|
220
|
+
## Inspect Mode
|
|
221
|
+
|
|
222
|
+
Press **Shift+Cmd+U** (Shift+Ctrl+U on Windows/Linux) to enter inspect mode. Hover over elements to highlight them, click to select. Press **Escape** to exit.
|
|
214
223
|
|
|
215
|
-
|
|
224
|
+
Disable or customize the shortcut:
|
|
216
225
|
|
|
217
226
|
```tsx
|
|
218
|
-
|
|
219
|
-
<
|
|
227
|
+
// Disable
|
|
228
|
+
<UidexDevtools inspectShortcut={false} />
|
|
229
|
+
|
|
230
|
+
// Custom shortcut
|
|
231
|
+
<UidexDevtools inspectShortcut={{ key: 'i', ctrlKey: true }} />
|
|
220
232
|
```
|
|
221
233
|
|
|
222
|
-
|
|
234
|
+
## Playwright Integration
|
|
235
|
+
|
|
236
|
+
Test your annotated components with type-safe locators and coverage reporting.
|
|
223
237
|
|
|
224
|
-
|
|
238
|
+
### Test Fixture
|
|
225
239
|
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
// Do not edit this file manually
|
|
240
|
+
```ts
|
|
241
|
+
import { test, expect } from 'uidex/playwright';
|
|
229
242
|
|
|
230
|
-
|
|
243
|
+
test('submit button works', async ({ uidex }) => {
|
|
244
|
+
await uidex('submit-btn').click();
|
|
245
|
+
await uidex('success-message').waitFor();
|
|
246
|
+
});
|
|
247
|
+
```
|
|
231
248
|
|
|
232
|
-
|
|
233
|
-
"cta-button": [{ filePath: "src/pages/Home.tsx", line: 12 }],
|
|
234
|
-
"main-nav": [{ filePath: "src/components/Header.tsx", line: 5 }]
|
|
235
|
-
};
|
|
249
|
+
### Coverage Reporter
|
|
236
250
|
|
|
237
|
-
|
|
251
|
+
Track which `data-uidex` components are covered by tests:
|
|
238
252
|
|
|
239
|
-
|
|
253
|
+
```ts
|
|
254
|
+
// playwright.config.ts
|
|
255
|
+
import UidexCoverageReporter from 'uidex/playwright/reporter';
|
|
256
|
+
import { componentIds } from './src/uidex.gen.test';
|
|
240
257
|
|
|
241
|
-
|
|
242
|
-
|
|
258
|
+
export default defineConfig({
|
|
259
|
+
reporter: [
|
|
260
|
+
['html'],
|
|
261
|
+
[UidexCoverageReporter, { componentIds }],
|
|
262
|
+
],
|
|
263
|
+
});
|
|
243
264
|
```
|
|
244
265
|
|
|
245
|
-
|
|
266
|
+
Outputs `uidex-coverage.json` with covered/uncovered components and percentage.
|
|
246
267
|
|
|
247
|
-
|
|
268
|
+
### Scaffold Tests
|
|
248
269
|
|
|
249
|
-
|
|
250
|
-
|
|
270
|
+
Generate test stubs from your pages and features:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
npx uidex scaffold [dir]
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## Claude Code Integration
|
|
277
|
+
|
|
278
|
+
Set up Claude Code with uidex-aware rules, a `/uidex-audit` skill, and a post-edit hook that validates coverage:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
npx uidex claude init # Add rules + skill + hooks
|
|
282
|
+
npx uidex claude teardown # Remove everything
|
|
283
|
+
```
|
|
251
284
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
285
|
+
Manage individually:
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
npx uidex claude rules add|remove # .claude/rules/uidex.md
|
|
289
|
+
npx uidex claude skill add|remove # .claude/commands/uidex-audit.md
|
|
290
|
+
npx uidex claude hooks add|remove # PostToolUse hook in .claude/settings.json
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## Theming
|
|
294
|
+
|
|
295
|
+
All UI renders inside a Shadow DOM with CSS custom properties. Override any token at `:root`:
|
|
296
|
+
|
|
297
|
+
```css
|
|
298
|
+
:root {
|
|
299
|
+
--uidex-color-primary: #2e2e2e;
|
|
300
|
+
--uidex-color-bg: #ffffff;
|
|
301
|
+
--uidex-color-bg-elevated: #f5f5f5;
|
|
302
|
+
--uidex-color-text: #1f2937;
|
|
303
|
+
--uidex-color-text-strong: #111827;
|
|
304
|
+
--uidex-color-text-muted: #6b7280;
|
|
305
|
+
--uidex-color-surface-hover: #f3f4f6;
|
|
306
|
+
--uidex-color-surface-active: #e5e7eb;
|
|
307
|
+
--uidex-color-border: #d1d5db;
|
|
308
|
+
--uidex-color-border-light: #e5e7eb;
|
|
255
309
|
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
33 tokens available across colors, shadows, border-radius, z-index, typography, and transitions. The default theme is dark monochromatic with zero border-radius and monospace typography.
|
|
313
|
+
|
|
314
|
+
## Package Exports
|
|
315
|
+
|
|
316
|
+
| Import | Description |
|
|
317
|
+
|--------|-------------|
|
|
318
|
+
| `uidex` | React components (re-exports `uidex/react`) |
|
|
319
|
+
| `uidex/core` | Vanilla JS classes (`createUidexUI`, `Overlay`, `Inspector`) |
|
|
320
|
+
| `uidex/react` | React wrappers (`UidexDevtools`, `UidexOverlay`) |
|
|
321
|
+
| `uidex/playwright` | Test fixture and helpers |
|
|
322
|
+
| `uidex/playwright/reporter` | Coverage reporter |
|
|
323
|
+
| `uidex/styles.css` | Standalone CSS (optional, auto-injected via Shadow DOM) |
|
|
256
324
|
|
|
257
|
-
|
|
258
|
-
|
|
325
|
+
## CLI Reference
|
|
326
|
+
|
|
327
|
+
```
|
|
328
|
+
npx uidex Initialize project (alias for init)
|
|
329
|
+
npx uidex init Create .uidex.json and update .gitignore
|
|
330
|
+
npx uidex scan Run component scanner
|
|
331
|
+
npx uidex scan --check Validate UIDEX_PAGE.md coverage
|
|
332
|
+
npx uidex scaffold [dir] Generate Playwright test stubs
|
|
333
|
+
npx uidex claude init Set up Claude Code integration
|
|
334
|
+
npx uidex claude teardown Remove Claude Code integration
|
|
259
335
|
```
|
|
260
336
|
|
|
261
337
|
## TypeScript
|
|
262
338
|
|
|
263
|
-
|
|
339
|
+
Full type definitions included:
|
|
264
340
|
|
|
265
|
-
```
|
|
341
|
+
```ts
|
|
266
342
|
import type {
|
|
267
343
|
UidexConfig,
|
|
268
344
|
UidexDefaults,
|
|
269
|
-
UidexDevtoolsProps,
|
|
270
|
-
UidexOverlayProps,
|
|
271
|
-
UidexLocation,
|
|
272
345
|
UidexMap,
|
|
346
|
+
UidexLocation,
|
|
347
|
+
UidexPage,
|
|
348
|
+
UidexFeature,
|
|
273
349
|
BorderStyle,
|
|
274
350
|
LabelPosition,
|
|
275
351
|
ButtonPosition,
|
|
352
|
+
KeyboardShortcut,
|
|
276
353
|
} from 'uidex';
|
|
277
354
|
```
|
|
278
355
|
|
|
356
|
+
## Examples
|
|
357
|
+
|
|
358
|
+
See `examples/` for working demos:
|
|
359
|
+
|
|
360
|
+
- `examples/next-app/` — Next.js App Router
|
|
361
|
+
- `examples/vite-app/` — Vite + React
|
|
362
|
+
|
|
279
363
|
## License
|
|
280
364
|
|
|
281
365
|
MIT
|