@zonsh/ui 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +76 -2
- package/assets/illustrations/drawing/bracket-construction-dark.svg +77 -0
- package/assets/illustrations/drawing/bracket-construction-filled-dark.svg +50 -0
- package/assets/illustrations/drawing/bracket-construction-filled.svg +50 -0
- package/assets/illustrations/drawing/bracket-construction.svg +77 -0
- package/assets/illustrations/drawing/crescent-dark.svg +28 -0
- package/assets/illustrations/drawing/crescent-guides-dark.svg +33 -0
- package/assets/illustrations/drawing/crescent-guides.svg +33 -0
- package/assets/illustrations/drawing/crescent.svg +28 -0
- package/assets/illustrations/drawing/eclipse-dark.svg +187 -0
- package/assets/illustrations/drawing/eclipse-guides-dark.svg +191 -0
- package/assets/illustrations/drawing/eclipse-guides.svg +191 -0
- package/assets/illustrations/drawing/eclipse.svg +187 -0
- package/assets/illustrations/drawing/elevation-guides-dark.svg +31 -0
- package/assets/illustrations/drawing/elevation-guides-plain-dark.svg +9 -0
- package/assets/illustrations/drawing/elevation-guides-plain.svg +9 -0
- package/assets/illustrations/drawing/elevation-guides.svg +31 -0
- package/assets/illustrations/drawing/horizon-dark.svg +30 -0
- package/assets/illustrations/drawing/horizon.svg +30 -0
- package/assets/illustrations/drawing/nib-study-dark.svg +107 -0
- package/assets/illustrations/drawing/nib-study-plain-dark.svg +93 -0
- package/assets/illustrations/drawing/nib-study-plain.svg +93 -0
- package/assets/illustrations/drawing/nib-study.svg +107 -0
- package/assets/illustrations/editorial/assistant-640.webp +0 -0
- package/assets/illustrations/editorial/assistant.webp +0 -0
- package/assets/illustrations/editorial/automation-640.webp +0 -0
- package/assets/illustrations/editorial/automation.webp +0 -0
- package/assets/illustrations/editorial/bracket-left-640.webp +0 -0
- package/assets/illustrations/editorial/bracket-left.webp +0 -0
- package/assets/illustrations/editorial/bracket-right-640.webp +0 -0
- package/assets/illustrations/editorial/bracket-right.webp +0 -0
- package/assets/illustrations/editorial/custom-software-640.webp +0 -0
- package/assets/illustrations/editorial/custom-software.webp +0 -0
- package/assets/illustrations/editorial/digitalization-640.webp +0 -0
- package/assets/illustrations/editorial/digitalization.webp +0 -0
- package/assets/illustrations/editorial/integration-640.webp +0 -0
- package/assets/illustrations/editorial/integration.webp +0 -0
- package/assets/illustrations/editorial/problem-640.webp +0 -0
- package/assets/illustrations/editorial/problem.webp +0 -0
- package/assets/illustrations/editorial/process-analysis-640.webp +0 -0
- package/assets/illustrations/editorial/process-analysis.webp +0 -0
- package/assets/illustrations/editorial/process-concept-640.webp +0 -0
- package/assets/illustrations/editorial/process-concept.webp +0 -0
- package/assets/illustrations/editorial/process-development-640.webp +0 -0
- package/assets/illustrations/editorial/process-development.webp +0 -0
- package/assets/illustrations/editorial/process-discovery-640.webp +0 -0
- package/assets/illustrations/editorial/process-discovery.webp +0 -0
- package/assets/illustrations/editorial/process-maintenance-640.webp +0 -0
- package/assets/illustrations/editorial/process-maintenance.webp +0 -0
- package/assets/illustrations/editorial/process-prototype-640.webp +0 -0
- package/assets/illustrations/editorial/process-prototype.webp +0 -0
- package/assets/illustrations/editorial/process-testing-640.webp +0 -0
- package/assets/illustrations/editorial/process-testing.webp +0 -0
- package/assets/illustrations/iso/automation-dark.svg +6 -0
- package/assets/illustrations/iso/automation.svg +6 -0
- package/assets/illustrations/iso/bar-chart-dark.svg +6 -0
- package/assets/illustrations/iso/bar-chart.svg +6 -0
- package/assets/illustrations/iso/brackets-classic-dark.svg +6 -0
- package/assets/illustrations/iso/brackets-classic.svg +6 -0
- package/assets/illustrations/iso/brackets-dark.svg +6 -0
- package/assets/illustrations/iso/brackets.svg +6 -0
- package/assets/illustrations/iso/city-dark.svg +6 -0
- package/assets/illustrations/iso/city.svg +6 -0
- package/assets/illustrations/iso/conveyor-dark.svg +6 -0
- package/assets/illustrations/iso/conveyor.svg +6 -0
- package/assets/illustrations/iso/database-dark.svg +6 -0
- package/assets/illustrations/iso/database.svg +6 -0
- package/assets/illustrations/iso/documents-dark.svg +6 -0
- package/assets/illustrations/iso/documents.svg +6 -0
- package/assets/illustrations/iso/inbox-dark.svg +6 -0
- package/assets/illustrations/iso/inbox.svg +6 -0
- package/assets/illustrations/iso/laptop-dark.svg +6 -0
- package/assets/illustrations/iso/laptop.svg +6 -0
- package/assets/illustrations/iso/monitor-dark.svg +6 -0
- package/assets/illustrations/iso/monitor.svg +6 -0
- package/assets/illustrations/iso/pipeline-dark.svg +6 -0
- package/assets/illustrations/iso/pipeline.svg +6 -0
- package/assets/illustrations/iso/platform-dark.svg +6 -0
- package/assets/illustrations/iso/platform.svg +6 -0
- package/assets/illustrations/iso/server-dark.svg +6 -0
- package/assets/illustrations/iso/server.svg +6 -0
- package/assets/illustrations/iso/spreadsheet-dark.svg +6 -0
- package/assets/illustrations/iso/spreadsheet.svg +6 -0
- package/assets/illustrations/iso/timeline-dark.svg +6 -0
- package/assets/illustrations/iso/timeline.svg +6 -0
- package/assets/illustrations/sheet/construction.svg +115 -0
- package/assets/illustrations/sheet/crescent.svg +40 -0
- package/assets/illustrations/sheet/limb.svg +42 -0
- package/assets/illustrations/sheet/stress-axis.svg +119 -0
- package/assets/illustrations/sheet/totality.svg +215 -0
- package/assets/illustrations/sheet/vertical-metrics.svg +43 -0
- package/assets/logo-left.svg +1 -0
- package/assets/logo-right.svg +1 -0
- package/assets/logo.svg +1 -0
- package/dist/components/_overlay.d.ts +47 -0
- package/dist/components/_overlay.js +59 -0
- package/dist/components/accordion.d.ts +32 -0
- package/dist/components/accordion.js +39 -0
- package/dist/components/alert-dialog.d.ts +45 -0
- package/dist/components/alert-dialog.js +56 -0
- package/dist/components/alert.d.ts +35 -0
- package/dist/components/alert.js +42 -0
- package/dist/components/ascii-field.d.ts +34 -0
- package/dist/components/ascii-field.js +410 -0
- package/dist/components/aspect-ratio.d.ts +14 -0
- package/dist/components/aspect-ratio.js +17 -0
- package/dist/components/avatar.d.ts +42 -0
- package/dist/components/avatar.js +55 -0
- package/dist/components/badge.d.ts +70 -0
- package/dist/components/badge.js +62 -0
- package/dist/components/breadcrumb.d.ts +22 -0
- package/dist/components/breadcrumb.js +32 -0
- package/dist/components/button-group.d.ts +30 -0
- package/dist/components/button-group.js +47 -0
- package/dist/components/button.d.ts +53 -0
- package/dist/components/button.js +130 -0
- package/dist/components/calendar.d.ts +26 -0
- package/dist/components/calendar.js +164 -0
- package/dist/components/card.d.ts +42 -0
- package/dist/components/card.js +76 -0
- package/dist/components/carousel.d.ts +90 -0
- package/dist/components/carousel.js +213 -0
- package/dist/components/chart.d.ts +180 -0
- package/dist/components/chart.js +286 -0
- package/dist/components/checkbox.d.ts +23 -0
- package/dist/components/checkbox.js +43 -0
- package/dist/components/code-block.d.ts +45 -0
- package/dist/components/code-block.js +58 -0
- package/dist/components/code-highlight.d.ts +13 -0
- package/dist/components/code-highlight.js +107 -0
- package/dist/components/collapsible.d.ts +20 -0
- package/dist/components/collapsible.js +32 -0
- package/dist/components/color-picker.d.ts +85 -0
- package/dist/components/color-picker.js +407 -0
- package/dist/components/combobox.d.ts +81 -0
- package/dist/components/combobox.js +100 -0
- package/dist/components/command.d.ts +112 -0
- package/dist/components/command.js +212 -0
- package/dist/components/context-menu.d.ts +29 -0
- package/dist/components/context-menu.js +35 -0
- package/dist/components/conversation.d.ts +27 -0
- package/dist/components/conversation.js +293 -0
- package/dist/components/copy-button.d.ts +46 -0
- package/dist/components/copy-button.js +118 -0
- package/dist/components/data-table.d.ts +175 -0
- package/dist/components/data-table.js +302 -0
- package/dist/components/date-picker.d.ts +91 -0
- package/dist/components/date-picker.js +207 -0
- package/dist/components/dialog.d.ts +48 -0
- package/dist/components/dialog.js +92 -0
- package/dist/components/direction.d.ts +16 -0
- package/dist/components/direction.js +18 -0
- package/dist/components/drawer.d.ts +60 -0
- package/dist/components/drawer.js +76 -0
- package/dist/components/empty.d.ts +31 -0
- package/dist/components/empty.js +50 -0
- package/dist/components/feature-list.d.ts +54 -0
- package/dist/components/feature-list.js +43 -0
- package/dist/components/field.d.ts +15 -0
- package/dist/components/field.js +36 -0
- package/dist/components/file-drop.d.ts +55 -0
- package/dist/components/file-drop.js +197 -0
- package/dist/components/filter-bar.d.ts +106 -0
- package/dist/components/filter-bar.js +296 -0
- package/dist/components/form.d.ts +33 -0
- package/dist/components/form.js +34 -0
- package/dist/components/graph.d.ts +105 -0
- package/dist/components/graph.js +786 -0
- package/dist/components/illustration.d.ts +85 -0
- package/dist/components/illustration.js +165 -0
- package/dist/components/input-group.d.ts +127 -0
- package/dist/components/input-group.js +292 -0
- package/dist/components/input.d.ts +16 -0
- package/dist/components/input.js +25 -0
- package/dist/components/item.d.ts +64 -0
- package/dist/components/item.js +116 -0
- package/dist/components/kbd.d.ts +33 -0
- package/dist/components/kbd.js +38 -0
- package/dist/components/label.d.ts +12 -0
- package/dist/components/label.js +24 -0
- package/dist/components/layout.d.ts +136 -0
- package/dist/components/layout.js +162 -0
- package/dist/components/logo.d.ts +54 -0
- package/dist/components/logo.js +96 -0
- package/dist/components/menu.d.ts +60 -0
- package/dist/components/menu.js +138 -0
- package/dist/components/menubar.d.ts +62 -0
- package/dist/components/menubar.js +223 -0
- package/dist/components/message.d.ts +42 -0
- package/dist/components/message.js +56 -0
- package/dist/components/meter.d.ts +31 -0
- package/dist/components/meter.js +25 -0
- package/dist/components/native-select.d.ts +26 -0
- package/dist/components/native-select.js +35 -0
- package/dist/components/navigation-menu.d.ts +42 -0
- package/dist/components/navigation-menu.js +97 -0
- package/dist/components/number-field.d.ts +36 -0
- package/dist/components/number-field.js +153 -0
- package/dist/components/otp-field.d.ts +35 -0
- package/dist/components/otp-field.js +94 -0
- package/dist/components/pagination.d.ts +31 -0
- package/dist/components/pagination.js +70 -0
- package/dist/components/pdf-viewer.d.ts +69 -0
- package/dist/components/pdf-viewer.js +929 -0
- package/dist/components/popover.d.ts +33 -0
- package/dist/components/popover.js +48 -0
- package/dist/components/preview-card.d.ts +25 -0
- package/dist/components/preview-card.js +22 -0
- package/dist/components/progress.d.ts +27 -0
- package/dist/components/progress.js +23 -0
- package/dist/components/prompt-input.d.ts +131 -0
- package/dist/components/prompt-input.js +403 -0
- package/dist/components/quote.d.ts +22 -0
- package/dist/components/quote.js +15 -0
- package/dist/components/radio-group.d.ts +18 -0
- package/dist/components/radio-group.js +34 -0
- package/dist/components/reasoning.d.ts +31 -0
- package/dist/components/reasoning.js +70 -0
- package/dist/components/resizable.d.ts +38 -0
- package/dist/components/resizable.js +41 -0
- package/dist/components/response.d.ts +30 -0
- package/dist/components/response.js +538 -0
- package/dist/components/scroll-area.d.ts +33 -0
- package/dist/components/scroll-area.js +31 -0
- package/dist/components/select.d.ts +35 -0
- package/dist/components/select.js +60 -0
- package/dist/components/separator.d.ts +14 -0
- package/dist/components/separator.js +17 -0
- package/dist/components/sidebar.d.ts +147 -0
- package/dist/components/sidebar.js +489 -0
- package/dist/components/site-header.d.ts +59 -0
- package/dist/components/site-header.js +67 -0
- package/dist/components/skeleton.d.ts +31 -0
- package/dist/components/skeleton.js +29 -0
- package/dist/components/slider.d.ts +24 -0
- package/dist/components/slider.js +129 -0
- package/dist/components/sources.d.ts +25 -0
- package/dist/components/sources.js +35 -0
- package/dist/components/spinner.d.ts +36 -0
- package/dist/components/spinner.js +72 -0
- package/dist/components/suggestions.d.ts +20 -0
- package/dist/components/suggestions.js +18 -0
- package/dist/components/switch.d.ts +14 -0
- package/dist/components/switch.js +26 -0
- package/dist/components/table.d.ts +162 -0
- package/dist/components/table.js +758 -0
- package/dist/components/tabs.d.ts +25 -0
- package/dist/components/tabs.js +162 -0
- package/dist/components/tag.d.ts +41 -0
- package/dist/components/tag.js +88 -0
- package/dist/components/tags-input.d.ts +40 -0
- package/dist/components/tags-input.js +239 -0
- package/dist/components/textarea.d.ts +13 -0
- package/dist/components/textarea.js +16 -0
- package/dist/components/theme.d.ts +41 -0
- package/dist/components/theme.js +112 -0
- package/dist/components/time-field.d.ts +51 -0
- package/dist/components/time-field.js +437 -0
- package/dist/components/timeline.d.ts +76 -0
- package/dist/components/timeline.js +99 -0
- package/dist/components/toast.d.ts +72 -0
- package/dist/components/toast.js +196 -0
- package/dist/components/toggle-group.d.ts +41 -0
- package/dist/components/toggle-group.js +140 -0
- package/dist/components/toggle.d.ts +23 -0
- package/dist/components/toggle.js +35 -0
- package/dist/components/tool-call.d.ts +52 -0
- package/dist/components/tool-call.js +57 -0
- package/dist/components/toolbar.d.ts +17 -0
- package/dist/components/toolbar.js +34 -0
- package/dist/components/tooltip.d.ts +42 -0
- package/dist/components/tooltip.js +47 -0
- package/dist/components/tree.d.ts +75 -0
- package/dist/components/tree.js +636 -0
- package/dist/components/typography.d.ts +134 -0
- package/dist/components/typography.js +176 -0
- package/dist/components/video-player.d.ts +276 -0
- package/dist/components/video-player.js +1352 -0
- package/dist/components/whiteboard.d.ts +80 -0
- package/dist/components/whiteboard.js +389 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +86 -0
- package/dist/lib/cn.d.ts +20 -0
- package/dist/lib/cn.js +38 -0
- package/dist/lib/code-highlight.d.ts +31 -0
- package/dist/lib/code-highlight.js +24 -0
- package/dist/lib/code-theme.d.ts +19 -0
- package/dist/lib/code-theme.js +140 -0
- package/dist/lib/collapse-row.d.ts +9 -0
- package/dist/lib/collapse-row.js +129 -0
- package/dist/lib/digit-roll.d.ts +21 -0
- package/dist/lib/digit-roll.js +31 -0
- package/dist/lib/editorial-assets.d.ts +16 -0
- package/dist/lib/editorial-assets.js +56 -0
- package/dist/lib/figure/catalog.d.ts +127 -0
- package/dist/lib/figure/catalog.js +130 -0
- package/dist/lib/figure/figures/automation.d.ts +7 -0
- package/dist/lib/figure/figures/automation.js +143 -0
- package/dist/lib/figure/figures/bar-chart.d.ts +7 -0
- package/dist/lib/figure/figures/bar-chart.js +99 -0
- package/dist/lib/figure/figures/brackets-classic.d.ts +11 -0
- package/dist/lib/figure/figures/brackets-classic.js +170 -0
- package/dist/lib/figure/figures/brackets.d.ts +8 -0
- package/dist/lib/figure/figures/brackets.js +84 -0
- package/dist/lib/figure/figures/city.d.ts +7 -0
- package/dist/lib/figure/figures/city.js +93 -0
- package/dist/lib/figure/figures/conveyor.d.ts +7 -0
- package/dist/lib/figure/figures/conveyor.js +97 -0
- package/dist/lib/figure/figures/database.d.ts +7 -0
- package/dist/lib/figure/figures/database.js +65 -0
- package/dist/lib/figure/figures/documents.d.ts +7 -0
- package/dist/lib/figure/figures/documents.js +83 -0
- package/dist/lib/figure/figures/inbox.d.ts +7 -0
- package/dist/lib/figure/figures/inbox.js +92 -0
- package/dist/lib/figure/figures/laptop.d.ts +7 -0
- package/dist/lib/figure/figures/laptop.js +67 -0
- package/dist/lib/figure/figures/monitor.d.ts +7 -0
- package/dist/lib/figure/figures/monitor.js +59 -0
- package/dist/lib/figure/figures/pipeline.d.ts +8 -0
- package/dist/lib/figure/figures/pipeline.js +117 -0
- package/dist/lib/figure/figures/platform.d.ts +7 -0
- package/dist/lib/figure/figures/platform.js +117 -0
- package/dist/lib/figure/figures/server.d.ts +7 -0
- package/dist/lib/figure/figures/server.js +115 -0
- package/dist/lib/figure/figures/spreadsheet.d.ts +7 -0
- package/dist/lib/figure/figures/spreadsheet.js +87 -0
- package/dist/lib/figure/figures/timeline.d.ts +7 -0
- package/dist/lib/figure/figures/timeline.js +65 -0
- package/dist/lib/figure/kernel.d.ts +152 -0
- package/dist/lib/figure/kernel.js +576 -0
- package/dist/lib/figure/parts.d.ts +42 -0
- package/dist/lib/figure/parts.js +126 -0
- package/dist/lib/form-reset.d.ts +11 -0
- package/dist/lib/form-reset.js +22 -0
- package/dist/lib/glide.d.ts +53 -0
- package/dist/lib/glide.js +138 -0
- package/dist/lib/graph-layout.d.ts +58 -0
- package/dist/lib/graph-layout.js +200 -0
- package/dist/lib/illustration-drawings.d.ts +89 -0
- package/dist/lib/illustration-drawings.js +539 -0
- package/dist/lib/illustration-info.d.ts +37 -0
- package/dist/lib/illustration-info.js +22 -0
- package/dist/lib/illustration-library.d.ts +87 -0
- package/dist/lib/illustration-library.js +352 -0
- package/dist/lib/logo-geometry.d.ts +29 -0
- package/dist/lib/logo-geometry.js +67 -0
- package/dist/lib/markdown-guard.d.ts +16 -0
- package/dist/lib/markdown-guard.js +123 -0
- package/dist/lib/merge-refs.d.ts +10 -0
- package/dist/lib/merge-refs.js +26 -0
- package/dist/lib/motion.d.ts +6 -0
- package/dist/lib/motion.js +12 -0
- package/dist/lib/pdf-worker.d.ts +1 -0
- package/dist/lib/pdf-worker.js +6 -0
- package/dist/lib/pdf.d.ts +19 -0
- package/dist/lib/pdf.js +58 -0
- package/dist/lib/platform.d.ts +33 -0
- package/dist/lib/platform.js +68 -0
- package/dist/lib/room.d.ts +25 -0
- package/dist/lib/room.js +46 -0
- package/dist/lib/table-fit.d.ts +143 -0
- package/dist/lib/table-fit.js +577 -0
- package/dist/lib/theme-script.d.ts +18 -0
- package/dist/lib/theme-script.js +29 -0
- package/dist/styles/expressive.css +188 -0
- package/dist/styles/fonts.css +145 -0
- package/dist/styles/index.css +206 -0
- package/dist/styles/material.css +313 -0
- package/dist/styles/parts/ai.css +360 -0
- package/dist/styles/parts/brand.css +75 -0
- package/dist/styles/parts/controls.css +725 -0
- package/dist/styles/parts/data.css +222 -0
- package/dist/styles/parts/editorial.css +120 -0
- package/dist/styles/parts/feedback.css +273 -0
- package/dist/styles/parts/foundations.css +166 -0
- package/dist/styles/parts/graph.css +214 -0
- package/dist/styles/parts/inputs.css +261 -0
- package/dist/styles/parts/isometric.css +124 -0
- package/dist/styles/parts/navigation.css +232 -0
- package/dist/styles/parts/overlays.css +250 -0
- package/dist/styles/parts/pdf.css +154 -0
- package/dist/styles/parts/react-flow.css +519 -0
- package/dist/styles/parts/whiteboard.css +855 -0
- package/dist/styles/tokens.css +290 -0
- package/dist/vite.d.ts +116 -0
- package/dist/vite.js +129 -0
- package/package.json +189 -3
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { ArrowUpIcon, FileTextIcon, PaperclipIcon, SquareIcon, XIcon } from "lucide-react";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { cn } from "../lib/cn.js";
|
|
6
|
+
import { cssDuration } from "../lib/motion.js";
|
|
7
|
+
import { mergeRefs } from "../lib/merge-refs.js";
|
|
8
|
+
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "./dialog.js";
|
|
9
|
+
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupTextarea, } from "./input-group.js";
|
|
10
|
+
import { Spinner } from "./spinner.js";
|
|
11
|
+
const PromptInputContext = React.createContext(null);
|
|
12
|
+
function usePromptInput(part) {
|
|
13
|
+
const context = React.useContext(PromptInputContext);
|
|
14
|
+
if (!context)
|
|
15
|
+
throw new Error(`${part} must be used inside <PromptInput>.`);
|
|
16
|
+
return context;
|
|
17
|
+
}
|
|
18
|
+
/* ── Motion helpers ────────────────────────────────────────────────────────── */
|
|
19
|
+
const reducedMotion = () => typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
20
|
+
/**
|
|
21
|
+
* The morph's timing: two and a half times `--duration` on an even ease-in-out, so the bar is seen to grow
|
|
22
|
+
* and settle (the brand ease front-loads a glide this size into one frame); none under reduced
|
|
23
|
+
* motion.
|
|
24
|
+
*/
|
|
25
|
+
function morphTiming() {
|
|
26
|
+
if (typeof document === "undefined" || reducedMotion())
|
|
27
|
+
return null;
|
|
28
|
+
const duration = cssDuration() * 2.5;
|
|
29
|
+
if (!duration)
|
|
30
|
+
return null;
|
|
31
|
+
return { duration, easing: "cubic-bezier(0.65, 0, 0.35, 1)" };
|
|
32
|
+
}
|
|
33
|
+
let measureContext;
|
|
34
|
+
/** The width of `text` on one line in the textarea's own font. */
|
|
35
|
+
function lineWidth(text, el) {
|
|
36
|
+
measureContext ??= document.createElement("canvas").getContext("2d");
|
|
37
|
+
if (!measureContext)
|
|
38
|
+
return 0;
|
|
39
|
+
const cs = getComputedStyle(el);
|
|
40
|
+
measureContext.font = `${cs.fontStyle} ${cs.fontWeight} ${cs.fontSize} ${cs.fontFamily}`;
|
|
41
|
+
const spacing = parseFloat(cs.letterSpacing) || 0;
|
|
42
|
+
return measureContext.measureText(text).width + spacing * text.length;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Where a part's content starts — its box plus its padding. The layouts pad the text and the
|
|
46
|
+
* toolbar differently, so the morph moves what is seen from where it was seen, not the box.
|
|
47
|
+
*/
|
|
48
|
+
function contentOrigin(el) {
|
|
49
|
+
const rect = el.getBoundingClientRect();
|
|
50
|
+
const cs = getComputedStyle(el);
|
|
51
|
+
return { left: rect.left + parseFloat(cs.paddingLeft), top: rect.top + parseFloat(cs.paddingTop) };
|
|
52
|
+
}
|
|
53
|
+
/** Text no wider than the room by this much more goes back to one line, so it never flickers at the edge. */
|
|
54
|
+
const RETURN_PX = 16;
|
|
55
|
+
/** Less room than this for the text on one line (a phone, a bar full of tools) and the bar stays stacked. */
|
|
56
|
+
const MIN_ROOM = 160;
|
|
57
|
+
const imageName = (name) => /\.(png|jpe?g|gif|webp|avif|svg)$/i.test(name);
|
|
58
|
+
/** An event that reached the bar through a React portal (the dialog an attachment opened). */
|
|
59
|
+
const fromPortal = (event) => !event.currentTarget.contains(event.target);
|
|
60
|
+
/**
|
|
61
|
+
* PromptInput — the prompt bar of an AI chat. It starts as one 38px line: tools on the left, the
|
|
62
|
+
* text, and the round send button on the right. The moment the text would run into the send
|
|
63
|
+
* button, or gets a second line, the bar morphs: it grows, the text takes the full width, and
|
|
64
|
+
* the tools and send button glide down into a toolbar. Empty, or short enough again, it morphs
|
|
65
|
+
* back. Enter sends; Shift+Enter adds a line.
|
|
66
|
+
*
|
|
67
|
+
* Compose: `PromptInput` → `PromptInputHeader` (`PromptInputAttachment`s) · `PromptInputTextarea` ·
|
|
68
|
+
* `PromptInputToolbar` → `PromptInputTools` (`PromptInputButton`s, `PromptInputAttachButton`) +
|
|
69
|
+
* `PromptInputSubmit`. With `onFiles` it also takes pasted screenshots and dropped files.
|
|
70
|
+
* The rule people break: a second primary button in the bar. Send is the one action; tools are ghost.
|
|
71
|
+
*/
|
|
72
|
+
export function PromptInput({ value: valueProp, defaultValue = "", onValueChange, onSubmit, status = "ready", onStop, onFiles, allowEmpty = false, stacked = false, disabled = false, className, children, ref, onDragOver, onDragLeave, onDrop, ...props }) {
|
|
73
|
+
const [own, setOwn] = React.useState(defaultValue);
|
|
74
|
+
// `null` (a draft not loaded yet) counts as no value, as it does on React's own fields.
|
|
75
|
+
const controlled = valueProp != null;
|
|
76
|
+
const value = controlled ? valueProp : own;
|
|
77
|
+
const formRef = React.useRef(null);
|
|
78
|
+
const formRefs = React.useMemo(() => mergeRefs(formRef, ref), [ref]);
|
|
79
|
+
const groupRef = React.useRef(null);
|
|
80
|
+
const textareaRef = React.useRef(null);
|
|
81
|
+
const [dragging, setDragging] = React.useState(false);
|
|
82
|
+
const setValue = React.useCallback((next) => {
|
|
83
|
+
if (!controlled)
|
|
84
|
+
setOwn(next);
|
|
85
|
+
onValueChange?.(next);
|
|
86
|
+
}, [controlled, onValueChange]);
|
|
87
|
+
/* ── The morph between one line and the stacked bar (FLIP) ── */
|
|
88
|
+
const [layout, setLayout] = React.useState(stacked ? "stacked" : "inline");
|
|
89
|
+
const layoutRef = React.useRef(layout);
|
|
90
|
+
layoutRef.current = layout;
|
|
91
|
+
/** Group width minus the text's room, read while inline: gives the inline room at any width. */
|
|
92
|
+
const chrome = React.useRef(null);
|
|
93
|
+
const first = React.useRef(null);
|
|
94
|
+
const running = React.useRef([]);
|
|
95
|
+
/** The morph now playing: an older one that ends late must not undo this one's settings. */
|
|
96
|
+
const morphing = React.useRef(0);
|
|
97
|
+
const mounted = React.useRef(false);
|
|
98
|
+
const morph = React.useCallback((next, animate) => {
|
|
99
|
+
if (next === layoutRef.current)
|
|
100
|
+
return;
|
|
101
|
+
const group = groupRef.current;
|
|
102
|
+
if (group && animate) {
|
|
103
|
+
// Read where everything is drawn now (mid-morph included), before the layout changes.
|
|
104
|
+
first.current = {
|
|
105
|
+
box: group.getBoundingClientRect(),
|
|
106
|
+
parts: new Map([...group.querySelectorAll("[data-morph]")].map((el) => [el, contentOrigin(el)])),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
layoutRef.current = next;
|
|
110
|
+
setLayout(next);
|
|
111
|
+
}, []);
|
|
112
|
+
/** One line or stacked, for the text as it is now. */
|
|
113
|
+
const decide = React.useCallback((animate) => {
|
|
114
|
+
const group = groupRef.current;
|
|
115
|
+
const textarea = textareaRef.current;
|
|
116
|
+
if (!group || !textarea)
|
|
117
|
+
return;
|
|
118
|
+
if (layoutRef.current === "inline") {
|
|
119
|
+
const cs = getComputedStyle(textarea);
|
|
120
|
+
const room = textarea.clientWidth - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight);
|
|
121
|
+
chrome.current = group.clientWidth - room;
|
|
122
|
+
}
|
|
123
|
+
if (stacked)
|
|
124
|
+
return morph("stacked", animate);
|
|
125
|
+
// Too little room beside the tools: stacked, even empty.
|
|
126
|
+
if (chrome.current != null && group.clientWidth - chrome.current < MIN_ROOM)
|
|
127
|
+
return morph("stacked", animate);
|
|
128
|
+
const text = textarea.value;
|
|
129
|
+
if (!text)
|
|
130
|
+
return morph("inline", animate);
|
|
131
|
+
if (text.includes("\n"))
|
|
132
|
+
return morph("stacked", animate);
|
|
133
|
+
if (chrome.current == null)
|
|
134
|
+
return;
|
|
135
|
+
const room = group.clientWidth - chrome.current;
|
|
136
|
+
// A long paste is wider than any bar long before its end: measuring all of it (a megabyte
|
|
137
|
+
// of log) would hold up every keystroke after it.
|
|
138
|
+
const width = lineWidth(text.slice(0, 2000), textarea);
|
|
139
|
+
if (layoutRef.current === "inline" && width > room)
|
|
140
|
+
morph("stacked", animate);
|
|
141
|
+
else if (layoutRef.current === "stacked" && width < room - RETURN_PX)
|
|
142
|
+
morph("inline", animate);
|
|
143
|
+
}, [morph, stacked]);
|
|
144
|
+
// Every change of the text: decide before the frame paints. The first decision does not animate.
|
|
145
|
+
React.useLayoutEffect(() => {
|
|
146
|
+
decide(mounted.current);
|
|
147
|
+
mounted.current = true;
|
|
148
|
+
}, [value, decide]);
|
|
149
|
+
// The width changes the room: decide again, without the morph.
|
|
150
|
+
React.useEffect(() => {
|
|
151
|
+
const group = groupRef.current;
|
|
152
|
+
if (!group)
|
|
153
|
+
return;
|
|
154
|
+
const resize = new ResizeObserver(() => decide(false));
|
|
155
|
+
resize.observe(group);
|
|
156
|
+
return () => resize.disconnect();
|
|
157
|
+
}, [decide]);
|
|
158
|
+
// Play the morph: the bar's height, and each part from where it was to where it is now.
|
|
159
|
+
React.useLayoutEffect(() => {
|
|
160
|
+
const from = first.current;
|
|
161
|
+
first.current = null;
|
|
162
|
+
const group = groupRef.current;
|
|
163
|
+
const timing = morphTiming();
|
|
164
|
+
if (!from || !group || !timing)
|
|
165
|
+
return;
|
|
166
|
+
for (const a of running.current)
|
|
167
|
+
a.cancel();
|
|
168
|
+
running.current = [];
|
|
169
|
+
// The text wraps as the new layout does before anything is measured: its final height sets the bar's.
|
|
170
|
+
const control = group.querySelector("[data-slot=input-group-control]");
|
|
171
|
+
if (control)
|
|
172
|
+
control.wrap = layout === "inline" ? "off" : "soft";
|
|
173
|
+
// Every part's new place, read before the bar's height starts playing: that resizes the bar
|
|
174
|
+
// at once, and on a page that centres it, moves it.
|
|
175
|
+
const box = group.getBoundingClientRect();
|
|
176
|
+
const moves = [];
|
|
177
|
+
for (const [el, was] of from.parts) {
|
|
178
|
+
if (!el.isConnected)
|
|
179
|
+
continue;
|
|
180
|
+
const now = contentOrigin(el);
|
|
181
|
+
const dx = was.left - from.box.left - (now.left - box.left);
|
|
182
|
+
const dy = was.top - from.box.top - (now.top - box.top);
|
|
183
|
+
if (Math.abs(dx) >= 0.5 || Math.abs(dy) >= 0.5)
|
|
184
|
+
moves.push([el, dx, dy]);
|
|
185
|
+
}
|
|
186
|
+
// While the bar's height plays, its contents keep their final layout: rows packed at the top
|
|
187
|
+
// (data-morphing) and the text at its final height, so nothing is squeezed, scrolled or
|
|
188
|
+
// floated — the bar opens and closes around them, clipped.
|
|
189
|
+
const id = ++morphing.current;
|
|
190
|
+
group.style.overflow = "clip";
|
|
191
|
+
group.dataset.morphing = "";
|
|
192
|
+
if (control)
|
|
193
|
+
control.style.minHeight = `${control.offsetHeight}px`;
|
|
194
|
+
const settle = () => {
|
|
195
|
+
if (id !== morphing.current)
|
|
196
|
+
return;
|
|
197
|
+
group.style.overflow = "";
|
|
198
|
+
delete group.dataset.morphing;
|
|
199
|
+
if (control)
|
|
200
|
+
control.style.minHeight = "";
|
|
201
|
+
};
|
|
202
|
+
const grow = group.animate([{ height: `${from.box.height}px` }, { height: `${box.height}px` }], timing);
|
|
203
|
+
running.current.push(grow);
|
|
204
|
+
grow.finished.then(settle, settle);
|
|
205
|
+
for (const [el, dx, dy] of moves)
|
|
206
|
+
running.current.push(el.animate([{ translate: `${dx}px ${dy}px` }, { translate: "0px 0px" }], timing));
|
|
207
|
+
}, [layout]);
|
|
208
|
+
React.useEffect(() => () => running.current.forEach((a) => a.cancel()), []);
|
|
209
|
+
const busy = status === "submitted" || status === "streaming";
|
|
210
|
+
const context = React.useMemo(() => ({
|
|
211
|
+
value,
|
|
212
|
+
setValue,
|
|
213
|
+
status,
|
|
214
|
+
disabled,
|
|
215
|
+
allowEmpty,
|
|
216
|
+
layout,
|
|
217
|
+
onStop,
|
|
218
|
+
onFiles,
|
|
219
|
+
submit: () => formRef.current?.requestSubmit(),
|
|
220
|
+
textareaRef,
|
|
221
|
+
}), [value, setValue, status, disabled, allowEmpty, layout, onStop, onFiles]);
|
|
222
|
+
const takesFiles = onFiles != null && !disabled;
|
|
223
|
+
const hasFiles = (event) => event.dataTransfer.types.includes("Files");
|
|
224
|
+
return (_jsx(PromptInputContext.Provider, { value: context, children: _jsx("form", { ref: formRefs, "data-slot": "prompt-input", "data-status": status, "data-layout": layout, className: cn("w-full", className), onSubmit: (event) => {
|
|
225
|
+
event.preventDefault();
|
|
226
|
+
const text = value.trim();
|
|
227
|
+
if ((!text && !allowEmpty) || busy || disabled)
|
|
228
|
+
return;
|
|
229
|
+
onSubmit?.(text, event);
|
|
230
|
+
if (!controlled)
|
|
231
|
+
setValue("");
|
|
232
|
+
}, onDragOver: (event) => {
|
|
233
|
+
onDragOver?.(event);
|
|
234
|
+
if (!takesFiles || !hasFiles(event))
|
|
235
|
+
return;
|
|
236
|
+
event.preventDefault();
|
|
237
|
+
event.dataTransfer.dropEffect = "copy";
|
|
238
|
+
setDragging(true);
|
|
239
|
+
}, onDragLeave: (event) => {
|
|
240
|
+
onDragLeave?.(event);
|
|
241
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
242
|
+
setDragging(false);
|
|
243
|
+
}, onDrop: (event) => {
|
|
244
|
+
onDrop?.(event);
|
|
245
|
+
setDragging(false);
|
|
246
|
+
if (!takesFiles || !hasFiles(event))
|
|
247
|
+
return;
|
|
248
|
+
event.preventDefault();
|
|
249
|
+
const files = [...event.dataTransfer.files];
|
|
250
|
+
if (files.length)
|
|
251
|
+
onFiles(files);
|
|
252
|
+
}, ...props, children: _jsx(InputGroup, { ref: groupRef, "data-layout": layout, "data-dragging": dragging ? "" : undefined, className: "has-[>textarea]:min-h-0 data-dragging:border-control-focus", onMouseDown: (event) => {
|
|
253
|
+
// Empty space in the bar focuses the text, as on a native field — not a click in the
|
|
254
|
+
// preview dialog an attachment opened, which reaches here through React's portal.
|
|
255
|
+
if (fromPortal(event) ||
|
|
256
|
+
event.target.closest("button, a, input, textarea, select"))
|
|
257
|
+
return;
|
|
258
|
+
event.preventDefault();
|
|
259
|
+
textareaRef.current?.focus();
|
|
260
|
+
}, children: children }) }) }));
|
|
261
|
+
}
|
|
262
|
+
/* ── Attachments ───────────────────────────────────────────────────────────── */
|
|
263
|
+
/** A row above the text, for `PromptInputAttachment`s. */
|
|
264
|
+
export function PromptInputHeader({ className, ...props }) {
|
|
265
|
+
return (_jsx(InputGroupAddon, { "data-slot": "prompt-input-header", align: "block-start", className: cn("flex-wrap items-center gap-2 pb-0", className), ...props }));
|
|
266
|
+
}
|
|
267
|
+
/** The image a file or URL points to, as an object URL that is released when it is no longer shown. */
|
|
268
|
+
function usePreview(file, src, image) {
|
|
269
|
+
const [url, setUrl] = React.useState(src);
|
|
270
|
+
React.useEffect(() => {
|
|
271
|
+
if (src || !file || !image) {
|
|
272
|
+
setUrl(src);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const objectUrl = URL.createObjectURL(file);
|
|
276
|
+
setUrl(objectUrl);
|
|
277
|
+
return () => URL.revokeObjectURL(objectUrl);
|
|
278
|
+
}, [file, src, image]);
|
|
279
|
+
return url;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* A file attached to the prompt. An image — a pasted screenshot, a PNG — shows as a 56px
|
|
283
|
+
* thumbnail that opens a larger preview; anything else, a PDF or a spreadsheet, as a raised mono
|
|
284
|
+
* key with its name. Both have a remove button.
|
|
285
|
+
*/
|
|
286
|
+
export function PromptInputAttachment({ file, name: nameProp, src, type, onRemove, labels, className, ...props }) {
|
|
287
|
+
const name = nameProp ?? file?.name ?? "Attachment";
|
|
288
|
+
const mime = type ?? file?.type;
|
|
289
|
+
// A picture with something to show: an image without its file or URL yet is a chip.
|
|
290
|
+
const image = (mime ? mime.startsWith("image/") : src != null || imageName(name)) && (src != null || file != null);
|
|
291
|
+
const url = usePreview(file, src, image);
|
|
292
|
+
// A 24px target, the inset size of a chip's remover. On a thumbnail it is a 20px raised disc on
|
|
293
|
+
// the corner, the target reaching a little past the disc.
|
|
294
|
+
const remove = onRemove && (_jsx("button", { type: "button", "data-slot": "prompt-input-attachment-remove", "aria-label": labels?.remove ?? `Remove ${name}`, onClick: onRemove, className: cn("inline-flex size-(--control-inset-sm) shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground focus-ring transition-[background-color,color] duration-(--duration) ease-(--ease) hover:text-foreground", image ? "absolute -end-2 -top-2 z-10" : "hover:bg-control-hover"), children: image ? (_jsx("span", { className: "inline-flex size-5 items-center justify-center rounded-full material-raised", children: _jsx(XIcon, { "aria-hidden": true, className: "size-3" }) })) : (_jsx(XIcon, { "aria-hidden": true, className: "size-3.5" })) }));
|
|
295
|
+
if (image)
|
|
296
|
+
return (_jsxs("div", { "data-slot": "prompt-input-attachment", "data-kind": "image", className: cn("relative size-14 shrink-0", className), ...props, children: [_jsxs(Dialog, { children: [_jsx(DialogTrigger, { "aria-label": labels?.preview ?? `Preview ${name}`, className: "block size-full cursor-zoom-in overflow-hidden rounded-item border border-field-edge bg-control-surface focus-ring", children: url && _jsx("img", { src: url, alt: "", draggable: false, className: "size-full object-cover" }) }), _jsxs(DialogContent, { size: "xl", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { className: "truncate font-mono text-sm", children: name }) }), url && (_jsx("img", { src: url, alt: name, className: "mx-auto block h-auto max-h-[min(70vh,calc(100dvh-12rem))] min-h-0 w-auto max-w-full rounded-item" }))] })] }), remove] }));
|
|
297
|
+
const Icon = mime === "application/pdf" || /\.pdf$/i.test(name) ? FileTextIcon : PaperclipIcon;
|
|
298
|
+
return (_jsxs("div", { "data-slot": "prompt-input-attachment", "data-kind": "file", className: cn("inline-flex min-h-(--control-inset-sm) max-w-56 items-center gap-1.5 rounded-item bg-control-surface bg-linear-to-b from-control-inner-edge to-transparent ps-2 font-mono text-[11px] text-foreground shadow-key", onRemove ? "pe-0" : "pe-2", className), ...props, children: [_jsx(Icon, { "aria-hidden": true, className: "size-3 shrink-0 text-muted-foreground" }), _jsx("span", { className: "truncate", children: name }), remove] }));
|
|
299
|
+
}
|
|
300
|
+
/** A ghost paperclip that opens the file picker. */
|
|
301
|
+
export function PromptInputAttachButton({ onFiles, accept, multiple = true, label = "Attach files", disabled, ...props }) {
|
|
302
|
+
const input = React.useRef(null);
|
|
303
|
+
const context = React.useContext(PromptInputContext);
|
|
304
|
+
return (_jsxs(_Fragment, { children: [_jsx(PromptInputButton, { "aria-label": label, disabled: disabled ?? context?.disabled, onClick: () => input.current?.click(), ...props, children: _jsx(PaperclipIcon, {}) }), _jsx("input", { ref: input, type: "file", tabIndex: -1, "aria-hidden": true, hidden: true, accept: accept, multiple: multiple, onChange: (event) => {
|
|
305
|
+
const files = [...(event.currentTarget.files ?? [])];
|
|
306
|
+
event.currentTarget.value = "";
|
|
307
|
+
if (files.length)
|
|
308
|
+
onFiles(files);
|
|
309
|
+
} })] }));
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* The prompt itself: one line while it fits, then a borderless textarea that grows with its
|
|
313
|
+
* content up to 240px and scrolls. Enter sends; Shift+Enter adds a line, and the Enter that
|
|
314
|
+
* confirms an input method's text does not send. Pasted files go to the bar's `onFiles`.
|
|
315
|
+
*/
|
|
316
|
+
export function PromptInputTextarea({ className, ref, onChange, onKeyDown, onPaste, placeholder = "Ask anything", ...props }) {
|
|
317
|
+
const { value, setValue, submit, disabled, layout, onFiles, textareaRef } = usePromptInput("PromptInputTextarea");
|
|
318
|
+
const refs = React.useMemo(() => mergeRefs(textareaRef, ref), [textareaRef, ref]);
|
|
319
|
+
// One row, and no wrapping while the bar is one line (Base UI's control does not type these).
|
|
320
|
+
React.useLayoutEffect(() => {
|
|
321
|
+
const textarea = textareaRef.current;
|
|
322
|
+
if (!textarea)
|
|
323
|
+
return;
|
|
324
|
+
textarea.rows = 1;
|
|
325
|
+
textarea.wrap = layout === "inline" ? "off" : "soft";
|
|
326
|
+
}, [layout, textareaRef]);
|
|
327
|
+
// Where `field-sizing: content` is missing, grow with the text by hand; the max height still caps it.
|
|
328
|
+
React.useLayoutEffect(() => {
|
|
329
|
+
const textarea = textareaRef.current;
|
|
330
|
+
if (!textarea || typeof CSS === "undefined" || CSS.supports("field-sizing", "content"))
|
|
331
|
+
return;
|
|
332
|
+
textarea.style.height = "auto";
|
|
333
|
+
textarea.style.height = `${textarea.scrollHeight}px`;
|
|
334
|
+
}, [value, layout, textareaRef]);
|
|
335
|
+
return (_jsxs(_Fragment, { children: [placeholder ? (_jsx("span", { "data-slot": "prompt-input-placeholder", "data-morph": "", "aria-hidden": "true", dir: props.dir, className: "font-body text-base sm:text-[15px]", children: placeholder })) : null, _jsx(InputGroupTextarea
|
|
336
|
+
// Base UI types the control's ref as an input; it renders the textarea here.
|
|
337
|
+
, {
|
|
338
|
+
// Base UI types the control's ref as an input; it renders the textarea here.
|
|
339
|
+
ref: refs, "data-morph": "", name: "prompt", value: value, placeholder: placeholder, disabled: disabled, onChange: (event) => {
|
|
340
|
+
onChange?.(event);
|
|
341
|
+
setValue(event.currentTarget.value);
|
|
342
|
+
}, onPaste: (event) => {
|
|
343
|
+
onPaste?.(event);
|
|
344
|
+
const data = event.clipboardData;
|
|
345
|
+
if (event.defaultPrevented || !onFiles || !data.files.length)
|
|
346
|
+
return;
|
|
347
|
+
// Copied text — plain and rich together — pastes as text, though spreadsheets and word
|
|
348
|
+
// processors add a picture of it. Anything else with files (a screenshot, a copied image) attaches.
|
|
349
|
+
if (data.types.includes("text/plain") && data.types.includes("text/html"))
|
|
350
|
+
return;
|
|
351
|
+
event.preventDefault();
|
|
352
|
+
onFiles([...data.files]);
|
|
353
|
+
}, onKeyDown: (event) => {
|
|
354
|
+
onKeyDown?.(event);
|
|
355
|
+
if (event.defaultPrevented)
|
|
356
|
+
return;
|
|
357
|
+
// Not the Enter that confirms an input method's text: Safari ends the composition before
|
|
358
|
+
// that keydown, which then shows only as key code 229.
|
|
359
|
+
const composing = event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229;
|
|
360
|
+
if (event.key === "Enter" && !event.shiftKey && !composing) {
|
|
361
|
+
event.preventDefault();
|
|
362
|
+
submit();
|
|
363
|
+
}
|
|
364
|
+
}, className: className, ...props })] }));
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* The tools and the send button. On one line they sit either side of the text; stacked, they
|
|
368
|
+
* form the row under it.
|
|
369
|
+
*/
|
|
370
|
+
export function PromptInputToolbar({ className, ...props }) {
|
|
371
|
+
return _jsx("div", { "data-slot": "prompt-input-toolbar", className: cn("contents", className), ...props });
|
|
372
|
+
}
|
|
373
|
+
export function PromptInputTools({ side = "start", className, ...props }) {
|
|
374
|
+
return (_jsx("div", { "data-slot": "prompt-input-tools", "data-side": side, "data-morph": "", className: cn("flex min-w-0 items-center gap-1", className), ...props }));
|
|
375
|
+
}
|
|
376
|
+
/** A tool in the toolbar (attach, search, a mode): ghost and 30px. Icon-only ones need `aria-label`. */
|
|
377
|
+
export function PromptInputButton({ variant = "ghost", size, children, ...props }) {
|
|
378
|
+
const icon = React.Children.count(children) === 1 && React.isValidElement(children);
|
|
379
|
+
return (_jsx(InputGroupButton, { type: "button", variant: variant, size: size ?? (icon ? "icon" : "default"), ...props, children: children }));
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* The send button: round, primary, an arrow. While the reply is on its way it shows a spinner,
|
|
383
|
+
* then a stop square that calls `onStop`; it is disabled while the prompt is empty.
|
|
384
|
+
*/
|
|
385
|
+
export function PromptInputSubmit({ labels, className, onClick, ...props }) {
|
|
386
|
+
const { value, status, disabled, allowEmpty, onStop } = usePromptInput("PromptInputSubmit");
|
|
387
|
+
const busy = status === "submitted" || status === "streaming";
|
|
388
|
+
const stop = busy && onStop != null;
|
|
389
|
+
const label = stop
|
|
390
|
+
? (labels?.stop ?? "Stop")
|
|
391
|
+
: busy
|
|
392
|
+
? (labels?.waiting ?? "Waiting for the reply")
|
|
393
|
+
: (labels?.send ?? "Send");
|
|
394
|
+
return (_jsx("span", { "data-slot": "prompt-input-submit", "data-morph": "", className: "flex", children: _jsx(InputGroupButton, { "data-status": status, variant: "primary", size: "icon", type: stop ? "button" : "submit", "aria-label": label, disabled: disabled || (busy ? !stop : !allowEmpty && value.trim() === ""), onClick: (event) => {
|
|
395
|
+
onClick?.(event);
|
|
396
|
+
if (!stop || event.defaultPrevented)
|
|
397
|
+
return;
|
|
398
|
+
// Stopping re-renders this button as Send before the click's default action runs:
|
|
399
|
+
// cancel it, or the form would send whatever is in the prompt.
|
|
400
|
+
event.preventDefault();
|
|
401
|
+
onStop();
|
|
402
|
+
}, className: className, ...props, children: status === "streaming" && stop ? (_jsx(SquareIcon, { "aria-hidden": true, className: "size-3 fill-current" })) : busy ? (_jsx(Spinner, { size: "sm", "aria-hidden": true })) : (_jsx(ArrowUpIcon, { "aria-hidden": true })) }) }));
|
|
403
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ComponentProps, ReactNode } from "react";
|
|
2
|
+
export interface QuoteProps extends Omit<ComponentProps<"figure">, "children"> {
|
|
3
|
+
/** The quote itself, set in Licht. Real words from a real person only. */
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
/** Who said it. */
|
|
6
|
+
author?: ReactNode;
|
|
7
|
+
/** Their role and organisation, e.g. `Editor, Organisation`. */
|
|
8
|
+
byline?: ReactNode;
|
|
9
|
+
/** A small single-colour logo or mark, in the current ink, beside the attribution. */
|
|
10
|
+
logo?: ReactNode;
|
|
11
|
+
/** `cite` URL of the source, if the quote is published elsewhere. */
|
|
12
|
+
cite?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Quote — a quote card: an object on the page (the card material at 20px) holding a Licht
|
|
16
|
+
* quote, a mono attribution and an optional logo.
|
|
17
|
+
*
|
|
18
|
+
* The rule people break: inventing it. Never write a quote, a name or a logo that
|
|
19
|
+
* does not exist and is not approved for use. In drafts, use plain placeholder text
|
|
20
|
+
* ("Quote from a real customer goes here.") so nothing fictional can ship by accident.
|
|
21
|
+
*/
|
|
22
|
+
export declare function Quote({ author, byline, logo, cite, className, children, ...props }: QuoteProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { cn } from "../lib/cn.js";
|
|
4
|
+
/**
|
|
5
|
+
* Quote — a quote card: an object on the page (the card material at 20px) holding a Licht
|
|
6
|
+
* quote, a mono attribution and an optional logo.
|
|
7
|
+
*
|
|
8
|
+
* The rule people break: inventing it. Never write a quote, a name or a logo that
|
|
9
|
+
* does not exist and is not approved for use. In drafts, use plain placeholder text
|
|
10
|
+
* ("Quote from a real customer goes here.") so nothing fictional can ship by accident.
|
|
11
|
+
*/
|
|
12
|
+
export function Quote({ author, byline, logo, cite, className, children, ...props }) {
|
|
13
|
+
const hasAttribution = author != null || byline != null || logo != null;
|
|
14
|
+
return (_jsxs("figure", { "data-slot": "quote", className: cn("m-0 flex w-full flex-col gap-8 surface-card break-words sm:gap-10", className), ...props, children: [_jsxs("blockquote", { cite: cite, className: "m-0 flex flex-col gap-4", children: [_jsx("span", { "aria-hidden": true, className: "font-heading text-[48px] leading-[0.6] font-light text-muted-foreground select-none", children: "\u201C" }), _jsx("div", { "data-slot": "quote-text", className: "font-heading text-[24px] leading-[1.25] font-light tracking-[-0.015em] text-pretty text-foreground sm:text-[28px] [&>p]:m-0 [&>p+p]:mt-4", children: children })] }), hasAttribution ? (_jsxs("figcaption", { "data-slot": "quote-attribution", className: "flex items-center justify-between gap-6 border-t border-border pt-5 font-mono text-xs leading-snug", children: [_jsxs("span", { className: "flex min-w-0 flex-col gap-1", children: [author != null ? _jsx("span", { className: "text-foreground", children: author }) : null, byline != null ? _jsx("span", { className: "text-muted-foreground", children: byline }) : null] }), logo != null ? (_jsx("span", { "data-slot": "quote-logo", className: "flex shrink-0 items-center text-foreground-soft [&_img]:h-6 [&_svg]:h-6 [&_svg]:w-auto", children: logo })) : null] })) : null] }));
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Radio as BaseRadio } from "@base-ui/react/radio";
|
|
2
|
+
import { RadioGroup as BaseRadioGroup } from "@base-ui/react/radio-group";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
/**
|
|
5
|
+
* RadioGroup — one choice from a short list where every option should stay visible.
|
|
6
|
+
*
|
|
7
|
+
* Render it through `<Fieldset render={<RadioGroup />}>` inside a `<Field name>` so the options
|
|
8
|
+
* share a legend and validation. For 2–5 short, comparable options consider `ToggleGroup`; past
|
|
9
|
+
* about seven options use `Select`. The rule people break: a radio group with nothing selected
|
|
10
|
+
* and no `required` — give it a sensible `defaultValue` or make the choice mandatory.
|
|
11
|
+
*/
|
|
12
|
+
export declare function RadioGroup<Value>({ className, ref, ...props }: BaseRadioGroup.Props<Value>): React.JSX.Element;
|
|
13
|
+
/**
|
|
14
|
+
* Radio — an 18px round control in the field material. Selected, it takes the primary fill
|
|
15
|
+
* with an inner dot. Always place it inside `<RadioGroup>` and next to a visible label
|
|
16
|
+
* (`<FieldLabel><Radio value="…" />Label</FieldLabel>`).
|
|
17
|
+
*/
|
|
18
|
+
export declare function Radio<Value>({ className, ...props }: BaseRadio.Root.Props<Value>): React.JSX.Element;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Radio as BaseRadio } from "@base-ui/react/radio";
|
|
4
|
+
import { RadioGroup as BaseRadioGroup } from "@base-ui/react/radio-group";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { sx } from "../lib/cn.js";
|
|
7
|
+
import { useFormReset } from "../lib/form-reset.js";
|
|
8
|
+
import { mergeRefs } from "../lib/merge-refs.js";
|
|
9
|
+
/**
|
|
10
|
+
* RadioGroup — one choice from a short list where every option should stay visible.
|
|
11
|
+
*
|
|
12
|
+
* Render it through `<Fieldset render={<RadioGroup />}>` inside a `<Field name>` so the options
|
|
13
|
+
* share a legend and validation. For 2–5 short, comparable options consider `ToggleGroup`; past
|
|
14
|
+
* about seven options use `Select`. The rule people break: a radio group with nothing selected
|
|
15
|
+
* and no `required` — give it a sensible `defaultValue` or make the choice mandatory.
|
|
16
|
+
*/
|
|
17
|
+
export function RadioGroup({ className, ref, ...props }) {
|
|
18
|
+
// A form's reset remounts the group, and its radios, from its defaults (lib/form-reset).
|
|
19
|
+
const [resetKey, formRef] = useFormReset();
|
|
20
|
+
const refs = React.useMemo(() => mergeRefs(formRef, ref), [formRef, ref]);
|
|
21
|
+
return (_jsx(BaseRadioGroup, { ref: refs, "data-slot": "radio-group", className: sx("flex flex-col items-start gap-3", className), ...props }, resetKey));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Radio — an 18px round control in the field material. Selected, it takes the primary fill
|
|
25
|
+
* with an inner dot. Always place it inside `<RadioGroup>` and next to a visible label
|
|
26
|
+
* (`<FieldLabel><Radio value="…" />Label</FieldLabel>`).
|
|
27
|
+
*/
|
|
28
|
+
export function Radio({ className, ...props }) {
|
|
29
|
+
return (_jsx(BaseRadio.Root, { "data-slot": "radio", className: sx([
|
|
30
|
+
"relative inline-flex size-[18px] shrink-0 material-field cursor-pointer items-center justify-center rounded-full p-0",
|
|
31
|
+
"data-checked:border-transparent data-checked:bg-primary data-checked:bg-none data-checked:text-primary-foreground data-checked:shadow-checked",
|
|
32
|
+
"data-readonly:cursor-default",
|
|
33
|
+
], className), ...props, children: _jsx(BaseRadio.Indicator, { "data-slot": "radio-indicator", className: "pointer-events-none flex items-center justify-center before:size-1.5 before:rounded-full before:bg-current" }) }));
|
|
34
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Collapsible as BaseCollapsible } from "@base-ui/react/collapsible";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { type CollapsibleTriggerProps } from "./collapsible.js";
|
|
4
|
+
export interface ReasoningProps extends BaseCollapsible.Root.Props {
|
|
5
|
+
/** The model is thinking right now: the label shimmers and the panel opens. */
|
|
6
|
+
streaming?: boolean;
|
|
7
|
+
/** How long it thought, in seconds. Measured from `streaming` when not given. */
|
|
8
|
+
duration?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Reasoning — the model's thinking, folded away. While `streaming` the trigger reads
|
|
12
|
+
* "Thinking…" with a soft shimmer and the panel opens, so the reasoning can be followed as it
|
|
13
|
+
* arrives; when it ends the label becomes "Thought for 4 seconds" and the panel closes a second
|
|
14
|
+
* later, unless the reader has opened or closed it by hand.
|
|
15
|
+
*
|
|
16
|
+
* The rule people break: showing the reasoning in full as the answer. It is supporting detail
|
|
17
|
+
* under its own trigger; the `Response` is the answer.
|
|
18
|
+
*/
|
|
19
|
+
export declare function Reasoning({ streaming, duration: durationProp, open: openProp, defaultOpen, onOpenChange, className, ...props }: ReasoningProps): React.JSX.Element;
|
|
20
|
+
export interface ReasoningTriggerProps extends Omit<CollapsibleTriggerProps, "showIcon"> {
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The trigger: a brain, the label and a chevron, in mono. Children replace the label;
|
|
24
|
+
* the default reads "Thinking…", then "Thought for n seconds".
|
|
25
|
+
*/
|
|
26
|
+
export declare function ReasoningTrigger({ className, children, ...props }: ReasoningTriggerProps): React.JSX.Element;
|
|
27
|
+
/**
|
|
28
|
+
* The reasoning itself, muted and set in from a hairline. Plain text keeps its line breaks;
|
|
29
|
+
* a `Response` inside renders markdown.
|
|
30
|
+
*/
|
|
31
|
+
export declare function ReasoningContent({ className, children, ...props }: React.ComponentProps<"div">): React.JSX.Element;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { BrainIcon, ChevronDownIcon } from "lucide-react";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { cn, sx } from "../lib/cn.js";
|
|
6
|
+
import { Collapsible, CollapsiblePanel, CollapsibleTrigger, } from "./collapsible.js";
|
|
7
|
+
const ReasoningContext = React.createContext({
|
|
8
|
+
streaming: false,
|
|
9
|
+
duration: undefined,
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Reasoning — the model's thinking, folded away. While `streaming` the trigger reads
|
|
13
|
+
* "Thinking…" with a soft shimmer and the panel opens, so the reasoning can be followed as it
|
|
14
|
+
* arrives; when it ends the label becomes "Thought for 4 seconds" and the panel closes a second
|
|
15
|
+
* later, unless the reader has opened or closed it by hand.
|
|
16
|
+
*
|
|
17
|
+
* The rule people break: showing the reasoning in full as the answer. It is supporting detail
|
|
18
|
+
* under its own trigger; the `Response` is the answer.
|
|
19
|
+
*/
|
|
20
|
+
export function Reasoning({ streaming = false, duration: durationProp, open: openProp, defaultOpen, onOpenChange, className, ...props }) {
|
|
21
|
+
const [own, setOwn] = React.useState(defaultOpen ?? streaming);
|
|
22
|
+
const open = openProp ?? own;
|
|
23
|
+
const touched = React.useRef(false);
|
|
24
|
+
const started = React.useRef(null);
|
|
25
|
+
const [measured, setMeasured] = React.useState();
|
|
26
|
+
React.useEffect(() => {
|
|
27
|
+
if (streaming) {
|
|
28
|
+
started.current = performance.now();
|
|
29
|
+
if (!touched.current)
|
|
30
|
+
setOwn(true);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (started.current == null)
|
|
34
|
+
return;
|
|
35
|
+
setMeasured(Math.max(1, Math.round((performance.now() - started.current) / 1000)));
|
|
36
|
+
started.current = null;
|
|
37
|
+
if (touched.current)
|
|
38
|
+
return;
|
|
39
|
+
const t = setTimeout(() => setOwn(false), 1000);
|
|
40
|
+
return () => clearTimeout(t);
|
|
41
|
+
}, [streaming]);
|
|
42
|
+
const context = React.useMemo(() => ({ streaming, duration: durationProp ?? measured }), [streaming, durationProp, measured]);
|
|
43
|
+
return (_jsx(ReasoningContext.Provider, { value: context, children: _jsx(Collapsible, { "data-slot": "reasoning", "data-streaming": streaming ? "" : undefined, open: open, onOpenChange: (next, details) => {
|
|
44
|
+
touched.current = true;
|
|
45
|
+
if (openProp === undefined)
|
|
46
|
+
setOwn(next);
|
|
47
|
+
onOpenChange?.(next, details);
|
|
48
|
+
}, className: sx("gap-1", className), ...props }) }));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The trigger: a brain, the label and a chevron, in mono. Children replace the label;
|
|
52
|
+
* the default reads "Thinking…", then "Thought for n seconds".
|
|
53
|
+
*/
|
|
54
|
+
export function ReasoningTrigger({ className, children, ...props }) {
|
|
55
|
+
const { streaming, duration } = React.useContext(ReasoningContext);
|
|
56
|
+
const label = children ??
|
|
57
|
+
(streaming
|
|
58
|
+
? "Thinking…"
|
|
59
|
+
: duration == null
|
|
60
|
+
? "Thought for a few seconds"
|
|
61
|
+
: `Thought for ${duration} ${duration === 1 ? "second" : "seconds"}`);
|
|
62
|
+
return (_jsxs(CollapsibleTrigger, { "data-slot": "reasoning-trigger", showIcon: false, className: sx("gap-1.5 text-muted-foreground", className), ...props, children: [_jsx(BrainIcon, { "aria-hidden": true, className: "size-3.5 shrink-0" }), _jsx("span", { "data-slot": "reasoning-label", "data-streaming": streaming ? "" : undefined, children: label }), _jsx(ChevronDownIcon, { "aria-hidden": true, className: "size-3.5 shrink-0 transition-[rotate] duration-(--duration) ease-(--ease) group-data-panel-open/collapsible-trigger:rotate-180" })] }));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The reasoning itself, muted and set in from a hairline. Plain text keeps its line breaks;
|
|
66
|
+
* a `Response` inside renders markdown.
|
|
67
|
+
*/
|
|
68
|
+
export function ReasoningContent({ className, children, ...props }) {
|
|
69
|
+
return (_jsx(CollapsiblePanel, { "data-slot": "reasoning-content", children: _jsx("div", { className: cn("ml-1.5 border-l border-border/60 py-1 pl-4 text-sm leading-relaxed text-muted-foreground", typeof children === "string" && "whitespace-pre-wrap", className), ...props, children: children }) }));
|
|
70
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type GroupProps, type PanelProps, type SeparatorProps } from "react-resizable-panels";
|
|
3
|
+
export interface ResizablePanelGroupProps extends GroupProps {
|
|
4
|
+
/** `horizontal` lays panels side by side (a vertical handle); `vertical` stacks them. */
|
|
5
|
+
orientation?: "horizontal" | "vertical";
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* ResizablePanelGroup — split panes the user can resize: an editor beside its preview, a list
|
|
9
|
+
* beside its detail, a console under a canvas.
|
|
10
|
+
*
|
|
11
|
+
* Panels are divided by a 1px hairline that turns `--control-focus` on hover, drag and focus,
|
|
12
|
+
* with a hit area of at least 10px (20px on touch). Every handle is a keyboard separator: Tab to
|
|
13
|
+
* it, then arrow keys resize, Home/End jump to the limits and Enter collapses a collapsible panel.
|
|
14
|
+
*
|
|
15
|
+
* The rule people break: boxing every pane. The group is one region — put the material on the
|
|
16
|
+
* group (`surface-container`, or `surface-card` when it is an object) and let hairlines divide it.
|
|
17
|
+
* The group fills its parent, so give the parent (or the group) a height.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ResizablePanelGroup({ orientation, className, ...props }: ResizablePanelGroupProps): React.JSX.Element;
|
|
20
|
+
export interface ResizablePanelProps extends PanelProps {
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* One pane. Sizes take numbers (pixels) or strings: `"30%"`, `"30"` (percent), `"240px"`, `"16rem"`.
|
|
24
|
+
* Give each panel an `id` when the layout is persisted with `defaultLayout`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function ResizablePanel({ className, ...props }: ResizablePanelProps): React.JSX.Element;
|
|
27
|
+
export interface ResizableHandleProps extends SeparatorProps {
|
|
28
|
+
/** Show a small raised grip with mono dots in the middle of the hairline. */
|
|
29
|
+
withHandle?: boolean;
|
|
30
|
+
/** Accessible name of the separator. Defaults to "Resize". */
|
|
31
|
+
"aria-label"?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The divider between two panels: a 1px hairline in `--border` that becomes `--control-focus`
|
|
35
|
+
* while hovered, dragged or focused. `withHandle` adds a tiny raised pill with mono dots — use it
|
|
36
|
+
* when the split is not obviously draggable (a narrow pane, a touch layout).
|
|
37
|
+
*/
|
|
38
|
+
export declare function ResizableHandle({ withHandle, className, children, ...props }: ResizableHandleProps): React.JSX.Element;
|