@preset.nz/ux-kit 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -42
- package/THIRD_PARTY_NOTICES.md +253 -0
- package/package.json +13 -13
- package/src/chat/index.ts +9 -0
- package/src/chat/message.tsx +80 -0
- package/src/chat/prompt-input.tsx +121 -0
- package/src/chat/reasoning.tsx +182 -0
- package/src/chat/scroller.tsx +147 -0
- package/src/chat/suggestion.tsx +65 -0
- package/src/chat/tool.tsx +143 -0
- package/src/chat/types.ts +8 -0
- package/src/components/alert-shell.tsx +66 -0
- package/src/components/avatar.tsx +1 -1
- package/src/components/badge.tsx +6 -6
- package/src/components/breadcrumb.tsx +8 -10
- package/src/components/button.tsx +1 -1
- package/src/components/card.tsx +4 -21
- package/src/components/checkbox.tsx +3 -5
- package/src/components/color-field.tsx +20 -7
- package/src/components/color-swatch.tsx +3 -3
- package/src/components/confirm-dialog.tsx +93 -0
- package/src/components/context-menu.tsx +16 -13
- package/src/components/dialog.tsx +8 -9
- package/src/components/download-prompt.tsx +108 -0
- package/src/components/dropdown-menu.tsx +16 -13
- package/src/components/empty-state.tsx +6 -3
- package/src/components/input.tsx +2 -2
- package/src/components/label.tsx +3 -2
- package/src/components/list.tsx +205 -0
- package/src/components/navigation-menu.tsx +17 -10
- package/src/components/number-field.tsx +30 -26
- package/src/components/popover.tsx +6 -10
- package/src/components/progress.tsx +77 -0
- package/src/components/select.tsx +16 -28
- package/src/components/separator.tsx +2 -6
- package/src/components/sheet.tsx +16 -8
- package/src/components/side-panel.tsx +31 -8
- package/src/components/sidebar.tsx +19 -52
- package/src/components/skeleton.tsx +1 -1
- package/src/components/slider.tsx +4 -8
- package/src/components/snackbar.tsx +39 -36
- package/src/components/status-bar.tsx +10 -3
- package/src/components/tabs.tsx +5 -6
- package/src/components/textarea.tsx +2 -2
- package/src/components/toggle-group.tsx +4 -4
- package/src/components/toggle.tsx +3 -1
- package/src/components/toolbar.tsx +8 -11
- package/src/components/tooltip.tsx +1 -1
- package/src/graphics/adsr.ts +21 -13
- package/src/graphics/curve-editor.tsx +56 -14
- package/src/graphics/curve-edits.ts +20 -3
- package/src/graphics/index.ts +6 -6
- package/src/graphics/scale.ts +4 -1
- package/src/graphics/use-canvas.ts +1 -1
- package/src/graphics/use-tokens.ts +4 -1
- package/src/index.css +9 -1
- package/src/index.ts +7 -5
- package/src/lib/use-mobile.ts +1 -1
- package/src/lib/utils.ts +1 -1
- package/src/shadcn-tailwind.css +665 -0
package/README.md
CHANGED
|
@@ -15,44 +15,7 @@ Like [facets](https://github.com/preset-nz/facets), the kit ships unbuilt TypeSc
|
|
|
15
15
|
|
|
16
16
|
## Components
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
| Component | In kit | Came from | Notes |
|
|
21
|
-
|---|---|---|---|
|
|
22
|
-
| button | yes | Strata, Shard, M&T | Base UI Button |
|
|
23
|
-
| checkbox | yes | Strata, Oblique, Shard | |
|
|
24
|
-
| input | yes | all four | |
|
|
25
|
-
| label | yes | Strata, Oblique, Shard | |
|
|
26
|
-
| select | yes | Strata, Oblique, Shard | |
|
|
27
|
-
| separator | yes | all four | |
|
|
28
|
-
| dialog | yes | Oblique, Shard, M&T | Shard's themed variant. `render={<Button />}` replaces `asChild` |
|
|
29
|
-
| sheet | yes | M&T | Base UI Dialog docked to an edge (`side`) |
|
|
30
|
-
| popover | yes | Oblique | `PopoverAnchor` dropped: Base UI anchors through the Positioner's `anchor` prop |
|
|
31
|
-
| tooltip | yes | Oblique, M&T | `TooltipProvider delay` replaces `delayDuration` |
|
|
32
|
-
| tabs | yes | Oblique | `TabsTrigger` / `TabsContent` wrap Base UI `Tab` / `Panel`. Orientation uses `data-[orientation=...]` |
|
|
33
|
-
| toggle | yes | Oblique | `data-pressed` replaces `data-[state=on]` |
|
|
34
|
-
| toggle-group | yes | Oblique | Base UI `value` is always an array and `multiple` replaces `type="single" \| "multiple"` |
|
|
35
|
-
| slider | yes | Oblique, Shard, M&T | Takes a number or an array; one thumb per value |
|
|
36
|
-
| dropdown-menu | yes | Shard, M&T | M&T's fuller variant. `DropdownMenuLabel` is Base UI's `GroupLabel`, so it must sit inside a `DropdownMenuGroup` |
|
|
37
|
-
| context-menu | yes | Shard | Same shape as dropdown-menu, same `Label` caveat |
|
|
38
|
-
| navigation-menu | yes | M&T | Always the shared-viewport form. Radix's `NavigationMenuIndicator` and the `viewport={false}` mode are gone |
|
|
39
|
-
| snackbar | yes | Strata, Oblique | The kit's one toast, on Base UI Toast. `useSnackbar().show({ message, kind, description, action, persistent, timeout })` returns an id and `dismiss(id?)` closes one or all; kinds are `plain`, `success`, `warning`, `error`. Mount `SnackbarProvider` once and a `SnackbarViewport` inside it. `notify(opts)` and `dismissNotification(id?)` do the same from outside React |
|
|
40
|
-
| avatar | yes | M&T | Base UI Avatar |
|
|
41
|
-
| badge | yes | M&T | Plain, `render` prop replaces `asChild` |
|
|
42
|
-
| breadcrumb | yes | M&T | Plain `<a>`, no `next/link`. Use `render` for a router link |
|
|
43
|
-
| card | yes | M&T | Plain |
|
|
44
|
-
| skeleton | yes | M&T | Plain |
|
|
45
|
-
| textarea | yes | M&T | Plain, restyled to match Input |
|
|
46
|
-
| sidebar | yes | M&T | Plain, 700 lines. `asChild` became `render`. `useIsMobile` moved into the kit. Untested beyond the `collapsible="none"` form in the playground |
|
|
47
|
-
| toolbar | yes | Oblique, M&T | Base UI Toolbar (roving focus). `ToolbarItems` takes `groups` of `ToolbarItemSpec` (id, label, icon, shortcut, enabled, disabledReason, pressed, menu) and `onCommand(id)`; Oblique's `ToolButtonSpec` table with M&T's disabled reason. Disabled items stay focusable so the tooltip can say why. `ToolbarButton`, `ToolbarGroup`, `ToolbarSeparator`, `ToolbarSpacer` compose by hand. Shard's header buttons are inline JSX and Fault's are not a toolbar, so neither contributed |
|
|
48
|
-
| color-field | yes | M&T, Oblique, Strata | Swatch, hex text (commits on blur or Enter, bad input reverts), optional alpha (`#rrggbbaa`), preset grid in a Popover, native picker with `onPickStart`/`onPickEnd` for undo transactions (Oblique), `clearable` and null value (Strata, Oblique's optional colour), read-only, `trailing` slot for an eyedropper |
|
|
49
|
-
| number-field | yes | Base UI, Oblique | Base UI NumberField with the label as the ScrubArea (drag it; click it to type). Shift is coarse (x10), Alt/Option fine (x0.1), as Oblique's InputNumber, and `integer` keeps Alt on whole steps (integerStepFix). `onValueChange(value, { reason })` is `scrub`, `step` or `typed` (typed commits on blur or Enter, never per keystroke; Escape reverts). `onScrubStart`/`onScrubEnd` bracket one drag as the undo transaction, `onScrubCancel` is Escape mid-drag. `VectorField` is N of them with X/Y/Z/W labels. Scrubbing only on the label: no gutter scrub |
|
|
50
|
-
| color-swatch | yes | Strata, M&T, Oblique | Chip over a checkerboard; `null` is the dashed empty chip |
|
|
51
|
-
| side-panel | yes | Strata, M&T | Docked panel, props only (`open`, `width` owned by the app). Collapsed it leaves an icon rail that reopens it; the inner edge resizes by pointer drag (pointer capture) or arrow keys, clamped by `clampWidth`. `SidePanelHeader`, `SidePanelContent`. Strata's `SidePanel` ideas; persistence stays app-side |
|
|
52
|
-
| status-bar | yes | Oblique, Strata, M&T | `StatusBar`, `StatusItem` (optional label), `StatusSpacer`. Contents stay app-side |
|
|
53
|
-
| empty-state | yes | new | Icon, title, description, action slot |
|
|
54
|
-
|
|
55
|
-
M&T's `src/palettes/` (presets and derivation) was considered for the colour field and left out: it is map domain data and stays in the app, which passes its colours in through `presets`.
|
|
18
|
+
Every component is exported from `src/index.ts`, which is the list. Each file's top comment says how it differs from shadcn and Radix. M&T's `src/palettes/` (presets and derivation) stays in the app, as map domain data; it passes its colours to the colour field through `presets`.
|
|
56
19
|
|
|
57
20
|
## Using it
|
|
58
21
|
|
|
@@ -77,15 +40,41 @@ Without the `@source` line the build passes and the components render unstyled,
|
|
|
77
40
|
|
|
78
41
|
[facets](https://github.com/preset-nz/facets) 0.2 draws its number, slider and colour fields with the host app's components. An app on the kit re-exports them, for example `export { NumberField } from "@preset.nz/ux-kit"` in `src/components/ui/number-field.tsx`.
|
|
79
42
|
|
|
43
|
+
## Chat
|
|
44
|
+
|
|
45
|
+
`@preset.nz/ux-kit/chat` is a separate subpath, so apps without chat don't pull in streamdown. It is presentational: props in, callbacks out, no Tauri, no events, no model or fetch code. The host owns the messages and appends text deltas to the last one.
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
import { ChatMarkdown, ChatMessage, ChatMessageContent, ChatScroller, ChatScrollerItem, PromptInput } from "@preset.nz/ux-kit/chat"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Add streamdown's classes to the app's CSS, next to the kit's `@source` line:
|
|
52
|
+
|
|
53
|
+
```css
|
|
54
|
+
@source "../node_modules/streamdown/dist/*.js";
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
| Export | Props worth knowing |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `ChatScroller`, `ChatScrollerItem` | The scrolling list. It follows a streamed reply and stops following when the person scrolls up; a jump-to-latest button appears. `autoScroll`, `defaultScrollPosition`, `scrollButton`. Give an item `scrollAnchor` (on a user turn) to pin the view to it. Fills its parent, so give the parent a height. Built on `@shadcn/react/message-scroller` |
|
|
60
|
+
| `ChatMessage`, `ChatMessageContent` | `from: "user" \| "assistant"`. A user turn is a right-hand bubble |
|
|
61
|
+
| `ChatMarkdown` | Streamdown core: `children` is the text so far, `isAnimating` while it arrives. No code highlighting, diagrams or maths |
|
|
62
|
+
| `ToolCall`, `ToolCallHeader`, `ToolCallContent`, `ToolCallInput`, `ToolCallOutput` | A collapsible row. Header takes `name` and `state: "running" \| "done" \| "refused"`; input and output show JSON or text; `errorText` replaces the output |
|
|
63
|
+
| `Reasoning`, `ReasoningTrigger`, `ReasoningContent` | A folded "Thinking…" block. `isStreaming` opens it and folds it a second after it ends; `duration` is measured if not given; `open` / `defaultOpen` / `onOpenChange` for host control |
|
|
64
|
+
| `Suggestions`, `Suggestion` | Starter prompts: `suggestion` text, `onClick(text)` |
|
|
65
|
+
| `PromptInput` | `onSubmit(text)`, `onStop`, `status: "idle" \| "streaming" \| "stopped" \| "error"` (send becomes stop while streaming), `value` / `onValueChange` (optional, so a suggestion can fill it), `tools` (the toolbar slot, for example a `ToggleGroup`), `disabled`, `placeholder`. Enter sends, Shift+Enter breaks the line |
|
|
66
|
+
| `ChatRole`, `ToolCallState`, `ChatStatus` | The small types the above share |
|
|
67
|
+
|
|
68
|
+
The components are adapted from Vercel AI Elements (Apache-2.0) and shadcn/ui's MessageScroller (MIT). See `THIRD_PARTY_NOTICES.md`.
|
|
69
|
+
|
|
80
70
|
## Working on it
|
|
81
71
|
|
|
82
72
|
```sh
|
|
83
|
-
just install # pnpm install
|
|
73
|
+
just install # pnpm install, and the playground's crates
|
|
84
74
|
just dev # the playground as a desktop app
|
|
85
|
-
just check #
|
|
86
|
-
just check-all # the kit, the playground and cargo check
|
|
75
|
+
just check # the kit, the playground and cargo check
|
|
87
76
|
```
|
|
88
77
|
|
|
89
|
-
The playground links the
|
|
78
|
+
Run them in `ux-kit/` of [preset-nz/packages](https://github.com/preset-nz/packages). The playground links the other packages in that repo (rhizome, app-kit, preferences, facets, math), so a change to one of them that breaks it fails `just check`.
|
|
90
79
|
|
|
91
80
|
MIT.
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
`@preset.nz/ux-kit` is MIT (see `LICENSE`). The files under `src/chat/` are adapted from the projects below. Each adapted file keeps its original copyright and licence notice at the top, followed by a line saying what preset.nz changed. The dependencies the chat subpath installs (`streamdown` Apache-2.0, `@shadcn/react` MIT) are used unmodified and keep their own licences.
|
|
4
|
+
|
|
5
|
+
## Vercel AI Elements
|
|
6
|
+
|
|
7
|
+
- URL: https://github.com/vercel/ai-elements (registry: https://elements.ai-sdk.dev)
|
|
8
|
+
- Licence: Apache License 2.0
|
|
9
|
+
- Copyright 2023 Vercel, Inc.
|
|
10
|
+
- Derived files in ux-kit: `src/chat/message.tsx` (Message, response part), `src/chat/tool.tsx` (Tool), `src/chat/reasoning.tsx` (Reasoning, Shimmer), `src/chat/suggestion.tsx` (Suggestion), `src/chat/prompt-input.tsx` (Prompt Input, trimmed)
|
|
11
|
+
- Changes: our own types in place of the `ai` package's, Base UI in place of Radix, Phosphor in place of lucide, a CSS shimmer in place of `motion`, no attachments, model select, command menu or message branching, and ux-kit's tokens. Each file's header says which of these apply to it.
|
|
12
|
+
|
|
13
|
+
## shadcn/ui
|
|
14
|
+
|
|
15
|
+
- URL: https://github.com/shadcn-ui/ui (MessageScroller, https://ui.shadcn.com/docs/changelog/2026-06-chat-components)
|
|
16
|
+
- Licence: MIT
|
|
17
|
+
- Copyright (c) 2023 shadcn
|
|
18
|
+
- Derived files in ux-kit: `src/chat/scroller.tsx`. The `shimmer` utility in `src/shadcn-tailwind.css` is shadcn's too, vendored with that file.
|
|
19
|
+
- Changes: one `ChatScroller` that assembles the Provider, Root, Viewport, Content and jump button from `@shadcn/react/message-scroller`; Phosphor icon; ux-kit Button.
|
|
20
|
+
|
|
21
|
+
### MIT License (shadcn)
|
|
22
|
+
|
|
23
|
+
MIT License
|
|
24
|
+
|
|
25
|
+
Copyright (c) 2023 shadcn
|
|
26
|
+
|
|
27
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
28
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
29
|
+
in the Software without restriction, including without limitation the rights
|
|
30
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
31
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
32
|
+
furnished to do so, subject to the following conditions:
|
|
33
|
+
|
|
34
|
+
The above copyright notice and this permission notice shall be included in all
|
|
35
|
+
copies or substantial portions of the Software.
|
|
36
|
+
|
|
37
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
38
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
39
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
40
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
41
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
42
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
43
|
+
SOFTWARE.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### Apache License 2.0 (Vercel)
|
|
47
|
+
|
|
48
|
+
Copyright 2023 Vercel, Inc.
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Apache License
|
|
53
|
+
Version 2.0, January 2004
|
|
54
|
+
http://www.apache.org/licenses/
|
|
55
|
+
|
|
56
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
57
|
+
|
|
58
|
+
1. Definitions.
|
|
59
|
+
|
|
60
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
61
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
62
|
+
|
|
63
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
64
|
+
the copyright owner that is granting the License.
|
|
65
|
+
|
|
66
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
67
|
+
other entities that control, are controlled by, or are under common
|
|
68
|
+
control with that entity. For the purposes of this definition,
|
|
69
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
70
|
+
direction or management of such entity, whether by contract or
|
|
71
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
72
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
73
|
+
|
|
74
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
75
|
+
exercising permissions granted by this License.
|
|
76
|
+
|
|
77
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
78
|
+
including but not limited to software source code, documentation
|
|
79
|
+
source, and configuration files.
|
|
80
|
+
|
|
81
|
+
"Object" form shall mean any form resulting from mechanical
|
|
82
|
+
transformation or translation of a Source form, including but
|
|
83
|
+
not limited to compiled object code, generated documentation,
|
|
84
|
+
and conversions to other media types.
|
|
85
|
+
|
|
86
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
87
|
+
Object form, made available under the License, as indicated by a
|
|
88
|
+
copyright notice that is included in or attached to the work
|
|
89
|
+
(an example is provided in the Appendix below).
|
|
90
|
+
|
|
91
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
92
|
+
form, that is based on (or derived from) the Work and for which the
|
|
93
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
94
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
95
|
+
of this License, Derivative Works shall not include works that remain
|
|
96
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
97
|
+
the Work and Derivative Works thereof.
|
|
98
|
+
|
|
99
|
+
"Contribution" shall mean any work of authorship, including
|
|
100
|
+
the original version of the Work and any modifications or additions
|
|
101
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
102
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
103
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
104
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
105
|
+
means any form of electronic, verbal, or written communication sent
|
|
106
|
+
to the Licensor or its representatives, including but not limited to
|
|
107
|
+
communication on electronic mailing lists, source code control systems,
|
|
108
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
109
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
110
|
+
excluding communication that is conspicuously marked or otherwise
|
|
111
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
112
|
+
|
|
113
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
114
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
115
|
+
subsequently incorporated within the Work.
|
|
116
|
+
|
|
117
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
118
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
119
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
120
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
121
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
122
|
+
Work and such Derivative Works in Source or Object form.
|
|
123
|
+
|
|
124
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
125
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
126
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
127
|
+
(except as stated in this section) patent license to make, have made,
|
|
128
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
129
|
+
where such license applies only to those patent claims licensable
|
|
130
|
+
by such Contributor that are necessarily infringed by their
|
|
131
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
132
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
133
|
+
institute patent litigation against any entity (including a
|
|
134
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
135
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
136
|
+
or contributory patent infringement, then any patent licenses
|
|
137
|
+
granted to You under this License for that Work shall terminate
|
|
138
|
+
as of the date such litigation is filed.
|
|
139
|
+
|
|
140
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
141
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
142
|
+
modifications, and in Source or Object form, provided that You
|
|
143
|
+
meet the following conditions:
|
|
144
|
+
|
|
145
|
+
(a) You must give any other recipients of the Work or
|
|
146
|
+
Derivative Works a copy of this License; and
|
|
147
|
+
|
|
148
|
+
(b) You must cause any modified files to carry prominent notices
|
|
149
|
+
stating that You changed the files; and
|
|
150
|
+
|
|
151
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
152
|
+
that You distribute, all copyright, patent, trademark, and
|
|
153
|
+
attribution notices from the Source form of the Work,
|
|
154
|
+
excluding those notices that do not pertain to any part of
|
|
155
|
+
the Derivative Works; and
|
|
156
|
+
|
|
157
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
158
|
+
distribution, then any Derivative Works that You distribute must
|
|
159
|
+
include a readable copy of the attribution notices contained
|
|
160
|
+
within such NOTICE file, excluding those notices that do not
|
|
161
|
+
pertain to any part of the Derivative Works, in at least one
|
|
162
|
+
of the following places: within a NOTICE text file distributed
|
|
163
|
+
as part of the Derivative Works; within the Source form or
|
|
164
|
+
documentation, if provided along with the Derivative Works; or,
|
|
165
|
+
within a display generated by the Derivative Works, if and
|
|
166
|
+
wherever such third-party notices normally appear. The contents
|
|
167
|
+
of the NOTICE file are for informational purposes only and
|
|
168
|
+
do not modify the License. You may add Your own attribution
|
|
169
|
+
notices within Derivative Works that You distribute, alongside
|
|
170
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
171
|
+
that such additional attribution notices cannot be construed
|
|
172
|
+
as modifying the License.
|
|
173
|
+
|
|
174
|
+
You may add Your own copyright statement to Your modifications and
|
|
175
|
+
may provide additional or different license terms and conditions
|
|
176
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
177
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
178
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
179
|
+
the conditions stated in this License.
|
|
180
|
+
|
|
181
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
182
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
183
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
184
|
+
this License, without any additional terms or conditions.
|
|
185
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
186
|
+
the terms of any separate license agreement you may have executed
|
|
187
|
+
with Licensor regarding such Contributions.
|
|
188
|
+
|
|
189
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
190
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
191
|
+
except as required for reasonable and customary use in describing the
|
|
192
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
193
|
+
|
|
194
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
195
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
196
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
197
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
198
|
+
implied, including, without limitation, any warranties or conditions
|
|
199
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
200
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
201
|
+
appropriateness of using or redistributing the Work and assume any
|
|
202
|
+
risks associated with Your exercise of permissions under this License.
|
|
203
|
+
|
|
204
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
205
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
206
|
+
unless required by applicable law (such as deliberate and grossly
|
|
207
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
208
|
+
liable to You for damages, including any direct, indirect, special,
|
|
209
|
+
incidental, or consequential damages of any character arising as a
|
|
210
|
+
result of this License or out of the use or inability to use the
|
|
211
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
212
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
213
|
+
other commercial damages or losses), even if such Contributor
|
|
214
|
+
has been advised of the possibility of such damages.
|
|
215
|
+
|
|
216
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
217
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
218
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
219
|
+
or other liability obligations and/or rights consistent with this
|
|
220
|
+
License. However, in accepting such obligations, You may act only
|
|
221
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
222
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
223
|
+
defend, and hold each Contributor harmless for any liability
|
|
224
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
225
|
+
of your accepting any such warranty or additional liability.
|
|
226
|
+
|
|
227
|
+
END OF TERMS AND CONDITIONS
|
|
228
|
+
|
|
229
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
230
|
+
|
|
231
|
+
To apply the Apache License to your work, attach the following
|
|
232
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
233
|
+
replaced with your own identifying information. (Don't include
|
|
234
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
235
|
+
comment syntax for the file format. We also recommend that a
|
|
236
|
+
file or class name and description of purpose be included on the
|
|
237
|
+
same "printed page" as the copyright notice for easier
|
|
238
|
+
identification within third-party archives.
|
|
239
|
+
|
|
240
|
+
Copyright [yyyy] [name of copyright owner]
|
|
241
|
+
|
|
242
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
243
|
+
you may not use this file except in compliance with the License.
|
|
244
|
+
You may obtain a copy of the License at
|
|
245
|
+
|
|
246
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
247
|
+
|
|
248
|
+
Unless required by applicable law or agreed to in writing, software
|
|
249
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
250
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
251
|
+
See the License for the specific language governing permissions and
|
|
252
|
+
limitations under the License.
|
|
253
|
+
```
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preset.nz/ux-kit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "One look and one way of working for the preset.nz desktop apps: tokens, palettes, fonts and Base UI primitives.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/preset-nz/
|
|
8
|
+
"url": "git+https://github.com/preset-nz/packages.git",
|
|
9
|
+
"directory": "ux-kit"
|
|
9
10
|
},
|
|
10
11
|
"type": "module",
|
|
11
12
|
"sideEffects": [
|
|
@@ -13,11 +14,13 @@
|
|
|
13
14
|
],
|
|
14
15
|
"exports": {
|
|
15
16
|
".": "./src/index.ts",
|
|
17
|
+
"./chat": "./src/chat/index.ts",
|
|
16
18
|
"./graphics": "./src/graphics/index.ts",
|
|
17
19
|
"./index.css": "./src/index.css"
|
|
18
20
|
},
|
|
19
21
|
"files": [
|
|
20
|
-
"src"
|
|
22
|
+
"src",
|
|
23
|
+
"THIRD_PARTY_NOTICES.md"
|
|
21
24
|
],
|
|
22
25
|
"peerDependencies": {
|
|
23
26
|
"react": "^19",
|
|
@@ -28,25 +31,22 @@
|
|
|
28
31
|
"@fontsource-variable/geist": "^5.2.9",
|
|
29
32
|
"@fontsource-variable/jetbrains-mono": "^5.2.8",
|
|
30
33
|
"@phosphor-icons/react": "^2.1.10",
|
|
31
|
-
"@
|
|
34
|
+
"@shadcn/react": "^0.3.1",
|
|
32
35
|
"class-variance-authority": "^0.7.1",
|
|
33
36
|
"clsx": "^2.1.1",
|
|
34
|
-
"
|
|
37
|
+
"streamdown": "^2.7.0",
|
|
35
38
|
"tailwind-merge": "^3.6.0",
|
|
36
|
-
"tw-animate-css": "^1.4.0"
|
|
39
|
+
"tw-animate-css": "^1.4.0",
|
|
40
|
+
"@preset.nz/math": "^0.1.0"
|
|
37
41
|
},
|
|
38
42
|
"devDependencies": {
|
|
39
|
-
"@
|
|
43
|
+
"@biomejs/biome": "^2.5.15",
|
|
40
44
|
"@types/react": "^19.2.17",
|
|
41
45
|
"@types/react-dom": "^19.2.3",
|
|
42
|
-
"
|
|
43
|
-
"eslint-plugin-react-hooks": "^7.1.1",
|
|
44
|
-
"eslint-plugin-react-refresh": "^0.5.3",
|
|
45
|
-
"globals": "^16.5.0",
|
|
46
|
+
"lefthook": "^2.1.17",
|
|
46
47
|
"react": "^19.2.7",
|
|
47
48
|
"react-dom": "^19.2.7",
|
|
48
|
-
"typescript": "~
|
|
49
|
-
"typescript-eslint": "^8.61.1"
|
|
49
|
+
"typescript": "~7.0.2"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// The chat subpath: @preset.nz/ux-kit/chat. Presentational only, props in and
|
|
2
|
+
// callbacks out. Kept off the main index so apps without chat don't pull in streamdown.
|
|
3
|
+
export * from "./message"
|
|
4
|
+
export * from "./prompt-input"
|
|
5
|
+
export * from "./reasoning"
|
|
6
|
+
export * from "./scroller"
|
|
7
|
+
export * from "./suggestion"
|
|
8
|
+
export * from "./tool"
|
|
9
|
+
export * from "./types"
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Vercel, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* Adapted from Vercel AI Elements (https://github.com/vercel/ai-elements), message.tsx.
|
|
17
|
+
* Modified by preset.nz, 2026-10-14: own types instead of the `ai` package, no branching or actions, markdown through streamdown core only, ux-kit tokens.
|
|
18
|
+
*/
|
|
19
|
+
import type { ComponentProps, HTMLAttributes } from "react"
|
|
20
|
+
import { memo } from "react"
|
|
21
|
+
import { Streamdown } from "streamdown"
|
|
22
|
+
|
|
23
|
+
import { cn } from "../lib/utils"
|
|
24
|
+
import type { ChatRole } from "./types"
|
|
25
|
+
|
|
26
|
+
export type ChatMessageProps = HTMLAttributes<HTMLDivElement> & {
|
|
27
|
+
from: ChatRole
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** One turn. A user turn sits right in a bubble; an assistant turn runs the full width. */
|
|
31
|
+
export function ChatMessage({ className, from, ...props }: ChatMessageProps) {
|
|
32
|
+
return (
|
|
33
|
+
<div
|
|
34
|
+
data-slot="chat-message"
|
|
35
|
+
data-from={from}
|
|
36
|
+
className={cn(
|
|
37
|
+
// Selectable: a reply is something you copy (ux-kit turns selection off app-wide).
|
|
38
|
+
"group flex w-full max-w-[95%] flex-col gap-2 select-text",
|
|
39
|
+
from === "user" ? "is-user ml-auto justify-end" : "is-assistant",
|
|
40
|
+
className,
|
|
41
|
+
)}
|
|
42
|
+
{...props}
|
|
43
|
+
/>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type ChatMessageContentProps = HTMLAttributes<HTMLDivElement>
|
|
48
|
+
|
|
49
|
+
export function ChatMessageContent({ className, ...props }: ChatMessageContentProps) {
|
|
50
|
+
return (
|
|
51
|
+
<div
|
|
52
|
+
data-slot="chat-message-content"
|
|
53
|
+
className={cn(
|
|
54
|
+
"flex w-fit min-w-0 max-w-full flex-col gap-2 overflow-hidden text-xs text-foreground",
|
|
55
|
+
"group-[.is-user]:ml-auto group-[.is-user]:rounded-md group-[.is-user]:bg-secondary group-[.is-user]:px-3 group-[.is-user]:py-2",
|
|
56
|
+
className,
|
|
57
|
+
)}
|
|
58
|
+
{...props}
|
|
59
|
+
/>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type ChatMarkdownProps = ComponentProps<typeof Streamdown>
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Markdown that tolerates half-written input, for streamed text. Pass
|
|
67
|
+
* `isAnimating` while the text is still arriving. Streamdown core only: code
|
|
68
|
+
* blocks are plain, with no highlighting, diagrams or maths.
|
|
69
|
+
*/
|
|
70
|
+
export const ChatMarkdown = memo(
|
|
71
|
+
function ChatMarkdown({ className, ...props }: ChatMarkdownProps) {
|
|
72
|
+
return (
|
|
73
|
+
<Streamdown
|
|
74
|
+
className={cn("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0", className)}
|
|
75
|
+
{...props}
|
|
76
|
+
/>
|
|
77
|
+
)
|
|
78
|
+
},
|
|
79
|
+
(prev, next) => prev.children === next.children && next.isAnimating === prev.isAnimating,
|
|
80
|
+
)
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Vercel, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* Adapted from Vercel AI Elements (https://github.com/vercel/ai-elements), prompt-input.tsx.
|
|
17
|
+
* Modified by preset.nz, 2026-10-14: trimmed to a textarea, a toolbar slot and a submit or stop button (no attachments, model select, command menu or provider); own types instead of the `ai` package, ux-kit Textarea and Button, Phosphor icons.
|
|
18
|
+
*/
|
|
19
|
+
import { ArrowUpIcon, StopIcon } from "@phosphor-icons/react"
|
|
20
|
+
import type { ComponentProps, FormEvent, KeyboardEvent, ReactNode } from "react"
|
|
21
|
+
import { useState } from "react"
|
|
22
|
+
|
|
23
|
+
import { Button } from "../components/button"
|
|
24
|
+
import { Textarea } from "../components/textarea"
|
|
25
|
+
import { cn } from "../lib/utils"
|
|
26
|
+
import type { ChatStatus } from "./types"
|
|
27
|
+
|
|
28
|
+
export type PromptInputProps = Omit<ComponentProps<"form">, "onSubmit"> & {
|
|
29
|
+
/** Called with the trimmed text when the person presses Enter or the send button. */
|
|
30
|
+
onSubmit: (text: string) => void
|
|
31
|
+
/** Called by the stop button, which replaces send while `status` is "streaming". */
|
|
32
|
+
onStop?: () => void
|
|
33
|
+
status?: ChatStatus
|
|
34
|
+
/** The text, if the host holds it (so a suggestion can fill it). Uncontrolled when left out. */
|
|
35
|
+
value?: string
|
|
36
|
+
onValueChange?: (value: string) => void
|
|
37
|
+
placeholder?: string
|
|
38
|
+
/** The toolbar slot, left of the send button: mode toggles, model name, and the like. */
|
|
39
|
+
tools?: ReactNode
|
|
40
|
+
/** Disables typing and sending. The stop button still works. */
|
|
41
|
+
disabled?: boolean
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A message box: Enter sends, Shift+Enter breaks the line (and an IME
|
|
46
|
+
* composition is left alone). While streaming, the send button becomes stop.
|
|
47
|
+
*/
|
|
48
|
+
export function PromptInput({
|
|
49
|
+
onSubmit,
|
|
50
|
+
onStop,
|
|
51
|
+
status = "idle",
|
|
52
|
+
value,
|
|
53
|
+
onValueChange,
|
|
54
|
+
placeholder = "Ask for a pattern or a change…",
|
|
55
|
+
tools,
|
|
56
|
+
disabled = false,
|
|
57
|
+
className,
|
|
58
|
+
...props
|
|
59
|
+
}: PromptInputProps) {
|
|
60
|
+
const [inner, setInner] = useState("")
|
|
61
|
+
const text = value ?? inner
|
|
62
|
+
const setText = (next: string) => {
|
|
63
|
+
setInner(next)
|
|
64
|
+
onValueChange?.(next)
|
|
65
|
+
}
|
|
66
|
+
const streaming = status === "streaming"
|
|
67
|
+
const canSend = !disabled && !streaming && text.trim().length > 0
|
|
68
|
+
|
|
69
|
+
const send = () => {
|
|
70
|
+
if (!canSend) return
|
|
71
|
+
onSubmit(text.trim())
|
|
72
|
+
setText("")
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const handleSubmit = (event: FormEvent) => {
|
|
76
|
+
event.preventDefault()
|
|
77
|
+
if (streaming) onStop?.()
|
|
78
|
+
else send()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const handleKeyDown = (event: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
82
|
+
if (event.key !== "Enter" || event.shiftKey) return
|
|
83
|
+
if (event.nativeEvent.isComposing) return
|
|
84
|
+
event.preventDefault()
|
|
85
|
+
send()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<form
|
|
90
|
+
data-slot="prompt-input"
|
|
91
|
+
onSubmit={handleSubmit}
|
|
92
|
+
className={cn(
|
|
93
|
+
"flex w-full flex-col gap-1 rounded-md border border-input bg-background p-1.5 focus-within:border-ring focus-within:ring-1 focus-within:ring-ring/50 dark:bg-input/30",
|
|
94
|
+
className,
|
|
95
|
+
)}
|
|
96
|
+
{...props}
|
|
97
|
+
>
|
|
98
|
+
<Textarea
|
|
99
|
+
name="message"
|
|
100
|
+
rows={1}
|
|
101
|
+
value={text}
|
|
102
|
+
disabled={disabled}
|
|
103
|
+
placeholder={placeholder}
|
|
104
|
+
onChange={(event) => setText(event.currentTarget.value)}
|
|
105
|
+
onKeyDown={handleKeyDown}
|
|
106
|
+
className="field-sizing-content max-h-40 min-h-9 resize-none border-0 bg-transparent px-1 py-1 focus-visible:ring-0 dark:bg-transparent"
|
|
107
|
+
/>
|
|
108
|
+
<div className="flex items-center justify-between gap-1">
|
|
109
|
+
<div className="flex min-w-0 items-center gap-1">{tools}</div>
|
|
110
|
+
<Button
|
|
111
|
+
type="submit"
|
|
112
|
+
size="icon-sm"
|
|
113
|
+
aria-label={streaming ? "Stop" : "Send"}
|
|
114
|
+
disabled={streaming ? !onStop : !canSend}
|
|
115
|
+
>
|
|
116
|
+
{streaming ? <StopIcon weight="fill" /> : <ArrowUpIcon />}
|
|
117
|
+
</Button>
|
|
118
|
+
</div>
|
|
119
|
+
</form>
|
|
120
|
+
)
|
|
121
|
+
}
|