uidex 0.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.
- package/LICENSE +21 -0
- package/README.md +330 -0
- package/package.json +21 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024
|
|
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,330 @@
|
|
|
1
|
+
# uidex
|
|
2
|
+
|
|
3
|
+
A React library for highlighting and annotating components. Perfect for building tutorials, onboarding experiences, or debugging tools.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install uidex
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- React 18 or higher
|
|
14
|
+
- React DOM 18 or higher
|
|
15
|
+
|
|
16
|
+
## Configuration
|
|
17
|
+
|
|
18
|
+
Create a `.uidex.json` file in your project root to customize default settings:
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"$schema": "./node_modules/uidex/uidex.schema.json",
|
|
23
|
+
"defaults": {
|
|
24
|
+
"color": "#3b82f6",
|
|
25
|
+
"borderStyle": "solid",
|
|
26
|
+
"borderWidth": 2,
|
|
27
|
+
"showLabel": true,
|
|
28
|
+
"labelPosition": "top-left"
|
|
29
|
+
},
|
|
30
|
+
"colors": {
|
|
31
|
+
"primary": "#3b82f6",
|
|
32
|
+
"success": "#10b981",
|
|
33
|
+
"warning": "#f59e0b",
|
|
34
|
+
"error": "#ef4444",
|
|
35
|
+
"info": "#6366f1"
|
|
36
|
+
},
|
|
37
|
+
"disabled": false
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Using the Config Provider
|
|
42
|
+
|
|
43
|
+
Wrap your app with `AnnotateProvider` to apply configuration:
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import { AnnotateProvider } from 'uidex';
|
|
47
|
+
import config from './.uidex.json';
|
|
48
|
+
|
|
49
|
+
function App() {
|
|
50
|
+
return (
|
|
51
|
+
<AnnotateProvider config={config}>
|
|
52
|
+
{/* Your app */}
|
|
53
|
+
</AnnotateProvider>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Named Colors
|
|
59
|
+
|
|
60
|
+
Use named colors from your config:
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
<Annotate label="Error" color="error">
|
|
64
|
+
<button>Delete</button>
|
|
65
|
+
</Annotate>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
### Annotate Component
|
|
71
|
+
|
|
72
|
+
Wrap any component with `Annotate` to add hover-based highlighting:
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import { Annotate } from 'uidex';
|
|
76
|
+
|
|
77
|
+
function App() {
|
|
78
|
+
return (
|
|
79
|
+
<Annotate label="Submit Button" color="#10b981">
|
|
80
|
+
<button>Submit</button>
|
|
81
|
+
</Annotate>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
#### Props
|
|
87
|
+
|
|
88
|
+
| Prop | Type | Default | Description |
|
|
89
|
+
|------|------|---------|-------------|
|
|
90
|
+
| `children` | `ReactNode` | required | The content to wrap |
|
|
91
|
+
| `label` | `string` | - | Label text shown on hover |
|
|
92
|
+
| `color` | `string` | `#3b82f6` | Highlight color (hex or named color) |
|
|
93
|
+
| `borderStyle` | `'solid' \| 'dashed' \| 'dotted'` | `'solid'` | Border style |
|
|
94
|
+
| `borderWidth` | `number` | `2` | Border width in pixels |
|
|
95
|
+
| `showLabel` | `boolean` | `true` | Whether to show the label |
|
|
96
|
+
| `labelPosition` | `'top-left' \| 'top-right' \| 'bottom-left' \| 'bottom-right'` | `'top-left'` | Label position |
|
|
97
|
+
| `disabled` | `boolean` | `false` | Disable highlighting |
|
|
98
|
+
| `className` | `string` | - | Additional CSS class |
|
|
99
|
+
| `style` | `CSSProperties` | - | Additional inline styles |
|
|
100
|
+
| `onHover` | `(isHovered: boolean) => void` | - | Callback on hover state change |
|
|
101
|
+
|
|
102
|
+
### HighlightOverlay Component
|
|
103
|
+
|
|
104
|
+
For more control, use `HighlightOverlay` with a ref to any element:
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
import { useRef } from 'react';
|
|
108
|
+
import { HighlightOverlay } from 'uidex';
|
|
109
|
+
|
|
110
|
+
function App() {
|
|
111
|
+
const buttonRef = useRef<HTMLButtonElement>(null);
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<>
|
|
115
|
+
<button ref={buttonRef}>Click me</button>
|
|
116
|
+
<HighlightOverlay
|
|
117
|
+
targetRef={buttonRef}
|
|
118
|
+
label="Action Button"
|
|
119
|
+
color="#f59e0b"
|
|
120
|
+
visible={true}
|
|
121
|
+
/>
|
|
122
|
+
</>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Hooks
|
|
128
|
+
|
|
129
|
+
#### useHighlight
|
|
130
|
+
|
|
131
|
+
Simple state management for highlight visibility:
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
import { useHighlight } from 'uidex';
|
|
135
|
+
|
|
136
|
+
function App() {
|
|
137
|
+
const { isHighlighted, highlight, unhighlight, toggle } = useHighlight();
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<div>
|
|
141
|
+
<button onClick={toggle}>Toggle Highlight</button>
|
|
142
|
+
{isHighlighted && <div>Highlighted!</div>}
|
|
143
|
+
</div>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### useAnnotation
|
|
149
|
+
|
|
150
|
+
Combines a ref with highlight state:
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
import { useAnnotation, HighlightOverlay } from 'uidex';
|
|
154
|
+
|
|
155
|
+
function App() {
|
|
156
|
+
const { ref, isHighlighted, toggle } = useAnnotation();
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<>
|
|
160
|
+
<div ref={ref}>Target element</div>
|
|
161
|
+
<button onClick={toggle}>Toggle</button>
|
|
162
|
+
<HighlightOverlay targetRef={ref} visible={isHighlighted} label="Target" />
|
|
163
|
+
</>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### useAnnotateConfig
|
|
169
|
+
|
|
170
|
+
Access the current configuration:
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
import { useAnnotateConfig } from 'uidex';
|
|
174
|
+
|
|
175
|
+
function MyComponent() {
|
|
176
|
+
const config = useAnnotateConfig();
|
|
177
|
+
|
|
178
|
+
console.log(config.defaults?.color); // Current default color
|
|
179
|
+
console.log(config.colors?.primary); // Named color value
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Build-Time Scanner
|
|
184
|
+
|
|
185
|
+
The `uidex-scan` CLI tool scans your source files for `data-uidex` attributes and generates a TypeScript registry file. This enables type-safe access to all annotations in your codebase.
|
|
186
|
+
|
|
187
|
+
### Setup
|
|
188
|
+
|
|
189
|
+
Add scanner configuration to your `.uidex.json`:
|
|
190
|
+
|
|
191
|
+
```json
|
|
192
|
+
{
|
|
193
|
+
"$schema": "./node_modules/uidex/uidex.schema.json",
|
|
194
|
+
"scanner": {
|
|
195
|
+
"include": ["**/*.tsx"],
|
|
196
|
+
"exclude": ["**/*.test.*", "**/*.spec.*", "**/generated/**"],
|
|
197
|
+
"outputPath": "src/generated/annotations.ts",
|
|
198
|
+
"rootDir": "src"
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Note: The `include` and `exclude` patterns are relative to `rootDir`. If `rootDir` is `src`, use patterns like `**/*.tsx` (not `src/**/*.tsx`).
|
|
204
|
+
|
|
205
|
+
### Monorepo Support
|
|
206
|
+
|
|
207
|
+
For monorepos with multiple packages, use the `sources` array to scan multiple directories:
|
|
208
|
+
|
|
209
|
+
```json
|
|
210
|
+
{
|
|
211
|
+
"$schema": "./node_modules/uidex/uidex.schema.json",
|
|
212
|
+
"scanner": {
|
|
213
|
+
"sources": [
|
|
214
|
+
{
|
|
215
|
+
"rootDir": "src",
|
|
216
|
+
"include": ["**/*.tsx"]
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"rootDir": "../packages/ui/src",
|
|
220
|
+
"include": ["**/*.tsx"],
|
|
221
|
+
"prefix": "@myorg/ui"
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"rootDir": "../packages/components/src",
|
|
225
|
+
"include": ["**/*.tsx"],
|
|
226
|
+
"exclude": ["**/internal/**"],
|
|
227
|
+
"prefix": "@myorg/components"
|
|
228
|
+
}
|
|
229
|
+
],
|
|
230
|
+
"exclude": ["**/*.test.*", "**/*.spec.*", "**/generated/**"],
|
|
231
|
+
"outputPath": "src/generated/annotations.ts"
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Each source can have:
|
|
237
|
+
- `rootDir` - Directory to scan (can be relative path like `../packages/ui`)
|
|
238
|
+
- `include` - Glob patterns for files to include
|
|
239
|
+
- `exclude` - Additional exclude patterns for this source only
|
|
240
|
+
- `prefix` - Optional prefix for file paths in output (e.g., `@myorg/ui/Button.tsx`)
|
|
241
|
+
|
|
242
|
+
The `exclude` at the top level applies globally to all sources.
|
|
243
|
+
|
|
244
|
+
### Usage
|
|
245
|
+
|
|
246
|
+
Run the scanner as part of your build process:
|
|
247
|
+
|
|
248
|
+
```json
|
|
249
|
+
// package.json
|
|
250
|
+
{
|
|
251
|
+
"scripts": {
|
|
252
|
+
"prebuild": "npx uidex-scan",
|
|
253
|
+
"build": "next build"
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Or run it directly:
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
npx uidex-scan
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Adding Annotations
|
|
265
|
+
|
|
266
|
+
Add `data-uidex` attributes to your JSX elements:
|
|
267
|
+
|
|
268
|
+
```tsx
|
|
269
|
+
<nav data-uidex="main-nav">
|
|
270
|
+
<a href="/">Home</a>
|
|
271
|
+
</nav>
|
|
272
|
+
|
|
273
|
+
<button data-uidex="cta-button">Click Me</button>
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Generated Output
|
|
277
|
+
|
|
278
|
+
The scanner generates a TypeScript file with all discovered annotations:
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
// Auto-generated by uidex scanner
|
|
282
|
+
// Do not edit this file manually
|
|
283
|
+
|
|
284
|
+
export const annotations = {
|
|
285
|
+
"cta-button": [{ filePath: "src/pages/Home.tsx", line: 12 }],
|
|
286
|
+
"main-nav": [{ filePath: "src/components/Header.tsx", line: 5 }]
|
|
287
|
+
} as const;
|
|
288
|
+
|
|
289
|
+
export const annotationIds = ["cta-button", "main-nav"] as const;
|
|
290
|
+
|
|
291
|
+
export type AnnotationId = typeof annotationIds[number];
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Using Generated Types
|
|
295
|
+
|
|
296
|
+
Import the generated types for type-safe annotation access:
|
|
297
|
+
|
|
298
|
+
```tsx
|
|
299
|
+
import { annotations, AnnotationId } from './generated/annotations';
|
|
300
|
+
|
|
301
|
+
function highlightElement(id: AnnotationId) {
|
|
302
|
+
const locations = annotations[id];
|
|
303
|
+
console.log(`Found at: ${locations[0].filePath}:${locations[0].line}`);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Type error: "invalid-id" is not a valid AnnotationId
|
|
307
|
+
highlightElement("invalid-id");
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## TypeScript
|
|
311
|
+
|
|
312
|
+
This package is written in TypeScript and includes full type definitions. All types are exported:
|
|
313
|
+
|
|
314
|
+
```tsx
|
|
315
|
+
import type {
|
|
316
|
+
AnnotateProps,
|
|
317
|
+
AnnotateProviderProps,
|
|
318
|
+
BorderStyle,
|
|
319
|
+
HighlightOverlayProps,
|
|
320
|
+
LabelPosition,
|
|
321
|
+
ReactAnnotateConfig,
|
|
322
|
+
ReactAnnotateDefaults,
|
|
323
|
+
UseAnnotationOptions,
|
|
324
|
+
UseHighlightOptions,
|
|
325
|
+
} from 'uidex';
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## License
|
|
329
|
+
|
|
330
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "uidex",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A framework-agnostic library for highlighting and annotating UI elements",
|
|
5
|
+
"author": "",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": ""
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"annotation",
|
|
13
|
+
"highlight",
|
|
14
|
+
"overlay",
|
|
15
|
+
"component",
|
|
16
|
+
"react",
|
|
17
|
+
"vanilla-js",
|
|
18
|
+
"framework-agnostic"
|
|
19
|
+
],
|
|
20
|
+
"files": []
|
|
21
|
+
}
|