@ui-sdk/vue 0.0.0-stage → 0.1.0-beta.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.
Files changed (262) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +10 -2
  3. package/dist/accordion.d.ts +561 -0
  4. package/dist/accordion.js +24 -0
  5. package/dist/agent.d.ts +2 -0
  6. package/dist/agent.js +7 -0
  7. package/dist/alert-dialog.d.ts +231 -0
  8. package/dist/alert-dialog.js +33 -0
  9. package/dist/async-options.d.ts +18 -0
  10. package/dist/async-options.js +40 -0
  11. package/dist/autocomplete.d.ts +384 -0
  12. package/dist/autocomplete.js +344 -0
  13. package/dist/avatar.d.ts +40 -0
  14. package/dist/avatar.js +28 -0
  15. package/dist/button.d.ts +52 -0
  16. package/dist/button.js +43 -0
  17. package/dist/calendar-context.d.ts +10 -0
  18. package/dist/calendar-context.js +7 -0
  19. package/dist/calendar.d.ts +311 -0
  20. package/dist/calendar.js +349 -0
  21. package/dist/carousel.d.ts +236 -0
  22. package/dist/carousel.js +204 -0
  23. package/dist/checkbox.d.ts +211 -0
  24. package/dist/checkbox.js +151 -0
  25. package/dist/children.d.ts +41 -0
  26. package/dist/children.js +135 -0
  27. package/dist/collapsible.d.ts +54 -0
  28. package/dist/collapsible.js +18 -0
  29. package/dist/color-picker.d.ts +187 -0
  30. package/dist/color-picker.js +158 -0
  31. package/dist/color.d.ts +2 -0
  32. package/dist/color.js +21 -0
  33. package/dist/combobox.d.ts +517 -0
  34. package/dist/combobox.js +531 -0
  35. package/dist/command.d.ts +322 -0
  36. package/dist/command.js +345 -0
  37. package/dist/controller-target.d.ts +49 -0
  38. package/dist/controller-target.js +112 -0
  39. package/dist/create-parts.d.ts +126 -0
  40. package/dist/create-parts.js +206 -0
  41. package/dist/date-input.d.ts +133 -0
  42. package/dist/date-input.js +31 -0
  43. package/dist/date-picker.d.ts +328 -0
  44. package/dist/date-picker.js +354 -0
  45. package/dist/date.d.ts +2 -0
  46. package/dist/date.js +59 -0
  47. package/dist/dialog-parts.d.ts +259 -0
  48. package/dist/dialog-parts.js +300 -0
  49. package/dist/dialog.d.ts +251 -0
  50. package/dist/dialog.js +25 -0
  51. package/dist/drawer.d.ts +304 -0
  52. package/dist/drawer.js +373 -0
  53. package/dist/editor-context.d.ts +4 -0
  54. package/dist/editor-context.js +5 -0
  55. package/dist/field-context.d.ts +26 -0
  56. package/dist/field-context.js +44 -0
  57. package/dist/field.d.ts +154 -0
  58. package/dist/field.js +240 -0
  59. package/dist/file-input.d.ts +212 -0
  60. package/dist/file-input.js +255 -0
  61. package/dist/form-inputs.d.ts +16 -0
  62. package/dist/form-inputs.js +25 -0
  63. package/dist/gesture.d.ts +1 -0
  64. package/dist/gesture.js +15 -0
  65. package/dist/history.d.ts +2 -0
  66. package/dist/history.js +11 -0
  67. package/dist/hover-card.d.ts +137 -0
  68. package/dist/hover-card.js +153 -0
  69. package/dist/image-cropper.d.ts +74 -0
  70. package/dist/image-cropper.js +36 -0
  71. package/dist/image.d.ts +2 -0
  72. package/dist/image.js +5 -0
  73. package/dist/index.d.ts +59 -0
  74. package/dist/index.js +60 -0
  75. package/dist/input.d.ts +120 -0
  76. package/dist/input.js +73 -0
  77. package/dist/item-icon.d.ts +34 -0
  78. package/dist/item-icon.js +63 -0
  79. package/dist/label.d.ts +16 -0
  80. package/dist/label.js +8 -0
  81. package/dist/lifecycle.d.ts +11 -0
  82. package/dist/lifecycle.js +91 -0
  83. package/dist/list-items.d.ts +38 -0
  84. package/dist/list-items.js +59 -0
  85. package/dist/list-text.d.ts +7 -0
  86. package/dist/list-text.js +15 -0
  87. package/dist/listbox.d.ts +273 -0
  88. package/dist/listbox.js +126 -0
  89. package/dist/menu.d.ts +678 -0
  90. package/dist/menu.js +607 -0
  91. package/dist/menubar-context.d.ts +5 -0
  92. package/dist/menubar-context.js +5 -0
  93. package/dist/menubar.d.ts +61 -0
  94. package/dist/menubar.js +48 -0
  95. package/dist/meter.d.ts +41 -0
  96. package/dist/meter.js +37 -0
  97. package/dist/navigation-menu.d.ts +228 -0
  98. package/dist/navigation-menu.js +195 -0
  99. package/dist/number-input.d.ts +176 -0
  100. package/dist/number-input.js +231 -0
  101. package/dist/number.d.ts +2 -0
  102. package/dist/number.js +39 -0
  103. package/dist/nuxt/entries.json +977 -0
  104. package/dist/nuxt/module.d.ts +18 -0
  105. package/dist/nuxt/module.js +31 -0
  106. package/dist/nuxt/registrations.d.ts +22 -0
  107. package/dist/nuxt/registrations.js +22 -0
  108. package/dist/observe.d.ts +2 -0
  109. package/dist/observe.js +7 -0
  110. package/dist/otp-input.d.ts +142 -0
  111. package/dist/otp-input.js +130 -0
  112. package/dist/overlays.d.ts +40 -0
  113. package/dist/overlays.js +118 -0
  114. package/dist/pagination.d.ts +201 -0
  115. package/dist/pagination.js +146 -0
  116. package/dist/password-input.d.ts +144 -0
  117. package/dist/password-input.js +134 -0
  118. package/dist/popover.d.ts +211 -0
  119. package/dist/popover.js +258 -0
  120. package/dist/popup.d.ts +60 -0
  121. package/dist/popup.js +89 -0
  122. package/dist/preferences.d.ts +44 -0
  123. package/dist/preferences.js +102 -0
  124. package/dist/primitive.d.ts +2 -0
  125. package/dist/primitive.js +11 -0
  126. package/dist/progress.d.ts +41 -0
  127. package/dist/progress.js +37 -0
  128. package/dist/radio.d.ts +164 -0
  129. package/dist/radio.js +145 -0
  130. package/dist/rating.d.ts +149 -0
  131. package/dist/rating.js +146 -0
  132. package/dist/renderless.d.ts +4 -0
  133. package/dist/renderless.js +28 -0
  134. package/dist/resizable.d.ts +54 -0
  135. package/dist/resizable.js +22 -0
  136. package/dist/scroll-area.d.ts +72 -0
  137. package/dist/scroll-area.js +77 -0
  138. package/dist/segmented-control.d.ts +151 -0
  139. package/dist/segmented-control.js +110 -0
  140. package/dist/segmented-input.d.ts +76 -0
  141. package/dist/segmented-input.js +115 -0
  142. package/dist/select.d.ts +458 -0
  143. package/dist/select.js +468 -0
  144. package/dist/separator.d.ts +14 -0
  145. package/dist/separator.js +8 -0
  146. package/dist/shortcuts.d.ts +32 -0
  147. package/dist/shortcuts.js +56 -0
  148. package/dist/slider.d.ts +65 -0
  149. package/dist/slider.js +194 -0
  150. package/dist/switch.d.ts +103 -0
  151. package/dist/switch.js +71 -0
  152. package/dist/tabs.d.ts +338 -0
  153. package/dist/tabs.js +27 -0
  154. package/dist/text-control.d.ts +89 -0
  155. package/dist/text-control.js +51 -0
  156. package/dist/text-match.d.ts +2 -0
  157. package/dist/text-match.js +7 -0
  158. package/dist/textarea.d.ts +106 -0
  159. package/dist/textarea.js +68 -0
  160. package/dist/time-input.d.ts +131 -0
  161. package/dist/time-input.js +32 -0
  162. package/dist/timeline.d.ts +81 -0
  163. package/dist/timeline.js +30 -0
  164. package/dist/toast-parts.d.ts +203 -0
  165. package/dist/toast-parts.js +270 -0
  166. package/dist/toast.d.ts +2 -0
  167. package/dist/toast.js +21 -0
  168. package/dist/toggle-props.d.ts +22 -0
  169. package/dist/toggle-props.js +14 -0
  170. package/dist/toggle.d.ts +199 -0
  171. package/dist/toggle.js +129 -0
  172. package/dist/token-input.d.ts +136 -0
  173. package/dist/token-input.js +214 -0
  174. package/dist/toolbar-context.d.ts +7 -0
  175. package/dist/toolbar-context.js +20 -0
  176. package/dist/toolbar.d.ts +120 -0
  177. package/dist/toolbar.js +77 -0
  178. package/dist/tooltip.d.ts +160 -0
  179. package/dist/tooltip.js +224 -0
  180. package/dist/tree.d.ts +300 -0
  181. package/dist/tree.js +209 -0
  182. package/dist/trigger-menu.d.ts +452 -0
  183. package/dist/trigger-menu.js +254 -0
  184. package/dist/use-primitive.d.ts +132 -0
  185. package/dist/use-primitive.js +462 -0
  186. package/dist/waterfall.d.ts +201 -0
  187. package/dist/waterfall.js +171 -0
  188. package/docs/README.md +89 -0
  189. package/docs/agents.md +1523 -0
  190. package/docs/components/accordion.md +1369 -0
  191. package/docs/components/alert-dialog.md +799 -0
  192. package/docs/components/autocomplete.md +1857 -0
  193. package/docs/components/avatar.md +272 -0
  194. package/docs/components/button.md +435 -0
  195. package/docs/components/calendar.md +1589 -0
  196. package/docs/components/carousel.md +1171 -0
  197. package/docs/components/checkbox.md +1008 -0
  198. package/docs/components/collapsible.md +536 -0
  199. package/docs/components/color-picker.md +706 -0
  200. package/docs/components/combobox.md +3504 -0
  201. package/docs/components/command.md +1481 -0
  202. package/docs/components/date-input.md +536 -0
  203. package/docs/components/date-picker.md +1244 -0
  204. package/docs/components/dialog.md +1397 -0
  205. package/docs/components/drawer.md +1166 -0
  206. package/docs/components/field.md +538 -0
  207. package/docs/components/file-input.md +611 -0
  208. package/docs/components/hover-card.md +505 -0
  209. package/docs/components/image-cropper.md +556 -0
  210. package/docs/components/input.md +306 -0
  211. package/docs/components/label.md +203 -0
  212. package/docs/components/listbox.md +1004 -0
  213. package/docs/components/menu.md +1229 -0
  214. package/docs/components/menubar.md +443 -0
  215. package/docs/components/meter.md +315 -0
  216. package/docs/components/navigation-menu.md +1523 -0
  217. package/docs/components/number-input.md +1029 -0
  218. package/docs/components/otp-input.md +512 -0
  219. package/docs/components/pagination.md +613 -0
  220. package/docs/components/password-input.md +649 -0
  221. package/docs/components/popover.md +1448 -0
  222. package/docs/components/preferences.md +208 -0
  223. package/docs/components/progress.md +423 -0
  224. package/docs/components/radio.md +785 -0
  225. package/docs/components/rating.md +416 -0
  226. package/docs/components/resizable.md +910 -0
  227. package/docs/components/scroll-area.md +915 -0
  228. package/docs/components/segmented-control.md +435 -0
  229. package/docs/components/select.md +2015 -0
  230. package/docs/components/separator.md +229 -0
  231. package/docs/components/slider.md +1084 -0
  232. package/docs/components/switch.md +565 -0
  233. package/docs/components/tabs.md +944 -0
  234. package/docs/components/textarea.md +299 -0
  235. package/docs/components/time-input.md +224 -0
  236. package/docs/components/timeline.md +654 -0
  237. package/docs/components/toast.md +1224 -0
  238. package/docs/components/toggle.md +500 -0
  239. package/docs/components/token-input.md +953 -0
  240. package/docs/components/toolbar.md +739 -0
  241. package/docs/components/tooltip.md +818 -0
  242. package/docs/components/tree.md +1306 -0
  243. package/docs/components/trigger-menu.md +1223 -0
  244. package/docs/components/waterfall.md +717 -0
  245. package/docs/controllers.md +71 -0
  246. package/docs/core.md +8027 -0
  247. package/docs/custom-parts.md +89 -0
  248. package/docs/first-component.md +83 -0
  249. package/docs/forms.md +122 -0
  250. package/docs/installation.md +72 -0
  251. package/docs/introduction.md +32 -0
  252. package/docs/lists-and-menus.md +122 -0
  253. package/docs/llms.txt +1502 -0
  254. package/docs/parts-and-composition.md +85 -0
  255. package/docs/popups.md +108 -0
  256. package/docs/rendering.md +56 -0
  257. package/docs/server-rendering.md +180 -0
  258. package/docs/state-and-events.md +100 -0
  259. package/docs/styling-and-animation.md +148 -0
  260. package/docs/utilities/async-options.md +348 -0
  261. package/docs/utilities/shortcuts.md +159 -0
  262. package/package.json +352 -3
