@visulima/tui-kit 0.0.0 → 1.0.0

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 (371) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE.md +2095 -0
  3. package/README.md +115 -29
  4. package/dist/accordion.d.ts +59 -0
  5. package/dist/accordion.js +1 -0
  6. package/dist/alert.d.ts +26 -0
  7. package/dist/alert.js +1 -0
  8. package/dist/animate-presence.d.ts +18 -0
  9. package/dist/animate-presence.js +1 -0
  10. package/dist/approval-prompt.d.ts +65 -0
  11. package/dist/approval-prompt.js +1 -0
  12. package/dist/area-chart.d.ts +66 -0
  13. package/dist/area-chart.js +1 -0
  14. package/dist/badge.d.ts +22 -0
  15. package/dist/badge.js +1 -0
  16. package/dist/bar-chart.d.ts +67 -0
  17. package/dist/bar-chart.js +1 -0
  18. package/dist/big-text.d.ts +81 -0
  19. package/dist/big-text.js +1 -0
  20. package/dist/blink-dot.d.ts +36 -0
  21. package/dist/blink-dot.js +1 -0
  22. package/dist/breadcrumb.d.ts +33 -0
  23. package/dist/breadcrumb.js +1 -0
  24. package/dist/button.d.ts +45 -0
  25. package/dist/button.js +1 -0
  26. package/dist/calendar.d.ts +72 -0
  27. package/dist/calendar.js +1 -0
  28. package/dist/card.d.ts +57 -0
  29. package/dist/card.js +1 -0
  30. package/dist/checkbox-group.d.ts +59 -0
  31. package/dist/checkbox-group.js +1 -0
  32. package/dist/checkbox.d.ts +48 -0
  33. package/dist/checkbox.js +1 -0
  34. package/dist/code.d.ts +48 -0
  35. package/dist/code.js +2 -0
  36. package/dist/collapsible.d.ts +53 -0
  37. package/dist/collapsible.js +1 -0
  38. package/dist/color-picker.d.ts +71 -0
  39. package/dist/color-picker.js +1 -0
  40. package/dist/command-block.d.ts +47 -0
  41. package/dist/command-block.js +4 -0
  42. package/dist/command-palette.d.ts +82 -0
  43. package/dist/command-palette.js +1 -0
  44. package/dist/confirm-dialog.d.ts +75 -0
  45. package/dist/confirm-dialog.js +1 -0
  46. package/dist/confirm-input.d.ts +38 -0
  47. package/dist/confirm-input.js +1 -0
  48. package/dist/console-overlay.d.ts +54 -0
  49. package/dist/console-overlay.js +1 -0
  50. package/dist/content-switcher.d.ts +57 -0
  51. package/dist/content-switcher.js +1 -0
  52. package/dist/controlled-scroll-view.d.ts +3 -0
  53. package/dist/controlled-scroll-view.js +1 -0
  54. package/dist/data-grid.d.ts +49 -0
  55. package/dist/data-grid.js +1 -0
  56. package/dist/date-picker.d.ts +65 -0
  57. package/dist/date-picker.js +1 -0
  58. package/dist/definition-list.d.ts +44 -0
  59. package/dist/definition-list.js +1 -0
  60. package/dist/dialog.d.ts +110 -0
  61. package/dist/dialog.js +1 -0
  62. package/dist/diff-view.d.ts +85 -0
  63. package/dist/diff-view.js +1 -0
  64. package/dist/digits.d.ts +30 -0
  65. package/dist/digits.js +1 -0
  66. package/dist/directory-tree.d.ts +51 -0
  67. package/dist/directory-tree.js +1 -0
  68. package/dist/divider.d.ts +49 -0
  69. package/dist/divider.js +1 -0
  70. package/dist/drawer.d.ts +53 -0
  71. package/dist/drawer.js +1 -0
  72. package/dist/file-change.d.ts +40 -0
  73. package/dist/file-change.js +1 -0
  74. package/dist/file-picker-entry.d.ts +2 -0
  75. package/dist/file-picker-entry.js +1 -0
  76. package/dist/form.d.ts +81 -0
  77. package/dist/form.js +1 -0
  78. package/dist/gauge.d.ts +87 -0
  79. package/dist/gauge.js +1 -0
  80. package/dist/gradient.d.ts +42 -0
  81. package/dist/gradient.js +1 -0
  82. package/dist/grid.d.ts +40 -0
  83. package/dist/grid.js +1 -0
  84. package/dist/heading.d.ts +33 -0
  85. package/dist/heading.js +1 -0
  86. package/dist/heatmap.d.ts +62 -0
  87. package/dist/heatmap.js +1 -0
  88. package/dist/help.d.ts +52 -0
  89. package/dist/help.js +1 -0
  90. package/dist/histogram.d.ts +62 -0
  91. package/dist/histogram.js +1 -0
  92. package/dist/image.d.ts +26 -0
  93. package/dist/image.js +1 -0
  94. package/dist/index.d.ts +125 -0
  95. package/dist/index.js +1 -0
  96. package/dist/json.d.ts +58 -0
  97. package/dist/json.js +1 -0
  98. package/dist/kbd.d.ts +31 -0
  99. package/dist/kbd.js +1 -0
  100. package/dist/line-chart.d.ts +109 -0
  101. package/dist/line-chart.js +1 -0
  102. package/dist/link.d.ts +38 -0
  103. package/dist/link.js +1 -0
  104. package/dist/loading-indicator.d.ts +29 -0
  105. package/dist/loading-indicator.js +1 -0
  106. package/dist/log.d.ts +38 -0
  107. package/dist/log.js +1 -0
  108. package/dist/markdown.d.ts +40 -0
  109. package/dist/markdown.js +1 -0
  110. package/dist/masked-input.d.ts +50 -0
  111. package/dist/masked-input.js +1 -0
  112. package/dist/menu.d.ts +78 -0
  113. package/dist/menu.js +1 -0
  114. package/dist/message-bubble.d.ts +43 -0
  115. package/dist/message-bubble.js +1 -0
  116. package/dist/model-badge.d.ts +39 -0
  117. package/dist/model-badge.js +1 -0
  118. package/dist/model-selector.d.ts +52 -0
  119. package/dist/model-selector.js +1 -0
  120. package/dist/multi-progress.d.ts +55 -0
  121. package/dist/multi-progress.js +1 -0
  122. package/dist/multi-select.d.ts +65 -0
  123. package/dist/multi-select.js +1 -0
  124. package/dist/notification-badge.d.ts +47 -0
  125. package/dist/notification-badge.js +1 -0
  126. package/dist/number-input.d.ts +85 -0
  127. package/dist/number-input.js +1 -0
  128. package/dist/operation-tree.d.ts +49 -0
  129. package/dist/operation-tree.js +1 -0
  130. package/dist/option-list.d.ts +47 -0
  131. package/dist/option-list.js +1 -0
  132. package/dist/ordered-list.d.ts +24 -0
  133. package/dist/ordered-list.js +1 -0
  134. package/dist/packem_shared/ControlledScrollView-BzlbIUph.js +1 -0
  135. package/dist/packem_shared/FilePicker-V5H2fb-v.js +1 -0
  136. package/dist/packem_shared/ScrollBar-C9i3z3Ft.js +1 -0
  137. package/dist/packem_shared/ScrollBarBox-DZEC8YnV.js +1 -0
  138. package/dist/packem_shared/ScrollList-Djtb2vVy.js +1 -0
  139. package/dist/packem_shared/ScrollView-ESxpl6Hy.js +1 -0
  140. package/dist/packem_shared/TreeNodeMap-cJlYqckB.js +1 -0
  141. package/dist/packem_shared/TreeView-q0l446NV.js +1 -0
  142. package/dist/packem_shared/controlled-scroll-view-DerVKKv6.js +1 -0
  143. package/dist/packem_shared/controlled-scroll-view.d-vF4wevEJ.d.ts +54 -0
  144. package/dist/packem_shared/file-picker.d-Cie6aAMD.d.ts +104 -0
  145. package/dist/packem_shared/line-chart-BbhMhcZg.js +1 -0
  146. package/dist/packem_shared/scroll-bar-box.d-DSBbBsRc.d.ts +30 -0
  147. package/dist/packem_shared/scroll-bar.d-B4sD1hBR.d.ts +18 -0
  148. package/dist/packem_shared/scroll-list.d-BP0UZSY4.d.ts +12 -0
  149. package/dist/packem_shared/scroll-view.d-BqKpI-F-.d.ts +119 -0
  150. package/dist/packem_shared/treeViewTheme-Dq3ekRAC.js +1 -0
  151. package/dist/packem_shared/use-tree-view.d-dXTKoDPM.d.ts +350 -0
  152. package/dist/packem_shared/useTreeView-D0JEqT6W.js +1 -0
  153. package/dist/packem_shared/useTreeViewState-BiTJakkh.js +1 -0
  154. package/dist/packem_shared/variant-config-BJqpNo7H.js +1 -0
  155. package/dist/packem_shared/variant-config.d-D5NnrrQK.d.ts +2 -0
  156. package/dist/paginator.d.ts +69 -0
  157. package/dist/paginator.js +1 -0
  158. package/dist/paragraph.d.ts +38 -0
  159. package/dist/paragraph.js +1 -0
  160. package/dist/path-input.d.ts +67 -0
  161. package/dist/path-input.js +1 -0
  162. package/dist/pie-chart.d.ts +50 -0
  163. package/dist/pie-chart.js +1 -0
  164. package/dist/placeholder.d.ts +55 -0
  165. package/dist/placeholder.js +1 -0
  166. package/dist/popover.d.ts +46 -0
  167. package/dist/popover.js +1 -0
  168. package/dist/progress-bar.d.ts +51 -0
  169. package/dist/progress-bar.js +1 -0
  170. package/dist/progress-circle.d.ts +59 -0
  171. package/dist/progress-circle.js +1 -0
  172. package/dist/qr-code.d.ts +45 -0
  173. package/dist/qr-code.js +1 -0
  174. package/dist/r/accordion.json +24 -0
  175. package/dist/r/alert.json +24 -0
  176. package/dist/r/animate-presence.json +22 -0
  177. package/dist/r/approval-prompt.json +24 -0
  178. package/dist/r/area-chart.json +27 -0
  179. package/dist/r/badge.json +24 -0
  180. package/dist/r/bar-chart.json +24 -0
  181. package/dist/r/big-text.json +23 -0
  182. package/dist/r/blink-dot.json +24 -0
  183. package/dist/r/breadcrumb.json +24 -0
  184. package/dist/r/button.json +24 -0
  185. package/dist/r/calendar.json +24 -0
  186. package/dist/r/card.json +26 -0
  187. package/dist/r/chart-utils.json +24 -0
  188. package/dist/r/checkbox-group.json +24 -0
  189. package/dist/r/checkbox.json +24 -0
  190. package/dist/r/code.json +23 -0
  191. package/dist/r/collapsible.json +24 -0
  192. package/dist/r/color-picker.json +24 -0
  193. package/dist/r/command-block.json +26 -0
  194. package/dist/r/command-palette.json +24 -0
  195. package/dist/r/confirm-dialog.json +24 -0
  196. package/dist/r/confirm-input.json +22 -0
  197. package/dist/r/console-overlay.json +22 -0
  198. package/dist/r/content-switcher.json +24 -0
  199. package/dist/r/controlled-scroll-view.json +24 -0
  200. package/dist/r/data-grid.json +24 -0
  201. package/dist/r/date-picker.json +26 -0
  202. package/dist/r/definition-list.json +24 -0
  203. package/dist/r/dialog.json +24 -0
  204. package/dist/r/diff-view.json +24 -0
  205. package/dist/r/digits.json +24 -0
  206. package/dist/r/directory-tree.json +24 -0
  207. package/dist/r/divider.json +24 -0
  208. package/dist/r/drawer.json +24 -0
  209. package/dist/r/file-change.json +24 -0
  210. package/dist/r/file-picker.json +44 -0
  211. package/dist/r/form.json +24 -0
  212. package/dist/r/gauge.json +24 -0
  213. package/dist/r/gradient.json +24 -0
  214. package/dist/r/grid.json +22 -0
  215. package/dist/r/heading.json +24 -0
  216. package/dist/r/heatmap.json +24 -0
  217. package/dist/r/help.json +22 -0
  218. package/dist/r/histogram.json +26 -0
  219. package/dist/r/image.json +24 -0
  220. package/dist/r/json.json +24 -0
  221. package/dist/r/kbd.json +24 -0
  222. package/dist/r/line-chart.json +26 -0
  223. package/dist/r/link.json +23 -0
  224. package/dist/r/loading-indicator.json +27 -0
  225. package/dist/r/log.json +24 -0
  226. package/dist/r/markdown.json +29 -0
  227. package/dist/r/masked-input.json +22 -0
  228. package/dist/r/menu.json +24 -0
  229. package/dist/r/message-bubble.json +24 -0
  230. package/dist/r/model-badge.json +24 -0
  231. package/dist/r/model-selector.json +24 -0
  232. package/dist/r/multi-progress.json +24 -0
  233. package/dist/r/multi-select.json +24 -0
  234. package/dist/r/notification-badge.json +24 -0
  235. package/dist/r/number-input.json +24 -0
  236. package/dist/r/operation-tree.json +26 -0
  237. package/dist/r/option-list.json +24 -0
  238. package/dist/r/ordered-list.json +22 -0
  239. package/dist/r/paginator.json +22 -0
  240. package/dist/r/paragraph.json +24 -0
  241. package/dist/r/path-input.json +26 -0
  242. package/dist/r/pie-chart.json +24 -0
  243. package/dist/r/placeholder.json +24 -0
  244. package/dist/r/popover.json +24 -0
  245. package/dist/r/progress-bar.json +22 -0
  246. package/dist/r/progress-circle.json +24 -0
  247. package/dist/r/qr-code.json +24 -0
  248. package/dist/r/radio-group.json +24 -0
  249. package/dist/r/registry.json +1051 -0
  250. package/dist/r/scatter-plot.json +27 -0
  251. package/dist/r/scroll-bar-box.json +24 -0
  252. package/dist/r/scroll-bar.json +24 -0
  253. package/dist/r/scroll-list.json +24 -0
  254. package/dist/r/scroll-view.json +24 -0
  255. package/dist/r/scroll.json +58 -0
  256. package/dist/r/search-input.json +26 -0
  257. package/dist/r/select-input-indicator.json +24 -0
  258. package/dist/r/select-input-item.json +24 -0
  259. package/dist/r/select-input.json +28 -0
  260. package/dist/r/shimmer-text.json +24 -0
  261. package/dist/r/sidebar.json +24 -0
  262. package/dist/r/slider.json +24 -0
  263. package/dist/r/sparkline.json +24 -0
  264. package/dist/r/spinner.json +23 -0
  265. package/dist/r/status-line.json +24 -0
  266. package/dist/r/status-message.json +24 -0
  267. package/dist/r/stepper.json +24 -0
  268. package/dist/r/stopwatch.json +22 -0
  269. package/dist/r/streaming-text.json +24 -0
  270. package/dist/r/switch.json +24 -0
  271. package/dist/r/tab.json +22 -0
  272. package/dist/r/table.json +23 -0
  273. package/dist/r/tabs.json +26 -0
  274. package/dist/r/tag-input.json +24 -0
  275. package/dist/r/tag.json +24 -0
  276. package/dist/r/text-input.json +22 -0
  277. package/dist/r/textarea.json +22 -0
  278. package/dist/r/thinking-block.json +24 -0
  279. package/dist/r/time-picker.json +24 -0
  280. package/dist/r/timer.json +22 -0
  281. package/dist/r/toast.json +24 -0
  282. package/dist/r/token-usage.json +24 -0
  283. package/dist/r/tool-call.json +24 -0
  284. package/dist/r/tooltip.json +24 -0
  285. package/dist/r/transition.json +22 -0
  286. package/dist/r/tree-select.json +24 -0
  287. package/dist/r/tree-view.json +64 -0
  288. package/dist/r/unordered-list.json +22 -0
  289. package/dist/r/use-linked-scroll.json +24 -0
  290. package/dist/r/variant-config.json +22 -0
  291. package/dist/radio-group.d.ts +74 -0
  292. package/dist/radio-group.js +1 -0
  293. package/dist/scatter-plot.d.ts +35 -0
  294. package/dist/scatter-plot.js +1 -0
  295. package/dist/scroll-bar-box.d.ts +3 -0
  296. package/dist/scroll-bar-box.js +1 -0
  297. package/dist/scroll-bar.d.ts +3 -0
  298. package/dist/scroll-bar.js +1 -0
  299. package/dist/scroll-list.d.ts +4 -0
  300. package/dist/scroll-list.js +1 -0
  301. package/dist/scroll-view.d.ts +3 -0
  302. package/dist/scroll-view.js +1 -0
  303. package/dist/search-input.d.ts +55 -0
  304. package/dist/search-input.js +1 -0
  305. package/dist/select-input-indicator.d.ts +32 -0
  306. package/dist/select-input-indicator.js +1 -0
  307. package/dist/select-input-item.d.ts +41 -0
  308. package/dist/select-input-item.js +1 -0
  309. package/dist/select-input.d.ts +110 -0
  310. package/dist/select-input.js +1 -0
  311. package/dist/shimmer-text.d.ts +47 -0
  312. package/dist/shimmer-text.js +1 -0
  313. package/dist/sidebar.d.ts +47 -0
  314. package/dist/sidebar.js +1 -0
  315. package/dist/slider.d.ts +103 -0
  316. package/dist/slider.js +1 -0
  317. package/dist/sparkline.d.ts +42 -0
  318. package/dist/sparkline.js +1 -0
  319. package/dist/spinner.d.ts +17 -0
  320. package/dist/spinner.js +1 -0
  321. package/dist/status-line.d.ts +37 -0
  322. package/dist/status-line.js +1 -0
  323. package/dist/status-message.d.ts +21 -0
  324. package/dist/status-message.js +1 -0
  325. package/dist/stepper.d.ts +48 -0
  326. package/dist/stepper.js +1 -0
  327. package/dist/stopwatch.d.ts +49 -0
  328. package/dist/stopwatch.js +1 -0
  329. package/dist/streaming-text.d.ts +46 -0
  330. package/dist/streaming-text.js +1 -0
  331. package/dist/switch.d.ts +55 -0
  332. package/dist/switch.js +1 -0
  333. package/dist/tab.d.ts +19 -0
  334. package/dist/tab.js +1 -0
  335. package/dist/table.d.ts +119 -0
  336. package/dist/table.js +1 -0
  337. package/dist/tabs.d.ts +107 -0
  338. package/dist/tabs.js +1 -0
  339. package/dist/tag-input.d.ts +71 -0
  340. package/dist/tag-input.js +1 -0
  341. package/dist/tag.d.ts +35 -0
  342. package/dist/tag.js +1 -0
  343. package/dist/text-input.d.ts +48 -0
  344. package/dist/text-input.js +1 -0
  345. package/dist/textarea.d.ts +68 -0
  346. package/dist/textarea.js +2 -0
  347. package/dist/thinking-block.d.ts +57 -0
  348. package/dist/thinking-block.js +1 -0
  349. package/dist/time-picker.d.ts +67 -0
  350. package/dist/time-picker.js +1 -0
  351. package/dist/timer.d.ts +59 -0
  352. package/dist/timer.js +1 -0
  353. package/dist/toast.d.ts +49 -0
  354. package/dist/toast.js +1 -0
  355. package/dist/token-usage.d.ts +50 -0
  356. package/dist/token-usage.js +1 -0
  357. package/dist/tool-call.d.ts +33 -0
  358. package/dist/tool-call.js +1 -0
  359. package/dist/tooltip.d.ts +43 -0
  360. package/dist/tooltip.js +1 -0
  361. package/dist/transition.d.ts +74 -0
  362. package/dist/transition.js +1 -0
  363. package/dist/tree-select.d.ts +65 -0
  364. package/dist/tree-select.js +1 -0
  365. package/dist/tree-view-entry.d.ts +4 -0
  366. package/dist/tree-view-entry.js +1 -0
  367. package/dist/unordered-list.d.ts +30 -0
  368. package/dist/unordered-list.js +1 -0
  369. package/dist/use-linked-scroll.d.ts +42 -0
  370. package/dist/use-linked-scroll.js +1 -0
  371. package/package.json +553 -7
