@snap/valdi 1.0.6 → 1.0.8

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.
Files changed (161) hide show
  1. package/README.md +22 -10
  2. package/bundled-skills/CONTRIBUTING_SKILLS.md +74 -0
  3. package/bundled-skills/registry.json +20 -0
  4. package/bundled-skills/skills/valdi-android/skill.md +89 -0
  5. package/bundled-skills/skills/valdi-async/skill.md +246 -0
  6. package/bundled-skills/skills/valdi-async/tests/BUILD.bazel +19 -0
  7. package/bundled-skills/skills/valdi-async/tests/README.md +25 -0
  8. package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +210 -0
  9. package/bundled-skills/skills/valdi-async/tests/tsconfig.json +1 -0
  10. package/bundled-skills/skills/valdi-bazel/skill.md +122 -0
  11. package/bundled-skills/skills/valdi-compiler/skill.md +108 -0
  12. package/bundled-skills/skills/valdi-component-tests/skill.md +430 -0
  13. package/bundled-skills/skills/valdi-component-tests/tests/BUILD.bazel +24 -0
  14. package/bundled-skills/skills/valdi-component-tests/tests/README.md +35 -0
  15. package/bundled-skills/skills/valdi-component-tests/tests/src/ProfileCard.tsx +38 -0
  16. package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +107 -0
  17. package/bundled-skills/skills/valdi-component-tests/tests/tsconfig.json +1 -0
  18. package/bundled-skills/skills/valdi-cpp-runtime/skill.md +103 -0
  19. package/bundled-skills/skills/valdi-custom-view/skill.md +62 -0
  20. package/bundled-skills/skills/valdi-ios/skill.md +93 -0
  21. package/bundled-skills/skills/valdi-migrate/skill.md +175 -0
  22. package/bundled-skills/skills/valdi-migrate/tests/BUILD.bazel +23 -0
  23. package/bundled-skills/skills/valdi-migrate/tests/README.md +70 -0
  24. package/bundled-skills/skills/valdi-migrate/tests/check_antipatterns.py +89 -0
  25. package/bundled-skills/skills/valdi-migrate/tests/compose_example.kt +94 -0
  26. package/bundled-skills/skills/valdi-migrate/tests/flutter_example.dart +129 -0
  27. package/bundled-skills/skills/valdi-migrate/tests/react_example.tsx +98 -0
  28. package/bundled-skills/skills/valdi-migrate/tests/src/expected_valdi.tsx +267 -0
  29. package/bundled-skills/skills/valdi-migrate/tests/tsconfig.json +3 -0
  30. package/{.metadata/.cursorrules.template → bundled-skills/skills/valdi-overview/skill.md} +23 -13
  31. package/bundled-skills/skills/valdi-perf/skill.md +197 -0
  32. package/bundled-skills/skills/valdi-perf/tests/BUILD.bazel +19 -0
  33. package/bundled-skills/skills/valdi-perf/tests/README.md +26 -0
  34. package/bundled-skills/skills/valdi-perf/tests/src/reference.tsx +202 -0
  35. package/bundled-skills/skills/valdi-perf/tests/tsconfig.json +1 -0
  36. package/bundled-skills/skills/valdi-polyglot-module/skill.md +85 -0
  37. package/bundled-skills/skills/valdi-setup/skill.md +129 -0
  38. package/bundled-skills/skills/valdi-testing/skill.md +65 -0
  39. package/bundled-skills/skills/valdi-tsx/skill.md +385 -0
  40. package/bundled-skills/skills/valdi-tsx/tests/BUILD.bazel +19 -0
  41. package/bundled-skills/skills/valdi-tsx/tests/README.md +29 -0
  42. package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +173 -0
  43. package/bundled-skills/skills/valdi-tsx/tests/tsconfig.json +1 -0
  44. package/dist/commands/bootstrap.js +3 -9
  45. package/dist/commands/newModule.js +10 -14
  46. package/dist/commands/skills.js +16 -0
  47. package/dist/commands/skills_commands/create.js +125 -0
  48. package/dist/commands/skills_commands/install.js +96 -0
  49. package/dist/commands/skills_commands/list.js +83 -0
  50. package/dist/commands/skills_commands/remove.js +41 -0
  51. package/dist/commands/skills_commands/update.js +59 -0
  52. package/dist/core/constants.js +1 -1
  53. package/dist/index.js +5 -0
  54. package/dist/setup/versions.js +1 -1
  55. package/dist/utils/skillsAdapters.js +140 -0
  56. package/dist/utils/skillsRegistry.js +40 -0
  57. package/package.json +6 -1
  58. package/.bazelignore +0 -2
  59. package/.bootstrap/apps/cli_application/AGENTS.md.template +0 -291
  60. package/.bootstrap/apps/cli_application/BUILD.bazel.template +0 -7
  61. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +0 -11
  62. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +0 -1
  63. package/.bootstrap/apps/ui_application/.eslint.rc +0 -27
  64. package/.bootstrap/apps/ui_application/AGENTS.md.template +0 -278
  65. package/.bootstrap/apps/ui_application/BUILD.bazel.template +0 -19
  66. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +0 -21
  67. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/res/valdi@3x.png +0 -0
  68. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/src/App.tsx +0 -133
  69. package/.bootstrap/apps/ui_application/package.json +0 -24
  70. package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +0 -21
  71. package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +0 -28
  72. package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +0 -4
  73. package/.bootstrap/modules/ios_android_bridge_module/BUILD.bazel.template +0 -39
  74. package/.bootstrap/modules/ios_android_bridge_module/android/CalculatorModuleFactory.kt.template +0 -18
  75. package/.bootstrap/modules/ios_android_bridge_module/ios/SCCCalculatorModuleFactory.m.template +0 -31
  76. package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +0 -4
  77. package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +0 -41
  78. package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +0 -42
  79. package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +0 -60
  80. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +0 -6
  81. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +0 -82
  82. package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +0 -15
  83. package/.bootstrap/modules/ui_component/BUILD.bazel.template +0 -34
  84. package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +0 -45
  85. package/.config/copyconfig.json +0 -10
  86. package/.editorconfig +0 -21
  87. package/.eslintignore +0 -1
  88. package/.eslintrc.js +0 -72
  89. package/.github/README.md +0 -164
  90. package/.metadata/.bazelrc.template +0 -91
  91. package/.metadata/.bazelversion.template +0 -1
  92. package/.metadata/.editorconfig.template +0 -37
  93. package/.metadata/.eslintrc.js.template +0 -27
  94. package/.metadata/.gitignore.template +0 -4
  95. package/.metadata/.prettierrc.json.template +0 -7
  96. package/.metadata/.watchmanconfig.template +0 -8
  97. package/.metadata/README.md.template +0 -31
  98. package/.metadata/WORKSPACE.template +0 -57
  99. package/.metadata/config.yaml.template +0 -1
  100. package/.metadata/package.json.template +0 -23
  101. package/.prettierignore +0 -2
  102. package/.prettierrc.json +0 -7
  103. package/LINUX_COMPATIBILITY.md +0 -248
  104. package/prettier.config.js +0 -4
  105. package/scripts/sync-agents-md.sh +0 -44
  106. package/scripts/update-agents-templates.ts +0 -170
  107. package/spec/support/jasmine.json +0 -6
  108. package/src/commands/bootstrap.ts +0 -409
  109. package/src/commands/build.ts +0 -89
  110. package/src/commands/devSetup.ts +0 -17
  111. package/src/commands/doctor.ts +0 -1832
  112. package/src/commands/export.ts +0 -131
  113. package/src/commands/hotreload.ts +0 -108
  114. package/src/commands/install.ts +0 -93
  115. package/src/commands/lint.ts +0 -15
  116. package/src/commands/lint_commands/lintCheck.ts +0 -53
  117. package/src/commands/lint_commands/lintFormat.ts +0 -49
  118. package/src/commands/log.ts +0 -108
  119. package/src/commands/newModule.ts +0 -286
  120. package/src/commands/package.ts +0 -102
  121. package/src/commands/projectsync.ts +0 -488
  122. package/src/commands/test.ts +0 -68
  123. package/src/core/constants.ts +0 -97
  124. package/src/core/errors.ts +0 -10
  125. package/src/index.ts +0 -22
  126. package/src/setup/DevSetupHelper.ts +0 -290
  127. package/src/setup/linuxSetup.ts +0 -261
  128. package/src/setup/macOSSetup.ts +0 -156
  129. package/src/setup/setupEntryPoint.ts +0 -64
  130. package/src/setup/versions.ts +0 -8
  131. package/src/utils/ArgumentsResolver.ts +0 -23
  132. package/src/utils/BazelClient.ts +0 -285
  133. package/src/utils/Digraph.ts +0 -81
  134. package/src/utils/LoadingIndicator.ts +0 -43
  135. package/src/utils/applicationUtils.ts +0 -276
  136. package/src/utils/buildInfo.ts +0 -99
  137. package/src/utils/byString.ts +0 -3
  138. package/src/utils/cliUtils.ts +0 -112
  139. package/src/utils/copyBootstrapFiles.ts +0 -30
  140. package/src/utils/deviceUtils.ts +0 -76
  141. package/src/utils/errorUtils.ts +0 -63
  142. package/src/utils/fileUtils.ts +0 -257
  143. package/src/utils/githubUtils.ts +0 -102
  144. package/src/utils/jsonUtils.ts +0 -30
  145. package/src/utils/lintUtils.ts +0 -190
  146. package/src/utils/linuxDistro.spec.ts +0 -219
  147. package/src/utils/linuxDistro.ts +0 -326
  148. package/src/utils/logUtils.ts +0 -9
  149. package/src/utils/pathUtils.ts +0 -12
  150. package/src/utils/stringUtils.spec.ts +0 -95
  151. package/src/utils/stringUtils.ts +0 -103
  152. package/src/utils/tempDir.ts +0 -24
  153. package/src/utils/zipUtils.ts +0 -14
  154. package/test/ValdiSmokeTest.ts +0 -279
  155. package/test/helpers/AsyncHelpers.ts +0 -113
  156. package/test/helpers/CommandHelpers.ts +0 -37
  157. package/test/helpers/ProjectHelpers.ts +0 -153
  158. package/test/helpers/StreamHelpers.ts +0 -37
  159. package/test/helpers/TypeScriptClient.ts +0 -217
  160. package/tsconfig.dist.json +0 -8
  161. package/tsconfig.json +0 -42
