@zonsh/ui 0.0.0 → 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 +75 -1
- 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 +188 -5
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { ArrowDownIcon } from "lucide-react";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { cn, sx } from "../lib/cn.js";
|
|
6
|
+
import { mergeRefs } from "../lib/merge-refs.js";
|
|
7
|
+
import { Button } from "./button.js";
|
|
8
|
+
/** How close to the end (px) still counts as "at the latest message". */
|
|
9
|
+
const STICK_PX = 32;
|
|
10
|
+
const ConversationContext = React.createContext(null);
|
|
11
|
+
const reducedMotion = () => typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
12
|
+
/**
|
|
13
|
+
* Conversation — the scrolling column of messages in an AI chat. It sticks to the latest
|
|
14
|
+
* message: while you are at the end, new messages and a reply streaming in keep it there, and the
|
|
15
|
+
* view glides to each new line rather than jumping. Scroll up to read and it stays put, with a
|
|
16
|
+
* `ConversationScrollButton` to come back.
|
|
17
|
+
*
|
|
18
|
+
* The scroller is a `log` region: name it with `aria-label`. Give the conversation a height
|
|
19
|
+
* (it fills a flex column with `flex-1 min-h-0`). The rule people break: scrolling the whole
|
|
20
|
+
* page instead — the prompt bar belongs under the conversation, always in view.
|
|
21
|
+
*/
|
|
22
|
+
export function Conversation({ className, style, children, ref, onScroll, ...props }) {
|
|
23
|
+
const scroller = React.useRef(null);
|
|
24
|
+
const scrollerRefs = React.useMemo(() => mergeRefs(scroller, ref), [ref]);
|
|
25
|
+
const stuck = React.useRef(true);
|
|
26
|
+
const lastTop = React.useRef(0);
|
|
27
|
+
const lastMax = React.useRef(0);
|
|
28
|
+
const glide = React.useRef({ frame: 0, last: 0 });
|
|
29
|
+
/** Where the glide last put the view: the scroll event that write fires is not the reader's. */
|
|
30
|
+
const glideTop = React.useRef(Number.NaN);
|
|
31
|
+
const [atBottom, setAtBottom] = React.useState(true);
|
|
32
|
+
/**
|
|
33
|
+
* Following the reply, the conversation scrolls itself, and the browser's scroll anchoring would
|
|
34
|
+
* fight the glide (a panel folding above makes the view snap a line). Scrolled away to read,
|
|
35
|
+
* anchoring is back on, so the text being read stays put when something above it changes.
|
|
36
|
+
*/
|
|
37
|
+
const setStuck = React.useCallback((value) => {
|
|
38
|
+
stuck.current = value;
|
|
39
|
+
const el = scroller.current;
|
|
40
|
+
if (el)
|
|
41
|
+
el.style.overflowAnchor = value ? "none" : "";
|
|
42
|
+
}, []);
|
|
43
|
+
/**
|
|
44
|
+
* Eases the view to the end: each frame closes most of the distance left, so a line that
|
|
45
|
+
* appears slides into view instead of jumping it. Stops when the reader scrolls away.
|
|
46
|
+
*/
|
|
47
|
+
const follow = React.useCallback(() => {
|
|
48
|
+
const el = scroller.current;
|
|
49
|
+
if (!el || !stuck.current)
|
|
50
|
+
return;
|
|
51
|
+
if (reducedMotion()) {
|
|
52
|
+
el.scrollTop = el.scrollHeight;
|
|
53
|
+
glideTop.current = el.scrollTop;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (glide.current.frame)
|
|
57
|
+
return;
|
|
58
|
+
const step = (now) => {
|
|
59
|
+
const g = glide.current;
|
|
60
|
+
const dt = Math.min(64, now - (g.last || now - 16));
|
|
61
|
+
g.last = now;
|
|
62
|
+
const end = el.scrollHeight - el.clientHeight;
|
|
63
|
+
const gap = end - el.scrollTop;
|
|
64
|
+
// Done within a pixel: at a fractional zoom the end can sit up to 1px past the last
|
|
65
|
+
// scrollTop the browser will take.
|
|
66
|
+
if (!stuck.current || gap < 1) {
|
|
67
|
+
if (stuck.current && gap > 0) {
|
|
68
|
+
el.scrollTop = end;
|
|
69
|
+
glideTop.current = el.scrollTop;
|
|
70
|
+
}
|
|
71
|
+
g.frame = 0;
|
|
72
|
+
g.last = 0;
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const before = el.scrollTop;
|
|
76
|
+
el.scrollTop += Math.max(1, gap * (1 - Math.pow(0.82, dt / 16)));
|
|
77
|
+
glideTop.current = el.scrollTop;
|
|
78
|
+
if (el.scrollTop === before) {
|
|
79
|
+
g.frame = 0;
|
|
80
|
+
g.last = 0;
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
g.frame = requestAnimationFrame(step);
|
|
84
|
+
};
|
|
85
|
+
glide.current.frame = requestAnimationFrame(step);
|
|
86
|
+
}, []);
|
|
87
|
+
const scrollToBottom = React.useCallback((behavior = "smooth") => {
|
|
88
|
+
const el = scroller.current;
|
|
89
|
+
if (!el)
|
|
90
|
+
return;
|
|
91
|
+
setStuck(true);
|
|
92
|
+
setAtBottom(true);
|
|
93
|
+
el.scrollTo({ top: el.scrollHeight, behavior: reducedMotion() ? "auto" : behavior });
|
|
94
|
+
}, [setStuck]);
|
|
95
|
+
const focusLog = React.useCallback(() => scroller.current?.focus({ preventScroll: true }), []);
|
|
96
|
+
React.useEffect(() => () => {
|
|
97
|
+
const g = glide.current;
|
|
98
|
+
cancelAnimationFrame(g.frame);
|
|
99
|
+
g.frame = 0;
|
|
100
|
+
g.last = 0;
|
|
101
|
+
}, []);
|
|
102
|
+
React.useLayoutEffect(() => {
|
|
103
|
+
const el = scroller.current;
|
|
104
|
+
if (!el)
|
|
105
|
+
return;
|
|
106
|
+
el.scrollTop = el.scrollHeight;
|
|
107
|
+
lastTop.current = el.scrollTop;
|
|
108
|
+
lastMax.current = el.scrollHeight - el.clientHeight;
|
|
109
|
+
setStuck(stuck.current);
|
|
110
|
+
const near = () => el.scrollHeight - el.clientHeight - el.scrollTop <= STICK_PX;
|
|
111
|
+
// Content or the log changed size: follow it, or, scrolled away, say whether the end is
|
|
112
|
+
// still in reach (text growing below fires no scroll event to say so). With nothing left to
|
|
113
|
+
// scroll, there is nothing to be away from: it follows again, for the next reply.
|
|
114
|
+
const changed = () => {
|
|
115
|
+
if (!stuck.current && el.scrollHeight - el.clientHeight <= 0.5)
|
|
116
|
+
setStuck(true);
|
|
117
|
+
if (stuck.current)
|
|
118
|
+
follow();
|
|
119
|
+
else
|
|
120
|
+
setAtBottom(near());
|
|
121
|
+
};
|
|
122
|
+
const resize = new ResizeObserver(changed);
|
|
123
|
+
// The messages, and the log itself: a prompt bar that grows below it makes it shorter.
|
|
124
|
+
const observeAll = () => {
|
|
125
|
+
resize.disconnect();
|
|
126
|
+
resize.observe(el);
|
|
127
|
+
for (const child of el.children)
|
|
128
|
+
resize.observe(child);
|
|
129
|
+
};
|
|
130
|
+
observeAll();
|
|
131
|
+
const mutations = new MutationObserver(() => {
|
|
132
|
+
observeAll();
|
|
133
|
+
changed();
|
|
134
|
+
});
|
|
135
|
+
mutations.observe(el, { childList: true });
|
|
136
|
+
// The reader's own move up — a wheel, a finger, a key — lets go at once, even mid-glide,
|
|
137
|
+
// where the scroll it makes could be outrun by the glide's; the glide stops there. Only when
|
|
138
|
+
// there is somewhere to go: on a log that does not scroll yet, nothing changes. A move down
|
|
139
|
+
// at the end, where there may be nothing left to scroll, takes it up again.
|
|
140
|
+
let touchX = 0;
|
|
141
|
+
let touchY = 0;
|
|
142
|
+
/** Something inside the log (a message's own scroller) that this move scrolls instead. */
|
|
143
|
+
const inner = (target, up) => {
|
|
144
|
+
for (let node = target; node && node !== el; node = node.parentElement) {
|
|
145
|
+
if (!/(auto|scroll)/.test(getComputedStyle(node).overflowY) || node.scrollHeight <= node.clientHeight + 1)
|
|
146
|
+
continue;
|
|
147
|
+
if (up ? node.scrollTop > 0.5 : node.scrollTop + node.clientHeight < node.scrollHeight - 0.5)
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
return false;
|
|
151
|
+
};
|
|
152
|
+
const letGo = () => {
|
|
153
|
+
if (el.scrollTop <= 0.5)
|
|
154
|
+
return;
|
|
155
|
+
setStuck(false);
|
|
156
|
+
const g = glide.current;
|
|
157
|
+
cancelAnimationFrame(g.frame);
|
|
158
|
+
g.frame = 0;
|
|
159
|
+
g.last = 0;
|
|
160
|
+
};
|
|
161
|
+
const rejoin = () => {
|
|
162
|
+
if (stuck.current || !near())
|
|
163
|
+
return;
|
|
164
|
+
setStuck(true);
|
|
165
|
+
setAtBottom(true);
|
|
166
|
+
follow();
|
|
167
|
+
};
|
|
168
|
+
// Not a pinch or Ctrl+wheel (that zooms), and not a wheel a message's own scroller takes.
|
|
169
|
+
const wheel = (event) => {
|
|
170
|
+
if (event.ctrlKey || !event.deltaY || inner(event.target, event.deltaY < 0))
|
|
171
|
+
return;
|
|
172
|
+
if (event.deltaY < 0)
|
|
173
|
+
letGo();
|
|
174
|
+
else
|
|
175
|
+
rejoin();
|
|
176
|
+
};
|
|
177
|
+
const touchStart = (event) => {
|
|
178
|
+
touchX = event.touches[0]?.clientX ?? 0;
|
|
179
|
+
touchY = event.touches[0]?.clientY ?? 0;
|
|
180
|
+
};
|
|
181
|
+
// One finger, mostly up or down, past a tap's slop: a finger drifting on the way to a button,
|
|
182
|
+
// a pan along a code block or a pinch is not a scroll of the log. It counts again from each
|
|
183
|
+
// decision, so a drag that turns back is read too.
|
|
184
|
+
const touchMove = (event) => {
|
|
185
|
+
const touch = event.touches[0];
|
|
186
|
+
if (!touch || event.touches.length > 1)
|
|
187
|
+
return;
|
|
188
|
+
const dy = touch.clientY - touchY;
|
|
189
|
+
if (Math.abs(dy) <= 10 || Math.abs(dy) < Math.abs(touch.clientX - touchX))
|
|
190
|
+
return;
|
|
191
|
+
if (!inner(event.target, dy > 0)) {
|
|
192
|
+
if (dy > 0)
|
|
193
|
+
letGo();
|
|
194
|
+
else
|
|
195
|
+
rejoin();
|
|
196
|
+
}
|
|
197
|
+
touchX = touch.clientX;
|
|
198
|
+
touchY = touch.clientY;
|
|
199
|
+
};
|
|
200
|
+
// Keys pressed on a control or a widget inside the log (a button, tabs, a menu, a field)
|
|
201
|
+
// are theirs.
|
|
202
|
+
const OWN_KEYS = "a, button, summary, input, textarea, select, [contenteditable], [role=button], [role=combobox], [role=toolbar], [role=menubar], [role=group], [role=tablist], [role=radiogroup], [role=slider], [role=spinbutton], [role=menu], [role=listbox], [role=grid], [role=tree]";
|
|
203
|
+
const key = (event) => {
|
|
204
|
+
if (event.target !== el && event.target.closest?.(OWN_KEYS))
|
|
205
|
+
return;
|
|
206
|
+
const space = event.key === " ";
|
|
207
|
+
if (["ArrowUp", "PageUp", "Home"].includes(event.key) || (space && event.shiftKey))
|
|
208
|
+
letGo();
|
|
209
|
+
else if (["ArrowDown", "PageDown", "End"].includes(event.key) || space)
|
|
210
|
+
rejoin();
|
|
211
|
+
};
|
|
212
|
+
el.addEventListener("wheel", wheel, { passive: true });
|
|
213
|
+
el.addEventListener("touchstart", touchStart, { passive: true });
|
|
214
|
+
el.addEventListener("touchmove", touchMove, { passive: true });
|
|
215
|
+
el.addEventListener("keydown", key);
|
|
216
|
+
return () => {
|
|
217
|
+
resize.disconnect();
|
|
218
|
+
mutations.disconnect();
|
|
219
|
+
el.removeEventListener("wheel", wheel);
|
|
220
|
+
el.removeEventListener("touchstart", touchStart);
|
|
221
|
+
el.removeEventListener("touchmove", touchMove);
|
|
222
|
+
el.removeEventListener("keydown", key);
|
|
223
|
+
};
|
|
224
|
+
}, [follow, setStuck]);
|
|
225
|
+
const context = React.useMemo(() => ({ atBottom, scrollToBottom, focusLog }), [atBottom, scrollToBottom, focusLog]);
|
|
226
|
+
// The scroll button sits over the conversation, not in the scroller, so it stays on the bottom edge.
|
|
227
|
+
const parts = React.Children.toArray(children);
|
|
228
|
+
const isButton = (child) => React.isValidElement(child) && child.type === ConversationScrollButton;
|
|
229
|
+
return (_jsx(ConversationContext.Provider, { value: context, children: _jsxs("div", { "data-slot": "conversation", className: cn("relative flex min-h-0 flex-1 flex-col", className), style: style, children: [_jsx("div", { role: "log", tabIndex: 0, "data-slot": "conversation-scroller", ...props, ref: scrollerRefs, onScroll: (event) => {
|
|
230
|
+
const el = event.currentTarget;
|
|
231
|
+
const max = el.scrollHeight - el.clientHeight;
|
|
232
|
+
const end = max - el.scrollTop <= STICK_PX;
|
|
233
|
+
// A move in a frame where the log also changed size is layout's — a panel folding
|
|
234
|
+
// above, a line arriving below — not the reader's: it changes nothing. Otherwise a
|
|
235
|
+
// move up, even a few pixels, lets go (the glide only moves down), and a move down
|
|
236
|
+
// into the end takes up following again. The reader's wheel, finger and keys say so
|
|
237
|
+
// at once, too (see the listeners above).
|
|
238
|
+
// The glide's own move is not the reader's either; any other move is measured from where
|
|
239
|
+
// the glide last put the view, so a slow scroll up is not swallowed by its steps.
|
|
240
|
+
const glided = Math.abs(el.scrollTop - glideTop.current) < 0.5;
|
|
241
|
+
const from = !glided && !Number.isNaN(glideTop.current) ? glideTop.current : lastTop.current;
|
|
242
|
+
glideTop.current = Number.NaN;
|
|
243
|
+
const resized = Math.abs(max - lastMax.current) > 0.5;
|
|
244
|
+
// In a resized frame, only a jump further than the end zone (to a find, a focused
|
|
245
|
+
// link) is the reader's; a few pixels, or a clamp to the end, is layout.
|
|
246
|
+
const clamped = max - el.scrollTop < 1;
|
|
247
|
+
const up = !glided && !clamped && el.scrollTop < from - 1 && (!resized || from - el.scrollTop > STICK_PX);
|
|
248
|
+
// Down, and nearer the end than before: layout never does both (anchoring keeps the
|
|
249
|
+
// distance, a clamp moves the view up), so this holds through a resize too.
|
|
250
|
+
const down = !glided &&
|
|
251
|
+
el.scrollTop > lastTop.current + 0.5 &&
|
|
252
|
+
max - el.scrollTop < lastMax.current - lastTop.current - 0.5;
|
|
253
|
+
if (up)
|
|
254
|
+
setStuck(false);
|
|
255
|
+
else if (end && down)
|
|
256
|
+
setStuck(true);
|
|
257
|
+
lastTop.current = el.scrollTop;
|
|
258
|
+
lastMax.current = max;
|
|
259
|
+
setAtBottom(end || stuck.current);
|
|
260
|
+
onScroll?.(event);
|
|
261
|
+
},
|
|
262
|
+
// Its corners are the conversation's: round that (`rounded-t-card` in a card), and the
|
|
263
|
+
// messages, the scrollbar and the focus ring follow, with no `overflow-hidden` to clip them.
|
|
264
|
+
// Its own scrolling is instant, whatever an app sets for `scroll-behavior`: the glide does the easing.
|
|
265
|
+
className: "min-h-0 flex-1 [border-radius:inherit] [--scrollbar-inset:var(--radius-card)] [scroll-behavior:auto] overflow-y-auto overscroll-contain focus-ring", children: parts.filter((child) => !isButton(child)) }), parts.filter(isButton)] }) }));
|
|
266
|
+
}
|
|
267
|
+
/** The column of messages: 24px apart, padded, at a reading width. */
|
|
268
|
+
export function ConversationContent({ className, ...props }) {
|
|
269
|
+
return (_jsx("div", { "data-slot": "conversation-content", className: cn("mx-auto flex w-full max-w-3xl flex-col gap-6 px-4 py-6", className), ...props }));
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* A round raised button, centred on the bottom edge of the conversation, that brings back the
|
|
273
|
+
* latest message. It appears only once you have scrolled away from it. Put it inside
|
|
274
|
+
* `Conversation`, after `ConversationContent`.
|
|
275
|
+
*/
|
|
276
|
+
export function ConversationScrollButton({ label = "Scroll to the latest message", className, onClick, ...props }) {
|
|
277
|
+
const context = React.useContext(ConversationContext);
|
|
278
|
+
if (!context)
|
|
279
|
+
throw new Error("ConversationScrollButton must be used inside <Conversation>.");
|
|
280
|
+
const visible = !context.atBottom;
|
|
281
|
+
return (_jsx(Button, { "data-slot": "conversation-scroll-button", "data-visible": visible ? "" : undefined, variant: "secondary", size: "icon", "aria-label": label, "aria-hidden": !visible, tabIndex: visible ? 0 : -1, onClick: (event) => {
|
|
282
|
+
onClick?.(event);
|
|
283
|
+
if (event.defaultPrevented)
|
|
284
|
+
return;
|
|
285
|
+
// It hides once at the end: give focus to the log rather than leave it on a hidden button.
|
|
286
|
+
if (event.currentTarget === document.activeElement)
|
|
287
|
+
context.focusLog();
|
|
288
|
+
context.scrollToBottom();
|
|
289
|
+
}, className: sx([
|
|
290
|
+
"absolute bottom-4 left-1/2 -translate-x-1/2 transition-[opacity,translate] duration-(--duration) ease-(--ease)",
|
|
291
|
+
visible ? "opacity-100" : "pointer-events-none translate-y-2 opacity-0",
|
|
292
|
+
], className), ...props, children: _jsx(ArrowDownIcon, { "aria-hidden": true }) }));
|
|
293
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type ButtonProps } from "./button.js";
|
|
3
|
+
export interface CopyButtonProps extends Omit<ButtonProps, "value" | "onCopy" | "render" | "onError"> {
|
|
4
|
+
/**
|
|
5
|
+
* What to copy: a string, or a function that returns it (or a promise of it) at the moment of
|
|
6
|
+
* the click. A function that throws or rejects counts as a failed copy.
|
|
7
|
+
*/
|
|
8
|
+
value: string | (() => string | Promise<string>);
|
|
9
|
+
/** Called with the text once it is on the clipboard. */
|
|
10
|
+
onCopy?: (text: string) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Called when the copy failed: the clipboard refused it, or `value` threw or rejected. The
|
|
13
|
+
* button shows a cross and announces the failure.
|
|
14
|
+
*/
|
|
15
|
+
onError?: (error: unknown) => void;
|
|
16
|
+
/** How long the check (or the cross) stays, in milliseconds. Default 1500. */
|
|
17
|
+
timeout?: number;
|
|
18
|
+
/**
|
|
19
|
+
* The accessible names: `copy` names the button at rest (default "Copy"), `copied` and `failed`
|
|
20
|
+
* are announced after a click (default "Copied" and "Couldn't copy"). Say what is copied:
|
|
21
|
+
* "Copy API key".
|
|
22
|
+
*/
|
|
23
|
+
labels?: {
|
|
24
|
+
copy?: string;
|
|
25
|
+
copied?: string;
|
|
26
|
+
failed?: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Draw another button instead of `Button` — most often `<InputGroupButton size="icon" />` in
|
|
30
|
+
* an `InputGroup`. It receives the click, the accessible name and the icon; its own variant
|
|
31
|
+
* and size stay.
|
|
32
|
+
*/
|
|
33
|
+
render?: React.ReactElement<Record<string, unknown>>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* CopyButton — copies a value to the clipboard and says so: the copy icon turns into a check for
|
|
37
|
+
* a moment and a polite live region announces "Copied". If the clipboard refuses, it shows a
|
|
38
|
+
* cross and announces that instead. Icon-only by default (a raised 30px circle); give it
|
|
39
|
+
* children and it becomes a labelled button whose label reads "Copied" for the moment, at the
|
|
40
|
+
* same width.
|
|
41
|
+
*
|
|
42
|
+
* Put it next to the thing it copies: an API key in an `InputGroup` (`render={<InputGroupButton
|
|
43
|
+
* size="icon" />}`), an invite link, an ID in mono. The rule people break: a bare "Copy" name.
|
|
44
|
+
* Say what it copies in `labels.copy` ("Copy invite link"), since a page has several.
|
|
45
|
+
*/
|
|
46
|
+
export declare function CopyButton({ value, onCopy, onError, timeout, labels, render, variant, size, onClick, className, children, ...props }: CopyButtonProps): React.JSX.Element;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { CheckIcon, CopyIcon, XIcon } from "lucide-react";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { cn } from "../lib/cn.js";
|
|
6
|
+
import { Button } from "./button.js";
|
|
7
|
+
/**
|
|
8
|
+
* Writes text to the clipboard: the async Clipboard API where the page may use it, and the old
|
|
9
|
+
* `execCommand("copy")` on a hidden textarea where it may not (an `http:` page, an iframe without
|
|
10
|
+
* the permission). Rejects when neither works.
|
|
11
|
+
*/
|
|
12
|
+
async function writeClipboard(text) {
|
|
13
|
+
try {
|
|
14
|
+
if (!navigator.clipboard?.writeText)
|
|
15
|
+
throw new Error("No Clipboard API");
|
|
16
|
+
await navigator.clipboard.writeText(text);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
const area = document.createElement("textarea");
|
|
20
|
+
area.value = text;
|
|
21
|
+
area.setAttribute("readonly", "");
|
|
22
|
+
area.style.cssText = "position:fixed;top:0;left:0;opacity:0;pointer-events:none";
|
|
23
|
+
const active = document.activeElement;
|
|
24
|
+
document.body.append(area);
|
|
25
|
+
area.select();
|
|
26
|
+
let ok = false;
|
|
27
|
+
try {
|
|
28
|
+
ok = document.execCommand("copy");
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
area.remove();
|
|
32
|
+
active?.focus({ preventScroll: true });
|
|
33
|
+
}
|
|
34
|
+
if (!ok)
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/* Two faces stacked in one grid cell: the one at rest and the one that answers. They cross-fade
|
|
39
|
+
and swap scale on --duration (0 under reduced motion), so the button never changes size. */
|
|
40
|
+
const face = "col-start-1 row-start-1 place-self-center transition-[opacity,scale] duration-(--duration) ease-(--ease)";
|
|
41
|
+
const shown = "scale-100 opacity-100";
|
|
42
|
+
const hidden = "scale-50 opacity-0";
|
|
43
|
+
/**
|
|
44
|
+
* CopyButton — copies a value to the clipboard and says so: the copy icon turns into a check for
|
|
45
|
+
* a moment and a polite live region announces "Copied". If the clipboard refuses, it shows a
|
|
46
|
+
* cross and announces that instead. Icon-only by default (a raised 30px circle); give it
|
|
47
|
+
* children and it becomes a labelled button whose label reads "Copied" for the moment, at the
|
|
48
|
+
* same width.
|
|
49
|
+
*
|
|
50
|
+
* Put it next to the thing it copies: an API key in an `InputGroup` (`render={<InputGroupButton
|
|
51
|
+
* size="icon" />}`), an invite link, an ID in mono. The rule people break: a bare "Copy" name.
|
|
52
|
+
* Say what it copies in `labels.copy` ("Copy invite link"), since a page has several.
|
|
53
|
+
*/
|
|
54
|
+
export function CopyButton({ value, onCopy, onError, timeout = 1500, labels, render, variant = "secondary", size, onClick, className, children, ...props }) {
|
|
55
|
+
const [state, setState] = React.useState("idle");
|
|
56
|
+
const timer = React.useRef(undefined);
|
|
57
|
+
// A copy that settles after the button has gone (a slow `value`) leaves no state or timer behind.
|
|
58
|
+
const mounted = React.useRef(false);
|
|
59
|
+
React.useEffect(() => {
|
|
60
|
+
mounted.current = true;
|
|
61
|
+
return () => {
|
|
62
|
+
mounted.current = false;
|
|
63
|
+
clearTimeout(timer.current);
|
|
64
|
+
};
|
|
65
|
+
}, []);
|
|
66
|
+
const settle = (next) => {
|
|
67
|
+
if (!mounted.current)
|
|
68
|
+
return;
|
|
69
|
+
setState(next);
|
|
70
|
+
clearTimeout(timer.current);
|
|
71
|
+
timer.current = setTimeout(() => setState("idle"), timeout);
|
|
72
|
+
};
|
|
73
|
+
const copy = async (event) => {
|
|
74
|
+
onClick?.(event);
|
|
75
|
+
if (event.defaultPrevented)
|
|
76
|
+
return;
|
|
77
|
+
let text;
|
|
78
|
+
try {
|
|
79
|
+
const next = typeof value === "function" ? value() : value;
|
|
80
|
+
// A string is written at once, inside the click, as Safari requires; only a promise waits.
|
|
81
|
+
text = typeof next === "string" ? next : await next;
|
|
82
|
+
await writeClipboard(text);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
settle("failed");
|
|
86
|
+
onError?.(error);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
settle("copied");
|
|
90
|
+
onCopy?.(text);
|
|
91
|
+
};
|
|
92
|
+
const copyLabel = labels?.copy ?? "Copy";
|
|
93
|
+
const copiedLabel = labels?.copied ?? "Copied";
|
|
94
|
+
const failedLabel = labels?.failed ?? "Couldn't copy";
|
|
95
|
+
const labelled = children != null;
|
|
96
|
+
const announcement = state === "copied" ? copiedLabel : state === "failed" ? failedLabel : "";
|
|
97
|
+
const buttonSize = size ?? (labelled ? "sm" : "icon-sm");
|
|
98
|
+
// 14px on the dense sizes, as in CodeBlock; otherwise the button's own icon size.
|
|
99
|
+
const iconSize = !render && (buttonSize === "sm" || buttonSize === "icon-sm") ? "size-3.5" : undefined;
|
|
100
|
+
const icons = (_jsxs("span", { "aria-hidden": true, "data-slot": "copy-button-icon", className: "grid", children: [_jsx(CopyIcon, { className: cn(face, iconSize, state === "idle" ? shown : hidden) }), _jsx(CheckIcon, { className: cn(face, iconSize, state === "copied" ? shown : hidden) }), _jsx(XIcon, { className: cn(face, iconSize, state === "failed" ? shown : hidden) })] }));
|
|
101
|
+
const content = labelled ? (_jsxs(_Fragment, { children: [icons, _jsxs("span", { "data-slot": "copy-button-label", className: "grid", children: [_jsx("span", { className: cn(face, state === "copied" ? hidden : shown), children: children }), _jsx("span", { "aria-hidden": true, className: cn(face, state === "copied" ? shown : hidden), children: copiedLabel })] })] })) : (icons);
|
|
102
|
+
const shared = {
|
|
103
|
+
"data-copied": state === "copied" ? "" : undefined,
|
|
104
|
+
"data-copy-failed": state === "failed" ? "" : undefined,
|
|
105
|
+
// A labelled button is named by its visible label; an icon-only one by `labels`.
|
|
106
|
+
"aria-label": labelled ? undefined : announcement || copyLabel,
|
|
107
|
+
onClick: copy,
|
|
108
|
+
};
|
|
109
|
+
return (_jsxs(_Fragment, { children: [render ? (
|
|
110
|
+
// Keep the rendered button's own slot (an addon pads around `input-group-button`).
|
|
111
|
+
React.cloneElement(render, {
|
|
112
|
+
...props,
|
|
113
|
+
...shared,
|
|
114
|
+
...(className !== undefined && { className }),
|
|
115
|
+
"data-copy-button": "",
|
|
116
|
+
children: content,
|
|
117
|
+
})) : (_jsx(Button, { "data-slot": "copy-button", variant: variant, size: buttonSize, className: className, ...shared, ...props, children: content })), _jsx("span", { "data-slot": "copy-button-status", className: "sr-only", "aria-live": "polite", children: announcement })] }));
|
|
118
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { type CellContext, type ColumnDef, type Row, type RowData, type SortingState } from "@tanstack/react-table";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
/** Per-column options read by `DataTable`. Set them on a column's `meta`. */
|
|
4
|
+
export interface DataTableColumnMeta {
|
|
5
|
+
/** The column's name in the "Columns" menu when its `header` is not a plain string. */
|
|
6
|
+
label?: string;
|
|
7
|
+
/** Numbers, durations, dates and IDs: mono, tabular, right-aligned header and cells. */
|
|
8
|
+
numeric?: boolean;
|
|
9
|
+
/** Extra classes for this column's cells. */
|
|
10
|
+
className?: string;
|
|
11
|
+
/** With `fit`: lower steps out first when the titles stop fitting. Without it, never. */
|
|
12
|
+
priority?: number;
|
|
13
|
+
/** With `fit`: when the column steps out, show its cells inline after the title. */
|
|
14
|
+
inline?: boolean;
|
|
15
|
+
/** With `fit`: below this container width (rem) the column steps out regardless. */
|
|
16
|
+
minWidth?: number;
|
|
17
|
+
/** With `fit`: the column's grid track while it has its own column (`auto`, `6rem`). */
|
|
18
|
+
width?: string;
|
|
19
|
+
/** With `fit`: the column that names each row. Defaults to the first data column. */
|
|
20
|
+
title?: boolean;
|
|
21
|
+
/** `end` right-aligns the column without setting it in mono. Defaults by `numeric`. */
|
|
22
|
+
align?: "start" | "end";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The TanStack Table v9 features `DataTable` registers: global and column filtering, sorting,
|
|
26
|
+
* column visibility, row selection, grouping and pagination, all processed on the client.
|
|
27
|
+
*/
|
|
28
|
+
export declare const dataTableFeatures: {
|
|
29
|
+
columnFilteringFeature: import("@tanstack/react-table").TableFeature;
|
|
30
|
+
globalFilteringFeature: import("@tanstack/react-table").TableFeature;
|
|
31
|
+
filteredRowModel: (table: import("@tanstack/react-table").Table<any, any>) => () => import("@tanstack/react-table").RowModel<any, any>;
|
|
32
|
+
filterFns: {
|
|
33
|
+
includesString: import("@tanstack/react-table").CreatedFilterFn<any, any>;
|
|
34
|
+
};
|
|
35
|
+
rowSortingFeature: import("@tanstack/react-table").TableFeature;
|
|
36
|
+
sortedRowModel: (table: import("@tanstack/react-table").Table<any, any>) => () => import("@tanstack/react-table").RowModel<any, any>;
|
|
37
|
+
sortFns: {
|
|
38
|
+
alphanumeric: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
39
|
+
basic: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
40
|
+
datetime: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
41
|
+
text: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
42
|
+
};
|
|
43
|
+
columnVisibilityFeature: import("@tanstack/react-table").TableFeature;
|
|
44
|
+
columnGroupingFeature: import("@tanstack/react-table").TableFeature;
|
|
45
|
+
groupedRowModel: (table: import("@tanstack/react-table").Table<any, any>) => () => import("@tanstack/react-table").RowModel<any, any>;
|
|
46
|
+
rowSelectionFeature: import("@tanstack/react-table").TableFeature;
|
|
47
|
+
rowPaginationFeature: import("@tanstack/react-table").TableFeature;
|
|
48
|
+
paginatedRowModel: (table: import("@tanstack/react-table").Table<any, any>) => () => import("@tanstack/react-table").RowModel<any, any>;
|
|
49
|
+
columnMeta: DataTableColumnMeta;
|
|
50
|
+
};
|
|
51
|
+
export type DataTableFeatures = typeof dataTableFeatures;
|
|
52
|
+
/** A column definition for `DataTable`. Prefer building them with `createDataTableColumnHelper`. */
|
|
53
|
+
export type DataTableColumnDef<TData extends RowData> = ColumnDef<DataTableFeatures, TData, any>;
|
|
54
|
+
/** A row as passed to `cell: ({ row }) => …`; `row.original` is your data object. */
|
|
55
|
+
export type DataTableRow<TData extends RowData> = Row<DataTableFeatures, TData>;
|
|
56
|
+
/** The argument of a column's `cell` renderer. */
|
|
57
|
+
export type DataTableCellContext<TData extends RowData, TValue = unknown> = CellContext<DataTableFeatures, TData, TValue>;
|
|
58
|
+
export type DataTableSortingState = SortingState;
|
|
59
|
+
/**
|
|
60
|
+
* Typed helpers for `DataTable` columns: `accessor(key, def)`, `display(def)` and
|
|
61
|
+
* `columns([...])`. Create one per row type at module scope.
|
|
62
|
+
*
|
|
63
|
+
* const column = createDataTableColumnHelper<Deploy>();
|
|
64
|
+
* const columns = column.columns([column.accessor("name", { header: "Name" })]);
|
|
65
|
+
*/
|
|
66
|
+
export declare function createDataTableColumnHelper<TData extends RowData>(): import("@tanstack/react-table").ColumnHelper<{
|
|
67
|
+
columnFilteringFeature: import("@tanstack/react-table").TableFeature;
|
|
68
|
+
globalFilteringFeature: import("@tanstack/react-table").TableFeature;
|
|
69
|
+
filteredRowModel: (table: import("@tanstack/react-table").Table<any, any>) => () => import("@tanstack/react-table").RowModel<any, any>;
|
|
70
|
+
filterFns: {
|
|
71
|
+
includesString: import("@tanstack/react-table").CreatedFilterFn<any, any>;
|
|
72
|
+
};
|
|
73
|
+
rowSortingFeature: import("@tanstack/react-table").TableFeature;
|
|
74
|
+
sortedRowModel: (table: import("@tanstack/react-table").Table<any, any>) => () => import("@tanstack/react-table").RowModel<any, any>;
|
|
75
|
+
sortFns: {
|
|
76
|
+
alphanumeric: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
77
|
+
basic: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
78
|
+
datetime: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
79
|
+
text: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
80
|
+
};
|
|
81
|
+
columnVisibilityFeature: import("@tanstack/react-table").TableFeature;
|
|
82
|
+
columnGroupingFeature: import("@tanstack/react-table").TableFeature;
|
|
83
|
+
groupedRowModel: (table: import("@tanstack/react-table").Table<any, any>) => () => import("@tanstack/react-table").RowModel<any, any>;
|
|
84
|
+
rowSelectionFeature: import("@tanstack/react-table").TableFeature;
|
|
85
|
+
rowPaginationFeature: import("@tanstack/react-table").TableFeature;
|
|
86
|
+
paginatedRowModel: (table: import("@tanstack/react-table").Table<any, any>) => () => import("@tanstack/react-table").RowModel<any, any>;
|
|
87
|
+
columnMeta: DataTableColumnMeta;
|
|
88
|
+
}, TData>;
|
|
89
|
+
export interface DataTableProps<TData extends RowData> extends Omit<React.ComponentProps<"div">, "children" | "onChange"> {
|
|
90
|
+
/** Column definitions. Keep them stable: module scope or `useMemo`. */
|
|
91
|
+
columns: ReadonlyArray<DataTableColumnDef<TData>>;
|
|
92
|
+
/** The rows. Keep the array stable between real changes. */
|
|
93
|
+
data: ReadonlyArray<TData>;
|
|
94
|
+
/** Search one column (its id or accessor key). Omit to search every text and number column. */
|
|
95
|
+
searchKey?: string;
|
|
96
|
+
/** Placeholder for the search field. */
|
|
97
|
+
searchPlaceholder?: string;
|
|
98
|
+
/** Show the search field. Defaults to `true`. */
|
|
99
|
+
searchable?: boolean;
|
|
100
|
+
/** Rows per page. Defaults to 10. */
|
|
101
|
+
pageSize?: number;
|
|
102
|
+
/** Choices in the "Rows" select. Pass `[]` to hide it. Defaults to `[10, 20, 50]`. */
|
|
103
|
+
pageSizeOptions?: number[];
|
|
104
|
+
/** Add a checkbox column. On by default when `onRowSelectionChange` is set. */
|
|
105
|
+
selectable?: boolean;
|
|
106
|
+
/** Called with the selected rows' data whenever the selection changes. */
|
|
107
|
+
onRowSelectionChange?: (rows: TData[]) => void;
|
|
108
|
+
/** A stable id per row, so selection survives sorting and new data. Defaults to the index. */
|
|
109
|
+
getRowId?: (row: TData, index: number) => string;
|
|
110
|
+
/** Show the "Columns" visibility menu. Defaults to `true`. */
|
|
111
|
+
columnToggle?: boolean;
|
|
112
|
+
/** 30px rows and 30px controls throughout, for admin and dashboard screens. */
|
|
113
|
+
dense?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* `card` (default): the table in a 20px card. `plain`: the same table without the card —
|
|
116
|
+
* always inside a `Card`, a `Dialog` or a `Drawer`, never a card in a card.
|
|
117
|
+
*/
|
|
118
|
+
variant?: "card" | "plain";
|
|
119
|
+
/**
|
|
120
|
+
* Fit the columns to the container's width instead of scrolling: columns step out by their
|
|
121
|
+
* `meta.priority` as it narrows, or move inline after the title (`meta.inline`), and glide.
|
|
122
|
+
*/
|
|
123
|
+
fit?: boolean;
|
|
124
|
+
/** Sorting to start with, e.g. `[{ id: "started", desc: true }]`. */
|
|
125
|
+
initialSorting?: SortingState;
|
|
126
|
+
/**
|
|
127
|
+
* A BCP 47 locale whose order text sorts in, e.g. `"sv"` puts "Å" after "Z". Default: the
|
|
128
|
+
* Unicode collation order, the same on the server and in every browser.
|
|
129
|
+
*/
|
|
130
|
+
locale?: string;
|
|
131
|
+
/** Columns hidden at first, e.g. `{ id: false }`. */
|
|
132
|
+
initialColumnVisibility?: Record<string, boolean>;
|
|
133
|
+
/** Shown in one full-width row when nothing matches. */
|
|
134
|
+
emptyMessage?: React.ReactNode;
|
|
135
|
+
/** Extra controls at the end of the toolbar (a secondary "Export", a filter select). */
|
|
136
|
+
toolbar?: React.ReactNode;
|
|
137
|
+
/** A short visible description under the table. */
|
|
138
|
+
caption?: React.ReactNode;
|
|
139
|
+
/** The table's accessible name when there is no caption. */
|
|
140
|
+
label?: string;
|
|
141
|
+
/**
|
|
142
|
+
* Group rows by this column (its id or accessor key). Each group opens with a collapsible
|
|
143
|
+
* `TableGroupHeader` showing the column's cell for the group's value and a row count. The
|
|
144
|
+
* column itself starts hidden, and the pager is replaced by a row and group count.
|
|
145
|
+
*/
|
|
146
|
+
groupBy?: string;
|
|
147
|
+
/** A short summary at the end of each group header, e.g. a total. Receives the group's rows. */
|
|
148
|
+
groupSummary?: (group: {
|
|
149
|
+
value: unknown;
|
|
150
|
+
rows: TData[];
|
|
151
|
+
}) => React.ReactNode;
|
|
152
|
+
/** Keep group headers at the top of the table while their rows scroll; give the table a height. */
|
|
153
|
+
stickyGroupHeaders?: boolean;
|
|
154
|
+
/** Props for the table's scrolling card, e.g. `{ className: "max-h-96" }` for sticky group headers. */
|
|
155
|
+
tableContainerProps?: React.ComponentProps<"div">;
|
|
156
|
+
/**
|
|
157
|
+
* Render only the rows in view and a few beyond (`TableVirtualBody`), as the card or the page
|
|
158
|
+
* scrolls. On by default when more than 100 rows could show: a grouped table of more than 100
|
|
159
|
+
* rows, or a page of more than 100. Rows out of view can't be found with the browser's search,
|
|
160
|
+
* and don't print.
|
|
161
|
+
*/
|
|
162
|
+
virtualize?: boolean;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* DataTable — a `Table` with the controls people expect from a data grid: sortable mono
|
|
166
|
+
* headers, a search field, a "Columns" visibility menu, row selection with `Checkbox`, grouped
|
|
167
|
+
* rows (`groupBy`) and a compact pager with a mono "1–10 of 48" count and a rows-per-page
|
|
168
|
+
* select. Powered by TanStack Table v9; define columns with `createDataTableColumnHelper` and you never touch
|
|
169
|
+
* the TanStack table instance.
|
|
170
|
+
*
|
|
171
|
+
* Use it for lists people search, sort and act on: deploys, orders, members. The rule people
|
|
172
|
+
* break: reaching for it for a handful of rows. Under ~10 rows with nothing to sort, use a
|
|
173
|
+
* plain `Table`.
|
|
174
|
+
*/
|
|
175
|
+
export declare function DataTable<TData extends RowData>({ columns, data, searchKey, searchPlaceholder, searchable, pageSize, pageSizeOptions, selectable, onRowSelectionChange, getRowId, columnToggle, dense, variant, fit, initialSorting, locale, initialColumnVisibility, emptyMessage, toolbar, caption, label, groupBy, groupSummary, stickyGroupHeaders, tableContainerProps, virtualize, className, ...props }: DataTableProps<TData>): React.JSX.Element;
|