@@ -0,0 +1,953 @@
1
+ # Token Input
2
+
3
+ Mix editable text with tokens for files, people, tags, and other references.
4
+
5
+ A token input is a text field that holds tokens alongside the text, like the people mentioned in a message or the files attached to a prompt. Each token moves, deletes and copies as one piece.
6
+
7
+ ```vue title="demo.vue"
8
+ <script setup lang="ts">
9
+ import { XIcon } from "@lucide/vue"
10
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
11
+ import {
12
+ TokenInput,
13
+ TokenInputEditor,
14
+ TokenInputToken,
15
+ TokenInputTokenRemove,
16
+ } from "@ui-sdk/vue/token-input"
17
+ import {
18
+ type TriggerMenuDataItem,
19
+ TriggerMenu,
20
+ TriggerMenuContent,
21
+ TriggerMenuItem,
22
+ TriggerMenuList,
23
+ } from "@ui-sdk/vue/trigger-menu"
24
+
25
+ const people = [
26
+ { value: "hollis", label: "Hollis Grant" },
27
+ { value: "ines", label: "Inès Moreau" },
28
+ { value: "kofi", label: "Kofi Mensah" },
29
+ { value: "wren", label: "Wren Takahashi" },
30
+ { value: "tomasz", label: "Tomasz Wójcik" },
31
+ ]
32
+ </script>
33
+
34
+ <template>
35
+ <Field>
36
+ <FieldLabel>Message</FieldLabel>
37
+ <TokenInput>
38
+ <TokenInputEditor placeholder="Type @ to mention someone…" />
39
+ <TriggerMenu :triggers="[{ char: '@', type: 'mention', items: people }]">
40
+ <TriggerMenuContent>
41
+ <TriggerMenuList v-slot="{ state }">
42
+ <TriggerMenuItem
43
+ v-for="item in state.items as TriggerMenuDataItem[]"
44
+ :key="item.value"
45
+ :value="item.value"
46
+ :label="item.label"
47
+ >
48
+ {{ item.label }}
49
+ </TriggerMenuItem>
50
+ </TriggerMenuList>
51
+ </TriggerMenuContent>
52
+ </TriggerMenu>
53
+ <template #token="{ token }">
54
+ <TokenInputToken>
55
+ {{ token.label }}
56
+ <TokenInputTokenRemove>
57
+ <XIcon aria-hidden="true" />
58
+ </TokenInputTokenRemove>
59
+ </TokenInputToken>
60
+ </template>
61
+ </TokenInput>
62
+ </Field>
63
+ </template>
64
+ ```
65
+
66
+ Type @ and choose a person with the arrow keys and Enter. Remove a token with Backspace, or press its remove button.
67
+
68
+ ## Installation
69
+
70
+ ```bash
71
+ npm install @ui-sdk/vue @ui-sdk/core
72
+ ```
73
+
74
+ ## Composition
75
+
76
+ Use the following composition to build a `TokenInput`:
77
+
78
+ ```text
79
+ TokenInput
80
+ ├── TokenInputEditor
81
+ └── TriggerMenu
82
+ ```
83
+
84
+ And for each token, inside the `#token` slot:
85
+
86
+ ```text
87
+ TokenInputToken
88
+ └── TokenInputTokenRemove
89
+ ```
90
+
91
+ `TokenInput` holds the value, and `TokenInputEditor` is the text people edit. A [Trigger Menu](./trigger-menu.md) inside it suggests tokens when someone types `@`, `/`, or another trigger. Use the `#token` slot to give each token your own markup.
92
+
93
+ ## Usage
94
+
95
+ Import the parts and put them together:
96
+
97
+ ```vue
98
+ <script setup lang="ts">
99
+ import {
100
+ TokenInput,
101
+ TokenInputEditor,
102
+ type TokenInputValue,
103
+ } from "@ui-sdk/vue/token-input"
104
+
105
+ const draft: TokenInputValue = [
106
+ "Explain ",
107
+ { type: "file", value: "src/routes.ts", label: "routes.ts" },
108
+ ]
109
+ </script>
110
+
111
+ <template>
112
+ <TokenInput :default-value="draft">
113
+ <TokenInputEditor aria-label="Prompt" />
114
+ </TokenInput>
115
+ </template>
116
+ ```
117
+
118
+ A value is an array of text and tokens. Each token has a type, a value for your app, and a label for the reader. The editor manages its own content, including tokens, selection, and undo, so let it render that content and use the `#token` slot for custom token markup.
119
+
120
+ ## Token Input or Trigger Menu
121
+
122
+ Token Input holds the text and tokens. [Trigger Menu](./trigger-menu.md) suggests what to insert when someone types a trigger character.
123
+
124
+ Use Token Input on its own when your code supplies the tokens. Add a Trigger Menu for suggestions, as in the demo above. Trigger Menu also works with ordinary inputs and textareas.
125
+
126
+ ## Prompt Input
127
+
128
+ Combine file suggestions, skills, and a send action. This example marks files as pending while they load, then uses `updateToken()` to show a skill running. Enter sends; Shift+Enter adds a line. An open suggestion menu or an active input method takes precedence over sending.
129
+
130
+ ```vue title="prompt-input.vue"
131
+ <script setup lang="ts">
132
+ import {
133
+ ArrowUpIcon,
134
+ CheckIcon,
135
+ ClockIcon,
136
+ CodeIcon,
137
+ FileIcon,
138
+ XIcon,
139
+ } from "@lucide/vue"
140
+ import {
141
+ createTokenInputController,
142
+ toText,
143
+ TokenInput,
144
+ TokenInputEditor,
145
+ TokenInputToken,
146
+ TokenInputTokenRemove,
147
+ type TokenInputValue,
148
+ } from "@ui-sdk/vue/token-input"
149
+ import {
150
+ type TriggerMenuDataItem,
151
+ type TriggerMenuSelectDetails,
152
+ TriggerMenu,
153
+ TriggerMenuContent,
154
+ TriggerMenuEmpty,
155
+ TriggerMenuHint,
156
+ TriggerMenuItem,
157
+ TriggerMenuList,
158
+ } from "@ui-sdk/vue/trigger-menu"
159
+ import { onBeforeUnmount, ref } from "vue"
160
+ import { useLog } from "./log"
161
+
162
+ const files = [
163
+ { value: "src/app.tsx", label: "app.tsx", keywords: ["src"] },
164
+ { value: "src/routes.ts", label: "routes.ts", keywords: ["src"] },
165
+ { value: "src/styles.css", label: "styles.css", keywords: ["src"] },
166
+ { value: "README.md", label: "README.md" },
167
+ { value: "package.json", label: "package.json" },
168
+ ]
169
+
170
+ const skills = [
171
+ {
172
+ value: "search",
173
+ label: "search",
174
+ arguments: [{ name: "query", hint: "<query>", required: true }],
175
+ },
176
+ { value: "review", label: "review" },
177
+ { value: "summarize", label: "summarize" },
178
+ ]
179
+
180
+ const loadFile = () => new Promise<void>((resolve) => setTimeout(resolve, 800))
181
+
182
+ const log = useLog()
183
+ const prompt = createTokenInputController()
184
+ const running = ref(false)
185
+ let sendTimer: ReturnType<typeof setTimeout> | undefined
186
+
187
+ onBeforeUnmount(() => clearTimeout(sendTimer))
188
+
189
+ function send(value: TokenInputValue) {
190
+ if (running.value || !prompt.getLabel().trim()) {
191
+ return
192
+ }
193
+ running.value = true
194
+ const skillTokens = value.filter(
195
+ (segment) => typeof segment !== "string" && segment.type === "skill"
196
+ )
197
+ for (const skill of skillTokens) {
198
+ if (typeof skill !== "string") {
199
+ prompt.updateToken(skill.id!, { data: { ...skill.data, run: "running" } })
200
+ }
201
+ }
202
+ sendTimer = setTimeout(() => {
203
+ for (const skill of skillTokens) {
204
+ if (typeof skill !== "string") {
205
+ prompt.updateToken(skill.id!, { data: { ...skill.data, run: "done" } })
206
+ }
207
+ }
208
+ log(`Sent ${toText(prompt.getValue())}`)
209
+ prompt.clear()
210
+ running.value = false
211
+ }, 1500)
212
+ }
213
+
214
+ function onSelect(value: string, details: TriggerMenuSelectDetails<string>) {
215
+ return details.trigger === "@" ? loadFile() : undefined
216
+ }
217
+
218
+ function attachReadme() {
219
+ prompt.insert(
220
+ { type: "file", value: "README.md", label: "README.md" },
221
+ { resolve: loadFile() }
222
+ )
223
+ }
224
+ </script>
225
+
226
+ <template>
227
+ <TokenInput :controller="prompt" @submit="send">
228
+ <div data-slot="card">
229
+ <TokenInputEditor aria-label="Prompt" placeholder="Ask anything. Type @ or /" />
230
+ <div data-slot="row">
231
+ <button type="button" data-size="sm" @mousedown.prevent @click="attachReadme">
232
+ Attach README
233
+ </button>
234
+ <button
235
+ type="button"
236
+ data-variant="solid"
237
+ data-size="sm"
238
+ data-shape="round"
239
+ :aria-label="running ? 'Running' : 'Send'"
240
+ :disabled="running"
241
+ @click="send(prompt.getValue())"
242
+ >
243
+ <ClockIcon v-if="running" aria-hidden="true" />
244
+ <ArrowUpIcon v-else aria-hidden="true" />
245
+ </button>
246
+ </div>
247
+ </div>
248
+ <TriggerMenu
249
+ :triggers="[
250
+ { char: '@', type: 'file', items: files },
251
+ { char: '/', boundary: 'start', type: 'skill', items: skills },
252
+ ]"
253
+ @select="onSelect"
254
+ >
255
+ <TriggerMenuHint />
256
+ <TriggerMenuContent>
257
+ <TriggerMenuEmpty>No matches</TriggerMenuEmpty>
258
+ <TriggerMenuList v-slot="{ state }">
259
+ <TriggerMenuItem
260
+ v-for="item in state.items as TriggerMenuDataItem[]"
261
+ :key="item.value"
262
+ :value="item.value"
263
+ :label="item.label"
264
+ :disabled="item.disabled"
265
+ >
266
+ {{ item.label }}
267
+ </TriggerMenuItem>
268
+ </TriggerMenuList>
269
+ </TriggerMenuContent>
270
+ </TriggerMenu>
271
+ <template #token="{ token }">
272
+ <TokenInputToken>
273
+ <CodeIcon v-if="token.type === 'skill'" aria-hidden="true" />
274
+ <FileIcon v-else aria-hidden="true" />
275
+ {{ token.type === "skill" ? `/${token.label}` : token.label }}
276
+ <ClockIcon v-if="token.data?.run === 'running'" aria-hidden="true" />
277
+ <CheckIcon v-if="token.data?.run === 'done'" aria-hidden="true" />
278
+ <TokenInputTokenRemove>
279
+ <XIcon aria-hidden="true" />
280
+ </TokenInputTokenRemove>
281
+ </TokenInputToken>
282
+ </template>
283
+ </TokenInput>
284
+ </template>
285
+ ```
286
+
287
+ Type @ for files or / at the start for skills. For /search, enter a query and press Enter to insert the command. Press Enter again to send, and the console logs the message.
288
+
289
+ ## Deleting Tokens
290
+
291
+ Choose what Backspace does at a token with `token-deletion`:
292
+
293
+ - `whole` removes the token in one press.
294
+ - `select` selects it first, then removes it on the next press.
295
+ - `revert` turns it back into editable text, so the trigger menu opens on it again.
296
+
297
+ ```vue title="deletion.vue"
298
+ <script setup lang="ts">
299
+ import { CheckIcon, ChevronDownIcon, FileIcon } from "@lucide/vue"
300
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
301
+ import {
302
+ Select,
303
+ SelectContent,
304
+ SelectItem,
305
+ SelectItemIndicator,
306
+ SelectLabel,
307
+ SelectTrigger,
308
+ SelectValue,
309
+ } from "@ui-sdk/vue/select"
310
+ import {
311
+ TokenInput,
312
+ TokenInputEditor,
313
+ TokenInputToken,
314
+ type TokenDeletion,
315
+ type TokenInputValue,
316
+ type TokenInputValueChangeDetails,
317
+ } from "@ui-sdk/vue/token-input"
318
+ import {
319
+ type TriggerMenuDataItem,
320
+ TriggerMenu,
321
+ TriggerMenuContent,
322
+ TriggerMenuItem,
323
+ TriggerMenuList,
324
+ } from "@ui-sdk/vue/trigger-menu"
325
+ import { ref } from "vue"
326
+ import { useLog } from "./log"
327
+
328
+ const modes = [
329
+ { value: "whole", label: "Whole" },
330
+ { value: "select", label: "Select" },
331
+ { value: "revert", label: "Revert" },
332
+ ]
333
+
334
+ const files = [
335
+ { value: "src/app.tsx", label: "app.tsx", keywords: ["src"] },
336
+ { value: "src/routes.ts", label: "routes.ts", keywords: ["src"] },
337
+ { value: "src/styles.css", label: "styles.css", keywords: ["src"] },
338
+ { value: "README.md", label: "README.md" },
339
+ { value: "package.json", label: "package.json" },
340
+ ]
341
+
342
+ const draft: TokenInputValue = [
343
+ "Explain ",
344
+ {
345
+ type: "file",
346
+ value: "src/routes.ts",
347
+ label: "routes.ts",
348
+ data: { trigger: "@" },
349
+ },
350
+ " in two sentences.",
351
+ ]
352
+
353
+ const log = useLog()
354
+ const deletion = ref<TokenDeletion>("whole")
355
+
356
+ function onValueChange(
357
+ value: TokenInputValue,
358
+ details: TokenInputValueChangeDetails
359
+ ) {
360
+ for (const token of details.removed) {
361
+ log(`Removed ${token.label} (${deletion.value})`)
362
+ }
363
+ }
364
+ </script>
365
+
366
+ <template>
367
+ <div data-slot="stack">
368
+ <div data-slot="controls">
369
+ <Select
370
+ :items="modes"
371
+ :value="deletion"
372
+ @value-change="(next) => next && (deletion = next as TokenDeletion)"
373
+ >
374
+ <SelectLabel>Backspace</SelectLabel>
375
+ <SelectTrigger>
376
+ <SelectValue />
377
+ <ChevronDownIcon aria-hidden="true" />
378
+ </SelectTrigger>
379
+ <SelectContent>
380
+ <SelectItem v-for="mode in modes" :key="mode.value" :value="mode.value">
381
+ {{ mode.label }}
382
+ <SelectItemIndicator>
383
+ <CheckIcon aria-hidden="true" />
384
+ </SelectItemIndicator>
385
+ </SelectItem>
386
+ </SelectContent>
387
+ </Select>
388
+ </div>
389
+ <Field>
390
+ <FieldLabel>Prompt</FieldLabel>
391
+ <TokenInput :token-deletion="deletion" :default-value="draft" @value-change="onValueChange">
392
+ <TokenInputEditor />
393
+ <TriggerMenu :triggers="[{ char: '@', type: 'file', items: files }]">
394
+ <TriggerMenuContent>
395
+ <TriggerMenuList v-slot="{ state }">
396
+ <TriggerMenuItem
397
+ v-for="item in state.items as TriggerMenuDataItem[]"
398
+ :key="item.value"
399
+ :value="item.value"
400
+ :label="item.label"
401
+ >
402
+ {{ item.label }}
403
+ </TriggerMenuItem>
404
+ </TriggerMenuList>
405
+ </TriggerMenuContent>
406
+ </TriggerMenu>
407
+ <template #token="{ token }">
408
+ <TokenInputToken>
409
+ <FileIcon aria-hidden="true" />
410
+ {{ token.label }}
411
+ </TokenInputToken>
412
+ </template>
413
+ </TokenInput>
414
+ </Field>
415
+ </div>
416
+ </template>
417
+ ```
418
+
419
+ Choose a Backspace behavior, click just after routes.ts, and press Backspace. Undo to try another behavior.
420
+
421
+ ## Codec
422
+
423
+ A codec converts tokens to text for the clipboard, forms, and saved drafts. The default writes `[@label](type:value)`. Copy that text into another app and paste it back to restore the token.
424
+
425
+ Use `toText`, `fromText`, and `toLabel` to convert values yourself. Supply a custom codec for another format, as this example does for `<@hollis>`. With `copy="label"`, copying writes what people read, and pasting back into a token input still restores the tokens. The default parser accepts letters, digits, `_`, and `-` in token types; other types need a custom codec.
426
+
427
+ ```vue title="codec.vue"
428
+ <script setup lang="ts">
429
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
430
+ import {
431
+ fromText,
432
+ toText,
433
+ TokenInput,
434
+ TokenInputEditor,
435
+ type TokenCodec,
436
+ } from "@ui-sdk/vue/token-input"
437
+ import { useLog } from "./log"
438
+
439
+ const chat: TokenCodec = {
440
+ format: (token) => `<@${token.value}>`,
441
+ parse: (text) =>
442
+ text.split(/(<@[\w.-]+>)/).map((part) => {
443
+ const id = /^<@([\w.-]+)>$/.exec(part)?.[1]
444
+ return id ? { type: "mention", value: id, label: `@${id}` } : part
445
+ }),
446
+ }
447
+
448
+ const draft = fromText("Ping <@hollis> and <@ines> about the launch", chat)
449
+
450
+ const log = useLog()
451
+ </script>
452
+
453
+ <template>
454
+ <Field>
455
+ <FieldLabel>Message</FieldLabel>
456
+ <TokenInput
457
+ :codec="chat"
458
+ copy="label"
459
+ :default-value="draft"
460
+ @value-change="(value) => log(toText(value, chat))"
461
+ >
462
+ <TokenInputEditor />
463
+ </TokenInput>
464
+ </Field>
465
+ </template>
466
+ ```
467
+
468
+ Edit the message. The console logs it in the custom format, with each mention as <@id>.
469
+
470
+ ## Form
471
+
472
+ Give the input a `name` to submit its serialized text. `required`, `disabled`, and `read-only` control form behavior. The `form` option associates it with a form elsewhere on the page, as shown here.
473
+
474
+ ```vue title="form.vue"
475
+ <script setup lang="ts">
476
+ import { CheckIcon } from "@lucide/vue"
477
+ import { Checkbox, CheckboxIndicator } from "@ui-sdk/vue/checkbox"
478
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
479
+ import {
480
+ TokenInput,
481
+ TokenInputEditor,
482
+ type TokenInputValue,
483
+ } from "@ui-sdk/vue/token-input"
484
+ import { ref, useId } from "vue"
485
+ import { useLog } from "./log"
486
+
487
+ const draft: TokenInputValue = [
488
+ "Explain ",
489
+ { type: "file", value: "src/routes.ts", label: "routes.ts" },
490
+ " in two sentences.",
491
+ ]
492
+
493
+ const log = useLog()
494
+ const disabled = ref(false)
495
+ const readOnly = ref(false)
496
+ const formId = useId()
497
+
498
+ function onSubmit(event: Event) {
499
+ log(
500
+ `Submitted ${new FormData(event.currentTarget as HTMLFormElement).get("prompt") ?? ""}`
501
+ )
502
+ }
503
+ </script>
504
+
505
+ <template>
506
+ <div data-slot="stack">
507
+ <div data-slot="controls">
508
+ <label data-slot="label">
509
+ <Checkbox
510
+ :checked="disabled"
511
+ @checked-change="(next) => (disabled = next === true)"
512
+ >
513
+ <CheckboxIndicator>
514
+ <CheckIcon aria-hidden="true" />
515
+ </CheckboxIndicator>
516
+ </Checkbox>
517
+ Disabled
518
+ </label>
519
+ <label data-slot="label">
520
+ <Checkbox
521
+ :checked="readOnly"
522
+ @checked-change="(next) => (readOnly = next === true)"
523
+ >
524
+ <CheckboxIndicator>
525
+ <CheckIcon aria-hidden="true" />
526
+ </CheckboxIndicator>
527
+ </Checkbox>
528
+ Read-only
529
+ </label>
530
+ </div>
531
+ <div data-slot="stack">
532
+ <Field :disabled="disabled">
533
+ <FieldLabel>Prompt</FieldLabel>
534
+ <TokenInput :form="formId" name="prompt" required :default-value="draft" :read-only="readOnly">
535
+ <TokenInputEditor />
536
+ </TokenInput>
537
+ </Field>
538
+ <form :id="formId" data-slot="row" @submit.prevent="onSubmit">
539
+ <button type="submit" data-variant="solid">Submit</button>
540
+ <button type="reset">Reset</button>
541
+ </form>
542
+ </div>
543
+ </div>
544
+ </template>
545
+ ```
546
+
547
+ Press Submit to log the prompt's serialized value. Try Disabled and Read-only, then Reset.
548
+
549
+ ## Controlled
550
+
551
+ Bind `v-model:value`, or pass `value` and update it in `@value-change`. The change details include the reason, input type, and removed tokens. The input still manages its editing history.
552
+
553
+ ```vue title="controlled.vue"
554
+ <script setup lang="ts">
555
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
556
+ import {
557
+ toText,
558
+ TokenInput,
559
+ TokenInputEditor,
560
+ type Token,
561
+ type TokenInputValue,
562
+ type TokenInputValueChangeDetails,
563
+ } from "@ui-sdk/vue/token-input"
564
+ import {
565
+ type TriggerMenuDataItem,
566
+ TriggerMenu,
567
+ TriggerMenuContent,
568
+ TriggerMenuItem,
569
+ TriggerMenuList,
570
+ } from "@ui-sdk/vue/trigger-menu"
571
+ import { ref } from "vue"
572
+ import { useLog } from "./log"
573
+
574
+ const files = [
575
+ { value: "src/app.tsx", label: "app.tsx", keywords: ["src"] },
576
+ { value: "src/routes.ts", label: "routes.ts", keywords: ["src"] },
577
+ { value: "src/styles.css", label: "styles.css", keywords: ["src"] },
578
+ { value: "README.md", label: "README.md" },
579
+ { value: "package.json", label: "package.json" },
580
+ ]
581
+
582
+ const draft: TokenInputValue = [
583
+ "Explain ",
584
+ { type: "file", value: "src/routes.ts", label: "routes.ts" },
585
+ " in two sentences.",
586
+ ]
587
+
588
+ const log = useLog()
589
+ const value = ref<TokenInputValue>(draft)
590
+
591
+ function onValueChange(
592
+ next: TokenInputValue,
593
+ details: TokenInputValueChangeDetails
594
+ ) {
595
+ const removed = details.removed.map((token) => token.label).join(", ")
596
+ log(
597
+ `${toText(next)} (${details.reason}${removed ? `, removed ${removed}` : ""})`
598
+ )
599
+ }
600
+ </script>
601
+
602
+ <template>
603
+ <Field>
604
+ <FieldLabel>Prompt</FieldLabel>
605
+ <TokenInput
606
+ v-model:value="value"
607
+ :history="{ limit: 50, groupDelay: 1000 }"
608
+ :get-token-description="
609
+ (token: Token) => (token.type === 'file' ? 'attached file' : token.type)
610
+ "
611
+ @value-change="onValueChange"
612
+ >
613
+ <TokenInputEditor />
614
+ <TriggerMenu :triggers="[{ char: '@', type: 'file', items: files }]">
615
+ <TriggerMenuContent>
616
+ <TriggerMenuList v-slot="{ state }">
617
+ <TriggerMenuItem
618
+ v-for="item in state.items as TriggerMenuDataItem[]"
619
+ :key="item.value"
620
+ :value="item.value"
621
+ :label="item.label"
622
+ >
623
+ {{ item.label }}
624
+ </TriggerMenuItem>
625
+ </TriggerMenuList>
626
+ </TriggerMenuContent>
627
+ </TriggerMenu>
628
+ </TokenInput>
629
+ </Field>
630
+ </template>
631
+ ```
632
+
633
+ Type, add a file with @, or remove a token. The console logs the value and the reason for each change.
634
+
635
+ ## Controller
636
+
637
+ Use `createTokenInputController()` to insert, update, or remove tokens from code. Pass a promise as `resolve` to mark an inserted token as pending until its data is ready. Updating a token doesn't add an undo step.
638
+
639
+ ```vue title="controller.vue"
640
+ <script setup lang="ts">
641
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
642
+ import {
643
+ createTokenInputController,
644
+ TokenInput,
645
+ TokenInputEditor,
646
+ type Token,
647
+ type TokenInputValue,
648
+ } from "@ui-sdk/vue/token-input"
649
+
650
+ const draft: TokenInputValue = [
651
+ "Compare ",
652
+ { type: "file", value: "src/routes.ts", label: "routes.ts" },
653
+ " with ",
654
+ ]
655
+
656
+ const loadFile = () => new Promise<void>((resolve) => setTimeout(resolve, 800))
657
+
658
+ const prompt = createTokenInputController()
659
+ const firstToken = () =>
660
+ prompt
661
+ .getValue()
662
+ .find((segment): segment is Token => typeof segment !== "string")
663
+
664
+ function attachFile() {
665
+ prompt.insert(
666
+ { type: "file", value: "package.json", label: "package.json" },
667
+ { at: "end", resolve: loadFile() }
668
+ )
669
+ }
670
+
671
+ function showPath() {
672
+ const token = firstToken()
673
+ if (token) {
674
+ prompt.updateToken(token.id!, { label: token.value })
675
+ }
676
+ }
677
+
678
+ function removeFirst() {
679
+ const token = firstToken()
680
+ if (token) {
681
+ prompt.removeToken(token.id!)
682
+ }
683
+ }
684
+ </script>
685
+
686
+ <template>
687
+ <div data-slot="stack">
688
+ <div data-slot="controls" @mousedown.prevent>
689
+ <button type="button" @click="attachFile">Attach File</button>
690
+ <button type="button" @click="showPath">Show Path</button>
691
+ <button type="button" @click="removeFirst">Remove First</button>
692
+ <button type="button" @click="prompt.undo()">Undo</button>
693
+ <button type="button" @click="prompt.clear()">Clear</button>
694
+ </div>
695
+ <Field>
696
+ <FieldLabel>Prompt</FieldLabel>
697
+ <TokenInput :controller="prompt" :default-value="draft">
698
+ <TokenInputEditor />
699
+ </TokenInput>
700
+ </Field>
701
+ </div>
702
+ </template>
703
+ ```
704
+
705
+ Attach a file and watch it load. Show the first token's full path or remove it, then use Undo or Clear.
706
+
707
+ ## Submit Shortcut
708
+
709
+ Set `submit-shortcut` to `mod+enter` for a multiline message. Enter then inserts a line, and Command or Control+Enter submits.
710
+
711
+ ```vue title="submit-shortcut.vue"
712
+ <script setup lang="ts">
713
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
714
+ import { toLabel, TokenInput, TokenInputEditor } from "@ui-sdk/vue/token-input"
715
+ import { useLog } from "./log"
716
+
717
+ const log = useLog()
718
+ </script>
719
+
720
+ <template>
721
+ <Field>
722
+ <FieldLabel>Message</FieldLabel>
723
+ <TokenInput
724
+ submit-shortcut="mod+enter"
725
+ @submit="(value) => log(`Sent ${toLabel(value)}`)"
726
+ >
727
+ <TokenInputEditor placeholder="Write a message…" />
728
+ </TokenInput>
729
+ </Field>
730
+ </template>
731
+ ```
732
+
733
+ Write a message. Enter adds a line; Command+Enter on a Mac or Control+Enter elsewhere sends it to the console.
734
+
735
+ ## Custom Rendering
736
+
737
+ Use the `#token` slot to render each token's content, usually a `TokenInputToken` with a `TokenInputTokenRemove` inside. It receives the token, so you can choose an icon by its type or show its `data`. Without it, each token shows its label.
738
+
739
+ Every part also takes a `render` slot. [Parts and Composition](../parts-and-composition.md#choose-the-element) explains how props merge, and each part's state is listed under [State](#state).
740
+
741
+ ## Styling
742
+
743
+ Style the editor, the tokens and their remove buttons. The editor shows `data-empty` while it holds nothing; show the placeholder with `content: attr(aria-placeholder)` on its `::before`. Tokens show `data-token-type`, `data-pending`, `data-unresolved` and `data-selected`. Without a `#token` slot, the element that holds each token, `token-input-host`, carries the same attributes, so you can style tokens without the slot.
744
+
745
+ Each part has a `data-slot`, such as `token-input-token`, and shows its state through the attributes listed under [Data Attributes](#data-attributes).
746
+
747
+ ## Data Attributes
748
+
749
+ ### TokenInputEditor
750
+ `[data-slot="token-input-editor"]`
751
+
752
+ - `data-empty`: Present while the input holds nothing. Show the placeholder with it.
753
+ - `data-disabled`: Present when the input is disabled, by its own prop, a field or a `<fieldset>`.
754
+ - `data-readonly`: Present when the input is read-only.
755
+
756
+ ### TokenInputToken
757
+ `[data-slot="token-input-token"]`
758
+
759
+ - `data-token-type` (`file`): The token's type, like `file` or `mention`. Also on its host.
760
+ - `data-pending`: Present while the token loads. Also on its host.
761
+ - `data-disabled`: Present when the input is disabled, by its own prop, a field or a `<fieldset>`.
762
+ - `data-readonly`: Present when the input is read-only.
763
+ - `data-slot`
764
+ - `data-selected`: Present while the token is in the selection, or selected for removal. Also on its host.
765
+ - `data-unresolved`: Present while the token needs the user, like an ambiguous mention. Also on its host.
766
+
767
+ ### TokenInputTokenRemove
768
+ `[data-slot="token-input-token-remove"]`
769
+
770
+ - `data-disabled`: Present when the input is disabled, by its own prop, a field or a `<fieldset>`.
771
+ - `data-readonly`: Present when the input is read-only.
772
+
773
+ ## API Reference
774
+
775
+ Props are the same as below, and callbacks are events.
776
+
777
+ ### TokenInput
778
+
779
+ - `value?` (`TokenInputValue`): The value. Pass it to control the input.
780
+ - `defaultValue?` (`TokenInputValue`): The value at first, when uncontrolled. A form reset returns to it.
781
+ - `@value-change` (`((value: TokenInputValue, details: TokenInputValueChangeDetails) => void)`): Runs when typing, pasting, a menu, undo or a controller wants to change the value. `details.reason` says why, `details.removed` lists removed tokens, and `details.cancel()` stops it.
782
+ - `@submit` (`((value: TokenInputValue, details: TokenInputSubmitDetails) => void)`): Runs on the submit shortcut, unless an input method is composing or a trigger menu is open. Without it, the shortcut submits the form the input is in. With neither, the key is left alone, so Enter starts a new line.
783
+ - `submitShortcut?` (`"enter" | "mod+enter"`): Which keys submit: `"enter"`, with Shift+Enter for a new line, or `"mod+enter"`, with Enter for a new line, which many Japanese and Chinese writers prefer.
784
+ - `tokenDeletion?` (`TokenDeletion`): How Backspace and Delete treat a token next to the caret. `"whole"` removes it in one press, `"select"` selects it first and removes it on the second, and `"revert"` turns it back into its text, so a trigger menu opens on it again.
785
+ - `copy?` (`"codec" | "label"`): What copying writes as plain text: `"codec"` keeps tokens through any app that pastes text, `"label"` writes what people read.
786
+ - `codec?` (`TokenCodec`): How tokens become text and back, for the clipboard and forms.
787
+ - `getTokenDescription?` (`((token: Token) => string)`): What a token says to screen readers besides its label, like its kind and status.
788
+ - `history?` (`UndoStackOptions`): Undo history: how many steps it keeps, and how long a typing pause starts a new step.
789
+ - `disabled?` (`boolean`): Disables the input: it can't be focused or changed, and isn't submitted.
790
+ - `readOnly?` (`boolean`): Keeps the input focusable and submitted, but stops changes.
791
+ - `required?` (`boolean`): Blocks form submission while the input is empty.
792
+ - `name?` (`string`): The name the codec text submits under. Without one, the input submits nothing.
793
+ - `form?` (`string`): The id of a form to belong to, when the input isn't inside it.
794
+ - `controller?` (`object`): Reads, edits and focuses the input from anywhere. Create one with `createTokenInputController()`.
795
+ - `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
796
+
797
+ The `#token` slot receives each token and renders its content, usually a `TokenInputToken`.
798
+
799
+ ### TokenInputEditor
800
+
801
+ - `placeholder?` (`string`): Text shown while the input is empty, through `aria-placeholder`. Show it with `data-empty:before:content-[attr(aria-placeholder)]`.
802
+
803
+ ### TokenInputToken
804
+
805
+ A token's content, inside the `#token` slot, with its state for styling. Renders a `span`.
806
+
807
+ ### TokenInputTokenRemove
808
+
809
+ Removes its token when pressed and keeps focus in the editor. Renders a `span`, hidden from assistive technology, since keyboard users remove tokens with Backspace.
810
+
811
+ ### Token
812
+
813
+ - `type` (`string`): Kind, like `"mention"`, `"file"` or `"skill"`.
814
+ - `value` (`string`): The id it stands for.
815
+ - `label` (`string`): The text it shows, reads as and falls back to.
816
+ - `id?` (`string`): Stable identity, generated when missing.
817
+ - `status?` (`"pending" | "unresolved"`): `"pending"` while it loads, `"unresolved"` when it needs the user, like an ambiguous mention.
818
+ - `data?` (`Record<string, unknown>`): What the chip renders from, like an icon or a run state. Never serialized.
819
+
820
+ ### Codec
821
+
822
+ - `format` (`(token: Token) => string`): The text a token is written as.
823
+ - `parse` (`(text: string) => TokenInputValue`): Text back into a value, with tokens wherever their text appears.
824
+ - `escape?` (`((text: string, next: Token | undefined) => string)`): How plain text is written so `parse` reads it back as text. `next` is the token that follows it, if any. Defaults to the text as is.
825
+
826
+ ### State
827
+
828
+ `TokenInputEditor`:
829
+
830
+ - `empty` (`boolean`): Whether the input holds nothing.
831
+ - `disabled` (`boolean`): Whether the input is disabled, by itself or by a `<fieldset>`.
832
+ - `readOnly` (`boolean`): Whether the input is read-only: it stays focusable, but typing, pastes and drops don't change it.
833
+
834
+ `TokenInputToken`:
835
+
836
+ - `token` (`Token`): The token this part shows: the one the token input renders its content for.
837
+ - `selected` (`boolean`): Whether the token is in the selection, or selected for removal.
838
+ - `pending` (`boolean`): Whether the token is loading.
839
+ - `unresolved` (`boolean`): Whether the token needs the user, like an ambiguous mention.
840
+ - `disabled` (`boolean`): Whether the input is disabled, by itself or by a `<fieldset>`.
841
+ - `readOnly` (`boolean`): Whether the input is read-only, so the token's remove button does nothing.
842
+
843
+ ### Reasons
844
+
845
+ - `input-change` (`Event`): Typing, pasting or dropping changed a text field's value; in a combobox it can also open or close it, or Enter keeps the typed text as the value.
846
+ - `paste` (`ClipboardEvent`): Files were pasted, like a screenshot, or text and tokens into a token input.
847
+ - `drop` (`DragEvent`): Files were dropped on a drop zone, or text and tokens on a token input.
848
+ - `cut` (`ClipboardEvent`): A selection was cut from a token input.
849
+ - `undo` (`KeyboardEvent | InputEvent`): Undo, from the keyboard, the Edit menu or a controller.
850
+ - `redo` (`KeyboardEvent | InputEvent`): Redo, from the keyboard, the Edit menu or a controller.
851
+ - `remove-press` (`MouseEvent | KeyboardEvent`): A chip's remove part was pressed, or Backspace or Delete removed a chip or a span.
852
+ - `item-press` (`MouseEvent | KeyboardEvent`): A member of a collection was chosen: a menu item, a tab, a radio or a checkbox item.
853
+ - `reset` (`none`): A form reset.
854
+ - `restore` (`none`): The browser restored state, like after going back, or a saved value was read back from storage.
855
+ - `imperative` (`none`): A controller or `api` call, or a property set on a web component.
856
+
857
+ ### Controller
858
+
859
+ Create one with `createTokenInputController()` and pass it as `controller`.
860
+
861
+ - `getValue()` (`() => TokenInputValue`): The value: text and tokens.
862
+ - `setValue(value, options?)` (`(value: TokenInputValue, options?: TokenInputChangeOptions | undefined) => boolean`): Replaces the value as one undoable step. Returns false when the change was canceled or nothing changed.
863
+ - `getText(codec?)` (`(codec?: TokenCodec | undefined) => string`): The value as codec text, like `Ask [@Ada](mention:ada)`.
864
+ - `getLabel()` (`() => string`): The value as people read it, with each token's label.
865
+ - `insert(content, options?)` (`(content: string | Token | TokenInputValue, options?: (TokenInputChangeOptions & { at?: TextRange | "caret" | "end" | undefined; resolve?: PromiseLike<...> | undefined; }) | undefined) => boolean`): Inserts text, a token or a value at the caret, the end or a range, as one undoable step. With `resolve`, a token is pending until it settles: updated with what it resolves to, removed if it rejects. Returns false when the change was canceled.
866
+ - `updateToken(id, patch)` (`(id: string, patch: Partial<Omit<Token, "id">>) => boolean`): Changes a token's status, data or label without an undo step or a caret move. Returns false when there's no such token or nothing changed.
867
+ - `removeToken(id, options?)` (`(id: string, options?: TokenInputChangeOptions | undefined) => boolean`): Removes a token as one undoable step. Returns false when the change was canceled or nothing changed.
868
+ - `undo()` (`() => boolean`): Undoes the last step. Returns false when there was none or the change was canceled.
869
+ - `redo()` (`() => boolean`): Redoes the last undone step. Returns false when there was none or the change was canceled.
870
+ - `canUndo()` (`() => boolean`): Whether there's a step to undo.
871
+ - `canRedo()` (`() => boolean`): Whether there's a step to redo.
872
+ - `clear(options?)` (`(options?: TokenInputChangeOptions | undefined) => boolean`): Empties the input as one undoable step. Returns false when the change was canceled or nothing changed.
873
+ - `focus(options?)` (`(options?: { at?: "end" | "start" | undefined; } | undefined) => void`): Focuses the editor, with the caret at its start or end.
874
+ - `editor` (`TextEditorAdapter`): The editor a TriggerMenu outside the token input reads and writes. A menu inside it finds it on its own.
875
+
876
+ ### Events
877
+
878
+ Events get the new state first, then the details. `v-model` only updates when the change event wasn't canceled.
879
+
880
+ | Binding | On | Receives |
881
+ | --------------- | ------------ | -------------------------------------------------------------------------------- |
882
+ | `v-model:value` | `TokenInput` | The value |
883
+ | `@value-change` | `TokenInput` | `(value, details)`: the value, the [reason](#reasons), `inputType` and `removed` |
884
+ | `@submit` | `TokenInput` | `(value, details)`: the value, and the key press or menu choice that submitted |
885
+
886
+ ## Accessibility
887
+
888
+ The editor is a multiline text box: it has the `textbox` role with `aria-multiline`, and a Trigger Menu inside it adds `aria-autocomplete` and `aria-haspopup` for its suggestions. Give it a visible label through a [Field](./field.md), or an `aria-label`. Each token reads as its label and its kind, like "routes.ts file", and inserting or removing one is announced. Typing keeps the browser's spelling, autocorrect, and input method support.
889
+
890
+ ### Keyboard
891
+
892
+ | Key | Does |
893
+ | ---------------------------- | ----------------------------------------------------------------------------- |
894
+ | Backspace, Delete | Removes the token before or after the caret, as `token-deletion` says |
895
+ | ArrowLeft, ArrowRight | Moves the caret past a token in one press; the caret never stops inside one |
896
+ | Enter | Submits. While a trigger menu is open, chooses the highlighted suggestion |
897
+ | Shift+Enter | Starts a new line |
898
+ | Command+Enter, Control+Enter | Submits when `submit-shortcut` is `"mod+enter"`; Enter then starts a new line |
899
+ | Command+Z, Control+Z | Undoes the last step. Typing is grouped; pastes and token changes are steps |
900
+ | Shift+Command+Z, Control+Y | Redoes the last undone step |
901
+
902
+ ### Tested Behavior
903
+
904
+ Every line below is an automated test.
905
+
906
+ **Value**
907
+
908
+ - Renders text and tokens, each token as one chip.
909
+ - Tokens it starts with show their rendered content once, and read as their label and kind.
910
+ - Tokens and their remove parts mark a read-only or disabled input.
911
+ - Is empty with a placeholder until something is typed.
912
+ - Typing after a token goes after it.
913
+ - Shift+Enter starts a new line.
914
+
915
+ **Tokens**
916
+
917
+ - @ opens the menu inside the input, and choosing inserts a token and a space.
918
+ - A controlled input takes tokens from its menu and keeps typing in order.
919
+ - Enter in an open menu chooses and doesn't submit.
920
+ - One Backspace removes a whole token, and says so.
921
+ - Backspace removes tokens one by one, with no keystroke spent on anchors.
922
+ - Delete removes the token after the caret.
923
+ - The caret crosses a token with one arrow press each way.
924
+ - The caret can sit between two adjacent tokens.
925
+ - Clicking past a final token and typing lands after it.
926
+ - Word deletion stops at a token.
927
+ - The remove button removes its token and keeps focus.
928
+ - With tokenDeletion select, the first Backspace selects the token and the second removes it.
929
+ - With tokenDeletion revert, Backspace turns the token back into text and the menu opens on it.
930
+
931
+ **History**
932
+
933
+ - Undo and Redo step through edits, a token insertion on its own.
934
+ - Undo brings back a removed token.
935
+ - A pending token shows loading, then settles without an undo step.
936
+ - A pending token whose load fails is removed.
937
+
938
+ **Clipboard**
939
+
940
+ - Copying tokens into plain text and back keeps them.
941
+ - Copy writes codec text and HTML with the tokens.
942
+ - Pasting codec text makes tokens.
943
+ - With copy label, plain text gets what people read.
944
+
945
+ **Submit**
946
+
947
+ - Enter submits the codec text.
948
+ - With mod+enter, Enter is a new line and Cmd or Ctrl+Enter submits.
949
+ - A form submits the codec text under the input's name.
950
+ - Enter submits the form the input's form attribute names, not the one it's in.
951
+ - Enter while an input method composes doesn't submit.
952
+
953
+ Runs in React, Vue and web components.