@snap/valdi 1.0.8 → 1.1.5
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/.bootstrap/apps/cli_application/BUILD.bazel.template +7 -0
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +11 -0
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +1 -0
- package/.bootstrap/apps/ui_application/.eslint.rc +27 -0
- package/.bootstrap/apps/ui_application/BUILD.bazel.template +19 -0
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +21 -0
- 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 +133 -0
- package/.bootstrap/apps/ui_application/package.json +24 -0
- package/.bootstrap/modules/polyglot_bridge_module/BUILD.bazel.template +54 -0
- package/.bootstrap/modules/polyglot_bridge_module/android/CalculatorModuleFactory.kt.template +18 -0
- package/.bootstrap/modules/polyglot_bridge_module/ios/SCCCalculatorModuleFactory.m.template +31 -0
- package/.bootstrap/modules/polyglot_bridge_module/src/Calculator.d.ts +4 -0
- package/.bootstrap/modules/polyglot_bridge_module/web/Calculator.ts +11 -0
- package/.bootstrap/modules/polyglot_bridge_module/web/tsconfig.json +16 -0
- package/.bootstrap/modules/polyglot_view_module/BUILD.bazel.template +75 -0
- package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeView.kt.template +41 -0
- package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeViewAttributesBinder.kt.template +17 -0
- package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.h +8 -0
- package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.m +23 -0
- package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.h +8 -0
- package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.m +23 -0
- package/.bootstrap/modules/polyglot_view_module/src/PolyglotCustomView.tsx.template +23 -0
- package/.bootstrap/modules/polyglot_view_module/web/PolyglotWeb.ts.template +30 -0
- package/.bootstrap/modules/polyglot_view_module/web/tsconfig.json +16 -0
- package/.bootstrap/modules/ui_component/BUILD.bazel.template +34 -0
- package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +45 -0
- package/.metadata/.bazelrc.template +92 -0
- package/.metadata/.bazelversion.template +1 -0
- package/.metadata/.editorconfig.template +37 -0
- package/.metadata/.eslintrc.js.template +27 -0
- package/.metadata/.gitignore.template +4 -0
- package/.metadata/.prettierrc.json.template +7 -0
- package/.metadata/.watchmanconfig.template +8 -0
- package/.metadata/AGENTS.md.template +16 -0
- package/.metadata/MODULE.bazel.template +62 -0
- package/.metadata/README.md.template +31 -0
- package/.metadata/config.yaml.template +1 -0
- package/.metadata/package.json.template +23 -0
- package/.metadata/skill-reference.tsx.template +8 -0
- package/.metadata/skill-tests-BUILD.bazel.template +21 -0
- package/.metadata/skill-tests-README.md.template +17 -0
- package/.metadata/skill.md.template +27 -0
- package/bundled-skills/registry.json +14 -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-bazel/skill.md +21 -2
- 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 +49 -5
- 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 +217 -0
- 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 +131 -12
- package/bundled-skills/skills/valdi-preview/skill.md +303 -0
- package/bundled-skills/skills/valdi-profile/skill.md +126 -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/doctor.js +40 -203
- package/dist/commands/hotreload.js +15 -0
- package/dist/commands/inspect.js +16 -0
- package/dist/commands/inspect_commands/contexts.js +55 -0
- package/dist/commands/inspect_commands/devices.js +53 -0
- package/dist/commands/inspect_commands/heap.js +59 -0
- package/dist/commands/inspect_commands/select.js +43 -0
- package/dist/commands/inspect_commands/snapshot.js +129 -0
- package/dist/commands/inspect_commands/snapshot.spec.js +105 -0
- package/dist/commands/inspect_commands/status.js +68 -0
- package/dist/commands/inspect_commands/tree.js +86 -0
- package/dist/commands/preview.js +81 -0
- package/dist/commands/profile.js +16 -0
- package/dist/commands/profile_commands/capture.js +106 -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 +1 -1
- package/dist/core/packageFiles.spec.js +29 -0
- 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 -51
- package/dist/setup/linuxSetup.js +0 -2
- package/dist/setup/macOSSetup.js +1 -4
- package/dist/utils/BazelClient.js +15 -0
- package/dist/utils/daemonClient.js +344 -0
- package/dist/utils/hermesClient.js +252 -0
- package/dist/utils/skillsAdapters.js +86 -5
- package/dist/utils/skillsAdapters.spec.js +60 -0
- package/dist/utils/skillsRegistry.js +8 -0
- package/dist/utils/stringUtils.spec.js +1 -1
- package/package.json +30 -12
- package/dist/setup/versions.js +0 -8
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Valdi Animations
|
|
2
|
+
|
|
3
|
+
Imperative animation API for animating element attributes and state changes.
|
|
4
|
+
|
|
5
|
+
## When to use
|
|
6
|
+
|
|
7
|
+
When animating layout changes, view attributes, or state transitions. Almost all element attributes can be animated in Valdi.
|
|
8
|
+
|
|
9
|
+
## Key concepts
|
|
10
|
+
|
|
11
|
+
Valdi uses an **imperative animation model** inspired by iOS's `animateWithDuration:animations:`. You call `this.animate()` or `this.animatePromise()` with options and a block of mutations — all changes inside the block are animated automatically.
|
|
12
|
+
|
|
13
|
+
**Not CSS transitions.** There is no `transition` property, no `@keyframes`, no `animation-duration`. Animations are triggered programmatically.
|
|
14
|
+
|
|
15
|
+
## animate and animatePromise
|
|
16
|
+
|
|
17
|
+
Both methods are available on any `Component`:
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
// ✅ Fire-and-forget animation
|
|
21
|
+
this.animate({ duration: 0.3 }, () => {
|
|
22
|
+
this.myLabel.setAttribute('font', 'title');
|
|
23
|
+
this.myContainer.setAttribute('width', 200);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// ✅ Wait for animation to complete
|
|
27
|
+
await this.animatePromise({ duration: 0.5, curve: AnimationCurve.EaseOut }, () => {
|
|
28
|
+
this.setState({ expanded: true });
|
|
29
|
+
});
|
|
30
|
+
// Animation finished — safe to do next step
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## AnimationOptions
|
|
34
|
+
|
|
35
|
+
Three curve types: preset, custom bezier, and spring.
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
import { AnimationCurve } from 'valdi_core/src/AnimationOptions';
|
|
39
|
+
|
|
40
|
+
// Preset curves
|
|
41
|
+
{ duration: 0.3, curve: AnimationCurve.Linear }
|
|
42
|
+
{ duration: 0.3, curve: AnimationCurve.EaseIn }
|
|
43
|
+
{ duration: 0.3, curve: AnimationCurve.EaseOut }
|
|
44
|
+
{ duration: 0.3, curve: AnimationCurve.EaseInOut } // default
|
|
45
|
+
|
|
46
|
+
// Custom bezier control points
|
|
47
|
+
{ duration: 0.4, controlPoints: [0.25, 0.1, 0.25, 1.0] }
|
|
48
|
+
|
|
49
|
+
// Spring animation (no duration — spring physics determine timing)
|
|
50
|
+
{ stiffness: 300, damping: 30 }
|
|
51
|
+
|
|
52
|
+
// Crossfade (alpha transition between old and new state)
|
|
53
|
+
{ duration: 0.3, crossfade: true }
|
|
54
|
+
|
|
55
|
+
// Continue from current animation state
|
|
56
|
+
{ duration: 0.3, beginFromCurrentState: true }
|
|
57
|
+
|
|
58
|
+
// Completion callback
|
|
59
|
+
{ duration: 0.3, completion: (wasCancelled) => { /* done */ } }
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Animating element attributes via ElementRef
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import { ElementRef } from 'valdi_core/src/ElementRef';
|
|
66
|
+
|
|
67
|
+
export class MyComponent extends Component {
|
|
68
|
+
private titleRef = new ElementRef();
|
|
69
|
+
private containerRef = new ElementRef();
|
|
70
|
+
|
|
71
|
+
onRender(): void {
|
|
72
|
+
<view ref={this.containerRef} width={100}>
|
|
73
|
+
<label ref={this.titleRef} value="Hello" font={systemFont(14)} />
|
|
74
|
+
</view>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private expand = () => {
|
|
78
|
+
// ✅ Animate attribute changes via ElementRef
|
|
79
|
+
this.animate({ duration: 0.3 }, () => {
|
|
80
|
+
this.titleRef.setAttribute('font', systemBoldFont(17));
|
|
81
|
+
this.containerRef.setAttribute('width', 300);
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Animating state changes
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
interface State {
|
|
91
|
+
expanded: boolean;
|
|
92
|
+
text: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class MyComponent extends StatefulComponent<{}, State> {
|
|
96
|
+
state = { expanded: false, text: 'Collapsed' };
|
|
97
|
+
|
|
98
|
+
onRender(): void {
|
|
99
|
+
<view width={this.state.expanded ? 300 : 100} height={this.state.expanded ? 200 : 50}>
|
|
100
|
+
<label value={this.state.text} />
|
|
101
|
+
</view>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private toggle = () => {
|
|
105
|
+
// ✅ setStateAnimated — renders with new state, animates all resulting mutations
|
|
106
|
+
this.setStateAnimated(
|
|
107
|
+
{ expanded: !this.state.expanded, text: this.state.expanded ? 'Collapsed' : 'Expanded' },
|
|
108
|
+
{ duration: 0.3, curve: AnimationCurve.EaseInOut },
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Spring animations
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
// ✅ Bouncy spring — lower damping = more bounce
|
|
118
|
+
this.animate({ stiffness: 300, damping: 15 }, () => {
|
|
119
|
+
this.cardRef.setAttribute('scale', 1.0);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// ✅ Stiff spring — high damping = smooth settle
|
|
123
|
+
this.animate({ stiffness: 500, damping: 40 }, () => {
|
|
124
|
+
this.panelRef.setAttribute('translateY', 0);
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Common patterns
|
|
129
|
+
|
|
130
|
+
### Show/hide with fade
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
private show = () => {
|
|
134
|
+
this.animate({ duration: 0.2 }, () => {
|
|
135
|
+
this.overlayRef.setAttribute('opacity', 1);
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
private hide = () => {
|
|
140
|
+
this.animate({ duration: 0.2 }, () => {
|
|
141
|
+
this.overlayRef.setAttribute('opacity', 0);
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Sequential animations
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
private async runSequence() {
|
|
150
|
+
await this.animatePromise({ duration: 0.2 }, () => {
|
|
151
|
+
this.step1Ref.setAttribute('opacity', 1);
|
|
152
|
+
});
|
|
153
|
+
await this.animatePromise({ duration: 0.3 }, () => {
|
|
154
|
+
this.step2Ref.setAttribute('translateY', 0);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Common mistakes
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
// ❌ WRONG — CSS-style transitions don't exist
|
|
163
|
+
<view style={{ transition: 'all 0.3s ease' }} /> // ❌
|
|
164
|
+
<view className="animate-fade-in" /> // ❌
|
|
165
|
+
|
|
166
|
+
// ❌ WRONG — React-style animation libraries
|
|
167
|
+
import { animated, useSpring } from 'react-spring'; // ❌
|
|
168
|
+
|
|
169
|
+
// ❌ WRONG — Calling setState inside animate (use setStateAnimated instead)
|
|
170
|
+
this.animate({ duration: 0.3 }, () => {
|
|
171
|
+
this.setState({ expanded: true }); // ❌ Won't animate the re-render
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// ✅ Correct — use setStateAnimated for state-driven animations
|
|
175
|
+
this.setStateAnimated({ expanded: true }, { duration: 0.3 });
|
|
176
|
+
|
|
177
|
+
// ❌ WRONG — Duration in milliseconds (it's seconds)
|
|
178
|
+
this.animate({ duration: 300 }, () => { ... }); // ❌ This is 300 seconds!
|
|
179
|
+
|
|
180
|
+
// ✅ Correct — Duration in seconds
|
|
181
|
+
this.animate({ duration: 0.3 }, () => { ... });
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## CoreUI animation components
|
|
185
|
+
|
|
186
|
+
The `coreui` library includes pre-built animation components:
|
|
187
|
+
|
|
188
|
+
| Component | Purpose |
|
|
189
|
+
|-----------|---------|
|
|
190
|
+
| `AnimatableVisibilityView` | Animate show/hide transitions |
|
|
191
|
+
| `AnimationShimmer` | Loading shimmer effect |
|
|
192
|
+
| `AnimationSliding` | Slide in/out animations |
|
|
193
|
+
| `AnimationSquishy` | Press-and-squish feedback |
|
|
194
|
+
| `AnimationRotate` | Continuous rotation |
|
|
195
|
+
| `VerticallyOpenableComponent` | Expand/collapse vertically |
|
|
196
|
+
|
|
197
|
+
Import from `coreui/src/components/animation/`.
|
|
@@ -73,7 +73,7 @@ class LiveClock extends StatefulComponent<ClockViewModel, ClockState> {
|
|
|
73
73
|
onCreate(): void {
|
|
74
74
|
// ✅ Automatically cancelled on destroy — no onDestroy() needed
|
|
75
75
|
const id = setInterval(() => this.tick(), 1000);
|
|
76
|
-
this.registerDisposable({
|
|
76
|
+
this.registerDisposable({ unsubscribe: () => clearInterval(id) });
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
private tick = (): void => {
|
|
@@ -39,6 +39,8 @@ bazel clean
|
|
|
39
39
|
### Common Targets
|
|
40
40
|
|
|
41
41
|
```python
|
|
42
|
+
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
|
|
43
|
+
|
|
42
44
|
# Valdi application
|
|
43
45
|
valdi_application(
|
|
44
46
|
name = "my_app",
|
|
@@ -48,10 +50,27 @@ valdi_application(
|
|
|
48
50
|
deps = ["//apps/my_app/src/valdi/my_app"],
|
|
49
51
|
)
|
|
50
52
|
|
|
51
|
-
#
|
|
53
|
+
# Web polyglot views — MUST be ts_project, never filegroup
|
|
54
|
+
ts_project(
|
|
55
|
+
name = "my_module_web",
|
|
56
|
+
srcs = glob(
|
|
57
|
+
["web/**/*.ts", "src/**/*.d.ts"],
|
|
58
|
+
exclude = ["web/**/*.d.ts"],
|
|
59
|
+
),
|
|
60
|
+
allow_js = True,
|
|
61
|
+
composite = True,
|
|
62
|
+
transpiler = "tsc",
|
|
63
|
+
tsconfig = "web/tsconfig.json",
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
# Valdi module with platform deps
|
|
52
67
|
valdi_module(
|
|
53
68
|
name = "my_module",
|
|
54
|
-
srcs = glob(["src/**/*.ts", "src/**/*.tsx"]),
|
|
69
|
+
srcs = glob(["src/**/*.ts", "src/**/*.tsx"]) + ["tsconfig.json"],
|
|
70
|
+
ios_deps = [":my_ios_views"], # objc_library
|
|
71
|
+
macos_deps = [":my_macos_views"], # objc_library (or omit to share ios_deps)
|
|
72
|
+
android_deps = [":my_android_views"], # valdi_android_library
|
|
73
|
+
web_deps = [":my_module_web"], # ts_project (never filegroup)
|
|
55
74
|
deps = [
|
|
56
75
|
"//src/valdi_modules/src/valdi/valdi_core",
|
|
57
76
|
],
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
# Valdi Component Deduplication
|
|
2
|
+
|
|
3
|
+
Find and extract duplicated UI patterns across Valdi modules into shared components.
|
|
4
|
+
|
|
5
|
+
## When to use
|
|
6
|
+
|
|
7
|
+
When you want to identify components that multiple modules have independently implemented, then extract them into a shared library so future modules can reuse them instead of reinventing.
|
|
8
|
+
|
|
9
|
+
## Running the analysis
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Full scan of all modules
|
|
13
|
+
valdi analyze duplicates
|
|
14
|
+
|
|
15
|
+
# Scope to one module
|
|
16
|
+
valdi analyze duplicates --module my_module
|
|
17
|
+
|
|
18
|
+
# Machine-readable output
|
|
19
|
+
valdi analyze duplicates --json
|
|
20
|
+
|
|
21
|
+
# Only check for a specific pattern
|
|
22
|
+
valdi analyze duplicates --pattern async
|
|
23
|
+
|
|
24
|
+
# Custom scan roots and shared libraries
|
|
25
|
+
valdi analyze duplicates --scan-root src/modules --shared-lib valdi_widgets
|
|
26
|
+
valdi analyze duplicates --scan-root src/modules --shared-lib my_shared_lib --shared-lib another_lib
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### CLI flags
|
|
30
|
+
|
|
31
|
+
| Flag | Effect |
|
|
32
|
+
|---|---|
|
|
33
|
+
| `--module <name>` | Scope to one module |
|
|
34
|
+
| `--json` | Machine-readable JSON output |
|
|
35
|
+
| `--threshold <0-1>` | Similarity threshold (default 0.6) |
|
|
36
|
+
| `--pattern <name>` | Only detect: `async`, `button`, `shimmer` |
|
|
37
|
+
| `--output <path>` | Write JSON report to file |
|
|
38
|
+
| `--verbose` | Show per-file detail |
|
|
39
|
+
| `--scan-root <path>` | Root directory to scan (repeatable) |
|
|
40
|
+
| `--shared-lib <name>` | Shared component library name (repeatable) |
|
|
41
|
+
|
|
42
|
+
## Understanding the report
|
|
43
|
+
|
|
44
|
+
The report has two sections:
|
|
45
|
+
|
|
46
|
+
**Known Patterns** — pre-built detectors for the most common duplication:
|
|
47
|
+
- **Async State Container**: Components that implement loading→error/content state machines
|
|
48
|
+
- **Button Wrapper**: Thin wrappers around a shared button with hardcoded sizing/coloring
|
|
49
|
+
- **Shimmer / Skeleton Layout**: Custom loading placeholder components
|
|
50
|
+
|
|
51
|
+
**Similar Clusters** — generic similarity analysis that finds groups of components with overlapping ViewModel props, render trees, and import signatures.
|
|
52
|
+
|
|
53
|
+
Each cluster shows:
|
|
54
|
+
- Number of files and average similarity score
|
|
55
|
+
- Shared ViewModel props across the cluster
|
|
56
|
+
- A suggested extraction approach
|
|
57
|
+
|
|
58
|
+
## Extraction workflow
|
|
59
|
+
|
|
60
|
+
Once you identify a cluster worth extracting:
|
|
61
|
+
|
|
62
|
+
### 1. Read the candidates
|
|
63
|
+
|
|
64
|
+
Read each file in the cluster. Identify:
|
|
65
|
+
- The shared ViewModel props (these become the new component's ViewModel)
|
|
66
|
+
- The shared render structure (this becomes the new component's `onRender`)
|
|
67
|
+
- Module-specific variations (these become optional props or render callbacks)
|
|
68
|
+
|
|
69
|
+
### 2. Check for an existing shared component to extend
|
|
70
|
+
|
|
71
|
+
Before creating anything new, search the shared library for a component that already solves part of the problem. Often the right fix is adding props, a preset enum, or a render callback to an existing component rather than building from scratch.
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Search the shared library for related components
|
|
75
|
+
grep -rl "Button\|Shimmer\|AsyncContent" <your-shared-lib>/src/components/
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
If an existing component covers 70%+ of the use cases, extend it:
|
|
79
|
+
- Add optional props for the missing behavior
|
|
80
|
+
- Add a preset or variant enum if consumers just need different default combos
|
|
81
|
+
- Add a render callback slot if consumers need to inject custom UI
|
|
82
|
+
|
|
83
|
+
Only create a new component when nothing in the shared library is close enough to extend.
|
|
84
|
+
|
|
85
|
+
### 3. Design or extend the shared component
|
|
86
|
+
|
|
87
|
+
**Extending an existing component** (preferred):
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
// Add a preset to an existing button component
|
|
91
|
+
export enum CoreButtonPreset {
|
|
92
|
+
PRIMARY_CTA,
|
|
93
|
+
SECONDARY_ACTION,
|
|
94
|
+
PILL_ACTION,
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Add an optional prop to the existing ViewModel
|
|
98
|
+
interface CoreButtonViewModel {
|
|
99
|
+
// ... existing props ...
|
|
100
|
+
preset?: CoreButtonPreset;
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Creating a new component** (when nothing exists to extend):
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { Component } from 'valdi_core/src/Component';
|
|
108
|
+
|
|
109
|
+
interface SharedComponentViewModel {
|
|
110
|
+
commonProp: string;
|
|
111
|
+
optionalVariant?: VariantType;
|
|
112
|
+
renderCustomSection?: () => void;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export class SharedComponent extends Component<SharedComponentViewModel> {
|
|
116
|
+
onRender(): void {
|
|
117
|
+
<view>
|
|
118
|
+
<label value={this.viewModel.commonProp} />;
|
|
119
|
+
{this.viewModel.renderCustomSection?.()};
|
|
120
|
+
</view>;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### 4. Place it in the shared library
|
|
126
|
+
|
|
127
|
+
If you created a new component, place it in your project's shared component library
|
|
128
|
+
(e.g. `<shared-lib>/src/components/<category>/`). Follow your project's conventions
|
|
129
|
+
for directory structure and naming.
|
|
130
|
+
|
|
131
|
+
### 5. Migrate consumers
|
|
132
|
+
|
|
133
|
+
For each file in the cluster:
|
|
134
|
+
1. Replace the local component class with an import of the shared one
|
|
135
|
+
2. Map the old ViewModel props to the new shared ViewModel
|
|
136
|
+
3. Move module-specific rendering into render callbacks
|
|
137
|
+
4. Delete the old local component file
|
|
138
|
+
5. Run `valdi agent-check --module <name>` to verify
|
|
139
|
+
|
|
140
|
+
### 6. Verify
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# Re-run analysis — the cluster should shrink or disappear
|
|
144
|
+
valdi analyze duplicates --pattern async
|
|
145
|
+
|
|
146
|
+
# Build and test affected modules
|
|
147
|
+
valdi agent-check --module module_a
|
|
148
|
+
valdi agent-check --module module_b
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Common extraction patterns
|
|
152
|
+
|
|
153
|
+
### Async State Container
|
|
154
|
+
|
|
155
|
+
The most common duplication. Components that manage loading→loaded/error states:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { StatefulComponent } from 'valdi_core/src/Component';
|
|
159
|
+
import { promiseToCancelablePromise } from 'valdi_core/src/CancelablePromise';
|
|
160
|
+
|
|
161
|
+
interface AsyncStateContainerViewModel<T> {
|
|
162
|
+
resultProvider: () => PromiseLike<T>;
|
|
163
|
+
renderLoading: () => void;
|
|
164
|
+
renderResult: (data: T) => void;
|
|
165
|
+
renderError: (error: string, retry: () => void) => void;
|
|
166
|
+
renderEmpty?: () => void;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
type AsyncState<T> = { phase: 'loading' } | { phase: 'result'; data: T } | { phase: 'error'; message: string };
|
|
170
|
+
|
|
171
|
+
export class AsyncStateContainer<T> extends StatefulComponent<AsyncStateContainerViewModel<T>, { state: AsyncState<T> }> {
|
|
172
|
+
state = { state: { phase: 'loading' } as AsyncState<T> };
|
|
173
|
+
|
|
174
|
+
onCreate(): void {
|
|
175
|
+
this.load();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
onRender(): void {
|
|
179
|
+
const s = this.state.state;
|
|
180
|
+
switch (s.phase) {
|
|
181
|
+
case 'loading': this.viewModel.renderLoading(); break;
|
|
182
|
+
case 'result': this.viewModel.renderResult(s.data); break;
|
|
183
|
+
case 'error': this.viewModel.renderError(s.message, () => this.load()); break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private load(): void {
|
|
188
|
+
this.setState({ state: { phase: 'loading' } });
|
|
189
|
+
const cancelable = promiseToCancelablePromise(
|
|
190
|
+
Promise.resolve(this.viewModel.resultProvider()),
|
|
191
|
+
() => {},
|
|
192
|
+
);
|
|
193
|
+
this.registerDisposable(() => cancelable.cancel?.());
|
|
194
|
+
cancelable.then(
|
|
195
|
+
data => { this.setState({ state: { phase: 'result', data } }); },
|
|
196
|
+
error => { this.setState({ state: { phase: 'error', message: (error as Error).message } }); },
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Button Presets
|
|
203
|
+
|
|
204
|
+
Instead of per-module button wrappers, use preset enums:
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
// Instead of a new wrapper component, add presets to the existing shared button
|
|
208
|
+
enum ButtonPreset {
|
|
209
|
+
PRIMARY_CTA,
|
|
210
|
+
SECONDARY_ACTION,
|
|
211
|
+
PILL_ACTION,
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function presetProps(preset: ButtonPreset): { sizing: ButtonSizing; coloring: ButtonColoring } {
|
|
215
|
+
switch (preset) {
|
|
216
|
+
case ButtonPreset.PRIMARY_CTA: return { sizing: ButtonSizing.XL, coloring: ButtonColoring.PRIMARY_BRAND };
|
|
217
|
+
case ButtonPreset.SECONDARY_ACTION: return { sizing: ButtonSizing.LARGE, coloring: ButtonColoring.SECONDARY };
|
|
218
|
+
case ButtonPreset.PILL_ACTION: return { sizing: ButtonSizing.SMALL, coloring: ButtonColoring.TERTIARY };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Shimmer Layout
|
|
224
|
+
|
|
225
|
+
Configurable skeleton loading placeholder:
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
import { Component } from 'valdi_core/src/Component';
|
|
229
|
+
|
|
230
|
+
interface ShimmerRow {
|
|
231
|
+
widthRatio: number;
|
|
232
|
+
height: number;
|
|
233
|
+
borderRadius?: number;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
interface ShimmerLayoutViewModel {
|
|
237
|
+
rows: ShimmerRow[];
|
|
238
|
+
spacing?: number;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export class ShimmerLayout extends Component<ShimmerLayoutViewModel> {
|
|
242
|
+
onRender(): void {
|
|
243
|
+
const spacing = this.viewModel.spacing ?? 8;
|
|
244
|
+
<view>
|
|
245
|
+
{this.viewModel.rows.forEach((row, i) => {
|
|
246
|
+
<AnimationShimmer
|
|
247
|
+
width={`${row.widthRatio * 100}%`}
|
|
248
|
+
height={row.height}
|
|
249
|
+
borderRadius={row.borderRadius ?? 4}
|
|
250
|
+
marginTop={i > 0 ? spacing : 0}
|
|
251
|
+
/>;
|
|
252
|
+
})}
|
|
253
|
+
</view>;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Tips
|
|
259
|
+
|
|
260
|
+
- Start with the highest-severity known patterns — they have the most impact
|
|
261
|
+
- Extract the simplest shared interface first, then iterate to handle edge cases
|
|
262
|
+
- Use render callbacks for module-specific UI instead of trying to generalize everything
|
|
263
|
+
- Run `valdi analyze duplicates --json --output report.json` to save a baseline, then re-run after extraction to measure impact
|
|
@@ -100,7 +100,7 @@ describe('ProfileCardTest', () => {
|
|
|
100
100
|
componentGetElements(nodes[0].component!),
|
|
101
101
|
'follow-button',
|
|
102
102
|
)[0];
|
|
103
|
-
button?.getAttribute('onTap')?.();
|
|
103
|
+
button?.getAttribute('onTap')?.({} as any);
|
|
104
104
|
expect(onFollowTap).toHaveBeenCalled();
|
|
105
105
|
});
|
|
106
106
|
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
| `macosClass` | macOS | `NSClassFromString()`; must be linked via `macos_deps` |
|
|
27
27
|
| `webClass` | Web | Looked up in `WebViewClassRegistry`; registered via `webPolyglotViews` export |
|
|
28
28
|
|
|
29
|
-
## Platform
|
|
29
|
+
## Platform Resolution
|
|
30
30
|
|
|
31
31
|
- **Android**: The view class needs a single-arg `(Context)` constructor. An `@RegisterAttributesBinder`-annotated binder is discovered from assets at runtime.
|
|
32
|
-
- **iOS**: The ObjC class must be
|
|
33
|
-
- **macOS**:
|
|
34
|
-
- **Web**: The `webClass` name is matched against the `WebViewClassRegistry`. Register by exporting `webPolyglotViews` from a web polyglot entry file (see `
|
|
32
|
+
- **iOS**: The ObjC class must be a `UIView` subclass linked into the binary via `ios_deps`.
|
|
33
|
+
- **macOS**: Falls through to `iosClass` when `macosClass` is not specified — both in TypeScript (`JSXBootstrap.ts`) and C++ (`ViewNode.cpp`). Only specify `macosClass` when the macOS view is different from iOS.
|
|
34
|
+
- **Web**: The `webClass` name is matched against the `WebViewClassRegistry`. Register by exporting `webPolyglotViews` from a typed TypeScript web polyglot entry file compiled via `ts_project` (see `valdi-polyglot-module` skill). Factories return an `AttributeHandler` with `changeAttribute(name, value)` to receive attribute updates.
|
|
35
35
|
|
|
36
36
|
## viewFactory Pattern
|
|
37
37
|
|
|
@@ -55,8 +55,52 @@ class MyComponent extends Component<MyViewModel> {
|
|
|
55
55
|
|
|
56
56
|
`viewFactory` and `*Class` attributes are mutually exclusive — use one or the other. `viewFactory` takes precedence when both are provided.
|
|
57
57
|
|
|
58
|
+
## macOS Attribute Binding
|
|
59
|
+
|
|
60
|
+
macOS custom views can bind attributes (including callbacks) from TSX using `+bindAttributes:`. The view manager calls this class method at registration time.
|
|
61
|
+
|
|
62
|
+
```objc
|
|
63
|
+
#import "valdi/macos/SCValdiMacOSAttributesBinder.h"
|
|
64
|
+
#import "valdi/macos/SCValdiMacOSFunction.h"
|
|
65
|
+
|
|
66
|
+
@interface SCMyView () {
|
|
67
|
+
SCValdiMacOSFunction *_onMyCallback;
|
|
68
|
+
}
|
|
69
|
+
@end
|
|
70
|
+
|
|
71
|
+
@implementation SCMyView
|
|
72
|
+
- (void)valdi_setOnMyCallback:(id)value { _onMyCallback = value; }
|
|
73
|
+
|
|
74
|
+
+ (void)bindAttributes:(SCValdiMacOSAttributesBinder *)attributesBinder {
|
|
75
|
+
[attributesBinder bindUntypedAttribute:@"onMyCallback"
|
|
76
|
+
invalidateLayoutOnChange:NO
|
|
77
|
+
selector:@selector(valdi_setOnMyCallback:)];
|
|
78
|
+
}
|
|
79
|
+
@end
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Binder methods:**
|
|
83
|
+
- `bindUntypedAttribute:invalidateLayoutOnChange:selector:` — binds any attribute (strings, numbers, functions)
|
|
84
|
+
- `bindColorAttribute:invalidateLayoutOnChange:selector:` — binds color attributes specifically
|
|
85
|
+
|
|
86
|
+
**Invoking callbacks:** Call `[_onMyCallback performWithParameters:@[@{@"key": @"value"}]]` — the NSArray/NSDictionary is auto-converted to JS objects.
|
|
87
|
+
|
|
88
|
+
## Keyboard Input on macOS
|
|
89
|
+
|
|
90
|
+
Valdi doesn't have built-in keyboard event support. Use a polyglot `<custom-view>` with an NSView that:
|
|
91
|
+
1. Overrides `acceptsFirstResponder` → `YES`
|
|
92
|
+
2. Overrides `keyDown:` to map key codes to callback invocations
|
|
93
|
+
3. Calls `[self.window makeFirstResponder:self]` in `viewDidMoveToWindow` to grab focus
|
|
94
|
+
4. Has **non-zero dimensions** (wrap visible content inside it)
|
|
95
|
+
|
|
96
|
+
See the `valdi-polyglot-module` skill for a complete macOS attribute binding example with BUILD.bazel wiring.
|
|
97
|
+
|
|
58
98
|
## Common Mistakes
|
|
59
99
|
|
|
60
|
-
- Using `<custom-view>` without checking the platform — wrap in `Device.isAndroid()` / `Device.isIOS()`
|
|
100
|
+
- Using `<custom-view>` without checking the platform — wrap in `Device.isAndroid()` / `Device.isIOS()` / `Device.isDesktop()` if not all platforms are supported
|
|
61
101
|
- Forgetting to link native implementations — the class name string alone isn't enough; the native code must be compiled and linked via platform `_deps` in BUILD.bazel
|
|
62
102
|
- Wrong package name in `androidClass` — must match the Kotlin/Java package exactly
|
|
103
|
+
- Specifying `macosClass` when it's the same as `iosClass` — omit it and let the fallthrough handle it
|
|
104
|
+
- Using a `filegroup` for `web_deps` — always use `ts_project` with `transpiler = "tsc"`
|
|
105
|
+
- Creating a 0×0 custom-view for keyboard focus — it won't become first responder; wrap content inside it
|
|
106
|
+
- **Duplicate ObjC class names across modules** — if two modules define the same native class (e.g. both have `SCKeyboardView`), the linker will fail with "duplicate symbol" errors. Always use a unique class name per module (e.g. prefix with module name: `SCSnakeGameKeyboardView`)
|