@colletdev/docs 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -0
- package/angular.md +254 -0
- package/cli.mjs +300 -0
- package/components.md +2268 -0
- package/core.md +684 -0
- package/index.md +53 -0
- package/package.json +40 -0
- package/react.md +290 -0
- package/svelte.md +234 -0
- package/vue.md +195 -0
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @collet/docs
|
|
2
|
+
|
|
3
|
+
API reference and framework integration guides for the Collet component library -- 48 accessible web components built in Rust/WASM.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @collet/docs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Contents
|
|
12
|
+
|
|
13
|
+
| File | Export | Description |
|
|
14
|
+
|------|--------|-------------|
|
|
15
|
+
| `index.md` | `@collet/docs` | Library overview and architecture |
|
|
16
|
+
| `components.md` | `@collet/docs/components` | All 48 components: props, events, slots, ARIA |
|
|
17
|
+
| `core.md` | `@collet/docs/core` | `init()` options, theming, CSS architecture, SSR |
|
|
18
|
+
| `react.md` | `@collet/docs/react` | React 18+ wrappers, hooks, ref types, events |
|
|
19
|
+
| `vue.md` | `@collet/docs/vue` | Vue 3.3+ wrappers, Volar setup, emits |
|
|
20
|
+
| `svelte.md` | `@collet/docs/svelte` | Svelte 5 runes wrappers, callback props |
|
|
21
|
+
| `angular.md` | `@collet/docs/angular` | Angular 16+ standalone components, forms |
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Import the markdown content directly:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import components from '@collet/docs/components';
|
|
29
|
+
import react from '@collet/docs/react';
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
This package ships `.md` files and a CLI. Use it to build documentation sites, power in-app help, or set up AI agent context.
|
|
33
|
+
|
|
34
|
+
## AI Agent Setup
|
|
35
|
+
|
|
36
|
+
Set up Collet knowledge for your AI coding assistant:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npx @collet/docs init # auto-detect (Claude Code by default)
|
|
40
|
+
npx @collet/docs init --claude # Claude Code (.claude/skills/collet/)
|
|
41
|
+
npx @collet/docs init --codex # OpenAI Codex (AGENTS.md)
|
|
42
|
+
npx @collet/docs init --cursor # Cursor AI (.cursor/rules/collet.md)
|
|
43
|
+
npx @collet/docs init --all # All formats
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The CLI auto-detects your framework from `package.json` and generates context-aware agent configuration with the full 48-component API reference.
|
|
47
|
+
|
|
48
|
+
## Related Packages
|
|
49
|
+
|
|
50
|
+
| Package | Description |
|
|
51
|
+
|---------|-------------|
|
|
52
|
+
| `@collet/core` | Custom Elements + WASM runtime |
|
|
53
|
+
| `@collet/react` | React 18+ wrappers |
|
|
54
|
+
| `@collet/vue` | Vue 3.3+ wrappers |
|
|
55
|
+
| `@collet/svelte` | Svelte 5 wrappers |
|
|
56
|
+
| `@collet/angular` | Angular 16+ wrappers |
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
MIT -- [github.com/Danrozen87/collet](https://github.com/Danrozen87/collet)
|
package/angular.md
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# Collet Angular Reference
|
|
2
|
+
|
|
3
|
+
Angular wrappers for the Collet component library. Auto-generated from
|
|
4
|
+
`custom-elements.json` via `scripts/generate-angular.mjs`.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Package
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
@colletdev/angular
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
**Peer dependencies:** `@angular/core >= 16.0.0`, `@angular/forms >= 16.0.0` (optional), `@colletdev/core >= 0.1.0`
|
|
15
|
+
|
|
16
|
+
Ships raw TypeScript source — consumers compile with their own Angular toolchain.
|
|
17
|
+
|
|
18
|
+
## Architecture
|
|
19
|
+
|
|
20
|
+
Angular wrappers are standalone components with `CUSTOM_ELEMENTS_SCHEMA`,
|
|
21
|
+
`ChangeDetectionStrategy.OnPush`, and `c.detach()` for zero change detection
|
|
22
|
+
overhead. They handle:
|
|
23
|
+
|
|
24
|
+
- **Attribute serialization** — objects/arrays synced via `ngOnChanges` + `setAttribute`
|
|
25
|
+
- **Event bridging** — `@Output()` EventEmitters for `cx-{event}` CustomEvents
|
|
26
|
+
- **Slot projection** — `<ng-content>` with `select="[slot=name]"` for named slots
|
|
27
|
+
- **ControlValueAccessor** — form-associated components support `formControlName` and `ngModel`
|
|
28
|
+
- **Imperative methods** — public methods on the component class delegating to the CE
|
|
29
|
+
|
|
30
|
+
### Package Structure
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
packages/angular/
|
|
34
|
+
src/ ← Auto-generated wrappers (DO NOT EDIT)
|
|
35
|
+
button.component.ts
|
|
36
|
+
dialog.component.ts
|
|
37
|
+
...
|
|
38
|
+
index.ts ← Barrel exports
|
|
39
|
+
types.ts ← Shared TypeScript interfaces
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Selector Pattern
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
cx-{name}[collet]
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The `[collet]` attribute disambiguates the Angular wrapper from the bare
|
|
49
|
+
Custom Element. This means Angular components must add the `collet` attribute:
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
<cx-button collet label="Click me" />
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Patterns
|
|
58
|
+
|
|
59
|
+
### Basic Usage
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { Component } from '@angular/core';
|
|
63
|
+
import { CxButton, CxDialog } from '@colletdev/angular';
|
|
64
|
+
|
|
65
|
+
@Component({
|
|
66
|
+
selector: 'app-root',
|
|
67
|
+
standalone: true,
|
|
68
|
+
imports: [CxButton, CxDialog],
|
|
69
|
+
template: `
|
|
70
|
+
<cx-button collet label="Open" (cxClick)="dialog.open()" />
|
|
71
|
+
<cx-dialog collet
|
|
72
|
+
#dialog
|
|
73
|
+
title="Confirm"
|
|
74
|
+
(cxClose)="onClose($event)"
|
|
75
|
+
>
|
|
76
|
+
<p>Are you sure?</p>
|
|
77
|
+
<div slot="footer">
|
|
78
|
+
<cx-button collet label="OK" variant="filled" />
|
|
79
|
+
</div>
|
|
80
|
+
</cx-dialog>
|
|
81
|
+
`,
|
|
82
|
+
})
|
|
83
|
+
export class AppComponent {
|
|
84
|
+
onClose(e: CustomEvent) {
|
|
85
|
+
console.log(e.detail.reason);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Event Handling
|
|
91
|
+
|
|
92
|
+
Events use `(cxEventName)` syntax:
|
|
93
|
+
|
|
94
|
+
```html
|
|
95
|
+
<cx-text-input collet
|
|
96
|
+
label="Email"
|
|
97
|
+
(cxInput)="onInput($event)"
|
|
98
|
+
(cxChange)="onChange($event)"
|
|
99
|
+
(cxFocus)="onFocus($event)"
|
|
100
|
+
(cxKeydown)="onKeydown($event)"
|
|
101
|
+
/>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
onInput(e: CustomEvent<InputDetail>) {
|
|
106
|
+
this.value = e.detail.value;
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Imperative Methods
|
|
111
|
+
|
|
112
|
+
Access methods directly on the component instance via template ref:
|
|
113
|
+
|
|
114
|
+
```html
|
|
115
|
+
<cx-select collet #selectRef label="Country" [items]="countries" />
|
|
116
|
+
<button (click)="selectRef.open()">Open</button>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Or via `@ViewChild`:
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
@ViewChild('selectRef') selectRef!: CxSelect;
|
|
123
|
+
|
|
124
|
+
openSelect() {
|
|
125
|
+
this.selectRef.open();
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Named Slots
|
|
130
|
+
|
|
131
|
+
Project content into named slots using the `slot` attribute:
|
|
132
|
+
|
|
133
|
+
```html
|
|
134
|
+
<cx-card collet>
|
|
135
|
+
<div slot="header"><h3>Title</h3></div>
|
|
136
|
+
<p>Body content</p>
|
|
137
|
+
<div slot="footer">
|
|
138
|
+
<cx-button collet label="Action" />
|
|
139
|
+
</div>
|
|
140
|
+
</cx-card>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The wrapper template includes `<ng-content select="[slot=name]">` for each
|
|
144
|
+
named slot, so Angular's content projection passes through to Shadow DOM.
|
|
145
|
+
|
|
146
|
+
### Complex Props (Structured Data)
|
|
147
|
+
|
|
148
|
+
Props accepting arrays/objects use `[attr]` binding. The wrapper watches for
|
|
149
|
+
changes and serializes via `JSON.stringify` + `setAttribute`:
|
|
150
|
+
|
|
151
|
+
```html
|
|
152
|
+
<cx-table collet
|
|
153
|
+
caption="Users"
|
|
154
|
+
[columns]="columns"
|
|
155
|
+
[rows]="rows"
|
|
156
|
+
[sorts]="[{ column_id: 'name', direction: 'asc' }]"
|
|
157
|
+
(cxSort)="handleSort($event)"
|
|
158
|
+
/>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Reactive Forms (ControlValueAccessor)
|
|
162
|
+
|
|
163
|
+
Form-associated components implement `ControlValueAccessor` for Angular
|
|
164
|
+
Reactive Forms and `ngModel`:
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
import { ReactiveFormsModule, FormGroup, FormControl } from '@angular/forms';
|
|
168
|
+
import { CxTextInput, CxSelect, CxCheckbox } from '@colletdev/angular';
|
|
169
|
+
|
|
170
|
+
@Component({
|
|
171
|
+
imports: [ReactiveFormsModule, CxTextInput, CxSelect, CxCheckbox],
|
|
172
|
+
template: `
|
|
173
|
+
<form [formGroup]="form">
|
|
174
|
+
<cx-text-input collet formControlName="email" label="Email" />
|
|
175
|
+
<cx-select collet formControlName="country" label="Country" [items]="countries" />
|
|
176
|
+
<cx-checkbox collet formControlName="agree" label="I agree" />
|
|
177
|
+
</form>
|
|
178
|
+
`,
|
|
179
|
+
})
|
|
180
|
+
export class FormComponent {
|
|
181
|
+
form = new FormGroup({
|
|
182
|
+
email: new FormControl(''),
|
|
183
|
+
country: new FormControl(''),
|
|
184
|
+
agree: new FormControl(false),
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**CVA components:** TextInput, Select, Checkbox, RadioGroup, Switch, Slider,
|
|
190
|
+
Autocomplete, ToggleGroup, DatePicker, SearchBar, ChatInput.
|
|
191
|
+
|
|
192
|
+
The CVA implementation:
|
|
193
|
+
- `writeValue()` — sets the CE's `value` (or `checked` for checkbox/switch)
|
|
194
|
+
- `registerOnChange()` — listens to `cx-change` events
|
|
195
|
+
- `registerOnTouched()` — listens to `focusout`
|
|
196
|
+
- `setDisabledState()` — toggles the `disabled` attribute
|
|
197
|
+
|
|
198
|
+
### DOM Collision Handling
|
|
199
|
+
|
|
200
|
+
Attributes like `title`, `width`, `loading` are bound via `[attr.name]` to
|
|
201
|
+
avoid Angular setting them as DOM properties:
|
|
202
|
+
|
|
203
|
+
```html
|
|
204
|
+
<!-- Works correctly -->
|
|
205
|
+
<cx-dialog collet [attr.title]="dialogTitle" />
|
|
206
|
+
<cx-table collet [attr.loading]="loadPercent" />
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## TypeScript
|
|
212
|
+
|
|
213
|
+
### Type Imports
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
import type {
|
|
217
|
+
TableColumn, TableRow, SelectOption, MenuEntry,
|
|
218
|
+
InputDetail, ClickDetail, CloseDetail, FocusDetail,
|
|
219
|
+
} from '@colletdev/angular';
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Component Classes
|
|
223
|
+
|
|
224
|
+
All wrappers export PascalCase classes prefixed with `Cx`:
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
import {
|
|
228
|
+
CxButton, // <cx-button collet>
|
|
229
|
+
CxDialog, // <cx-dialog collet>
|
|
230
|
+
CxTextInput, // <cx-text-input collet>
|
|
231
|
+
CxTable, // <cx-table collet>
|
|
232
|
+
} from '@colletdev/angular';
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Performance
|
|
238
|
+
|
|
239
|
+
The wrappers use `ChangeDetectionStrategy.OnPush` with `c.detach()` in the
|
|
240
|
+
constructor, so Angular's change detection never runs for these components.
|
|
241
|
+
All reactivity is handled by the Custom Element itself and the `watch` /
|
|
242
|
+
`ngOnChanges` attribute syncing.
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Codegen
|
|
247
|
+
|
|
248
|
+
Angular wrappers are generated by `scripts/generate-angular.mjs`. Configuration
|
|
249
|
+
lives in `scripts/component-config.mjs` (shared across all framework generators).
|
|
250
|
+
|
|
251
|
+
**Do not edit** files in `packages/angular/src/` — they are overwritten by
|
|
252
|
+
`bash scripts/build-packages.sh`.
|
|
253
|
+
|
|
254
|
+
Raw TypeScript ships to consumers (compile with `tsc` or `ng-packagr`).
|
package/cli.mjs
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @colletdev/docs CLI — Set up AI agent context for Collet components
|
|
3
|
+
//
|
|
4
|
+
// Usage:
|
|
5
|
+
// npx @colletdev/docs init # auto-detect AI tool
|
|
6
|
+
// npx @colletdev/docs init --claude # Claude Code skills
|
|
7
|
+
// npx @colletdev/docs init --codex # OpenAI Codex AGENTS.md
|
|
8
|
+
// npx @colletdev/docs init --cursor # Cursor rules
|
|
9
|
+
// npx @colletdev/docs init --generic # Plain COLLET.md
|
|
10
|
+
// npx @colletdev/docs init --all # All formats
|
|
11
|
+
|
|
12
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync, cpSync } from 'node:fs';
|
|
13
|
+
import { resolve, dirname } from 'node:path';
|
|
14
|
+
import { fileURLToPath } from 'node:url';
|
|
15
|
+
|
|
16
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
const CWD = process.cwd();
|
|
18
|
+
|
|
19
|
+
// ─── Resolve doc files (from this package's directory) ───
|
|
20
|
+
|
|
21
|
+
function docPath(name) {
|
|
22
|
+
return resolve(__dirname, name);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function readDoc(name) {
|
|
26
|
+
return readFileSync(docPath(name), 'utf8');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// ─── Detect which AI tools are in use ───
|
|
30
|
+
|
|
31
|
+
function detectTools() {
|
|
32
|
+
const tools = [];
|
|
33
|
+
if (existsSync(resolve(CWD, '.claude')) || process.argv.includes('--claude')) tools.push('claude');
|
|
34
|
+
if (existsSync(resolve(CWD, 'AGENTS.md')) || process.argv.includes('--codex')) tools.push('codex');
|
|
35
|
+
if (existsSync(resolve(CWD, '.cursor')) || process.argv.includes('--cursor')) tools.push('cursor');
|
|
36
|
+
if (process.argv.includes('--generic')) tools.push('generic');
|
|
37
|
+
if (process.argv.includes('--all')) return ['claude', 'codex', 'cursor', 'generic'];
|
|
38
|
+
if (tools.length === 0) tools.push('claude'); // default
|
|
39
|
+
return [...new Set(tools)];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ─── Detect framework from package.json ───
|
|
43
|
+
|
|
44
|
+
function detectFramework() {
|
|
45
|
+
try {
|
|
46
|
+
const pkg = JSON.parse(readFileSync(resolve(CWD, 'package.json'), 'utf8'));
|
|
47
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies, ...pkg.peerDependencies };
|
|
48
|
+
if (deps['@colletdev/react'] || deps['react']) return 'react';
|
|
49
|
+
if (deps['@colletdev/vue'] || deps['vue']) return 'vue';
|
|
50
|
+
if (deps['@colletdev/svelte'] || deps['svelte']) return 'svelte';
|
|
51
|
+
if (deps['@colletdev/angular'] || deps['@angular/core']) return 'angular';
|
|
52
|
+
} catch { /* no package.json */ }
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ─── Generate Claude Code skills ───
|
|
57
|
+
|
|
58
|
+
function setupClaude(framework) {
|
|
59
|
+
const skillDir = resolve(CWD, '.claude/skills/collet');
|
|
60
|
+
const refDir = resolve(skillDir, 'references');
|
|
61
|
+
mkdirSync(refDir, { recursive: true });
|
|
62
|
+
|
|
63
|
+
// SKILL.md — adapted for consumer projects (no build/gallery references)
|
|
64
|
+
const skillMd = `---
|
|
65
|
+
name: collet
|
|
66
|
+
description: >
|
|
67
|
+
Collet component library — 48 accessible Custom Element + WASM components
|
|
68
|
+
with typed ${framework ? framework.charAt(0).toUpperCase() + framework.slice(1) : 'framework'} wrappers.
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
# Collet
|
|
72
|
+
|
|
73
|
+
48 accessible web components built in Rust/WASM. Distributed as Custom Elements
|
|
74
|
+
with first-class React, Vue, Svelte, and Angular wrappers.
|
|
75
|
+
|
|
76
|
+
## Context Detection
|
|
77
|
+
|
|
78
|
+
Read the reference that matches the user's context:
|
|
79
|
+
|
|
80
|
+
| Signal | Load |
|
|
81
|
+
|--------|------|
|
|
82
|
+
| .tsx / .jsx / React | core.md + react.md |
|
|
83
|
+
| .vue / Vue | core.md + vue.md |
|
|
84
|
+
| .svelte / Svelte | core.md + svelte.md |
|
|
85
|
+
| .component.ts / Angular | core.md + angular.md |
|
|
86
|
+
| Custom Elements / @colletdev/core | core.md only |
|
|
87
|
+
| Component API question | components.md |
|
|
88
|
+
|
|
89
|
+
Always read core.md first, then the framework-specific reference.
|
|
90
|
+
|
|
91
|
+
## Quick Reference
|
|
92
|
+
|
|
93
|
+
- **Install:** \`npm install @colletdev/core @colletdev/{react,vue,svelte,angular}\`
|
|
94
|
+
- **Prefix:** \`cx-\` (e.g., \`<cx-button>\`, \`<cx-dialog>\`)
|
|
95
|
+
- **Init:** \`import { init } from '@colletdev/core'; await init();\`
|
|
96
|
+
- **Theming:** CSS custom properties via custom \`tokens.css\`
|
|
97
|
+
- **Docs:** \`@colletdev/docs\` package or references/ in this directory
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
writeFileSync(resolve(skillDir, 'SKILL.md'), skillMd);
|
|
101
|
+
|
|
102
|
+
// Copy all reference docs
|
|
103
|
+
for (const file of ['core.md', 'components.md', 'react.md', 'vue.md', 'svelte.md', 'angular.md']) {
|
|
104
|
+
const src = docPath(file);
|
|
105
|
+
if (existsSync(src)) {
|
|
106
|
+
writeFileSync(resolve(refDir, file), readDoc(file));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
console.log(` Claude Code: .claude/skills/collet/ (SKILL.md + 6 references)`);
|
|
111
|
+
|
|
112
|
+
// Add to .claude/CLAUDE.md if it exists and doesn't already mention collet
|
|
113
|
+
const claudeMd = resolve(CWD, '.claude/CLAUDE.md');
|
|
114
|
+
if (existsSync(claudeMd)) {
|
|
115
|
+
const content = readFileSync(claudeMd, 'utf8');
|
|
116
|
+
if (!content.includes('@collet') && !content.includes('collet')) {
|
|
117
|
+
const snippet = `\n\n## Collet Components\n\nThis project uses Collet UI components. Read \`.claude/skills/collet/SKILL.md\` for the skill router that loads framework-specific references.\n`;
|
|
118
|
+
writeFileSync(claudeMd, content + snippet);
|
|
119
|
+
console.log(` Updated .claude/CLAUDE.md with Collet reference`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ─── Generate Codex AGENTS.md ───
|
|
125
|
+
|
|
126
|
+
function setupCodex(framework) {
|
|
127
|
+
const agentsMd = resolve(CWD, 'AGENTS.md');
|
|
128
|
+
const fwRef = framework ? readDoc(`${framework}.md`) : '';
|
|
129
|
+
const coreRef = readDoc('core.md');
|
|
130
|
+
|
|
131
|
+
// Trim to essential sections for context window efficiency
|
|
132
|
+
const lang = framework === 'react' ? 'tsx' : framework === 'vue' ? 'vue' : framework === 'svelte' ? 'svelte' : 'typescript';
|
|
133
|
+
const importLine = framework === 'react' ? "import { Button } from '@colletdev/react';"
|
|
134
|
+
: framework === 'vue' ? "import { Button } from '@colletdev/vue';"
|
|
135
|
+
: framework === 'svelte' ? "import { Button } from '@colletdev/svelte';"
|
|
136
|
+
: framework === 'angular' ? "import { CxButton } from '@colletdev/angular';"
|
|
137
|
+
: '';
|
|
138
|
+
|
|
139
|
+
const content = `# Collet Component Library
|
|
140
|
+
|
|
141
|
+
This project uses Collet — 48 accessible web components built in Rust/WASM.
|
|
142
|
+
|
|
143
|
+
## Setup
|
|
144
|
+
|
|
145
|
+
\`\`\`bash
|
|
146
|
+
npm install @colletdev/core${framework ? ` @colletdev/${framework}` : ''}
|
|
147
|
+
\`\`\`
|
|
148
|
+
|
|
149
|
+
\`\`\`${lang}
|
|
150
|
+
import { init } from '@colletdev/core';${importLine ? '\n' + importLine : ''}
|
|
151
|
+
await init();
|
|
152
|
+
\`\`\`
|
|
153
|
+
|
|
154
|
+
## Key Conventions
|
|
155
|
+
|
|
156
|
+
- Custom Element prefix: \`cx-\` (e.g., \`<cx-button>\`, \`<cx-dialog>\`)
|
|
157
|
+
- All props are typed with union literals (variant, intent, size, shape)
|
|
158
|
+
- Events use \`cx-\` prefix: \`cx-click\`, \`cx-change\`, \`cx-input\`
|
|
159
|
+
- Structured data props (items, columns, etc.) accept typed arrays or JSON strings
|
|
160
|
+
- Components with imperative methods expose typed refs (open, close, focus, etc.)
|
|
161
|
+
|
|
162
|
+
## Full API Reference
|
|
163
|
+
|
|
164
|
+
The complete component reference is in \`node_modules/@colletdev/docs/components.md\`.
|
|
165
|
+
Framework guide: \`node_modules/@colletdev/docs/${framework || 'core'}.md\`.
|
|
166
|
+
|
|
167
|
+
Read these files for props, events, methods, and types for all 48 components.
|
|
168
|
+
`;
|
|
169
|
+
|
|
170
|
+
if (existsSync(agentsMd)) {
|
|
171
|
+
const existing = readFileSync(agentsMd, 'utf8');
|
|
172
|
+
if (existing.includes('Collet')) {
|
|
173
|
+
console.log(` Codex: AGENTS.md already contains Collet section (skipped)`);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
writeFileSync(agentsMd, existing + '\n\n' + content);
|
|
177
|
+
console.log(` Codex: Appended Collet section to existing AGENTS.md`);
|
|
178
|
+
} else {
|
|
179
|
+
writeFileSync(agentsMd, content);
|
|
180
|
+
console.log(` Codex: AGENTS.md created`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// ─── Generate Cursor rules ───
|
|
185
|
+
|
|
186
|
+
function setupCursor(framework) {
|
|
187
|
+
const rulesDir = resolve(CWD, '.cursor/rules');
|
|
188
|
+
mkdirSync(rulesDir, { recursive: true });
|
|
189
|
+
|
|
190
|
+
const content = `# Collet Component Library
|
|
191
|
+
|
|
192
|
+
This project uses Collet — 48 accessible web components (Rust/WASM).
|
|
193
|
+
|
|
194
|
+
## Import Pattern
|
|
195
|
+
${framework === 'react' ? "```tsx\nimport { Button, TextInput, Dialog } from '@colletdev/react';\n```"
|
|
196
|
+
: framework === 'vue' ? "```typescript\nimport { Button, TextInput, Dialog } from '@colletdev/vue';\n```"
|
|
197
|
+
: framework === 'svelte' ? "```typescript\nimport { Button, TextInput, Dialog } from '@colletdev/svelte';\n```"
|
|
198
|
+
: framework === 'angular' ? "```typescript\nimport { CxButton, CxTextInput, CxDialog } from '@colletdev/angular';\n```"
|
|
199
|
+
: "```typescript\nimport { init } from '@colletdev/core';\n```"}
|
|
200
|
+
|
|
201
|
+
## Conventions
|
|
202
|
+
- Prefix: \`cx-\` for Custom Elements
|
|
203
|
+
- Events: \`cx-click\`, \`cx-change\`, \`cx-input\`, \`cx-close\`, etc.
|
|
204
|
+
- Structured data: typed arrays (SelectOption[], TableColumn[], MenuEntry[])
|
|
205
|
+
- Sizing: 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
|
206
|
+
- Variants: 'filled' | 'outline' | 'ghost' | 'soft'
|
|
207
|
+
- Intent: 'neutral' | 'primary' | 'info' | 'success' | 'warning' | 'danger'
|
|
208
|
+
|
|
209
|
+
## Reference
|
|
210
|
+
Full API docs: \`node_modules/@colletdev/docs/components.md\`
|
|
211
|
+
Framework guide: \`node_modules/@colletdev/docs/${framework || 'core'}.md\`
|
|
212
|
+
`;
|
|
213
|
+
|
|
214
|
+
writeFileSync(resolve(rulesDir, 'collet.md'), content);
|
|
215
|
+
console.log(` Cursor: .cursor/rules/collet.md created`);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// ─── Generate generic COLLET.md ───
|
|
219
|
+
|
|
220
|
+
function setupGeneric(framework) {
|
|
221
|
+
const content = `# Collet Components
|
|
222
|
+
|
|
223
|
+
This project uses [Collet](https://github.com/Danrozen87/collet) — 48 accessible
|
|
224
|
+
web components built in Rust/WASM with ${framework ? framework.charAt(0).toUpperCase() + framework.slice(1) : 'framework'} wrappers.
|
|
225
|
+
|
|
226
|
+
## API Reference
|
|
227
|
+
|
|
228
|
+
The full component reference (props, events, methods, types) is available at:
|
|
229
|
+
|
|
230
|
+
\`\`\`
|
|
231
|
+
node_modules/@colletdev/docs/components.md — 48 components, all props/events/methods
|
|
232
|
+
node_modules/@colletdev/docs/core.md — Init, theming, CSS, SSR, event conventions
|
|
233
|
+
node_modules/@colletdev/docs/${framework || 'react'}.md — Framework-specific patterns
|
|
234
|
+
\`\`\`
|
|
235
|
+
|
|
236
|
+
Or install the docs package directly: \`npm install @colletdev/docs\`
|
|
237
|
+
`;
|
|
238
|
+
|
|
239
|
+
writeFileSync(resolve(CWD, 'COLLET.md'), content);
|
|
240
|
+
console.log(` Generic: COLLET.md created`);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ─── Main ───
|
|
244
|
+
|
|
245
|
+
function main() {
|
|
246
|
+
const args = process.argv.slice(2);
|
|
247
|
+
|
|
248
|
+
if (args[0] === 'purge') {
|
|
249
|
+
console.log('');
|
|
250
|
+
console.log('To purge stale Collet artifacts, run:');
|
|
251
|
+
console.log(' npx collet-purge');
|
|
252
|
+
console.log(' # or: npx @colletdev/core purge');
|
|
253
|
+
console.log('');
|
|
254
|
+
console.log('This clears Vite caches, stale WASM copies, and old @collet/ scope packages.');
|
|
255
|
+
process.exit(0);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (args[0] !== 'init') {
|
|
259
|
+
console.log('Usage:');
|
|
260
|
+
console.log(' npx @colletdev/docs init [--claude|--codex|--cursor|--generic|--all]');
|
|
261
|
+
console.log(' npx @colletdev/docs purge (alias for npx collet-purge)');
|
|
262
|
+
console.log('');
|
|
263
|
+
console.log('Commands:');
|
|
264
|
+
console.log(' init Set up AI agent context for Collet components');
|
|
265
|
+
console.log(' purge Clear stale WASM/CSS/Vite caches after upgrading');
|
|
266
|
+
console.log('');
|
|
267
|
+
console.log('Options (init):');
|
|
268
|
+
console.log(' --claude Claude Code skills (.claude/skills/collet/)');
|
|
269
|
+
console.log(' --codex OpenAI Codex (AGENTS.md)');
|
|
270
|
+
console.log(' --cursor Cursor AI (.cursor/rules/collet.md)');
|
|
271
|
+
console.log(' --generic Plain COLLET.md at project root');
|
|
272
|
+
console.log(' --all All formats');
|
|
273
|
+
console.log('');
|
|
274
|
+
console.log('Default: auto-detects from project structure (falls back to --claude)');
|
|
275
|
+
process.exit(0);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const tools = detectTools();
|
|
279
|
+
const framework = detectFramework();
|
|
280
|
+
|
|
281
|
+
console.log('');
|
|
282
|
+
console.log(`Collet AI Setup — ${framework ? framework.charAt(0).toUpperCase() + framework.slice(1) + ' project' : 'no framework detected'}`);
|
|
283
|
+
console.log('─'.repeat(50));
|
|
284
|
+
|
|
285
|
+
for (const tool of tools) {
|
|
286
|
+
switch (tool) {
|
|
287
|
+
case 'claude': setupClaude(framework); break;
|
|
288
|
+
case 'codex': setupCodex(framework); break;
|
|
289
|
+
case 'cursor': setupCursor(framework); break;
|
|
290
|
+
case 'generic': setupGeneric(framework); break;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
console.log('');
|
|
295
|
+
console.log('Done. Your AI agent now has full Collet component knowledge.');
|
|
296
|
+
console.log('Reference: 7 doc files from @colletdev/docs (108 KB total)');
|
|
297
|
+
console.log('');
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
main();
|