@@ -0,0 +1,48 @@
1
+ import { AnsiColors } from '@visulima/colorize';
2
+ import { ReactNode, ReactElement } from 'react';
3
+ import { LiteralUnion } from 'type-fest';
4
+ type StepStatus = "active" | "completed" | "error" | "pending";
5
+ type StepperStep = {
6
+ readonly description?: string;
7
+ readonly key?: string;
8
+ readonly label: ReactNode;
9
+ readonly status?: StepStatus;
10
+ };
11
+ type Props = {
12
+ /**
13
+ * Color used for active and completed steps.
14
+ * @default "blue"
15
+ */
16
+ readonly accentColor?: LiteralUnion<AnsiColors, string>;
17
+ /**
18
+ * Index of the current step (used when steps do not provide a status).
19
+ * @default 0
20
+ */
21
+ readonly activeIndex?: number;
22
+ /**
23
+ * Color used for errors.
24
+ * @default "red"
25
+ */
26
+ readonly errorColor?: LiteralUnion<AnsiColors, string>;
27
+ /**
28
+ * Orientation of the stepper.
29
+ * @default "horizontal"
30
+ */
31
+ readonly orientation?: "horizontal" | "vertical";
32
+ /**
33
+ * List of steps.
34
+ */
35
+ readonly steps: ReadonlyArray<StepperStep>;
36
+ };
37
+ /**
38
+ * Step indicator for multi-stage flows.
39
+ * @returns A `ReactElement` rendering the steps horizontally or vertically.
40
+ */
41
+ declare function Stepper({
42
+ accentColor,
43
+ activeIndex,
44
+ errorColor,
45
+ orientation,
46
+ steps
47
+ }: Props): ReactElement;
48
+ export { Props, StepStatus, Stepper, type Props as StepperProps, StepperStep, Stepper as default };
@@ -0,0 +1 @@
1
+ import{jsx as i,jsxs as d}from"react/jsx-runtime";import n from"@visulima/tui/components/box";import l from"@visulima/tui/components/text";import{Fragment as v}from"react";const s={active:"●",completed:"✔",error:"✖",pending:"○"},u=(t,c,m)=>t.status!==void 0?t.status:c<m?"completed":c===m?"active":"pending";function y({accentColor:t="blue",activeIndex:c=0,errorColor:m="red",orientation:g="horizontal",steps:p}){return g==="vertical"?i(n,{flexDirection:"column",children:p.map((r,o)=>{const e=u(r,o,c),a=o===p.length-1,h=e==="error"?m:e==="pending"?void 0:t;return d(n,{flexDirection:"column",children:[d(n,{children:[d(l,{color:h,dimColor:e==="pending",children:[s[e]," "]}),i(l,{bold:e==="active",color:h,dimColor:e==="pending",children:r.label})]}),r.description===void 0?void 0:i(n,{marginLeft:2,children:i(l,{dimColor:!0,children:r.description})}),a?void 0:i(n,{marginLeft:0,children:i(l,{dimColor:!0,children:"│"})})]},r.key??o)})}):i(n,{children:p.map((r,o)=>{const e=u(r,o,c),a=e==="error"?m:e==="pending"?void 0:t,h=o===p.length-1;return d(v,{children:[d(n,{children:[d(l,{color:a,dimColor:e==="pending",children:[s[e]," "]}),i(l,{bold:e==="active",color:a,dimColor:e==="pending",children:r.label})]}),h?void 0:i(l,{dimColor:!0,children:" ── "})]},r.key??o)})})}export{y as Stepper,y as default};
@@ -0,0 +1,49 @@
1
+ import { UseStopwatchResult } from '@visulima/tui/hooks/use-stopwatch';
2
+ import { Ref, ReactElement } from 'react';
3
+ type StopwatchRef = Omit<UseStopwatchResult, "elapsed" | "isRunning" | "laps">;
4
+ type Props = {
5
+ /**
6
+ * Whether to start counting immediately.
7
+ * @default false
8
+ */
9
+ readonly autoStart?: boolean;
10
+ /**
11
+ * Make the rendered text bold.
12
+ */
13
+ readonly bold?: boolean;
14
+ /**
15
+ * Text color for the rendered time.
16
+ */
17
+ readonly color?: string;
18
+ /**
19
+ * Custom formatter for the elapsed time.
20
+ * Receives elapsed milliseconds, returns a display string.
21
+ * @default formatDuration (MM:SS or HH:MM:SS)
22
+ */
23
+ readonly format?: (elapsed: number) => string;
24
+ /**
25
+ * Tick interval in milliseconds.
26
+ * @default 1000
27
+ */
28
+ readonly interval?: number;
29
+ readonly ref?: Ref<StopwatchRef>;
30
+ };
31
+ /**
32
+ * A count-up stopwatch component.
33
+ *
34
+ * Exposes `start`, `stop`, `toggle`, `reset`, and `lap` methods via ref.
35
+ *
36
+ * ```tsx
37
+ * const ref = useRef&lt;StopwatchRef>(null);
38
+ * &lt;Stopwatch ref={ref} autoStart />
39
+ * ```
40
+ */
41
+ declare const Stopwatch: ({
42
+ autoStart,
43
+ bold,
44
+ color,
45
+ format,
46
+ interval,
47
+ ref
48
+ }: Props) => ReactElement;
49
+ export { Props, Stopwatch, type Props as StopwatchProps, StopwatchRef, Stopwatch as default };
@@ -0,0 +1 @@
1
+ import{jsx as p}from"react/jsx-runtime";import m from"@visulima/tui/components/text";import i from"@visulima/tui/hooks/use-stopwatch";import{formatDuration as f}from"@visulima/tui/utils";import{useImperativeHandle as n}from"react";const S=({autoStart:o,bold:r,color:e,format:a=f,interval:l,ref:s})=>{const t=i({autoStart:o,interval:l});return n(s,()=>({lap:t.lap,reset:t.reset,start:t.start,stop:t.stop,toggle:t.toggle}),[t.lap,t.reset,t.start,t.stop,t.toggle]),p(m,{bold:r,color:e,children:a(t.elapsed)})};export{S as Stopwatch,S as default};
@@ -0,0 +1,46 @@
1
+ import { AnsiColors } from '@visulima/colorize';
2
+ import { ReactElement } from 'react';
3
+ import { LiteralUnion } from 'type-fest';
4
+ type Props = {
5
+ /**
6
+ * Color applied to the streamed output.
7
+ */
8
+ readonly color?: LiteralUnion<AnsiColors, string>;
9
+ /**
10
+ * Glyph rendered at the streaming caret while characters are still being revealed.
11
+ * @default "▊" (left three quarters block)
12
+ */
13
+ readonly cursor?: string;
14
+ /**
15
+ * Milliseconds between characters.
16
+ * @default 20
17
+ */
18
+ readonly interval?: number;
19
+ /**
20
+ * Called exactly once per `text` value, after the full text has been revealed.
21
+ */
22
+ readonly onComplete?: () => void;
23
+ /**
24
+ * Whether to display the cursor after streaming completes.
25
+ * @default false
26
+ */
27
+ readonly showCursorWhenDone?: boolean;
28
+ /**
29
+ * Full text to stream into the output.
30
+ */
31
+ readonly text: string;
32
+ };
33
+ /**
34
+ * Typewriter animation that reveals text one character at a time.
35
+ * Automatically resets and replays when `text` changes. `onComplete`
36
+ * fires exactly once per `text` value once it is fully revealed.
37
+ */
38
+ declare function StreamingText({
39
+ color,
40
+ cursor,
41
+ interval,
42
+ onComplete,
43
+ showCursorWhenDone,
44
+ text
45
+ }: Props): ReactElement;
46
+ export { Props, StreamingText, type Props as StreamingTextProps, StreamingText as default };
@@ -0,0 +1 @@
1
+ import{jsxs as x}from"react/jsx-runtime";import d from"@visulima/tui/components/text";import{useState as T,useRef as c,useEffect as i}from"react";function v({color:l,cursor:f="▊",interval:o=20,onComplete:n,showCursorWhenDone:a=!1,text:r}){const[t,s]=T(0),u=c(n),e=c(!1);u.current=n,i(()=>{s(0),e.current=!1},[r]),i(()=>{if(t>=r.length){e.current||(e.current=!0,u.current?.());return}const p=setTimeout(()=>{s(g=>Math.min(r.length,g+1))},o);return()=>{clearTimeout(p)}},[t,r,o]);const m=!(t>=r.length)||a,h=r.slice(0,t);return x(d,{color:l,children:[h,m?f:""]})}export{v as StreamingText,v as default};
@@ -0,0 +1,55 @@
1
+ import { AnsiColors } from '@visulima/colorize';
2
+ import { ReactNode, ReactElement } from 'react';
3
+ import { LiteralUnion } from 'type-fest';
4
+ type Props = {
5
+ /**
6
+ * Accent color for the on state.
7
+ * @default "green"
8
+ */
9
+ readonly accentColor?: LiteralUnion<AnsiColors, string>;
10
+ /**
11
+ * Auto-focus when mounted if nothing else is focused.
12
+ */
13
+ readonly autoFocus?: boolean;
14
+ /**
15
+ * Optional label rendered after the switch.
16
+ */
17
+ readonly children?: ReactNode;
18
+ /**
19
+ * Initial value when uncontrolled.
20
+ */
21
+ readonly defaultValue?: boolean;
22
+ /**
23
+ * Disable input and dim the switch.
24
+ */
25
+ readonly isDisabled?: boolean;
26
+ /**
27
+ * Labels displayed inside the switch track.
28
+ * @default ["off", "on"]
29
+ */
30
+ readonly labels?: readonly [string, string];
31
+ /**
32
+ * Fired when the switch is toggled.
33
+ */
34
+ readonly onChange?: (value: boolean) => void;
35
+ /**
36
+ * Controlled value. Pair with `onChange` to update the parent.
37
+ */
38
+ readonly value?: boolean;
39
+ };
40
+ /**
41
+ * Focusable on/off switch. Toggles with Space or Enter.
42
+ * @returns A `ReactElement` rendering two labeled segments plus an optional
43
+ * trailing label.
44
+ */
45
+ declare function Switch({
46
+ accentColor,
47
+ autoFocus,
48
+ children,
49
+ defaultValue,
50
+ isDisabled,
51
+ labels,
52
+ onChange,
53
+ value
54
+ }: Props): ReactElement;
55
+ export { Props, Switch, type Props as SwitchProps, Switch as default };
package/dist/switch.js ADDED
@@ -0,0 +1 @@
1
+ import{jsxs as l,jsx as x}from"react/jsx-runtime";import u from"@visulima/tui/components/box";import a from"@visulima/tui/components/text";import F from"@visulima/tui/hooks/use-focus";import j from"@visulima/tui/hooks/use-input";import{useState as y,useCallback as A}from"react";const D=["off","on"];function z({accentColor:e="green",autoFocus:f=!1,children:d,defaultValue:m=!1,isDisabled:r=!1,labels:n=D,onChange:s,value:c}){const{isFocused:i}=F({autoFocus:f,isActive:!r}),[v,p]=y(m),o=c??v;j(A((h,k)=>{if(i&&(k.return||h===" ")){const t=!o;c===void 0&&p(t),s?.(t)}},[i,o,c,s]),{isActive:!r&&i});const C=n[0],b=n[1],g=i?e:void 0;return l(u,{gap:1,children:[l(u,{gap:0,children:[l(a,{backgroundColor:o?void 0:"gray",color:o?void 0:"black",dimColor:r,children:[" ",C," "]}),l(a,{backgroundColor:o?e:void 0,color:o?"black":void 0,dimColor:r,children:[" ",b," "]})]}),d===void 0?void 0:x(a,{color:g,dimColor:r,children:d})]})}export{z as Switch,z as default};
package/dist/tab.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { ReactNode, ReactElement } from 'react';
2
+ type Props = {
3
+ /**
4
+ * Tab content to render when the tab is active.
5
+ */
6
+ readonly children: ReactNode;
7
+ /**
8
+ * Unique name identifying this tab.
9
+ */
10
+ readonly name: string;
11
+ };
12
+ /**
13
+ * A single tab within a Tabs container.
14
+ * The `name` prop identifies the tab; `children` is rendered when active.
15
+ */
16
+ declare function Tab({
17
+ children
18
+ }: Props): ReactElement;
19
+ export { Props, Tab, type Props as TabProps, Tab as default };
package/dist/tab.js ADDED
@@ -0,0 +1 @@
1
+ import{jsx as e,Fragment as n}from"react/jsx-runtime";function a({children:r}){return e(n,{children:r})}export{a as Tab,a as default};
@@ -0,0 +1,119 @@
1
+ import { ReactElement } from 'react';
2
+ interface BorderComponent {
3
+ char: string;
4
+ width: number;
5
+ }
6
+ /**
7
+ * Represents the style of the border for a table or grid.
8
+ */
9
+ interface BorderStyle {
10
+ /** Box vertical character. */
11
+ bodyJoin: BorderComponent;
12
+ /** Box vertical character. */
13
+ bodyLeft: BorderComponent;
14
+ /** Box vertical character. */
15
+ bodyRight: BorderComponent;
16
+ /** Box horizontal character. */
17
+ bottomBody: BorderComponent;
18
+ /** Box bottom join character. */
19
+ bottomJoin: BorderComponent;
20
+ /** Box bottom left character. */
21
+ bottomLeft: BorderComponent;
22
+ /** Box bottom right character. */
23
+ bottomRight: BorderComponent;
24
+ /** Box horizontal character. */
25
+ joinBody: BorderComponent;
26
+ /** Box horizontal join character. */
27
+ joinJoin: BorderComponent;
28
+ /** Box left join character. */
29
+ joinLeft: BorderComponent;
30
+ /** Box right join character. */
31
+ joinRight: BorderComponent;
32
+ /** Box horizontal character. */
33
+ topBody: BorderComponent;
34
+ /** Box top join character. */
35
+ topJoin: BorderComponent;
36
+ /** Box top left character. */
37
+ topLeft: BorderComponent;
38
+ /** Box top right character. */
39
+ topRight: BorderComponent;
40
+ }
41
+ /** Base style properties applicable globally */
42
+ type HorizontalAlignment = "center" | "left" | "right";
43
+ /**
44
+ * Scalar value that can be displayed in a table cell.
45
+ */
46
+ type Scalar = bigint | boolean | number | string | null | undefined;
47
+ /**
48
+ * Dictionary with scalar values, representing a single row of data.
49
+ */
50
+ type ScalarDict = Record<string, Scalar>;
51
+ /**
52
+ * Configuration for a single table column.
53
+ */
54
+ type ColumnConfig<T extends ScalarDict> = {
55
+ /**
56
+ * Horizontal alignment of cell content.
57
+ */
58
+ readonly align?: HorizontalAlignment;
59
+ /**
60
+ * Custom header label. Defaults to the key name.
61
+ */
62
+ readonly header?: string;
63
+ /**
64
+ * Key from the data object to display in this column.
65
+ */
66
+ readonly key: keyof T & string;
67
+ /**
68
+ * Fixed width for this column in characters.
69
+ */
70
+ readonly width?: number;
71
+ };
72
+ type Props<T extends ScalarDict> = {
73
+ /**
74
+ * Border style preset name or a custom `BorderStyle` object from `@visulima/tabular`.
75
+ * @default "default"
76
+ */
77
+ readonly borderStyle?: "ascii" | "block" | "default" | "dots" | "double" | "markdown" | "minimal" | "none" | "rounded" | "thick" | BorderStyle;
78
+ /**
79
+ * Columns to display and their order.
80
+ * Accepts simple key strings or `ColumnConfig` objects for advanced control.
81
+ * If omitted, all keys from the first data item are used.
82
+ */
83
+ readonly columns?: ((keyof T & string) | ColumnConfig<T>)[];
84
+ /**
85
+ * Array of objects to display as rows.
86
+ */
87
+ readonly data: T[];
88
+ /**
89
+ * Format a cell value before rendering. Return a string to display in the cell.
90
+ */
91
+ readonly formatCell?: (value: Scalar, column: keyof T & string, rowIndex: number) => string;
92
+ /**
93
+ * Format a header label before rendering. Return a string to display as the column header.
94
+ */
95
+ readonly formatHeader?: (column: keyof T & string) => string;
96
+ /**
97
+ * Maximum width of the table in characters. Columns will be truncated or wrapped to fit.
98
+ */
99
+ readonly maxWidth?: number;
100
+ /**
101
+ * Cell padding (left and right) in characters.
102
+ * @default 1
103
+ */
104
+ readonly padding?: number;
105
+ /**
106
+ * Whether to show the header row.
107
+ * @default true
108
+ */
109
+ readonly showHeader?: boolean;
110
+ /** Placeholder shown in place of `null` or `undefined` cell values. Defaults to an empty string. */
111
+ readonly skeleton?: string;
112
+ /**
113
+ * Enable word wrap instead of truncation when cells exceed their width.
114
+ * @default false
115
+ */
116
+ readonly wordWrap?: boolean;
117
+ };
118
+ declare const Table: <T extends ScalarDict>(props: Props<T>) => ReactElement;
119
+ export { type ColumnConfig, type Props, type Scalar, type ScalarDict, Table, type ColumnConfig as TableColumnConfig, type Props as TableProps, type Scalar as TableScalar, type ScalarDict as TableScalarDict, Table as default };
package/dist/table.js ADDED
@@ -0,0 +1 @@
1
+ import{jsx as y}from"react/jsx-runtime";import{Table as _}from"@visulima/tabular";import{THICK_BORDER as g,ROUNDED_BORDER as b,NO_BORDER as w,MINIMAL_BORDER as S,MARKDOWN_BORDER as W,DOUBLE_BORDER as C,DOTS_BORDER as H,DEFAULT_BORDER as E,BLOCK_BORDER as I,ASCII_BORDER as L}from"@visulima/tabular/style";import M from"@visulima/tui/components/text";import{useMemo as N}from"react";const x={ascii:L,block:I,default:E,dots:H,double:C,markdown:W,minimal:S,none:w,rounded:b,thick:g},A=t=>typeof t=="string"?{key:t}:t,T=({borderStyle:t="default",columns:d,data:a,formatCell:n,formatHeader:i,maxWidth:f,padding:m=1,showHeader:s=!0,skeleton:u="",wordWrap:D=!1})=>{const h=N(()=>{if(a.length===0)return"";let r;if(d?r=d.map(e=>A(e)):r=Object.keys(a[0]).map(e=>({key:e})),r.length===0)return"";const B=typeof t=="string"?x[t]??E:t,O=r.map(e=>e.width),k=O.some(e=>e!==void 0),R=new _({columnWidths:k?O:void 0,maxWidth:f,showHeader:s,style:{border:B,paddingLeft:m,paddingRight:m},wordWrap:D});if(s){const e=r.map(o=>{const l=o.header??o.key;return i?i(o.key):l});R.setHeaders(e)}for(const[e,o]of a.entries()){const l=r.map(c=>{const p=o[c.key];return n?n(p,c.key,e):p==null?u:String(p)});R.addRow(l)}return R.toString()},[t,d,a,n,i,f,m,s,u,D]);return y(M,{children:h})},q=T;export{q as Table,q as default};
package/dist/tabs.d.ts ADDED
@@ -0,0 +1,107 @@
1
+ import { AnsiColors } from '@visulima/colorize';
2
+ import { ReactNode, ReactElement } from 'react';
3
+ import { LiteralUnion } from 'type-fest';
4
+ import { Props as Props$1 } from "./tab.js";
5
+ /**
6
+ * Keyboard navigation configuration for Tabs.
7
+ */
8
+ type KeyMap = {
9
+ /**
10
+ * Key names that move to the next tab.
11
+ * Defaults to `["rightArrow"]` for row layouts and `["downArrow"]` for column layouts.
12
+ */
13
+ readonly next?: ReadonlyArray<string>;
14
+ /**
15
+ * Key names that move to the previous tab.
16
+ * Defaults to `["leftArrow"]` for row layouts and `["upArrow"]` for column layouts.
17
+ */
18
+ readonly previous?: ReadonlyArray<string>;
19
+ /**
20
+ * Whether Meta/Cmd + 1–9 jumps to a specific tab.
21
+ * @default true
22
+ */
23
+ readonly useNumbers?: boolean;
24
+ /**
25
+ * Whether the Tab key cycles through tabs (only when `isFocused` is not managed by Ink).
26
+ * @default true
27
+ */
28
+ readonly useTab?: boolean;
29
+ };
30
+ /**
31
+ * Color customization for active tab styling.
32
+ */
33
+ type TabColors = {
34
+ readonly activeTab?: {
35
+ readonly backgroundColor?: LiteralUnion<AnsiColors, string>;
36
+ readonly color?: LiteralUnion<AnsiColors, string>;
37
+ };
38
+ };
39
+ type Props = {
40
+ /**
41
+ * Tab elements to render.
42
+ */
43
+ readonly children: ReactNode;
44
+ /**
45
+ * Active tab colors. When `isFocused` is `false`, the active tab uses gray.
46
+ */
47
+ readonly colors?: TabColors;
48
+ /**
49
+ * Name of the tab to select initially (uncontrolled mode).
50
+ * Ignored when `value` is provided.
51
+ */
52
+ readonly defaultValue?: string;
53
+ /**
54
+ * Layout direction for the tab bar.
55
+ * @default "row"
56
+ */
57
+ readonly flexDirection?: "column" | "column-reverse" | "row" | "row-reverse";
58
+ /**
59
+ * Whether the tabs are focused and respond to keyboard input.
60
+ * - `true`: focused, uses active colors.
61
+ * - `false`: unfocused, uses gray active color, ignores input.
62
+ * - `undefined`/`null`: always active (focus not managed by Ink).
63
+ * @default undefined
64
+ */
65
+ readonly isFocused?: boolean | null;
66
+ /**
67
+ * Custom keyboard mappings.
68
+ */
69
+ readonly keyMap?: KeyMap;
70
+ /**
71
+ * Called when the active tab changes.
72
+ */
73
+ readonly onChange: (name: string, activeTab: ReactElement<Props$1>) => void;
74
+ /**
75
+ * Whether to display 1-based index numbers before each tab name.
76
+ * @default true
77
+ */
78
+ readonly showIndex?: boolean;
79
+ /**
80
+ * Controlled active tab name. When provided, the component is controlled —
81
+ * the parent owns the active tab state and must update it via `onChange`.
82
+ * When omitted, the component manages its own state (uncontrolled mode).
83
+ */
84
+ readonly value?: string;
85
+ /**
86
+ * Width of the container Box. Also determines the separator width in column layouts.
87
+ */
88
+ readonly width?: number | string;
89
+ };
90
+ /**
91
+ * Tabbed navigation component. Renders a row or column of tabs with keyboard
92
+ * navigation (arrow keys, Tab, number keys) and calls `onChange` when the
93
+ * active tab changes.
94
+ */
95
+ declare function Tabs({
96
+ children,
97
+ colors: colorsProp,
98
+ defaultValue,
99
+ flexDirection,
100
+ isFocused,
101
+ keyMap: keyMapProp,
102
+ onChange,
103
+ showIndex,
104
+ value,
105
+ width
106
+ }: Props): ReactElement;
107
+ export { KeyMap, Props, TabColors, Tabs, type KeyMap as TabsKeyMap, type Props as TabsProps, Tabs as default };
package/dist/tabs.js ADDED
@@ -0,0 +1 @@
1
+ import{jsx as y,jsxs as A}from"react/jsx-runtime";import I from"@visulima/tui/components/box";import j from"@visulima/tui/components/text";import X from"@visulima/tui/hooks/use-input";import{useRef as D,useState as Y,useCallback as d,useEffect as Z,useMemo as M,Children as _}from"react";const $=/^\d$/u,G=e=>e!=null&&typeof e=="object"&&"props"in e&&"name"in e.props,H=e=>{const t=[];for(const n of _.toArray(e))G(n)&&t.push(n);return t},F=(e,t)=>e.some(n=>t[n]),J=(e,t,n)=>e?t?{backgroundColor:n?.activeTab?.backgroundColor??"green",color:n?.activeTab?.color??"black"}:{backgroundColor:"gray",color:"black"}:{backgroundColor:void 0,color:void 0};function nr({children:e,colors:t,defaultValue:n,flexDirection:f="row",isFocused:b,keyMap:u,onChange:N,showIndex:L=!0,value:x,width:v}){const s=H(e),c=s.length,p=D(s);p.current=s;const l=f==="column"||f==="column-reverse",g=x!==void 0,[O,P]=Y(()=>{const r=x??n;if(r==null||c===0)return 0;const o=s.findIndex(a=>a.props.name===r);return o===-1?0:o}),h=g?Math.max(0,s.findIndex(r=>r.props.name===x)):O,Q=d(()=>{},[]),i=g?Q:P,m=D(N);m.current=N,Z(()=>{if(g)return;const r=p.current[h];r&&m.current(r.props.name,r)},[]);const R=M(()=>u?.previous??[l?"upArrow":"leftArrow"],[u?.previous,l]),S=M(()=>u?.next??[l?"downArrow":"rightArrow"],[u?.next,l]),T=u?.useNumbers??!0,V=u?.useTab??!0,C=D(h);C.current=h;const q=d(r=>{i(r);const o=p.current[r];o&&m.current(o.props.name,o)},[i]),k=d(()=>{const r=(C.current+1)%c;i(r);const o=p.current[r];o&&m.current(o.props.name,o)},[c,i]),w=d(()=>{const r=(C.current-1+c)%c;i(r);const o=p.current[r];o&&m.current(o.props.name,o)},[c,i]);X(d((r,o)=>{if(F(R,o)){w();return}if(F(S,o)){k();return}if(o.tab&&V&&b==null){o.shift?w():k();return}if(T&&o.meta&&$.test(r)){const a=r==="0"?9:Number.parseInt(r,10)-1;a<c&&q(a)}},[R,S,V,T,b,w,k,c,q]),{isActive:b!==!1});const z=typeof v=="number"?v:6,U=M(()=>l?"─".repeat(z):" | ",[l,z]);return y(I,{flexDirection:f,width:v,children:s.map((r,o)=>{const{name:a}=r.props,B=J(h===o,b!==!1,t);let E=null;return L&&(E=A(j,{color:"grey",children:[o+1,"."," "]})),A(I,{flexDirection:f,children:[o!==0&&y(j,{color:"dim",children:U}),A(I,{children:[E,y(j,{backgroundColor:B.backgroundColor,color:B.color,children:r})]})]},a)})})}export{nr as Tabs,nr as default};
@@ -0,0 +1,71 @@
1
+ import { AnsiColors } from '@visulima/colorize';
2
+ import { ReactElement } from 'react';
3
+ import { LiteralUnion } from 'type-fest';
4
+ type Props = {
5
+ /**
6
+ * Accent color for the chips and focused border.
7
+ * @default "blue"
8
+ */
9
+ readonly accentColor?: LiteralUnion<AnsiColors, string>;
10
+ /**
11
+ * Auto-focus on mount.
12
+ */
13
+ readonly autoFocus?: boolean;
14
+ /**
15
+ * Reject duplicate tags (case-sensitive).
16
+ * @default true
17
+ */
18
+ readonly dedupe?: boolean;
19
+ /**
20
+ * Tags present when uncontrolled.
21
+ */
22
+ readonly defaultValue?: ReadonlyArray<string>;
23
+ /**
24
+ * Disable input and dim the display.
25
+ */
26
+ readonly isDisabled?: boolean;
27
+ /**
28
+ * Maximum number of tags. Further input is ignored once reached.
29
+ */
30
+ readonly max?: number;
31
+ /**
32
+ * Fires whenever the set of tags changes.
33
+ */
34
+ readonly onChange?: (tags: ReadonlyArray<string>) => void;
35
+ /**
36
+ * Fires on Enter with an empty draft (i.e. "done adding tags").
37
+ */
38
+ readonly onSubmit?: (tags: ReadonlyArray<string>) => void;
39
+ /**
40
+ * Placeholder shown when there are no tags and no draft.
41
+ * @default "Add tags…"
42
+ */
43
+ readonly placeholder?: string;
44
+ /**
45
+ * Besides Enter, which typed characters commit the current draft (default comma and space).
46
+ */
47
+ readonly separators?: ReadonlyArray<string>;
48
+ /**
49
+ * Controlled tags. When provided, `defaultValue` is ignored.
50
+ */
51
+ readonly value?: ReadonlyArray<string>;
52
+ };
53
+ /**
54
+ * A chip-style multi-value input. Type a tag and press Enter (or a separator)
55
+ * to commit it; Backspace on an empty draft removes the last tag. Renders each
56
+ * committed value as a colored chip followed by the live draft.
57
+ */
58
+ declare function TagInput({
59
+ accentColor,
60
+ autoFocus,
61
+ dedupe,
62
+ defaultValue,
63
+ isDisabled,
64
+ max,
65
+ onChange,
66
+ onSubmit,
67
+ placeholder,
68
+ separators,
69
+ value: controlledValue
70
+ }: Props): ReactElement;
71
+ export { Props, TagInput, type Props as TagInputProps, TagInput as default };
@@ -0,0 +1 @@
1
+ import{jsxs as I,jsx as l}from"react/jsx-runtime";import R from"@visulima/tui/components/box";import c from"@visulima/tui/components/text";import T from"@visulima/tui/hooks/use-focus";import w from"@visulima/tui/hooks/use-input";import{useState as F,useRef as P,useCallback as f}from"react";const V=[],W=[","," "];function H({accentColor:a="blue",autoFocus:S=!1,dedupe:m=!0,defaultValue:A=V,isDisabled:p=!1,max:u,onChange:h,onSubmit:g,placeholder:$="Add tags…",separators:b=W,value:v}){const{isFocused:s}=T({autoFocus:S,isActive:!p}),C=v!==void 0,[j,B]=F(A),[o,n]=F(""),t=v??j,k=P(h);k.current=h;const i=f(e=>{C||B(e),k.current?.(e)},[C]),d=f(e=>{const r=e.trim();if(r.length!==0&&!(u!==void 0&&t.length>=u)){if(m&&t.includes(r)){n("");return}i([...t,r]),n("")}},[m,u,i,t]),D=f((e,r)=>{if(r.return){o.trim().length>0?d(o):g?.(t);return}if((r.backspace||r.delete)&&o.length===0){t.length>0&&i(t.slice(0,-1));return}if(r.backspace||r.delete){n(o.slice(0,-1));return}if(b.includes(e)){d(o);return}e.length>0&&e.codePointAt(0)>=32&&n(`${o}${e}`)},[d,o,g,b,i,t]);w(D,{isActive:s&&!p});const x=t.length===0&&o.length===0;return I(R,{borderColor:s?a:void 0,borderStyle:"round",flexWrap:"wrap",gap:1,paddingX:1,children:[t.map((e,r)=>l(c,{backgroundColor:a,children:` ${e} `},r)),x?l(c,{dimColor:!0,children:$}):l(c,{children:o}),s&&!x?l(c,{color:a,children:"▏"}):void 0]})}export{H as TagInput,H as default};
package/dist/tag.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ import { AnsiColors } from '@visulima/colorize';
2
+ import { ReactNode, ReactElement } from 'react';
3
+ import { LiteralUnion } from 'type-fest';
4
+ type TagVariant = "outline" | "solid" | "subtle";
5
+ type Props = {
6
+ /**
7
+ * Tag content.
8
+ */
9
+ readonly children: ReactNode;
10
+ /**
11
+ * Base color.
12
+ * @default "blue"
13
+ */
14
+ readonly color?: LiteralUnion<AnsiColors, string>;
15
+ /**
16
+ * Optional symbol rendered before the label (e.g. `●`, `✔`, `★`).
17
+ */
18
+ readonly icon?: ReactNode;
19
+ /**
20
+ * Visual style.
21
+ * @default "subtle"
22
+ */
23
+ readonly variant?: TagVariant;
24
+ };
25
+ /**
26
+ * Render a short pill-shaped label.
27
+ * @returns A `ReactElement` rendering the tag in the requested variant.
28
+ */
29
+ declare function Tag({
30
+ children,
31
+ color,
32
+ icon,
33
+ variant
34
+ }: Props): ReactElement;
35
+ export { Props, Tag, type Props as TagProps, TagVariant, Tag as default };
package/dist/tag.js ADDED
@@ -0,0 +1 @@
1
+ import{jsx as e,jsxs as r,Fragment as l}from"react/jsx-runtime";import t from"@visulima/tui/components/box";import n from"@visulima/tui/components/text";function m({children:d,color:i="blue",icon:o,variant:c="subtle"}){return c==="outline"?e(t,{borderColor:i,borderStyle:"round",paddingX:1,children:r(n,{color:i,children:[o===void 0?void 0:r(l,{children:[o," "]}),d]})}):c==="solid"?r(n,{backgroundColor:i,color:"black",children:[" ",o===void 0?void 0:r(l,{children:[o," "]}),d," "]}):r(n,{color:i,children:[o===void 0?void 0:r(l,{children:[o," "]}),d]})}export{m as Tag,m as default};
@@ -0,0 +1,48 @@
1
+ import { ReactElement } from 'react';
2
+ type Props = {
3
+ /** @default "" */
4
+ readonly defaultValue?: string;
5
+ /**
6
+ * When true, all input is ignored and text is dimmed.
7
+ * @default false
8
+ */
9
+ readonly isDisabled?: boolean;
10
+ /**
11
+ * When true, renders asterisks instead of the actual characters.
12
+ * @default false
13
+ */
14
+ readonly mask?: boolean;
15
+ /**
16
+ * Fires on every keystroke with the updated text.
17
+ */
18
+ readonly onChange?: (value: string) => void;
19
+ /**
20
+ * Fires when the user presses Enter.
21
+ */
22
+ readonly onSubmit?: (value: string) => void;
23
+ /**
24
+ * Greyed-out text shown when the input is empty.
25
+ */
26
+ readonly placeholder?: string;
27
+ /**
28
+ * Autocomplete candidates. The first case-sensitive prefix match is shown
29
+ * dimmed after the current input. Press right-arrow or Enter to accept.
30
+ */
31
+ readonly suggestions?: ReadonlyArray<string>;
32
+ };
33
+ /**
34
+ * A single-line text input with cursor navigation, optional placeholder,
35
+ * autocomplete suggestions, and password masking.
36
+ *
37
+ * Supports arrow keys, Home/End, Ctrl+A/E, Ctrl+U/K/W, Backspace, Delete.
38
+ */
39
+ declare function TextInput({
40
+ defaultValue,
41
+ isDisabled,
42
+ mask,
43
+ onChange,
44
+ onSubmit,
45
+ placeholder,
46
+ suggestions
47
+ }: Props): ReactElement;
48
+ export { Props, TextInput, type Props as TextInputProps, TextInput as default };
@@ -0,0 +1 @@
1
+ import{jsx as a,jsxs as w}from"react/jsx-runtime";import I from"@visulima/tui/components/box";import h from"@visulima/tui/components/text";import H from"@visulima/tui/hooks/use-input";import{isInsertableInput as L}from"@visulima/tui/input";import{useState as q,useRef as k,useCallback as N}from"react";const O=/\S+\s*$/,S=(i,r)=>i.length===0||!r?void 0:r.find(t=>t.startsWith(i))?.slice(i.length)??void 0,y=-1,P=(i,r,t,e)=>r.leftArrow?Math.max(0,t-1):r.home||r.ctrl&&i==="a"?0:r.end||r.ctrl&&i==="e"?e:y,V=(i,r,t,e)=>{if(r.backspace&&e>0)return[t.slice(0,e-1)+t.slice(e),e-1];if(r.delete&&e<t.length)return[t.slice(0,e)+t.slice(e+1),e];if(r.ctrl&&i==="u")return[t.slice(e),0];if(r.ctrl&&i==="k")return[t.slice(0,e),e];if(r.ctrl&&i==="w"){const m=t.slice(0,e).replace(O,"");return[m+t.slice(e),m.length]}};function U({defaultValue:i="",isDisabled:r=!1,mask:t=!1,onChange:e,onSubmit:m,placeholder:b,suggestions:v}){const[o,x]=q(i),[d,u]=q(i.length),A=k(o);A.current=o;const D=k(d);D.current=d;const g=k(e);g.current=e;const M=k(m);M.current=m;const j=S(o,v),z=N((p,f)=>{const{current:s}=D,c=A.current;if(f.return){const n=S(c,v),l=n?c+n:c;n&&(x(l),u(l.length),g.current?.(l)),M.current?.(l);return}if(f.escape)return;if(f.rightArrow){const n=S(c,v);if(s===c.length&&n){const l=c+n;x(l),u(l.length),g.current?.(l);return}u(Math.min(c.length,s+1));return}const R=P(p,f,s,c.length);if(R!==y){u(R);return}const $=V(p,f,c,s);if($){const[n,l]=$;x(n),u(l),g.current?.(n);return}if(L(p,f)){const n=c.slice(0,s)+p+c.slice(s);x(n),u(s+p.length),g.current?.(n)}},[v]);H(z,{isActive:!r});const C=t?"*".repeat(o.length):o,B=C.slice(0,d),E=C[d],F=C.slice(d+1);return r?a(I,{children:a(h,{dimColor:!0,children:C||b||""})}):o.length===0&&b?w(I,{children:[a(h,{dimColor:!0,inverse:!0,children:b[0]}),a(h,{dimColor:!0,children:b.slice(1)})]}):w(I,{children:[w(h,{children:[B,a(h,{inverse:!0,children:E??" "}),F]}),j?a(h,{dimColor:!0,children:j}):void 0]})}export{U as TextInput,U as default};