@snap/valdi 1.0.11 → 1.1.7
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/.metadata/.bazelrc.template +7 -6
- package/.metadata/MODULE.bazel.template +154 -0
- package/bundled-skills/registry.json +13 -2
- package/bundled-skills/skills/valdi-animations/skill.md +197 -0
- package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +1 -1
- package/bundled-skills/skills/valdi-compiler/skill.md +4 -4
- package/bundled-skills/skills/valdi-component-dedup/skill.md +263 -0
- package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +1 -1
- package/bundled-skills/skills/valdi-custom-view/skill.md +43 -1
- package/bundled-skills/skills/valdi-error-handling/skill.md +238 -0
- package/bundled-skills/skills/valdi-gestures/skill.md +198 -0
- package/bundled-skills/skills/valdi-inspect/skill.md +19 -1
- package/bundled-skills/skills/valdi-localization/skill.md +142 -0
- package/bundled-skills/skills/valdi-mock-breakdown/skill.md +327 -0
- package/bundled-skills/skills/valdi-mock-iterate/skill.md +216 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/diff.py +392 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/extract_colors.py +277 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/find_icon.py +303 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/snapshot-and-diff.sh +53 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/test_diff.py +207 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/test_extract_colors.py +167 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/test_find_icon.py +188 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/watch-and-diff.sh +181 -0
- package/bundled-skills/skills/valdi-mock-to-module/skill.md +451 -0
- package/bundled-skills/skills/valdi-navigation/skill.md +187 -0
- package/bundled-skills/skills/valdi-overview/skill.md +7 -4
- package/bundled-skills/skills/valdi-perf/skill.md +223 -0
- package/bundled-skills/skills/valdi-polyglot-module/skill.md +80 -0
- package/bundled-skills/skills/valdi-preview/skill.md +303 -0
- package/bundled-skills/skills/valdi-setup/skill.md +55 -5
- package/bundled-skills/skills/valdi-testing/skill.md +23 -7
- package/bundled-skills/skills/valdi-tsx/skill.md +69 -5
- package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +29 -5
- package/dist/commands/agentCheck.js +184 -0
- package/dist/commands/analyze.js +16 -0
- package/dist/commands/analyze_commands/duplicates.js +134 -0
- package/dist/commands/bootstrap.js +57 -73
- package/dist/commands/build.js +6 -0
- package/dist/commands/doctor.js +42 -266
- package/dist/commands/hotreload.js +15 -0
- package/dist/commands/inspect_commands/snapshot.js +71 -6
- package/dist/commands/inspect_commands/snapshot.spec.js +105 -0
- package/dist/commands/install.js +6 -0
- package/dist/commands/preview.js +81 -0
- package/dist/commands/projectsync.js +9 -7
- package/dist/commands/skills_commands/install.js +6 -1
- package/dist/commands/skills_commands/update.js +2 -1
- package/dist/core/analyze/clusterer.js +150 -0
- package/dist/core/analyze/fingerprint.js +2 -0
- package/dist/core/analyze/knownPatterns.js +76 -0
- package/dist/core/analyze/parser.js +177 -0
- package/dist/core/analyze/reporter.js +83 -0
- package/dist/core/analyze/scanner.js +172 -0
- package/dist/core/analyze/similarity.js +56 -0
- package/dist/core/constants.js +6 -3
- package/dist/core/packageFiles.spec.js +1 -1
- package/dist/preview/previewGenerator.js +240 -0
- package/dist/preview/previewGenerator.spec.js +203 -0
- package/dist/preview/viewModelParser.js +86 -0
- package/dist/preview/viewModelParser.spec.js +171 -0
- package/dist/setup/DevSetupHelper.js +0 -54
- package/dist/setup/linuxSetup.js +0 -16
- package/dist/setup/macOSSetup.js +1 -5
- package/dist/utils/BazelClient.js +15 -0
- package/dist/utils/applicationUtils.js +15 -0
- package/dist/utils/daemonClient.js +3 -1
- package/dist/utils/linuxDistro.js +0 -21
- package/dist/utils/linuxDistro.spec.js +0 -48
- package/dist/utils/skillsAdapters.js +126 -19
- package/dist/utils/skillsAdapters.spec.js +141 -0
- package/dist/utils/skillsRegistry.js +8 -0
- package/package.json +16 -8
- package/.metadata/WORKSPACE.template +0 -57
- package/dist/setup/versions.js +0 -8
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
# valdi-preview
|
|
2
|
+
|
|
3
|
+
Use this skill to **understand and visually preview a Valdi module or component** — read its API, render it in the preview harness app, inspect the view hierarchy, and capture a screenshot.
|
|
4
|
+
|
|
5
|
+
## When to use
|
|
6
|
+
|
|
7
|
+
- You need to understand what a Valdi component looks like before using it
|
|
8
|
+
- You want to see a component's rendered output to verify your code
|
|
9
|
+
- User asks "what does X component look like?" or "show me how X renders"
|
|
10
|
+
- You're building a UI and need to evaluate which widget to use
|
|
11
|
+
- You want to explore a component's API (viewModel, slots, styling)
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
The workflow has two phases:
|
|
16
|
+
|
|
17
|
+
1. **Static analysis** — read source files to understand the component's API
|
|
18
|
+
2. **Live preview** (optional) — render it in the preview harness, inspect the tree, screenshot it
|
|
19
|
+
|
|
20
|
+
You can stop after phase 1 if you only need API understanding. Phase 2 requires a running app.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Phase 1: Understand the component
|
|
25
|
+
|
|
26
|
+
### Step 1: Find the module source
|
|
27
|
+
|
|
28
|
+
Given a component name or module path, locate its source files:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Find by component class name
|
|
32
|
+
grep -r "export class CoreButton" --include="*.tsx" --include="*.ts"
|
|
33
|
+
|
|
34
|
+
# Find by module name in BUILD.bazel
|
|
35
|
+
grep -r "name = \"valdi_widgets_core\"" --include="BUILD.bazel"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Step 2: Read the API surface
|
|
39
|
+
|
|
40
|
+
Read the component's main `.tsx` file and look for:
|
|
41
|
+
|
|
42
|
+
1. **ViewModel interface** — the props the component accepts. Look for `@ViewModel` JSDoc tag:
|
|
43
|
+
```typescript
|
|
44
|
+
/**
|
|
45
|
+
* @ViewModel
|
|
46
|
+
*/
|
|
47
|
+
export interface CoreButtonViewModel {
|
|
48
|
+
title: string;
|
|
49
|
+
onPress: () => void;
|
|
50
|
+
disabled?: boolean;
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
2. **Component class** — the rendering logic. Look for `@Component` JSDoc tag and the `onRender()` method.
|
|
55
|
+
|
|
56
|
+
3. **Slots** — child content areas. Look for `AnyRenderFunction` or `$slot` usage in the viewModel or render.
|
|
57
|
+
|
|
58
|
+
4. **JSDoc** — descriptions, `@example` tags, parameter docs.
|
|
59
|
+
|
|
60
|
+
5. **State interface** — if it's a `StatefulComponent`, read the state shape.
|
|
61
|
+
|
|
62
|
+
### Step 3: Find usage examples
|
|
63
|
+
|
|
64
|
+
Search the codebase for real usage of the component:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Find files that import this component
|
|
68
|
+
grep -r "import.*CoreButton" --include="*.tsx" --include="*.ts" -l
|
|
69
|
+
|
|
70
|
+
# Find JSX usage
|
|
71
|
+
grep -r "<CoreButton" --include="*.tsx"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Pick 2-3 representative usages to understand common prop combinations.
|
|
75
|
+
|
|
76
|
+
### Step 4: Summarize
|
|
77
|
+
|
|
78
|
+
Report to the user:
|
|
79
|
+
- Component name and location
|
|
80
|
+
- ViewModel props (required and optional)
|
|
81
|
+
- What it renders (layout structure from `onRender()`)
|
|
82
|
+
- How it's typically used (from real examples)
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Phase 2: Live preview
|
|
87
|
+
|
|
88
|
+
### Option A: `valdi preview` CLI (recommended)
|
|
89
|
+
|
|
90
|
+
The fastest path — automatically generates the preview harness and builds:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# By import path
|
|
94
|
+
valdi preview widgets/src/components/button/Checkbox
|
|
95
|
+
|
|
96
|
+
# By file path
|
|
97
|
+
valdi preview ./valdi_modules/widgets/src/components/button/Checkbox.tsx
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
This command:
|
|
101
|
+
1. Resolves the component file
|
|
102
|
+
2. Parses the ViewModel to extract props
|
|
103
|
+
3. Generates `apps/preview/PreviewRoot.tsx` with sample props and interactive state
|
|
104
|
+
4. Generates `apps/preview/BUILD.bazel` with correct deps
|
|
105
|
+
5. Generates `apps/preview/tsconfig.json` with correct path mappings
|
|
106
|
+
6. Builds and launches `//apps/preview:preview_app_macos`
|
|
107
|
+
|
|
108
|
+
First build takes 2-5 minutes; subsequent builds ~5-15 seconds.
|
|
109
|
+
|
|
110
|
+
### Option B: Manual harness setup
|
|
111
|
+
|
|
112
|
+
For full control or when `valdi preview` doesn't support your use case.
|
|
113
|
+
|
|
114
|
+
Requires a running Valdi app. If no app is running, tell the user to start one first.
|
|
115
|
+
|
|
116
|
+
### Step 1: Edit the preview harness
|
|
117
|
+
|
|
118
|
+
The preview harness app lives at `apps/preview/` in the Valdi repo. It has three files:
|
|
119
|
+
|
|
120
|
+
| File | Purpose |
|
|
121
|
+
|------|---------|
|
|
122
|
+
| `PreviewRoot.tsx` | Root component — **edit this** to render your target |
|
|
123
|
+
| `BUILD.bazel` | Module deps — **add deps here** if the target is in another module |
|
|
124
|
+
| `tsconfig.json` | Path mappings — **add path entries** for new module deps |
|
|
125
|
+
|
|
126
|
+
**Edit `PreviewRoot.tsx`** to import and render the target component:
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import { Component } from 'valdi_core/src/Component';
|
|
130
|
+
import { CoreButton } from 'valdi_widgets_core/src/components/button/CoreButton';
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @ViewModel
|
|
134
|
+
* @ExportModel
|
|
135
|
+
*/
|
|
136
|
+
export interface ViewModel {}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @Context
|
|
140
|
+
* @ExportModel
|
|
141
|
+
*/
|
|
142
|
+
export interface ComponentContext {}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @Component
|
|
146
|
+
* @ExportModel
|
|
147
|
+
*/
|
|
148
|
+
export class PreviewRoot extends Component<ViewModel, ComponentContext> {
|
|
149
|
+
onRender(): void {
|
|
150
|
+
<view backgroundColor="#ffffff" width="100%" height="100%" padding={24}
|
|
151
|
+
alignItems="center" justifyContent="center">
|
|
152
|
+
<CoreButton title="Example Button" onPress={() => {}} />
|
|
153
|
+
</view>;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**If the component is in another module**, add it to `BUILD.bazel` deps:
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
deps = [
|
|
162
|
+
"//src/valdi_modules/src/valdi/valdi_core",
|
|
163
|
+
"//src/valdi_modules/src/valdi/valdi_tsx",
|
|
164
|
+
"//path/to/target_module", # Add this
|
|
165
|
+
],
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
And add the path mapping to `tsconfig.json`:
|
|
169
|
+
|
|
170
|
+
```json
|
|
171
|
+
{
|
|
172
|
+
"compilerOptions": {
|
|
173
|
+
"paths": {
|
|
174
|
+
"target_module/*": ["../../path/to/target_module/*"]
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Step 2: Build and hot-reload
|
|
181
|
+
|
|
182
|
+
**Recommended workflow** — build once, then use hot-reload for instant iteration:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
# 1. Build the macOS app once
|
|
186
|
+
bazel build //apps/preview:preview_app_macos
|
|
187
|
+
|
|
188
|
+
# 2. Launch it directly (stays alive as background process)
|
|
189
|
+
open bazel-bin/apps/preview/preview_app_macos_archive-root/Valdi\ Preview.app
|
|
190
|
+
|
|
191
|
+
# 3. Start the hot-reloader
|
|
192
|
+
valdi hotreload --target //apps/preview:preview_app_hotreload
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Now any edit to `PreviewRoot.tsx` is automatically recompiled and pushed to the running app in ~1s.
|
|
196
|
+
|
|
197
|
+
**Alternative** — full rebuild (slower but simpler):
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
# macOS (fastest for preview)
|
|
201
|
+
bazel run //apps/preview:preview_app_macos
|
|
202
|
+
|
|
203
|
+
# iOS simulator
|
|
204
|
+
bazel run //apps/preview:preview_app_ios_sim
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Step 3: Inspect the rendered output
|
|
208
|
+
|
|
209
|
+
Once the component is on screen, use **port 13591** for standalone macOS apps:
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# Capture a screenshot by component name (stable across hot-reloads)
|
|
213
|
+
valdi inspect snapshot --key PreviewRoot --port 13591
|
|
214
|
+
|
|
215
|
+
# Or by a custom key prop you set on an element
|
|
216
|
+
valdi inspect snapshot --key my-card --port 13591
|
|
217
|
+
|
|
218
|
+
# Or by numeric element ID (from tree output — changes on each hot-reload)
|
|
219
|
+
valdi inspect snapshot <elementId> 2 --port 13591
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Prefer `--key`** — it resolves the component tag or element key to its numeric ID automatically, so you don't need to re-query the tree after every hot-reload.
|
|
223
|
+
|
|
224
|
+
If you're previewing inside a mobile app (Snapchat, etc.), use the default port 13592 instead.
|
|
225
|
+
|
|
226
|
+
Then read the PNG file to see what it looks like.
|
|
227
|
+
|
|
228
|
+
### Step 4: Iterate
|
|
229
|
+
|
|
230
|
+
If the rendering doesn't look right:
|
|
231
|
+
|
|
232
|
+
1. Adjust props, styles, or container layout in `PreviewRoot.tsx`
|
|
233
|
+
2. Hot-reload picks up the change automatically (~1s)
|
|
234
|
+
3. Re-query tree for new element IDs, then `valdi inspect snapshot`
|
|
235
|
+
4. Repeat until the component renders as expected
|
|
236
|
+
|
|
237
|
+
**Iteration priority** — for fastest convergence, fix in this order:
|
|
238
|
+
1. Font sizes (almost always too small on first pass)
|
|
239
|
+
2. Vertical spacing between sections
|
|
240
|
+
3. Text colors
|
|
241
|
+
4. Element sizing (padding, border radius)
|
|
242
|
+
5. Decorative elements (fills, shadows)
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Previewing multiple components
|
|
247
|
+
|
|
248
|
+
To compare several components side by side, render them all in `PreviewRoot.tsx`:
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
onRender(): void {
|
|
252
|
+
<view backgroundColor="#ffffff" width="100%" height="100%" padding={24}>
|
|
253
|
+
<scroll height="100%" width="100%">
|
|
254
|
+
<label value="CoreButton" font="system-bold 14" color="#666" marginBottom={8} />
|
|
255
|
+
<CoreButton title="Primary" onPress={() => {}} />
|
|
256
|
+
|
|
257
|
+
<view height={24} />
|
|
258
|
+
|
|
259
|
+
<label value="PillButton" font="system-bold 14" color="#666" marginBottom={8} />
|
|
260
|
+
<PillButton title="Secondary" onPress={() => {}} />
|
|
261
|
+
</scroll>
|
|
262
|
+
</view>;
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## Previewing with sample data
|
|
269
|
+
|
|
270
|
+
When a component needs complex viewModel data, create realistic sample data:
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
// For a component that needs a list of items
|
|
274
|
+
const sampleItems = [
|
|
275
|
+
{ id: '1', title: 'First item', subtitle: 'Description' },
|
|
276
|
+
{ id: '2', title: 'Second item', subtitle: 'Another one' },
|
|
277
|
+
{ id: '3', title: 'Third item', subtitle: 'And another' },
|
|
278
|
+
];
|
|
279
|
+
|
|
280
|
+
onRender(): void {
|
|
281
|
+
<MyListComponent items={sampleItems} onItemTap={() => {}} />;
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## Cleanup
|
|
288
|
+
|
|
289
|
+
After previewing, restore `PreviewRoot.tsx` to its placeholder state so the harness is ready for the next preview. Revert any deps added to `BUILD.bazel` and `tsconfig.json` unless the user wants to keep them.
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
## Troubleshooting
|
|
294
|
+
|
|
295
|
+
**"Module not found"** — You forgot to add the dep to `BUILD.bazel` or the path mapping to `tsconfig.json`.
|
|
296
|
+
|
|
297
|
+
**"Cannot resolve import"** — The tsconfig path is wrong. Check the relative path from `apps/preview/` to the target module.
|
|
298
|
+
|
|
299
|
+
**Hot-reload not picking up changes** — Stop and restart `valdi hotreload`. If that doesn't work, do a full `bazel run`.
|
|
300
|
+
|
|
301
|
+
**"Valdi daemon not running"** — The app isn't running. Build and launch it first with `bazel run`.
|
|
302
|
+
|
|
303
|
+
**Component renders blank** — Check that you're passing all required viewModel props. Read the ViewModel interface again.
|
|
@@ -38,13 +38,14 @@ valdi_module(
|
|
|
38
38
|
|
|
39
39
|
```json
|
|
40
40
|
{
|
|
41
|
-
"extends": "
|
|
41
|
+
"extends": "../_configs/base.tsconfig.json"
|
|
42
42
|
}
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
The `extends` path must resolve to a `_configs/base.tsconfig.json` file. The relative
|
|
46
|
+
depth depends on where your module lives — check neighboring modules for the correct
|
|
47
|
+
prefix. The base config sets up `paths` aliases so `'valdi_core/src/...'` imports
|
|
48
|
+
resolve correctly.
|
|
48
49
|
|
|
49
50
|
## Dependency Table
|
|
50
51
|
|
|
@@ -54,7 +55,6 @@ imports resolve correctly.
|
|
|
54
55
|
| JSX elements (`<view>`, `<label>`, etc.), `NativeTemplateElements` | `//src/valdi_modules/src/valdi/valdi_tsx` |
|
|
55
56
|
| `HTTPClient`, `HTTPResponse` | `//src/valdi_modules/src/valdi/valdi_http` |
|
|
56
57
|
| `PersistentStore` | `//src/valdi_modules/src/valdi/persistence` |
|
|
57
|
-
| Pre-built UI components (buttons, cards, etc.) | `//src/valdi_modules/src/valdi/valdi_widgets_core` |
|
|
58
58
|
|
|
59
59
|
## ios_module_name Convention
|
|
60
60
|
|
|
@@ -105,6 +105,21 @@ export class MyComponent extends StatefulComponent<MyComponentViewModel, MyState
|
|
|
105
105
|
}
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
+
## Registering in an App Target
|
|
109
|
+
|
|
110
|
+
Your module must be added as a dependency of an application target to be compiled
|
|
111
|
+
and linked. The exact location depends on your project — look for the list of
|
|
112
|
+
Valdi module deps in the app's `BUILD.bazel` (often a `VALDI_MODULES` list or
|
|
113
|
+
similar) and add your module:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
"//path/to/my_module:my_module",
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Without this, the module will not be compiled or bundled — the app will fail at
|
|
120
|
+
runtime with "No item named '...' in module '...'" even though the build itself
|
|
121
|
+
may succeed.
|
|
122
|
+
|
|
108
123
|
## Building
|
|
109
124
|
|
|
110
125
|
```bash
|
|
@@ -127,3 +142,38 @@ valdi hotreload --network # Discover device over Wi-Fi instead of USB
|
|
|
127
142
|
|
|
128
143
|
If hot reload stops reflecting changes, stop with `Ctrl+C` and restart — the CLI
|
|
129
144
|
will clean stale build artifacts automatically.
|
|
145
|
+
|
|
146
|
+
## Agent Iteration Workflow
|
|
147
|
+
|
|
148
|
+
When an AI agent is editing Valdi TypeScript, use the hot reloader for compile
|
|
149
|
+
feedback and `agent-check` for lint + test validation.
|
|
150
|
+
|
|
151
|
+
### During iteration
|
|
152
|
+
|
|
153
|
+
1. Hot reloader is running (`valdi hotreload`). It recompiles on every file save.
|
|
154
|
+
2. Watch the hot reloader output for compile results:
|
|
155
|
+
- `"Recompilation pass finished"` — change compiled successfully
|
|
156
|
+
- `[ERROR]` lines — compile error, fix before continuing
|
|
157
|
+
3. Run a quick validation (lint + tests, skips the Bazel build):
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
valdi agent-check --module my_module --quick
|
|
161
|
+
valdi agent-check --module my_module --quick --json # machine-readable
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Before committing
|
|
165
|
+
|
|
166
|
+
Run the full pipeline to catch build config issues, lint drift, and test regressions:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
valdi agent-check --module my_module
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### agent-check flags
|
|
173
|
+
|
|
174
|
+
| Flag | Effect |
|
|
175
|
+
|---|---|
|
|
176
|
+
| `--module <name>` | Valdi module name to validate |
|
|
177
|
+
| `--target <label>` | Bazel target path (alternative to --module) |
|
|
178
|
+
| `--quick` | Skip build step (hot reloader already compiled) |
|
|
179
|
+
| `--json` | Structured JSON output for agent consumption |
|
|
@@ -42,20 +42,24 @@ my_module/
|
|
|
42
42
|
|
|
43
43
|
## BUILD.bazel for Tests
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
Tests are included in the same `valdi_module` target as source files. The `valdi_module` rule auto-generates a test target from `test/` files:
|
|
46
46
|
|
|
47
47
|
```python
|
|
48
48
|
load("//bzl/valdi:valdi_module.bzl", "valdi_module")
|
|
49
49
|
|
|
50
50
|
valdi_module(
|
|
51
|
-
name = "
|
|
52
|
-
srcs = glob([
|
|
53
|
-
|
|
51
|
+
name = "my_module",
|
|
52
|
+
srcs = glob([
|
|
53
|
+
"src/**/*.ts",
|
|
54
|
+
"src/**/*.tsx",
|
|
55
|
+
"test/**/*.ts",
|
|
56
|
+
"test/**/*.tsx",
|
|
57
|
+
]) + ["tsconfig.json"],
|
|
54
58
|
deps = [
|
|
55
|
-
"
|
|
56
|
-
"//src/valdi_modules/src/valdi/valdi_test",
|
|
57
|
-
"//src/valdi_modules/src/foundation/test/util",
|
|
59
|
+
"//src/valdi_modules/src/valdi/valdi_core",
|
|
58
60
|
"//src/valdi_modules/src/valdi/valdi_tsx",
|
|
61
|
+
"//src/valdi_modules/src/valdi/valdi_test",
|
|
62
|
+
"//src/valdi_modules/src/valdi/foundation/test/util",
|
|
59
63
|
],
|
|
60
64
|
)
|
|
61
65
|
```
|
|
@@ -63,3 +67,15 @@ valdi_module(
|
|
|
63
67
|
## Platform Tests
|
|
64
68
|
|
|
65
69
|
For C++, iOS, and Android platform layer tests, see the `valdi-cpp-runtime`, `valdi-ios`, and `valdi-android` skills respectively.
|
|
70
|
+
|
|
71
|
+
## Combined Validation with agent-check
|
|
72
|
+
|
|
73
|
+
Instead of running build and test separately, use `agent-check`:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
valdi agent-check --module my_module # build + lint + test
|
|
77
|
+
valdi agent-check --module my_module --quick # lint + test only (hot reloader running)
|
|
78
|
+
valdi agent-check --module my_module --quick --json # machine-readable output
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
See the **valdi-setup** skill for the full hot reloader + agent-check iteration workflow.
|
|
@@ -106,9 +106,17 @@ document.addEventListener('click', ...); // Doesn't work!
|
|
|
106
106
|
onChange={this.handleTextChange}
|
|
107
107
|
onEditEnd={this.handleSubmit}
|
|
108
108
|
/>
|
|
109
|
+
|
|
110
|
+
// ✅ CORRECT - For keyboard input on macOS desktop, use a polyglot <custom-view>
|
|
111
|
+
// (see valdi-polyglot-module and valdi-custom-view skills for full pattern)
|
|
112
|
+
{Device.isDesktop() && (
|
|
113
|
+
<custom-view macosClass='SCKeyboardView' onKeyDown={this.handleKeyDown} width={200} height={200}>
|
|
114
|
+
{/* wrap visible content so the view has non-zero size for first responder */}
|
|
115
|
+
</custom-view>
|
|
116
|
+
)}
|
|
109
117
|
```
|
|
110
118
|
|
|
111
|
-
**Important**: Valdi doesn't support `addEventListener`, `keydown`, or other global DOM events. Use element-specific callbacks like `onTap`, `onPress`, `onChange`, etc.
|
|
119
|
+
**Important**: Valdi doesn't support `addEventListener`, `keydown`, or other global DOM events. Use element-specific callbacks like `onTap`, `onPress`, `onChange`, etc. For keyboard input on macOS desktop, use a polyglot `<custom-view>` with a native NSView that captures `keyDown:` events and forwards them via a bound callback attribute.
|
|
112
120
|
|
|
113
121
|
## Timers and Scheduling
|
|
114
122
|
|
|
@@ -178,6 +186,26 @@ onRender() {
|
|
|
178
186
|
}
|
|
179
187
|
```
|
|
180
188
|
|
|
189
|
+
### Font weights
|
|
190
|
+
|
|
191
|
+
Only two system font weights are available:
|
|
192
|
+
- `'system 16'` — regular weight
|
|
193
|
+
- `'system-bold 16'` — bold weight
|
|
194
|
+
|
|
195
|
+
**No other weights exist.** `system-semibold`, `system-light`, `system-medium` etc. will cause build errors. If you need semibold, use `system-bold` instead.
|
|
196
|
+
|
|
197
|
+
### ScrollView restrictions
|
|
198
|
+
|
|
199
|
+
`<scroll>` (ScrollView) does **not** support `flexDirection`. It always scrolls vertically. Do not set `flexDirection: 'column'` on a ScrollView style — it will cause a build error.
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
// ❌ WRONG - flexDirection not valid on ScrollView
|
|
203
|
+
new Style<ScrollView>({ flexDirection: 'column' })
|
|
204
|
+
|
|
205
|
+
// ✅ CORRECT - ScrollView scrolls vertically by default, no flexDirection needed
|
|
206
|
+
new Style<ScrollView>({ width: '100%', height: '100%' })
|
|
207
|
+
```
|
|
208
|
+
|
|
181
209
|
### Style Composition
|
|
182
210
|
|
|
183
211
|
```typescript
|
|
@@ -230,6 +258,11 @@ new Style<View>({
|
|
|
230
258
|
paddingVertical: 10, // ❌ Use padding: '10 0'
|
|
231
259
|
paddingInline: 15, // ❌ Doesn't exist
|
|
232
260
|
})
|
|
261
|
+
|
|
262
|
+
// ❌ WRONG - gap property doesn't exist on View
|
|
263
|
+
new Style<View>({ flexDirection: 'row', gap: '8' })
|
|
264
|
+
// ✅ CORRECT - use margin on child elements instead
|
|
265
|
+
// In JSX: <view marginRight={8}> or margin="0 8 0 0"
|
|
233
266
|
```
|
|
234
267
|
|
|
235
268
|
### Layout: Flexbox (Yoga)
|
|
@@ -328,6 +361,28 @@ const layoutStyle = new Style<Layout>({ padding: 10 });
|
|
|
328
361
|
>
|
|
329
362
|
> **📖 Best practices**: See `/docs/docs/core-styling.md` for styling patterns and examples
|
|
330
363
|
|
|
364
|
+
## @ExportModel ViewModel Restrictions
|
|
365
|
+
|
|
366
|
+
Interfaces annotated with `@ViewModel @ExportModel` are exported to native code. The Valdi compiler can only export **primitive types** (`string`, `number`, `boolean`) and other `@ExportModel`-annotated interfaces. Custom type aliases (e.g. `type Direction = 'UP' | 'DOWN'`) are **not supported** in exported ViewModels.
|
|
367
|
+
|
|
368
|
+
```typescript
|
|
369
|
+
// ❌ WRONG — type alias in @ExportModel ViewModel
|
|
370
|
+
type Direction = 'UP' | 'DOWN' | 'LEFT' | 'RIGHT';
|
|
371
|
+
|
|
372
|
+
/** @ViewModel @ExportModel */
|
|
373
|
+
interface GameViewModel {
|
|
374
|
+
initialDirection?: Direction; // ❌ Compiler error: "Unrecognized type"
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// ✅ CORRECT — keep custom types in State (internal), not ViewModel (exported)
|
|
378
|
+
/** @ViewModel @ExportModel */
|
|
379
|
+
interface GameViewModel {} // Only export what native code needs
|
|
380
|
+
|
|
381
|
+
interface GameState {
|
|
382
|
+
direction: Direction; // ✅ Fine — State is not exported
|
|
383
|
+
}
|
|
384
|
+
```
|
|
385
|
+
|
|
331
386
|
## Common Mistakes to Avoid
|
|
332
387
|
|
|
333
388
|
1. **Returning JSX from onRender()** - It returns void, JSX is a statement
|
|
@@ -337,10 +392,17 @@ const layoutStyle = new Style<Layout>({ padding: 10 });
|
|
|
337
392
|
5. **Suggesting scheduleRender()** - Deprecated, use StatefulComponent + setState()
|
|
338
393
|
6. **Using addEventListener** - Use element callbacks like onTap, onPress, onChange
|
|
339
394
|
7. **Using setInterval/setTimeout directly** - Use this.setTimeoutDisposable()
|
|
340
|
-
8. **Using CSS properties that don't exist** - No gap, paddingHorizontal, paddingVertical
|
|
395
|
+
8. **Using CSS properties that don't exist** - No gap, paddingHorizontal, paddingVertical; use margin on children for gap
|
|
341
396
|
9. **Using `flex: 1`** - `flex` doesn't exist on `View`; use `flexGrow: 1` instead
|
|
342
397
|
10. **Using `fontSize` on Label** - Labels use `font: 'system 20'` (string), not `fontSize`
|
|
343
|
-
11. **
|
|
398
|
+
11. **Typing SIGIcon values as `string`** - `SIGIcon.cameraStroke` etc. return `Asset`, not `string`; use `import { Asset } from 'valdi_core/src/Asset'` for ViewModel fields that store icon references
|
|
399
|
+
12. **Using `overflow: 'hidden'`** - `View` only accepts `'visible' | 'scroll'`; remove overflow or use 'scroll'
|
|
400
|
+
13. **Using type aliases in `@ExportModel` ViewModels** - Only primitives and other `@ExportModel` types are allowed
|
|
401
|
+
14. **Importing `Shape` instead of `ShapeView`** - `Shape` is not exported; use `import { ShapeView } from 'valdi_tsx/src/NativeTemplateElements'` and `new Style<ShapeView>({...})`
|
|
402
|
+
15. **Using per-side border properties** - No `borderRight`, `borderRightWidth`, etc. Only `borderWidth`, `borderColor`, `borderRadius` exist. Use a thin `<view>` as a divider instead.
|
|
403
|
+
16. **Using `font: 'system-semibold 16'`** - Only `system` (regular) and `system-bold` are reliably available. Use `system-bold` for semibold.
|
|
404
|
+
17. **ViewModel/Context name collisions** - When a module has multiple components, each exported `ViewModel` and `ComponentContext` must have a unique name (e.g. `WeatherCardViewModel` not just `ViewModel`), or the compiler will emit conflicting platform types.
|
|
405
|
+
18. **Using `flexDirection` on ScrollView** - ScrollView doesn't support flexDirection; it scrolls vertically by default
|
|
344
406
|
|
|
345
407
|
## Platform Detection
|
|
346
408
|
|
|
@@ -354,14 +416,16 @@ class MyComponent extends Component<MyViewModel> {
|
|
|
354
416
|
<view>
|
|
355
417
|
{Device.isIOS() && <IOSOnlyView />}
|
|
356
418
|
{Device.isAndroid() && <AndroidOnlyView />}
|
|
357
|
-
{Device.
|
|
419
|
+
{Device.isDesktop() && <DesktopOnlyView />}
|
|
358
420
|
{Device.isWeb() && <WebOnlyView />}
|
|
359
421
|
</view>;
|
|
360
422
|
}
|
|
361
423
|
}
|
|
362
424
|
```
|
|
363
425
|
|
|
364
|
-
|
|
426
|
+
**Available guards:** `Device.isIOS()`, `Device.isAndroid()`, `Device.isDesktop()`, `Device.isWeb()`
|
|
427
|
+
|
|
428
|
+
Use platform guards before using `<custom-view>` elements that don't have implementations on all platforms. `Device.isDesktop()` is true for macOS desktop apps (the preview/standalone app). There is no `Device.isMacOS()` — use `Device.isDesktop()` instead.
|
|
365
429
|
|
|
366
430
|
## Imports
|
|
367
431
|
|
|
@@ -71,12 +71,12 @@ class Counter extends StatefulComponent<CounterViewModel, CounterState> {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
// Class arrow functions — never inline lambdas in JSX props
|
|
74
|
-
private handleIncrement = (): void => {
|
|
74
|
+
private handleIncrement = (_event: unknown): void => {
|
|
75
75
|
this.setState({ count: this.state.count + 1 });
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
private handleTextChange = (text: string): void => {
|
|
79
|
-
this.setState({ inputText: text });
|
|
78
|
+
private handleTextChange = (event: { text: string }): void => {
|
|
79
|
+
this.setState({ inputText: event.text });
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
onRender(): void {
|
|
@@ -87,7 +87,7 @@ class Counter extends StatefulComponent<CounterViewModel, CounterState> {
|
|
|
87
87
|
value={this.state.inputText}
|
|
88
88
|
onChange={this.handleTextChange}
|
|
89
89
|
/>;
|
|
90
|
-
<
|
|
90
|
+
<label value="Increment" onTap={this.handleIncrement} />;
|
|
91
91
|
</view>;
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -127,7 +127,7 @@ class MediaPlayer extends Component<MediaPlayerViewModel> {
|
|
|
127
127
|
<view>
|
|
128
128
|
{Device.isIOS() && <label value="iOS player" />}
|
|
129
129
|
{Device.isAndroid() && <label value="Android player" />}
|
|
130
|
-
{Device.
|
|
130
|
+
{Device.isDesktop() && <label value="macOS player" />}
|
|
131
131
|
</view>;
|
|
132
132
|
}
|
|
133
133
|
}
|
|
@@ -165,9 +165,33 @@ class AppRoot extends Component {
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
// ─── @ExportModel ViewModel: only primitives, no type aliases ────────────────
|
|
169
|
+
|
|
170
|
+
type Direction = 'UP' | 'DOWN' | 'LEFT' | 'RIGHT';
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @ViewModel
|
|
174
|
+
* @ExportModel
|
|
175
|
+
*/
|
|
176
|
+
interface GameViewModel {} // Don't put Direction here — it can't be exported
|
|
177
|
+
|
|
178
|
+
interface GameState {
|
|
179
|
+
direction: Direction; // Type aliases are fine in State (not exported)
|
|
180
|
+
score: number;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
class GameComponent extends StatefulComponent<GameViewModel, GameState> {
|
|
184
|
+
state: GameState = { direction: 'RIGHT', score: 0 };
|
|
185
|
+
|
|
186
|
+
onRender(): void {
|
|
187
|
+
<label value={`Direction: ${this.state.direction}, Score: ${this.state.score}`} />;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
168
191
|
// Suppress unused-variable warnings for top-level declarations
|
|
169
192
|
void Counter;
|
|
170
193
|
void ItemList;
|
|
171
194
|
void Greeting;
|
|
172
195
|
void MediaPlayer;
|
|
173
196
|
void AppRoot;
|
|
197
|
+
void GameComponent;
|