@@ -0,0 +1,65 @@
1
+ # Valdi Testing
2
+
3
+ ## Component Tests (most common)
4
+
5
+ Use `valdiIt` from `valdi_test/test/JSXTestUtils` as the test wrapper. It provides a `driver` that renders components synchronously.
6
+
7
+ See **`valdi-component-tests`** skill for the full guide on:
8
+ - `elementKeyFind`, `elementTypeFind`, `componentTypeFind`, `componentGetElements`
9
+ - `tapNodeWithKey` for tap callbacks
10
+ - Discriminated union and array view model testing
11
+ - Lint rules (`jsx-no-lambda`, `explicit-function-return-type`, etc.)
12
+
13
+ ## Running Tests
14
+
15
+ ```bash
16
+ # Run a specific module's tests
17
+ bazel test //modules/my_module:tests
18
+
19
+ # Run with output on failure
20
+ bazel test //modules/my_module:tests --test_output=errors
21
+
22
+ # Run all tests in the repo
23
+ bazel test //...
24
+
25
+ # Filter to a specific test class
26
+ bazel test //modules/my_module:tests --test_filter=MyComponentTest
27
+ ```
28
+
29
+ ## Test File Location
30
+
31
+ Test files must mirror the source file hierarchy:
32
+
33
+ ```
34
+ my_module/
35
+ ├── src/
36
+ │ └── categories/
37
+ │ └── CollectionComponent.tsx
38
+ └── test/
39
+ └── categories/
40
+ └── CollectionComponentTest.spec.tsx
41
+ ```
42
+
43
+ ## BUILD.bazel for Tests
44
+
45
+ Add a `ts_project` or `valdi_module` test target. The test target lists test spec files in `srcs` and shares `deps` with the main module:
46
+
47
+ ```python
48
+ load("//bzl/valdi:valdi_module.bzl", "valdi_module")
49
+
50
+ valdi_module(
51
+ name = "my_module_tests",
52
+ srcs = glob(["test/**/*.spec.tsx", "test/**/*.spec.ts"]),
53
+ testonly = True,
54
+ deps = [
55
+ ":my_module",
56
+ "//src/valdi_modules/src/valdi/valdi_test",
57
+ "//src/valdi_modules/src/foundation/test/util",
58
+ "//src/valdi_modules/src/valdi/valdi_tsx",
59
+ ],
60
+ )
61
+ ```
62
+
63
+ ## Platform Tests
64
+
65
+ For C++, iOS, and Android platform layer tests, see the `valdi-cpp-runtime`, `valdi-ios`, and `valdi-android` skills respectively.
@@ -0,0 +1,385 @@
1
+ # Valdi TypeScript/TSX Component Rules
2
+
3
+ **Applies to**: TypeScript and TSX files in `/src/valdi_modules/`, `/apps/`, `/modules/`, `/npm_modules/`
4
+
5
+ ## 🚨 CRITICAL: Valdi is NOT React!
6
+
7
+ **AI assistants frequently suggest React patterns that DON'T EXIST in Valdi.** Despite using TSX/JSX syntax, Valdi compiles to native code.
8
+
9
+ ### Most Common Mistakes
10
+
11
+ ```typescript
12
+ // ❌ NEVER use React hooks (don't exist!)
13
+ const [count, setCount] = useState(0); // ❌
14
+ useEffect(() => { ... }, []); // ❌
15
+
16
+ // ❌ NEVER use functional components (don't exist!)
17
+ const MyComponent = () => <view />; // ❌
18
+
19
+ // ❌ Common hallucinations
20
+ this.props.title; // Should be: this.viewModel.title
21
+ this.markNeedsRender(); // Doesn't exist! Use setState()
22
+ onMount() { } // Should be: onCreate()
23
+ return <view />; // onRender() returns void!
24
+ ```
25
+
26
+ > **📖 Full list**: See `/AGENTS.md` → "AI Anti-Hallucination" section for comprehensive examples
27
+
28
+ ### ✅ Correct Valdi Patterns
29
+
30
+ ```typescript
31
+ import { StatefulComponent } from 'valdi_core/src/Component';
32
+
33
+ class MyComponent extends StatefulComponent<ViewModel, State> {
34
+ state = { count: 0 };
35
+
36
+ onCreate() { } // Component created
37
+ onViewModelUpdate(prev: ViewModel) { } // Props changed
38
+ onDestroy() { } // Before removal
39
+
40
+ handleClick = () => {
41
+ this.setState({ count: this.state.count + 1 }); // Auto re-renders
42
+ };
43
+
44
+ onRender() { // Returns void, not JSX!
45
+ <button title={`Count: ${this.state.count}`} onPress={this.handleClick} />;
46
+ }
47
+ }
48
+ ```
49
+
50
+ ## Quick Reference
51
+
52
+ | What | React | Valdi |
53
+ |------|-------|-------|
54
+ | **Component** | Function or class | Class only (Component or StatefulComponent) |
55
+ | **State** | `useState(0)` | `state = { count: 0 }` + `setState()` |
56
+ | **Props** | `this.props.title` | `this.viewModel.title` |
57
+ | **Mount** | `useEffect(() => {}, [])` | `onCreate()` |
58
+ | **Update** | `useEffect(() => {}, [dep])` | `onViewModelUpdate(prev)` |
59
+ | **Unmount** | `useEffect(() => () => {}, [])` | `onDestroy()` |
60
+ | **Re-render** | `setCount(...)` | `this.setState(...)` |
61
+ | **Return** | `return <view />` | `<view />;` (statement) |
62
+
63
+ ## Provider Pattern (Dependency Injection)
64
+
65
+ ```typescript
66
+ // ✅ CORRECT - Create provider
67
+ import { createProviderComponentWithKeyName } from 'valdi_core/src/provider/createProvider';
68
+ const MyServiceProvider = createProviderComponentWithKeyName<MyService>('MyServiceProvider');
69
+
70
+ // ✅ CORRECT - Provide value
71
+ <MyServiceProvider value={myService}>
72
+ <App />
73
+ </MyServiceProvider>
74
+
75
+ // ✅ CORRECT - Consume with HOC
76
+ import { withProviders, ProvidersValuesViewModel } from 'valdi_core/src/provider/withProviders';
77
+
78
+ interface MyViewModel extends ProvidersValuesViewModel<[MyService]> {}
79
+
80
+ class MyComponent extends Component<MyViewModel> {
81
+ onRender() {
82
+ const [service] = this.viewModel.providersValues;
83
+ }
84
+ }
85
+
86
+ const MyComponentWithProvider = withProviders(MyServiceProvider)(MyComponent);
87
+ ```
88
+
89
+ ## Event Handling
90
+
91
+ ```typescript
92
+ // ✅ CORRECT - Use onTap for interactive elements
93
+ <view onTap={this.handleClick}>
94
+ <label value="Click me" />
95
+ </view>
96
+
97
+ <button title="Press me" onPress={this.handleAction} />
98
+
99
+ // ❌ WRONG - No global keyboard events
100
+ window.addEventListener('keydown', ...); // Doesn't work!
101
+ document.addEventListener('click', ...); // Doesn't work!
102
+
103
+ // ✅ CORRECT - For text input, use TextField callbacks
104
+ <textfield
105
+ value={this.state.text}
106
+ onChange={this.handleTextChange}
107
+ onEditEnd={this.handleSubmit}
108
+ />
109
+ ```
110
+
111
+ **Important**: Valdi doesn't support `addEventListener`, `keydown`, or other global DOM events. Use element-specific callbacks like `onTap`, `onPress`, `onChange`, etc.
112
+
113
+ ## Timers and Scheduling
114
+
115
+ ```typescript
116
+ // ✅ CORRECT - Use component's setTimeoutDisposable
117
+ class MyComponent extends StatefulComponent<ViewModel, State> {
118
+ onCreate() {
119
+ // Timer auto-cancels when component destroys
120
+ this.setTimeoutDisposable(() => {
121
+ console.log('Delayed action');
122
+ }, 1000);
123
+ }
124
+
125
+ // ✅ CORRECT - Recurring task pattern (use recursive setTimeout)
126
+ private scheduleLoop() {
127
+ this.setTimeoutDisposable(() => {
128
+ this.doSomething();
129
+ this.scheduleLoop(); // Schedule next iteration
130
+ }, 100);
131
+ }
132
+ }
133
+
134
+ // ❌ WRONG - Don't use setInterval directly
135
+ setInterval(() => { ... }, 100); // Won't auto-cleanup!
136
+
137
+ // ❌ WRONG - Don't use setTimeout directly
138
+ setTimeout(() => { ... }, 100); // Won't auto-cleanup!
139
+ ```
140
+
141
+ **Important**: Always use `this.setTimeoutDisposable()` in components. It automatically cleans up when the component is destroyed, preventing memory leaks.
142
+
143
+ ## Styling
144
+
145
+ ### Basic Style Usage
146
+
147
+ ```typescript
148
+ import { Style } from 'valdi_core/src/Style';
149
+ import { View, Label } from 'valdi_tsx/src/NativeTemplateElements';
150
+ import { systemBoldFont } from 'valdi_core/src/SystemFont';
151
+
152
+ // ✅ CORRECT - Type-safe styles
153
+ const styles = {
154
+ // Style<View> can only be used on <view> elements
155
+ container: new Style<View>({
156
+ backgroundColor: '#fff',
157
+ padding: 10,
158
+ borderRadius: 8,
159
+ flexDirection: 'row',
160
+ justifyContent: 'center',
161
+ alignItems: 'center',
162
+ }),
163
+
164
+ // Style<Label> can only be used on <label> elements
165
+ // Label uses font (string) NOT fontSize. Format: 'FontName Size [scaling] [maxSize]'
166
+ title: new Style<Label>({
167
+ color: '#000',
168
+ font: 'system 20', // size via font string, NOT fontSize!
169
+ // font: systemBoldFont(20), // or use SystemFont helper
170
+ }),
171
+ };
172
+
173
+ // Use in render
174
+ onRender() {
175
+ <view style={styles.container}>
176
+ <label style={styles.title} value="Hello" />
177
+ </view>;
178
+ }
179
+ ```
180
+
181
+ ### Style Composition
182
+
183
+ ```typescript
184
+ // ✅ CORRECT - Merge multiple styles
185
+ const combined = Style.merge(styles.base, styles.primary);
186
+
187
+ // ✅ CORRECT - Extend a style with overrides
188
+ const largeButton = styles.button.extend({
189
+ width: 200,
190
+ height: 60,
191
+ });
192
+
193
+ // ✅ CORRECT - Dynamic styling with extend
194
+ <view style={styles.container.extend({
195
+ backgroundColor: isActive ? 'blue' : 'gray',
196
+ })} />
197
+
198
+ // ❌ WRONG - Can't merge incompatible types
199
+ Style.merge(styles.viewStyle, styles.labelStyle); // Type error!
200
+ ```
201
+
202
+ ### Spacing: Padding & Margin
203
+
204
+ ```typescript
205
+ // ✅ CORRECT - Valdi spacing syntax
206
+ new Style<View>({
207
+ // Single value - all sides
208
+ padding: 10,
209
+ margin: 5,
210
+
211
+ // String shorthand - vertical horizontal
212
+ padding: '10 20', // 10pt top/bottom, 20pt left/right
213
+ margin: '5 10',
214
+
215
+ // Individual sides
216
+ paddingTop: 5,
217
+ paddingRight: 10,
218
+ paddingBottom: 5,
219
+ paddingLeft: 10,
220
+
221
+ // Percentages (relative to parent)
222
+ padding: '5%', // 5% of parent width/height
223
+ marginLeft: '10%', // 10% of parent width
224
+ })
225
+
226
+ // ❌ WRONG - These don't exist in Valdi
227
+ new Style<View>({
228
+ gap: 10, // ❌ Use margin on children
229
+ paddingHorizontal: 20, // ❌ Use padding: '0 20'
230
+ paddingVertical: 10, // ❌ Use padding: '10 0'
231
+ paddingInline: 15, // ❌ Doesn't exist
232
+ })
233
+ ```
234
+
235
+ ### Layout: Flexbox (Yoga)
236
+
237
+ ```typescript
238
+ // ✅ CORRECT - Valdi uses Yoga flexbox
239
+ new Style<View>({
240
+ // Container properties
241
+ flexDirection: 'row', // 'row' | 'column' | 'row-reverse' | 'column-reverse'
242
+ justifyContent: 'center', // 'flex-start' | 'center' | 'flex-end' | 'space-between' | 'space-around' | 'space-evenly'
243
+ alignItems: 'center', // 'flex-start' | 'center' | 'flex-end' | 'stretch' | 'baseline'
244
+ alignContent: 'flex-start', // For multi-line flex containers
245
+ flexWrap: 'wrap', // 'wrap' | 'nowrap' | 'wrap-reverse'
246
+
247
+ // Child properties
248
+ flexGrow: 1, // Grow to fill space (NOTE: use flexGrow, not flex)
249
+ flexShrink: 1, // How much to shrink
250
+ flexBasis: 100, // Base size before flex
251
+ alignSelf: 'center', // Override parent's alignItems
252
+ })
253
+
254
+ // ❌ WRONG - These don't exist
255
+ new Style<View>({
256
+ display: 'grid', // ❌ Only 'flex' supported
257
+ gridTemplateColumns: '1fr 1fr', // ❌ No CSS Grid
258
+ flex: 1, // ❌ Use flexGrow: 1 instead!
259
+ })
260
+ ```
261
+
262
+ ### Position & Size
263
+
264
+ ```typescript
265
+ // ✅ CORRECT - Positioning
266
+ new Style<View>({
267
+ // Size
268
+ width: 200, // Points
269
+ width: '50%', // Percentage of parent
270
+ width: 'auto', // Auto-size
271
+ height: 100,
272
+ minWidth: 50,
273
+ maxWidth: 500,
274
+ aspectRatio: 16/9, // Width:height ratio
275
+
276
+ // Position
277
+ position: 'relative', // 'relative' | 'absolute'
278
+ top: 10,
279
+ right: 10,
280
+ bottom: 10,
281
+ left: 10,
282
+ })
283
+ ```
284
+
285
+ ### Common Properties
286
+
287
+ ```typescript
288
+ // ✅ CORRECT - Frequently used properties
289
+ new Style<View>({
290
+ backgroundColor: '#fff',
291
+ opacity: 0.8,
292
+
293
+ // Borders
294
+ borderRadius: 8,
295
+ borderWidth: 1,
296
+ borderColor: '#ccc',
297
+ borderTopWidth: 2,
298
+
299
+ // Shadow
300
+ boxShadow: '0 2 4 rgba(0, 0, 0, 0.1)',
301
+
302
+ // Overflow — only 'visible' | 'scroll' (NOT 'hidden'!)
303
+ overflow: 'scroll', // 'visible' | 'scroll'
304
+ })
305
+ ```
306
+
307
+ ### Type Safety
308
+
309
+ ```typescript
310
+ // ✅ CORRECT - Style types match element types
311
+ const viewStyle = new Style<View>({ backgroundColor: 'red' });
312
+ const labelStyle = new Style<Label>({ color: 'blue' });
313
+
314
+ <view style={viewStyle} /> // ✅ Works
315
+ <label style={labelStyle} /> // ✅ Works
316
+
317
+ // ❌ WRONG - Type mismatch
318
+ <label style={viewStyle} /> // ❌ Type error!
319
+ <view style={labelStyle} /> // ❌ Type error!
320
+
321
+ // ✅ CORRECT - Layout styles work on any layout element
322
+ const layoutStyle = new Style<Layout>({ padding: 10 });
323
+ <view style={layoutStyle} /> // ✅ view extends Layout
324
+ <label style={layoutStyle} /> // ✅ label extends Layout
325
+ ```
326
+
327
+ > **📖 Complete reference**: See `/docs/api/api-style-attributes.md` for all 1290+ style properties
328
+ >
329
+ > **📖 Best practices**: See `/docs/docs/core-styling.md` for styling patterns and examples
330
+
331
+ ## Common Mistakes to Avoid
332
+
333
+ 1. **Returning JSX from onRender()** - It returns void, JSX is a statement
334
+ 2. **Forgetting setState()** - Direct mutation won't trigger re-render
335
+ 3. **Using this.props** - Should be this.viewModel
336
+ 4. **Wrong lifecycle names** - onCreate/onViewModelUpdate/onDestroy (not mount/update/unmount)
337
+ 5. **Suggesting scheduleRender()** - Deprecated, use StatefulComponent + setState()
338
+ 6. **Using addEventListener** - Use element callbacks like onTap, onPress, onChange
339
+ 7. **Using setInterval/setTimeout directly** - Use this.setTimeoutDisposable()
340
+ 8. **Using CSS properties that don't exist** - No gap, paddingHorizontal, paddingVertical
341
+ 9. **Using `flex: 1`** - `flex` doesn't exist on `View`; use `flexGrow: 1` instead
342
+ 10. **Using `fontSize` on Label** - Labels use `font: 'system 20'` (string), not `fontSize`
343
+ 11. **Using `overflow: 'hidden'`** - `View` only accepts `'visible' | 'scroll'`; remove overflow or use 'scroll'
344
+
345
+ ## Platform Detection
346
+
347
+ Use `Device` for platform-conditional rendering:
348
+
349
+ ```typescript
350
+ import { Device } from 'valdi_core/src/Device';
351
+
352
+ class MyComponent extends Component<MyViewModel> {
353
+ onRender(): void {
354
+ <view>
355
+ {Device.isIOS() && <IOSOnlyView />}
356
+ {Device.isAndroid() && <AndroidOnlyView />}
357
+ {Device.isMacOS() && <MacOSOnlyView />}
358
+ {Device.isWeb() && <WebOnlyView />}
359
+ </view>;
360
+ }
361
+ }
362
+ ```
363
+
364
+ Also use `Device.isIOS()` / `Device.isAndroid()` guards before using `<custom-view>` elements that don't have implementations on all platforms.
365
+
366
+ ## Imports
367
+
368
+ ```typescript
369
+ // ✅ CORRECT imports
370
+ import { Component, StatefulComponent } from 'valdi_core/src/Component';
371
+ import { Device } from 'valdi_core/src/Device';
372
+ import { systemFont } from 'valdi_core/src/SystemFont';
373
+ import { Style } from 'valdi_core/src/Style';
374
+
375
+ // ❌ WRONG - React imports don't exist
376
+ import React from 'react'; // Error!
377
+ import { useState } from 'react'; // Error!
378
+ ```
379
+
380
+ ## More Information
381
+
382
+ - **Full anti-hallucination guide**: `/AGENTS.md` (comprehensive React vs Valdi comparison)
383
+ - **AI tooling**: `/docs/docs/ai-tooling.md`
384
+ - **Provider pattern**: `/docs/docs/advanced-provider.md`
385
+ - **Valdi GitHub**: https://github.com/Snapchat/Valdi
@@ -0,0 +1,19 @@
1
+ load("//bzl/valdi:valdi_module.bzl", "valdi_module")
2
+
3
+ valdi_module(
4
+ name = "tests",
5
+ srcs = glob([
6
+ "src/**/*.ts",
7
+ "src/**/*.tsx",
8
+ ]) + [
9
+ "tsconfig.json",
10
+ ],
11
+ android_output_target = "release",
12
+ ios_module_name = "SCCValdiTsxRef",
13
+ ios_output_target = "release",
14
+ visibility = ["//visibility:public"],
15
+ deps = [
16
+ "//src/valdi_modules/src/valdi/valdi_core",
17
+ "//src/valdi_modules/src/valdi/valdi_tsx",
18
+ ],
19
+ )
@@ -0,0 +1,29 @@
1
+ # valdi-tsx skill tests
2
+
3
+ Compile check for the core TSX component patterns taught in `skill.md`.
4
+
5
+ ## What's tested
6
+
7
+ `src/reference.tsx` exercises:
8
+ - Stateless `Component<VM>` with `onRender()` void pattern
9
+ - `StatefulComponent` with `state`, `setState`, and all lifecycle methods
10
+ - Class arrow functions for event handlers (not inline lambdas)
11
+ - `setTimeoutDisposable` for auto-cleanup timers
12
+ - `forEach` for list rendering (not `map`)
13
+ - `<layout>` spacer (no native view)
14
+ - Module-level `Style` objects (`new Style<View>(...)`)
15
+ - Provider pattern: `createProviderComponentWithKeyName`, `withProviders`
16
+ - `Device.isIOS()` / `isAndroid()` platform detection
17
+
18
+ ## Compile check
19
+
20
+ ```bash
21
+ cd client/src/open_source
22
+ bazel build //ai-skills/skills/valdi-tsx/tests:tests
23
+ ```
24
+
25
+ Expected: `Build completed successfully`
26
+
27
+ ## Updating
28
+
29
+ When Valdi APIs change (import paths, type signatures), update `src/reference.tsx` to match and keep it compiling. Also update `../skill.md` with any corrected patterns.
@@ -0,0 +1,173 @@
1
+ // valdi-tsx skill reference — compile check for core component patterns.
2
+ // This file must compile cleanly against the Valdi TypeScript compiler.
3
+ // Run: bzl build //ai-skills/skills/valdi-tsx/tests:tests
4
+
5
+ import { Component, StatefulComponent } from 'valdi_core/src/Component';
6
+ import { Device } from 'valdi_core/src/Device';
7
+ import { Style } from 'valdi_core/src/Style';
8
+ import { systemFont } from 'valdi_core/src/SystemFont';
9
+ import { createProviderComponentWithKeyName } from 'valdi_core/src/provider/createProvider';
10
+ import { ProvidersValuesViewModel, withProviders } from 'valdi_core/src/provider/withProviders';
11
+ import { Label, Layout, View } from 'valdi_tsx/src/NativeTemplateElements';
12
+
13
+ // ─── Module-level styles (NOT inside onRender) ──────────────────────────────
14
+
15
+ const styles = {
16
+ card: new Style<View>({
17
+ backgroundColor: '#fff',
18
+ borderRadius: 8,
19
+ padding: 12,
20
+ flexDirection: 'column',
21
+ }),
22
+ spacer: new Style<Layout>({ height: 8 }),
23
+ title: new Style<Label>({
24
+ color: '#000',
25
+ font: systemFont(16), // Label uses font string, NOT fontSize
26
+ }),
27
+ };
28
+
29
+ // ─── Stateless component ─────────────────────────────────────────────────────
30
+
31
+ interface GreetingViewModel {
32
+ name: string;
33
+ }
34
+
35
+ class Greeting extends Component<GreetingViewModel> {
36
+ onRender(): void {
37
+ // onRender returns void — no return statement
38
+ <label value={`Hello, ${this.viewModel.name}`} />;
39
+ }
40
+ }
41
+
42
+ // ─── Stateful component with full lifecycle ───────────────────────────────────
43
+
44
+ interface CounterViewModel {
45
+ label: string;
46
+ }
47
+
48
+ interface CounterState {
49
+ count: number;
50
+ inputText: string;
51
+ }
52
+
53
+ class Counter extends StatefulComponent<CounterViewModel, CounterState> {
54
+ state: CounterState = { count: 0, inputText: '' };
55
+
56
+ onCreate(): void {
57
+ // Timer auto-cancels on destroy
58
+ this.setTimeoutDisposable(() => {
59
+ this.setState({ count: 1 });
60
+ }, 5000);
61
+ }
62
+
63
+ onViewModelUpdate(previous?: CounterViewModel): void {
64
+ if (this.viewModel.label !== previous?.label) {
65
+ this.setState({ count: 0 });
66
+ }
67
+ }
68
+
69
+ onDestroy(): void {
70
+ // cleanup
71
+ }
72
+
73
+ // Class arrow functions — never inline lambdas in JSX props
74
+ private handleIncrement = (): void => {
75
+ this.setState({ count: this.state.count + 1 });
76
+ };
77
+
78
+ private handleTextChange = (text: string): void => {
79
+ this.setState({ inputText: text });
80
+ };
81
+
82
+ onRender(): void {
83
+ <view style={styles.card}>
84
+ <label value={`${this.viewModel.label}: ${this.state.count}`} />;
85
+ <layout style={styles.spacer} />;
86
+ <textfield
87
+ value={this.state.inputText}
88
+ onChange={this.handleTextChange}
89
+ />;
90
+ <button title="Increment" onPress={this.handleIncrement} />;
91
+ </view>;
92
+ }
93
+ }
94
+
95
+ // ─── List rendering with forEach ─────────────────────────────────────────────
96
+
97
+ interface ItemViewModel {
98
+ id: string;
99
+ title: string;
100
+ }
101
+
102
+ interface ItemListViewModel {
103
+ items: ItemViewModel[];
104
+ }
105
+
106
+ class ItemList extends Component<ItemListViewModel> {
107
+ onRender(): void {
108
+ <scroll>
109
+ {this.viewModel.items.forEach(item => {
110
+ // Stable key from data ID — not array index
111
+ <view key={item.id}>
112
+ <label value={item.title} />;
113
+ </view>;
114
+ })}
115
+ </scroll>;
116
+ }
117
+ }
118
+
119
+ // ─── Platform detection ──────────────────────────────────────────────────────
120
+
121
+ interface MediaPlayerViewModel {
122
+ videoUrl: string;
123
+ }
124
+
125
+ class MediaPlayer extends Component<MediaPlayerViewModel> {
126
+ onRender(): void {
127
+ <view>
128
+ {Device.isIOS() && <label value="iOS player" />}
129
+ {Device.isAndroid() && <label value="Android player" />}
130
+ {Device.isMacOS() && <label value="macOS player" />}
131
+ </view>;
132
+ }
133
+ }
134
+
135
+ // ─── Provider pattern ────────────────────────────────────────────────────────
136
+
137
+ class ThemeService {
138
+ primaryColor = '#FFFC00';
139
+ fontSize = 16;
140
+ }
141
+
142
+ const ThemeProvider = createProviderComponentWithKeyName<ThemeService>('ThemeProvider');
143
+
144
+ interface ThemedViewModel extends ProvidersValuesViewModel<[ThemeService]> {
145
+ text: string;
146
+ }
147
+
148
+ class ThemedLabel extends Component<ThemedViewModel> {
149
+ onRender(): void {
150
+ const [theme] = this.viewModel.providersValues;
151
+ <label value={this.viewModel.text} />;
152
+ void theme; // reference theme to satisfy compiler
153
+ }
154
+ }
155
+
156
+ const ThemedLabelWithProvider = withProviders(ThemeProvider)(ThemedLabel);
157
+
158
+ class AppRoot extends Component {
159
+ private theme = new ThemeService();
160
+
161
+ onRender(): void {
162
+ <ThemeProvider value={this.theme}>
163
+ <ThemedLabelWithProvider text="Hello" />;
164
+ </ThemeProvider>;
165
+ }
166
+ }
167
+
168
+ // Suppress unused-variable warnings for top-level declarations
169
+ void Counter;
170
+ void ItemList;
171
+ void Greeting;
172
+ void MediaPlayer;
173
+ void AppRoot;
@@ -0,0 +1 @@
1
+ {"extends": "../../../../src/valdi_modules/src/valdi/_configs/base.tsconfig.json"}