@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/vue.md ADDED
@@ -0,0 +1,195 @@
1
+ # Collet Vue Reference
2
+
3
+ Vue 3 wrappers for the Collet component library. Auto-generated from
4
+ `custom-elements.json` via `scripts/generate-vue.mjs`.
5
+
6
+ ---
7
+
8
+ ## Package
9
+
10
+ ```
11
+ @colletdev/vue
12
+ ```
13
+
14
+ **Peer dependencies:** `vue >= 3.3.0`, `@colletdev/core >= 0.1.0`
15
+
16
+ ## Architecture
17
+
18
+ Vue wrappers use `defineComponent` with typed props, emits, and `expose()`.
19
+ They handle:
20
+
21
+ - **Attribute serialization** — objects/arrays synced via `watch` + `setAttribute`
22
+ - **Event bridging** — `@cx-{event}` emits typed CustomEvents
23
+ - **Slot projection** — named slots via `h('div', { slot: 'name' }, slots.name())`
24
+ - **Typed expose** — `expose()` provides imperative methods + raw element ref
25
+
26
+ ### Package Structure
27
+
28
+ ```
29
+ packages/vue/
30
+ src/ ← Auto-generated wrappers (DO NOT EDIT)
31
+ button.ts
32
+ dialog.ts
33
+ ...
34
+ index.ts ← Barrel exports + type re-exports
35
+ types.ts ← Shared TypeScript interfaces
36
+ global.d.ts ← Volar GlobalComponents augmentation
37
+ dist/ ← Compiled output (JS + .d.ts)
38
+ ```
39
+
40
+ ---
41
+
42
+ ## Patterns
43
+
44
+ ### Basic Usage
45
+
46
+ ```vue
47
+ <script setup lang="ts">
48
+ import { ref } from 'vue';
49
+ import { Button, Dialog, type DialogRef } from '@colletdev/vue';
50
+
51
+ const dialogRef = ref<DialogRef | null>(null);
52
+ </script>
53
+
54
+ <template>
55
+ <Button label="Open" @cx-click="dialogRef?.open()" />
56
+ <Dialog
57
+ ref="dialogRef"
58
+ title="Confirm"
59
+ @cx-close="console.log($event.detail.reason)"
60
+ >
61
+ <p>Are you sure?</p>
62
+ <template #footer>
63
+ <Button label="OK" variant="filled" />
64
+ </template>
65
+ </Dialog>
66
+ </template>
67
+ ```
68
+
69
+ ### Event Handling
70
+
71
+ Events use `@cx-{name}` syntax. The `$event` is a typed `CustomEvent<Detail>`:
72
+
73
+ ```vue
74
+ <TextInput
75
+ label="Email"
76
+ @cx-input="(e) => value = e.detail.value"
77
+ @cx-change="(e) => validate(e.detail.value)"
78
+ @cx-focus="focused = true"
79
+ @cx-keydown="(e) => e.detail.key === 'Enter' && submit()"
80
+ />
81
+ ```
82
+
83
+ ### Imperative Methods
84
+
85
+ Components with methods expose them via `expose()`. Access through template refs:
86
+
87
+ ```vue
88
+ <script setup lang="ts">
89
+ import { ref } from 'vue';
90
+ import { Select, type SelectRef } from '@colletdev/vue';
91
+
92
+ const selectRef = ref<SelectRef | null>(null);
93
+ const open = () => selectRef.value?.open();
94
+ </script>
95
+
96
+ <template>
97
+ <Select ref="selectRef" label="Country" :items="countries" />
98
+ <button @click="open">Open dropdown</button>
99
+ </template>
100
+ ```
101
+
102
+ ### Named Slots
103
+
104
+ Vue named slots map to Shadow DOM slots:
105
+
106
+ ```vue
107
+ <Card>
108
+ <template #header><h3>Title</h3></template>
109
+ <p>Body content (default slot)</p>
110
+ <template #footer>
111
+ <Button label="Action" />
112
+ </template>
113
+ </Card>
114
+ ```
115
+
116
+ Under the hood, the wrapper renders `h('div', { slot: 'name' }, slots.name())`.
117
+
118
+ ### Complex Props (Structured Data)
119
+
120
+ Props accepting arrays/objects are synced via `watch` + `setAttribute(JSON.stringify())`:
121
+
122
+ ```vue
123
+ <Table
124
+ caption="Users"
125
+ :columns="[
126
+ { id: 'name', header: 'Name', sortable: true },
127
+ { id: 'email', header: 'Email' },
128
+ ]"
129
+ :rows="rows"
130
+ :sorts="[{ column_id: 'name', direction: 'asc' }]"
131
+ @cx-sort="handleSort"
132
+ />
133
+ ```
134
+
135
+ The `:prop` binding passes the object; the wrapper serializes it automatically.
136
+
137
+ ### Form Integration
138
+
139
+ Form-associated components work with `v-model` (coming) and template-driven forms:
140
+
141
+ ```vue
142
+ <form @submit.prevent="handleSubmit">
143
+ <TextInput name="email" label="Email" required />
144
+ <Select name="country" label="Country" :items="countries" />
145
+ <Button label="Submit" kind="submit" />
146
+ </form>
147
+ ```
148
+
149
+ ### DOM Collision Handling
150
+
151
+ Attributes like `title`, `width`, `loading` are routed through `watch` +
152
+ `setAttribute` to avoid Vue setting them as DOM properties:
153
+
154
+ ```vue
155
+ <!-- Works correctly — title goes through setAttribute -->
156
+ <Dialog title="My Dialog" />
157
+ <Table :loading="75" />
158
+ ```
159
+
160
+ ---
161
+
162
+ ## TypeScript & Volar
163
+
164
+ ### Type Imports
165
+
166
+ ```ts
167
+ import type {
168
+ TableColumn, TableRow, SelectOption, MenuEntry,
169
+ InputDetail, ClickDetail, CloseDetail,
170
+ DialogRef, SelectRef,
171
+ } from '@colletdev/vue';
172
+ ```
173
+
174
+ ### Volar Autocomplete
175
+
176
+ Import `@colletdev/vue/global` in your `env.d.ts` or `shims-vue.d.ts`:
177
+
178
+ ```ts
179
+ /// <reference types="@colletdev/vue/global" />
180
+ ```
181
+
182
+ This registers all Collet components in `GlobalComponents`, giving Volar
183
+ full autocomplete and type checking in templates without explicit imports.
184
+
185
+ ---
186
+
187
+ ## Codegen
188
+
189
+ Vue wrappers are generated by `scripts/generate-vue.mjs`. Configuration
190
+ lives in `scripts/component-config.mjs` (shared across all framework generators).
191
+
192
+ **Do not edit** files in `packages/vue/src/` — they are overwritten by
193
+ `bash scripts/build-packages.sh`.
194
+
195
+ Compiled output goes to `packages/vue/dist/` via `tsc`.