@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.
- package/README.md +22 -10
- package/bundled-skills/CONTRIBUTING_SKILLS.md +74 -0
- package/bundled-skills/registry.json +20 -0
- package/bundled-skills/skills/valdi-android/skill.md +89 -0
- package/bundled-skills/skills/valdi-async/skill.md +246 -0
- package/bundled-skills/skills/valdi-async/tests/BUILD.bazel +19 -0
- package/bundled-skills/skills/valdi-async/tests/README.md +25 -0
- package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +210 -0
- package/bundled-skills/skills/valdi-async/tests/tsconfig.json +1 -0
- package/bundled-skills/skills/valdi-bazel/skill.md +122 -0
- package/bundled-skills/skills/valdi-compiler/skill.md +108 -0
- package/bundled-skills/skills/valdi-component-tests/skill.md +430 -0
- package/bundled-skills/skills/valdi-component-tests/tests/BUILD.bazel +24 -0
- package/bundled-skills/skills/valdi-component-tests/tests/README.md +35 -0
- package/bundled-skills/skills/valdi-component-tests/tests/src/ProfileCard.tsx +38 -0
- package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +107 -0
- package/bundled-skills/skills/valdi-component-tests/tests/tsconfig.json +1 -0
- package/bundled-skills/skills/valdi-cpp-runtime/skill.md +103 -0
- package/bundled-skills/skills/valdi-custom-view/skill.md +62 -0
- package/bundled-skills/skills/valdi-ios/skill.md +93 -0
- package/bundled-skills/skills/valdi-migrate/skill.md +175 -0
- package/bundled-skills/skills/valdi-migrate/tests/BUILD.bazel +23 -0
- package/bundled-skills/skills/valdi-migrate/tests/README.md +70 -0
- package/bundled-skills/skills/valdi-migrate/tests/check_antipatterns.py +89 -0
- package/bundled-skills/skills/valdi-migrate/tests/compose_example.kt +94 -0
- package/bundled-skills/skills/valdi-migrate/tests/flutter_example.dart +129 -0
- package/bundled-skills/skills/valdi-migrate/tests/react_example.tsx +98 -0
- package/bundled-skills/skills/valdi-migrate/tests/src/expected_valdi.tsx +267 -0
- package/bundled-skills/skills/valdi-migrate/tests/tsconfig.json +3 -0
- package/{.metadata/.cursorrules.template → bundled-skills/skills/valdi-overview/skill.md} +23 -13
- package/bundled-skills/skills/valdi-perf/skill.md +197 -0
- package/bundled-skills/skills/valdi-perf/tests/BUILD.bazel +19 -0
- package/bundled-skills/skills/valdi-perf/tests/README.md +26 -0
- package/bundled-skills/skills/valdi-perf/tests/src/reference.tsx +202 -0
- package/bundled-skills/skills/valdi-perf/tests/tsconfig.json +1 -0
- package/bundled-skills/skills/valdi-polyglot-module/skill.md +85 -0
- package/bundled-skills/skills/valdi-setup/skill.md +129 -0
- package/bundled-skills/skills/valdi-testing/skill.md +65 -0
- package/bundled-skills/skills/valdi-tsx/skill.md +385 -0
- package/bundled-skills/skills/valdi-tsx/tests/BUILD.bazel +19 -0
- package/bundled-skills/skills/valdi-tsx/tests/README.md +29 -0
- package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +173 -0
- package/bundled-skills/skills/valdi-tsx/tests/tsconfig.json +1 -0
- package/dist/commands/bootstrap.js +3 -9
- package/dist/commands/newModule.js +10 -14
- package/dist/commands/skills.js +16 -0
- package/dist/commands/skills_commands/create.js +125 -0
- package/dist/commands/skills_commands/install.js +96 -0
- package/dist/commands/skills_commands/list.js +83 -0
- package/dist/commands/skills_commands/remove.js +41 -0
- package/dist/commands/skills_commands/update.js +59 -0
- package/dist/core/constants.js +1 -1
- package/dist/index.js +5 -0
- package/dist/setup/versions.js +1 -1
- package/dist/utils/skillsAdapters.js +140 -0
- package/dist/utils/skillsRegistry.js +40 -0
- package/package.json +6 -1
- package/.bazelignore +0 -2
- package/.bootstrap/apps/cli_application/AGENTS.md.template +0 -291
- package/.bootstrap/apps/cli_application/BUILD.bazel.template +0 -7
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +0 -11
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +0 -1
- package/.bootstrap/apps/ui_application/.eslint.rc +0 -27
- package/.bootstrap/apps/ui_application/AGENTS.md.template +0 -278
- package/.bootstrap/apps/ui_application/BUILD.bazel.template +0 -19
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +0 -21
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/res/valdi@3x.png +0 -0
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/src/App.tsx +0 -133
- package/.bootstrap/apps/ui_application/package.json +0 -24
- package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +0 -21
- package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +0 -28
- package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +0 -4
- package/.bootstrap/modules/ios_android_bridge_module/BUILD.bazel.template +0 -39
- package/.bootstrap/modules/ios_android_bridge_module/android/CalculatorModuleFactory.kt.template +0 -18
- package/.bootstrap/modules/ios_android_bridge_module/ios/SCCCalculatorModuleFactory.m.template +0 -31
- package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +0 -4
- package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +0 -41
- package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +0 -42
- package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +0 -60
- package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +0 -6
- package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +0 -82
- package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +0 -15
- package/.bootstrap/modules/ui_component/BUILD.bazel.template +0 -34
- package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +0 -45
- package/.config/copyconfig.json +0 -10
- package/.editorconfig +0 -21
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -72
- package/.github/README.md +0 -164
- package/.metadata/.bazelrc.template +0 -91
- package/.metadata/.bazelversion.template +0 -1
- package/.metadata/.editorconfig.template +0 -37
- package/.metadata/.eslintrc.js.template +0 -27
- package/.metadata/.gitignore.template +0 -4
- package/.metadata/.prettierrc.json.template +0 -7
- package/.metadata/.watchmanconfig.template +0 -8
- package/.metadata/README.md.template +0 -31
- package/.metadata/WORKSPACE.template +0 -57
- package/.metadata/config.yaml.template +0 -1
- package/.metadata/package.json.template +0 -23
- package/.prettierignore +0 -2
- package/.prettierrc.json +0 -7
- package/LINUX_COMPATIBILITY.md +0 -248
- package/prettier.config.js +0 -4
- package/scripts/sync-agents-md.sh +0 -44
- package/scripts/update-agents-templates.ts +0 -170
- package/spec/support/jasmine.json +0 -6
- package/src/commands/bootstrap.ts +0 -409
- package/src/commands/build.ts +0 -89
- package/src/commands/devSetup.ts +0 -17
- package/src/commands/doctor.ts +0 -1832
- package/src/commands/export.ts +0 -131
- package/src/commands/hotreload.ts +0 -108
- package/src/commands/install.ts +0 -93
- package/src/commands/lint.ts +0 -15
- package/src/commands/lint_commands/lintCheck.ts +0 -53
- package/src/commands/lint_commands/lintFormat.ts +0 -49
- package/src/commands/log.ts +0 -108
- package/src/commands/newModule.ts +0 -286
- package/src/commands/package.ts +0 -102
- package/src/commands/projectsync.ts +0 -488
- package/src/commands/test.ts +0 -68
- package/src/core/constants.ts +0 -97
- package/src/core/errors.ts +0 -10
- package/src/index.ts +0 -22
- package/src/setup/DevSetupHelper.ts +0 -290
- package/src/setup/linuxSetup.ts +0 -261
- package/src/setup/macOSSetup.ts +0 -156
- package/src/setup/setupEntryPoint.ts +0 -64
- package/src/setup/versions.ts +0 -8
- package/src/utils/ArgumentsResolver.ts +0 -23
- package/src/utils/BazelClient.ts +0 -285
- package/src/utils/Digraph.ts +0 -81
- package/src/utils/LoadingIndicator.ts +0 -43
- package/src/utils/applicationUtils.ts +0 -276
- package/src/utils/buildInfo.ts +0 -99
- package/src/utils/byString.ts +0 -3
- package/src/utils/cliUtils.ts +0 -112
- package/src/utils/copyBootstrapFiles.ts +0 -30
- package/src/utils/deviceUtils.ts +0 -76
- package/src/utils/errorUtils.ts +0 -63
- package/src/utils/fileUtils.ts +0 -257
- package/src/utils/githubUtils.ts +0 -102
- package/src/utils/jsonUtils.ts +0 -30
- package/src/utils/lintUtils.ts +0 -190
- package/src/utils/linuxDistro.spec.ts +0 -219
- package/src/utils/linuxDistro.ts +0 -326
- package/src/utils/logUtils.ts +0 -9
- package/src/utils/pathUtils.ts +0 -12
- package/src/utils/stringUtils.spec.ts +0 -95
- package/src/utils/stringUtils.ts +0 -103
- package/src/utils/tempDir.ts +0 -24
- package/src/utils/zipUtils.ts +0 -14
- package/test/ValdiSmokeTest.ts +0 -279
- package/test/helpers/AsyncHelpers.ts +0 -113
- package/test/helpers/CommandHelpers.ts +0 -37
- package/test/helpers/ProjectHelpers.ts +0 -153
- package/test/helpers/StreamHelpers.ts +0 -37
- package/test/helpers/TypeScriptClient.ts +0 -217
- package/tsconfig.dist.json +0 -8
- package/tsconfig.json +0 -42
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Jetpack Compose example — @Composable functions, remember, LaunchedEffect,
|
|
2
|
+
// LazyColumn, navigation, CompositionLocal.
|
|
3
|
+
// Goal: migrate this to Valdi.
|
|
4
|
+
|
|
5
|
+
import androidx.compose.foundation.layout.*
|
|
6
|
+
import androidx.compose.foundation.lazy.LazyColumn
|
|
7
|
+
import androidx.compose.foundation.lazy.items
|
|
8
|
+
import androidx.compose.material3.*
|
|
9
|
+
import androidx.compose.runtime.*
|
|
10
|
+
import androidx.compose.ui.Modifier
|
|
11
|
+
import androidx.compose.ui.unit.dp
|
|
12
|
+
import androidx.navigation.NavController
|
|
13
|
+
|
|
14
|
+
// --- CompositionLocal theme ---
|
|
15
|
+
val LocalAppTheme = compositionLocalOf { AppTheme() }
|
|
16
|
+
data class AppTheme(val primary: String = "#FFFC00")
|
|
17
|
+
|
|
18
|
+
// --- Stateless greeting ---
|
|
19
|
+
@Composable
|
|
20
|
+
fun Greeting(name: String) {
|
|
21
|
+
Text("Hello, $name")
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// --- Stateful counter ---
|
|
25
|
+
@Composable
|
|
26
|
+
fun Counter(label: String) {
|
|
27
|
+
var count by remember { mutableStateOf(0) }
|
|
28
|
+
Button(onClick = { count++ }) {
|
|
29
|
+
Text("$label: $count")
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// --- Data loading with LaunchedEffect ---
|
|
34
|
+
@Composable
|
|
35
|
+
fun UserProfile(userId: String) {
|
|
36
|
+
var profile by remember { mutableStateOf<Profile?>(null) }
|
|
37
|
+
|
|
38
|
+
LaunchedEffect(userId) {
|
|
39
|
+
profile = fetchProfile(userId) // suspend fun
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (profile == null) {
|
|
43
|
+
CircularProgressIndicator()
|
|
44
|
+
} else {
|
|
45
|
+
Text(profile!!.name)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// --- LazyColumn list ---
|
|
50
|
+
@Composable
|
|
51
|
+
fun UserList(users: List<User>) {
|
|
52
|
+
LazyColumn {
|
|
53
|
+
items(users, key = { it.id }) { user ->
|
|
54
|
+
UserRow(user = user)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// --- Layout with Column / Row / Modifier ---
|
|
60
|
+
@Composable
|
|
61
|
+
fun ProfileCard(user: User) {
|
|
62
|
+
Column(
|
|
63
|
+
modifier = Modifier
|
|
64
|
+
.fillMaxWidth()
|
|
65
|
+
.padding(16.dp)
|
|
66
|
+
) {
|
|
67
|
+
Row(modifier = Modifier.fillMaxWidth()) {
|
|
68
|
+
Text(user.name, style = MaterialTheme.typography.headlineSmall)
|
|
69
|
+
Spacer(Modifier.weight(1f))
|
|
70
|
+
Text(user.handle)
|
|
71
|
+
}
|
|
72
|
+
Spacer(modifier = Modifier.height(8.dp))
|
|
73
|
+
Text(user.bio)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// --- Navigation ---
|
|
78
|
+
@Composable
|
|
79
|
+
fun HomeScreen(navController: NavController) {
|
|
80
|
+
Button(onClick = { navController.navigate("detail/42") }) {
|
|
81
|
+
Text("Go to Detail")
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// --- CompositionLocal consumer ---
|
|
86
|
+
@Composable
|
|
87
|
+
fun ThemedBadge(text: String) {
|
|
88
|
+
val theme = LocalAppTheme.current
|
|
89
|
+
Box(
|
|
90
|
+
modifier = Modifier.background(Color(android.graphics.Color.parseColor(theme.primary)))
|
|
91
|
+
) {
|
|
92
|
+
Text(text)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Flutter example — mix of StatelessWidget, StatefulWidget, ListView.builder,
|
|
2
|
+
// navigation, SharedPreferences, and a Provider consumer.
|
|
3
|
+
// Goal: migrate this to Valdi.
|
|
4
|
+
|
|
5
|
+
import 'package:flutter/material.dart';
|
|
6
|
+
import 'package:provider/provider.dart';
|
|
7
|
+
import 'package:shared_preferences/shared_preferences.dart';
|
|
8
|
+
|
|
9
|
+
// --- Theme service (ChangeNotifier) ---
|
|
10
|
+
class ThemeService extends ChangeNotifier {
|
|
11
|
+
Color primary = Colors.yellow;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// --- Stateless greeting ---
|
|
15
|
+
class Greeting extends StatelessWidget {
|
|
16
|
+
final String name;
|
|
17
|
+
const Greeting({required this.name});
|
|
18
|
+
|
|
19
|
+
@override
|
|
20
|
+
Widget build(BuildContext context) {
|
|
21
|
+
return Text('Hello, $name');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// --- Stateful counter ---
|
|
26
|
+
class Counter extends StatefulWidget {
|
|
27
|
+
final String label;
|
|
28
|
+
const Counter({required this.label});
|
|
29
|
+
@override
|
|
30
|
+
State<Counter> createState() => _CounterState();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class _CounterState extends State<Counter> {
|
|
34
|
+
int _count = 0;
|
|
35
|
+
|
|
36
|
+
void _increment() {
|
|
37
|
+
setState(() { _count++; });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@override
|
|
41
|
+
Widget build(BuildContext context) {
|
|
42
|
+
return GestureDetector(
|
|
43
|
+
onTap: _increment,
|
|
44
|
+
child: Text('${widget.label}: $_count'),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// --- User list with async fetch and cancellation ---
|
|
50
|
+
class UserList extends StatefulWidget {
|
|
51
|
+
@override
|
|
52
|
+
State<UserList> createState() => _UserListState();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
class _UserListState extends State<UserList> {
|
|
56
|
+
List<String> _users = [];
|
|
57
|
+
|
|
58
|
+
@override
|
|
59
|
+
void initState() {
|
|
60
|
+
super.initState();
|
|
61
|
+
_loadUsers();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Future<void> _loadUsers() async {
|
|
65
|
+
// simulated network fetch
|
|
66
|
+
await Future.delayed(Duration(milliseconds: 500));
|
|
67
|
+
setState(() { _users = ['Alice', 'Bob', 'Carol']; });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@override
|
|
71
|
+
Widget build(BuildContext context) {
|
|
72
|
+
return ListView.builder(
|
|
73
|
+
itemCount: _users.length,
|
|
74
|
+
itemBuilder: (context, index) {
|
|
75
|
+
return ListTile(title: Text(_users[index]));
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// --- Settings screen using SharedPreferences ---
|
|
82
|
+
class SettingsScreen extends StatefulWidget {
|
|
83
|
+
@override
|
|
84
|
+
State<SettingsScreen> createState() => _SettingsScreenState();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
class _SettingsScreenState extends State<SettingsScreen> {
|
|
88
|
+
bool _notifications = false;
|
|
89
|
+
|
|
90
|
+
@override
|
|
91
|
+
void initState() {
|
|
92
|
+
super.initState();
|
|
93
|
+
_load();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
Future<void> _load() async {
|
|
97
|
+
final prefs = await SharedPreferences.getInstance();
|
|
98
|
+
setState(() { _notifications = prefs.getBool('notifications') ?? false; });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
Future<void> _toggle() async {
|
|
102
|
+
final prefs = await SharedPreferences.getInstance();
|
|
103
|
+
final next = !_notifications;
|
|
104
|
+
await prefs.setBool('notifications', next);
|
|
105
|
+
setState(() { _notifications = next; });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@override
|
|
109
|
+
Widget build(BuildContext context) {
|
|
110
|
+
return Column(
|
|
111
|
+
children: [
|
|
112
|
+
Text('Notifications: $_notifications'),
|
|
113
|
+
ElevatedButton(onPressed: _toggle, child: Text('Toggle')),
|
|
114
|
+
],
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// --- Provider consumer ---
|
|
120
|
+
class ThemedButton extends StatelessWidget {
|
|
121
|
+
@override
|
|
122
|
+
Widget build(BuildContext context) {
|
|
123
|
+
final theme = context.watch<ThemeService>();
|
|
124
|
+
return Container(
|
|
125
|
+
color: theme.primary,
|
|
126
|
+
child: Text('Themed'),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// React example — hooks, Context, FlatList, fetch, styled-components.
|
|
2
|
+
// Goal: migrate this to Valdi.
|
|
3
|
+
|
|
4
|
+
import React, { useState, useEffect, useContext, createContext } from 'react';
|
|
5
|
+
import { View, Text, FlatList, TouchableOpacity, StyleSheet } from 'react-native';
|
|
6
|
+
import styled from 'styled-components/native';
|
|
7
|
+
|
|
8
|
+
// --- Context / theme ---
|
|
9
|
+
const ThemeContext = createContext({ primary: '#FFFC00' });
|
|
10
|
+
|
|
11
|
+
// --- Stateless greeting ---
|
|
12
|
+
const Greeting: React.FC<{ name: string }> = ({ name }) => {
|
|
13
|
+
return <Text>Hello, {name}</Text>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// --- Stateful counter ---
|
|
17
|
+
const Counter: React.FC<{ label: string }> = ({ label }) => {
|
|
18
|
+
const [count, setCount] = useState(0);
|
|
19
|
+
return (
|
|
20
|
+
<TouchableOpacity onPress={() => setCount(c => c + 1)}>
|
|
21
|
+
<Text>{label}: {count}</Text>
|
|
22
|
+
</TouchableOpacity>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// --- Data fetching with useEffect ---
|
|
27
|
+
interface User { id: string; name: string; }
|
|
28
|
+
|
|
29
|
+
const UserList: React.FC = () => {
|
|
30
|
+
const [users, setUsers] = useState<User[]>([]);
|
|
31
|
+
const [loading, setLoading] = useState(true);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
let cancelled = false;
|
|
35
|
+
fetch('https://api.example.com/users')
|
|
36
|
+
.then(r => r.json())
|
|
37
|
+
.then(data => {
|
|
38
|
+
if (!cancelled) {
|
|
39
|
+
setUsers(data);
|
|
40
|
+
setLoading(false);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return () => { cancelled = true; };
|
|
44
|
+
}, []);
|
|
45
|
+
|
|
46
|
+
if (loading) return <Text>Loading...</Text>;
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<FlatList
|
|
50
|
+
data={users}
|
|
51
|
+
keyExtractor={u => u.id}
|
|
52
|
+
renderItem={({ item }) => <Text>{item.name}</Text>}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// --- styled-components ---
|
|
58
|
+
const Card = styled.View`
|
|
59
|
+
background-color: #ffffff;
|
|
60
|
+
border-radius: 12px;
|
|
61
|
+
padding: 16px;
|
|
62
|
+
shadow-color: #000;
|
|
63
|
+
shadow-opacity: 0.15;
|
|
64
|
+
shadow-radius: 8px;
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
const CardTitle = styled.Text`
|
|
68
|
+
font-size: 18px;
|
|
69
|
+
font-weight: bold;
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
const ProfileCard: React.FC<{ name: string; bio: string }> = ({ name, bio }) => (
|
|
73
|
+
<Card>
|
|
74
|
+
<CardTitle>{name}</CardTitle>
|
|
75
|
+
<Text>{bio}</Text>
|
|
76
|
+
</Card>
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// --- Context consumer ---
|
|
80
|
+
const ThemedBadge: React.FC<{ text: string }> = ({ text }) => {
|
|
81
|
+
const theme = useContext(ThemeContext);
|
|
82
|
+
return (
|
|
83
|
+
<View style={{ backgroundColor: theme.primary }}>
|
|
84
|
+
<Text>{text}</Text>
|
|
85
|
+
</View>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// --- Re-render bug: inline lambda + map() ---
|
|
90
|
+
const BadList: React.FC<{ items: { id: string; label: string }[] }> = ({ items }) => (
|
|
91
|
+
<View>
|
|
92
|
+
{items.map(item => (
|
|
93
|
+
<TouchableOpacity key={item.id} onPress={() => console.log(item.id)}>
|
|
94
|
+
<Text>{item.label}</Text>
|
|
95
|
+
</TouchableOpacity>
|
|
96
|
+
))}
|
|
97
|
+
</View>
|
|
98
|
+
);
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
// Expected Valdi migrations — used to validate skill output correctness.
|
|
2
|
+
// Each section corresponds to a source snippet in flutter/compose/react examples.
|
|
3
|
+
|
|
4
|
+
import { Component, StatefulComponent } from 'valdi_core/src/Component';
|
|
5
|
+
import { Style } from 'valdi_core/src/Style';
|
|
6
|
+
import { systemFont } from 'valdi_core/src/SystemFont';
|
|
7
|
+
import { createProviderComponentWithKeyName } from 'valdi_core/src/provider/createProvider';
|
|
8
|
+
import {
|
|
9
|
+
ProvidersValuesViewModel,
|
|
10
|
+
withProviders,
|
|
11
|
+
} from 'valdi_core/src/provider/withProviders';
|
|
12
|
+
import { CancelablePromise } from 'valdi_core/src/CancelablePromise';
|
|
13
|
+
import { HTTPClient } from 'valdi_http/src/HTTPClient';
|
|
14
|
+
import { HTTPResponse } from 'valdi_http/src/HTTPTypes';
|
|
15
|
+
import { PersistentStore } from 'persistence/src/PersistentStore';
|
|
16
|
+
import { View } from 'valdi_tsx/src/NativeTemplateElements';
|
|
17
|
+
|
|
18
|
+
// Stub for the async data-fetching function referenced in examples
|
|
19
|
+
declare function fetchProfile(id: string): Promise<{ name: string }>;
|
|
20
|
+
|
|
21
|
+
// ============================================================
|
|
22
|
+
// Theme service + Provider
|
|
23
|
+
// ============================================================
|
|
24
|
+
|
|
25
|
+
class AppThemeService {
|
|
26
|
+
primary = '#FFFC00';
|
|
27
|
+
}
|
|
28
|
+
const ThemeProvider = createProviderComponentWithKeyName<AppThemeService>('ThemeProvider');
|
|
29
|
+
|
|
30
|
+
// ============================================================
|
|
31
|
+
// Stateless greeting (Flutter Greeting / Compose Greeting / React Greeting)
|
|
32
|
+
// ============================================================
|
|
33
|
+
|
|
34
|
+
interface GreetingViewModel {
|
|
35
|
+
name: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class Greeting extends Component<GreetingViewModel> {
|
|
39
|
+
onRender(): void {
|
|
40
|
+
<label value={`Hello, ${this.viewModel.name}`} />;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ============================================================
|
|
45
|
+
// Stateful counter (Flutter Counter / Compose Counter / React Counter)
|
|
46
|
+
// ============================================================
|
|
47
|
+
|
|
48
|
+
interface CounterViewModel {
|
|
49
|
+
label: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface CounterState {
|
|
53
|
+
count: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
class Counter extends StatefulComponent<CounterViewModel, CounterState> {
|
|
57
|
+
state = { count: 0 };
|
|
58
|
+
|
|
59
|
+
// Class arrow function — never inline lambda in JSX props
|
|
60
|
+
private increment = () => {
|
|
61
|
+
this.setState({ count: this.state.count + 1 });
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
onRender(): void {
|
|
65
|
+
<view onTap={this.increment}>
|
|
66
|
+
<label value={`${this.viewModel.label}: ${this.state.count}`} />;
|
|
67
|
+
</view>;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ============================================================
|
|
72
|
+
// Data loading (Flutter _UserListState / Compose UserProfile / React UserList)
|
|
73
|
+
// ============================================================
|
|
74
|
+
|
|
75
|
+
interface UserProfileViewModel {
|
|
76
|
+
userId: string;
|
|
77
|
+
}
|
|
78
|
+
interface UserProfileState {
|
|
79
|
+
profile: { name: string } | null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
class UserProfile extends StatefulComponent<UserProfileViewModel, UserProfileState> {
|
|
83
|
+
state: UserProfileState = { profile: null };
|
|
84
|
+
|
|
85
|
+
onCreate(): void {
|
|
86
|
+
this.loadProfile(this.viewModel.userId);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
onViewModelUpdate(previous?: UserProfileViewModel): void {
|
|
90
|
+
if (this.viewModel.userId !== previous?.userId) {
|
|
91
|
+
this.loadProfile(this.viewModel.userId);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private async loadProfile(id: string) {
|
|
96
|
+
const profile = await fetchProfile(id);
|
|
97
|
+
this.setState({ profile });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
onRender(): void {
|
|
101
|
+
if (!this.state.profile) {
|
|
102
|
+
<spinner />;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
<label value={this.state.profile.name} />;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ============================================================
|
|
110
|
+
// List (Flutter ListView.builder / Compose LazyColumn / React FlatList)
|
|
111
|
+
// ============================================================
|
|
112
|
+
|
|
113
|
+
interface User { id: string; name: string; }
|
|
114
|
+
|
|
115
|
+
interface UserListViewModel {
|
|
116
|
+
users: User[];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
class UserList extends Component<UserListViewModel> {
|
|
120
|
+
onRender(): void {
|
|
121
|
+
// forEach, not map() — JSX is emitted as side-effects
|
|
122
|
+
<scroll>
|
|
123
|
+
{this.viewModel.users.forEach(user => {
|
|
124
|
+
<label key={user.id} value={user.name} />;
|
|
125
|
+
})}
|
|
126
|
+
</scroll>;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ============================================================
|
|
131
|
+
// Layout (Flutter ProfileCard / Compose ProfileCard)
|
|
132
|
+
// ============================================================
|
|
133
|
+
|
|
134
|
+
interface ProfileCardViewModel {
|
|
135
|
+
name: string;
|
|
136
|
+
handle: string;
|
|
137
|
+
bio: string;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
class ProfileCard extends Component<ProfileCardViewModel> {
|
|
141
|
+
onRender(): void {
|
|
142
|
+
<view flexDirection="column" width="100%" padding={16}>
|
|
143
|
+
<view flexDirection="row" width="100%">
|
|
144
|
+
<label value={this.viewModel.name} font={systemFont(20)} />;
|
|
145
|
+
<layout flexGrow={1} />;
|
|
146
|
+
<label value={this.viewModel.handle} />;
|
|
147
|
+
</view>;
|
|
148
|
+
<layout height={8} />;
|
|
149
|
+
<label value={this.viewModel.bio} />;
|
|
150
|
+
</view>;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ============================================================
|
|
155
|
+
// Styled card (React styled-components Card)
|
|
156
|
+
// Style objects defined after the class, grouped in a const styles object
|
|
157
|
+
// ============================================================
|
|
158
|
+
|
|
159
|
+
interface CardViewModel {
|
|
160
|
+
name: string;
|
|
161
|
+
bio: string;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
class ProfileCardStyled extends Component<CardViewModel> {
|
|
165
|
+
onRender(): void {
|
|
166
|
+
<view style={styles.card}>
|
|
167
|
+
<label value={this.viewModel.name} font={systemFont(18)} />;
|
|
168
|
+
<label value={this.viewModel.bio} />;
|
|
169
|
+
</view>;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const styles = {
|
|
174
|
+
card: new Style<View>({
|
|
175
|
+
backgroundColor: '#ffffff',
|
|
176
|
+
borderRadius: 12,
|
|
177
|
+
boxShadow: '0 2 8 rgba(0,0,0,0.15)',
|
|
178
|
+
padding: 16,
|
|
179
|
+
}),
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// ============================================================
|
|
183
|
+
// Provider consumer (Flutter ThemedButton / Compose ThemedBadge / React ThemedBadge)
|
|
184
|
+
// ============================================================
|
|
185
|
+
|
|
186
|
+
interface ThemedBadgeViewModel extends ProvidersValuesViewModel<[AppThemeService]> {
|
|
187
|
+
text: string;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
class ThemedBadge extends Component<ThemedBadgeViewModel> {
|
|
191
|
+
onRender(): void {
|
|
192
|
+
const [theme] = this.viewModel.providersValues;
|
|
193
|
+
<view backgroundColor={theme.primary}>
|
|
194
|
+
<label value={this.viewModel.text} />;
|
|
195
|
+
</view>;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const ThemedBadgeWithProvider = withProviders(ThemeProvider)(ThemedBadge);
|
|
199
|
+
|
|
200
|
+
// ============================================================
|
|
201
|
+
// Persistent storage (Flutter SharedPreferences / React AsyncStorage)
|
|
202
|
+
// ============================================================
|
|
203
|
+
|
|
204
|
+
const settingsStore = new PersistentStore('settings');
|
|
205
|
+
|
|
206
|
+
interface SettingsState {
|
|
207
|
+
notifications: boolean;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
class SettingsScreen extends StatefulComponent<{}, SettingsState> {
|
|
211
|
+
state = { notifications: false };
|
|
212
|
+
|
|
213
|
+
async onCreate() {
|
|
214
|
+
const raw = await settingsStore.fetchString('notifications');
|
|
215
|
+
this.setState({ notifications: raw === 'true' });
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private toggle = async () => {
|
|
219
|
+
const next = !this.state.notifications;
|
|
220
|
+
await settingsStore.storeString('notifications', String(next));
|
|
221
|
+
this.setState({ notifications: next });
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
onRender(): void {
|
|
225
|
+
<view flexDirection="column">
|
|
226
|
+
<label value={`Notifications: ${this.state.notifications}`} />;
|
|
227
|
+
<view onTap={this.toggle}>
|
|
228
|
+
<label value="Toggle" />;
|
|
229
|
+
</view>;
|
|
230
|
+
</view>;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ============================================================
|
|
235
|
+
// HTTP fetch (React UserList with fetch / Flutter _loadUsers)
|
|
236
|
+
// ============================================================
|
|
237
|
+
|
|
238
|
+
interface FetchState {
|
|
239
|
+
users: User[];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
class UserListFetch extends StatefulComponent<{}, FetchState> {
|
|
243
|
+
state: FetchState = { users: [] };
|
|
244
|
+
|
|
245
|
+
private client = new HTTPClient('https://api.example.com');
|
|
246
|
+
private request?: CancelablePromise<HTTPResponse>;
|
|
247
|
+
|
|
248
|
+
onCreate(): void {
|
|
249
|
+
this.request = this.client.get('/users');
|
|
250
|
+
this.request.then(response => {
|
|
251
|
+
const users = JSON.parse(new TextDecoder().decode(response.body));
|
|
252
|
+
this.setState({ users });
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
onDestroy(): void {
|
|
257
|
+
this.request?.cancel?.();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
onRender(): void {
|
|
261
|
+
<scroll>
|
|
262
|
+
{this.state.users.forEach(u => {
|
|
263
|
+
<label key={u.id} value={u.name} />;
|
|
264
|
+
})}
|
|
265
|
+
</scroll>;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
@@ -20,21 +20,31 @@ Valdi uses TSX/JSX syntax but is **fundamentally different from React**.
|
|
|
20
20
|
- ✅ `this.viewModel` for props
|
|
21
21
|
- ✅ `onCreate()`, `onViewModelUpdate()`, `onDestroy()` lifecycle
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## 📦 AI Skills
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
Install Valdi skills for your AI tool to get context-specific guidance:
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
| C++ runtime | `.cursor/rules/cpp-runtime.md` |
|
|
32
|
-
| Android (Kotlin) | `.cursor/rules/android.md` |
|
|
33
|
-
| iOS (Objective-C) | `.cursor/rules/ios.md` |
|
|
34
|
-
| Bazel files | `.cursor/rules/bazel.md` |
|
|
35
|
-
| Tests | `.cursor/rules/testing.md` |
|
|
27
|
+
```bash
|
|
28
|
+
npm install -g @snap/valdi
|
|
29
|
+
valdi skills install
|
|
30
|
+
```
|
|
36
31
|
|
|
37
|
-
|
|
32
|
+
Skills available (`valdi skills list`):
|
|
33
|
+
|
|
34
|
+
| Skill | Coverage |
|
|
35
|
+
|-------|----------|
|
|
36
|
+
| `valdi-tsx` | TSX component patterns, lifecycle, styling |
|
|
37
|
+
| `valdi-setup` | Module BUILD.bazel, tsconfig, hot reload |
|
|
38
|
+
| `valdi-async` | CancelablePromise, HTTPClient, lifecycle safety |
|
|
39
|
+
| `valdi-perf` | ViewModel stability, createReusableCallback, Style interning |
|
|
40
|
+
| `valdi-component-tests` | elementKeyFind, tapNodeWithKey, discriminated unions |
|
|
41
|
+
| `valdi-ios` | Swift/ObjC platform bridging |
|
|
42
|
+
| `valdi-android` | Kotlin platform bridging |
|
|
43
|
+
| `valdi-bazel` | Build rules, platform builds |
|
|
44
|
+
| `valdi-compiler` | Compiler pipeline internals |
|
|
45
|
+
| `valdi-cpp-runtime` | C++ runtime and renderer |
|
|
46
|
+
| `valdi-polyglot-module` | Cross-platform polyglot APIs, web polyglot entry pattern |
|
|
47
|
+
| `valdi-custom-view` | Native view integration, viewFactory |
|
|
38
48
|
|
|
39
49
|
## Quick Commands
|
|
40
50
|
|
|
@@ -47,7 +57,7 @@ valdi hotreload # Start hot reload
|
|
|
47
57
|
|
|
48
58
|
## More Information
|
|
49
59
|
|
|
50
|
-
- **Comprehensive guide**: `/AGENTS.md`
|
|
60
|
+
- **Comprehensive guide**: `/AGENTS.md`
|
|
51
61
|
- **AI tooling**: `/docs/docs/ai-tooling.md`
|
|
52
62
|
- **Support**: `/SUPPORT.md`
|
|
53
63
|
- **Discord**: https://discord.gg/uJyNEeYX2U
|