pixelize-design-library 3.1.0 → 3.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/CHANGELOG.md +24 -0
- package/COMPONENT-GOTCHAS.md +29 -0
- package/DESIGN-GUIDE.md +27 -0
- package/README.md +8 -8
- package/dist/Components/Assistant/assistantModel.d.ts +17 -0
- package/dist/Components/Assistant/assistantModel.js +35 -0
- package/dist/Components/Assistant/assistantStyles.d.ts +27 -0
- package/dist/Components/Assistant/assistantStyles.js +53 -0
- package/dist/Components/Assistant/assistantTypes.d.ts +163 -0
- package/dist/Components/Assistant/assistantTypes.js +2 -0
- package/dist/Components/Assistant/banner/AssistantStatusBanner.d.ts +3 -0
- package/dist/Components/Assistant/banner/AssistantStatusBanner.js +25 -0
- package/dist/Components/Assistant/banner/AssistantStatusBannerProps.d.ts +27 -0
- package/dist/Components/Assistant/banner/AssistantStatusBannerProps.js +2 -0
- package/dist/Components/Assistant/cards/AssistantApprovalCard.d.ts +3 -0
- package/dist/Components/Assistant/cards/AssistantApprovalCard.js +51 -0
- package/dist/Components/Assistant/cards/AssistantApprovalCardProps.d.ts +66 -0
- package/dist/Components/Assistant/cards/AssistantApprovalCardProps.js +2 -0
- package/dist/Components/Assistant/cards/AssistantProposalCard.d.ts +3 -0
- package/dist/Components/Assistant/cards/AssistantProposalCard.js +36 -0
- package/dist/Components/Assistant/cards/AssistantProposalCardProps.d.ts +56 -0
- package/dist/Components/Assistant/cards/AssistantProposalCardProps.js +2 -0
- package/dist/Components/Assistant/cards/CardShell.d.ts +31 -0
- package/dist/Components/Assistant/cards/CardShell.js +32 -0
- package/dist/Components/Assistant/composer/AssistantComposer.d.ts +3 -0
- package/dist/Components/Assistant/composer/AssistantComposer.js +264 -0
- package/dist/Components/Assistant/composer/AssistantComposerProps.d.ts +128 -0
- package/dist/Components/Assistant/composer/AssistantComposerProps.js +2 -0
- package/dist/Components/Assistant/composer/ComposerMenu.d.ts +24 -0
- package/dist/Components/Assistant/composer/ComposerMenu.js +38 -0
- package/dist/Components/Assistant/composer/composerLogic.d.ts +19 -0
- package/dist/Components/Assistant/composer/composerLogic.js +65 -0
- package/dist/Components/Assistant/context/AssistantContextBar.d.ts +3 -0
- package/dist/Components/Assistant/context/AssistantContextBar.js +27 -0
- package/dist/Components/Assistant/context/AssistantContextBarProps.d.ts +34 -0
- package/dist/Components/Assistant/context/AssistantContextBarProps.js +2 -0
- package/dist/Components/Assistant/history/AssistantHistoryList.d.ts +3 -0
- package/dist/Components/Assistant/history/AssistantHistoryList.js +123 -0
- package/dist/Components/Assistant/history/AssistantHistoryListProps.d.ts +83 -0
- package/dist/Components/Assistant/history/AssistantHistoryListProps.js +2 -0
- package/dist/Components/Assistant/history/groupConversations.d.ts +12 -0
- package/dist/Components/Assistant/history/groupConversations.js +55 -0
- package/dist/Components/Assistant/index.d.ts +16 -0
- package/dist/Components/Assistant/index.js +38 -0
- package/dist/Components/Assistant/launcher/AssistantLauncher.d.ts +3 -0
- package/dist/Components/Assistant/launcher/AssistantLauncher.js +45 -0
- package/dist/Components/Assistant/launcher/AssistantLauncherProps.d.ts +37 -0
- package/dist/Components/Assistant/launcher/AssistantLauncherProps.js +2 -0
- package/dist/Components/Assistant/markdown/AssistantMarkdown.d.ts +3 -0
- package/dist/Components/Assistant/markdown/AssistantMarkdown.js +146 -0
- package/dist/Components/Assistant/markdown/AssistantMarkdownProps.d.ts +38 -0
- package/dist/Components/Assistant/markdown/AssistantMarkdownProps.js +2 -0
- package/dist/Components/Assistant/markdown/parseMarkdown.d.ts +74 -0
- package/dist/Components/Assistant/markdown/parseMarkdown.js +328 -0
- package/dist/Components/Assistant/markdown/safeHref.d.ts +21 -0
- package/dist/Components/Assistant/markdown/safeHref.js +28 -0
- package/dist/Components/Assistant/message/AssistantMessage.d.ts +3 -0
- package/dist/Components/Assistant/message/AssistantMessage.js +131 -0
- package/dist/Components/Assistant/message/AssistantMessageProps.d.ts +83 -0
- package/dist/Components/Assistant/message/AssistantMessageProps.js +2 -0
- package/dist/Components/Assistant/message/MessageActions.d.ts +16 -0
- package/dist/Components/Assistant/message/MessageActions.js +23 -0
- package/dist/Components/Assistant/panel/AssistantPanel.d.ts +3 -0
- package/dist/Components/Assistant/panel/AssistantPanel.js +87 -0
- package/dist/Components/Assistant/panel/AssistantPanelProps.d.ts +86 -0
- package/dist/Components/Assistant/panel/AssistantPanelProps.js +2 -0
- package/dist/Components/Assistant/panel/ResizeHandle.d.ts +14 -0
- package/dist/Components/Assistant/panel/ResizeHandle.js +72 -0
- package/dist/Components/Assistant/sources/AssistantSources.d.ts +3 -0
- package/dist/Components/Assistant/sources/AssistantSources.js +63 -0
- package/dist/Components/Assistant/sources/AssistantSourcesProps.d.ts +29 -0
- package/dist/Components/Assistant/sources/AssistantSourcesProps.js +2 -0
- package/dist/Components/Assistant/steps/AssistantToolSteps.d.ts +3 -0
- package/dist/Components/Assistant/steps/AssistantToolSteps.js +41 -0
- package/dist/Components/Assistant/steps/AssistantToolStepsProps.d.ts +37 -0
- package/dist/Components/Assistant/steps/AssistantToolStepsProps.js +2 -0
- package/dist/Components/Assistant/suggestions/AssistantSuggestions.d.ts +3 -0
- package/dist/Components/Assistant/suggestions/AssistantSuggestions.js +18 -0
- package/dist/Components/Assistant/suggestions/AssistantSuggestionsProps.d.ts +15 -0
- package/dist/Components/Assistant/suggestions/AssistantSuggestionsProps.js +2 -0
- package/dist/Components/Assistant/thread/AssistantThread.d.ts +3 -0
- package/dist/Components/Assistant/thread/AssistantThread.js +112 -0
- package/dist/Components/Assistant/thread/AssistantThreadProps.d.ts +37 -0
- package/dist/Components/Assistant/thread/AssistantThreadProps.js +2 -0
- package/dist/Components/Assistant/typing/AssistantTypingIndicator.d.ts +3 -0
- package/dist/Components/Assistant/typing/AssistantTypingIndicator.js +33 -0
- package/dist/Components/Assistant/typing/AssistantTypingIndicatorProps.d.ts +9 -0
- package/dist/Components/Assistant/typing/AssistantTypingIndicatorProps.js +2 -0
- package/dist/Components/Assistant/welcome/AssistantWelcome.d.ts +3 -0
- package/dist/Components/Assistant/welcome/AssistantWelcome.js +30 -0
- package/dist/Components/Assistant/welcome/AssistantWelcomeProps.d.ts +40 -0
- package/dist/Components/Assistant/welcome/AssistantWelcomeProps.js +2 -0
- package/dist/Components/Table/components/TableBody.js +5 -1
- package/dist/esm/Components/Assistant/assistantModel.js +29 -0
- package/dist/esm/Components/Assistant/assistantStyles.js +47 -0
- package/dist/esm/Components/Assistant/assistantTypes.js +1 -0
- package/dist/esm/Components/Assistant/banner/AssistantStatusBanner.js +20 -0
- package/dist/esm/Components/Assistant/banner/AssistantStatusBannerProps.js +1 -0
- package/dist/esm/Components/Assistant/cards/AssistantApprovalCard.js +46 -0
- package/dist/esm/Components/Assistant/cards/AssistantApprovalCardProps.js +1 -0
- package/dist/esm/Components/Assistant/cards/AssistantProposalCard.js +31 -0
- package/dist/esm/Components/Assistant/cards/AssistantProposalCardProps.js +1 -0
- package/dist/esm/Components/Assistant/cards/CardShell.js +23 -0
- package/dist/esm/Components/Assistant/composer/AssistantComposer.js +259 -0
- package/dist/esm/Components/Assistant/composer/AssistantComposerProps.js +1 -0
- package/dist/esm/Components/Assistant/composer/ComposerMenu.js +30 -0
- package/dist/esm/Components/Assistant/composer/composerLogic.js +56 -0
- package/dist/esm/Components/Assistant/context/AssistantContextBar.js +22 -0
- package/dist/esm/Components/Assistant/context/AssistantContextBarProps.js +1 -0
- package/dist/esm/Components/Assistant/history/AssistantHistoryList.js +118 -0
- package/dist/esm/Components/Assistant/history/AssistantHistoryListProps.js +1 -0
- package/dist/esm/Components/Assistant/history/groupConversations.js +51 -0
- package/dist/esm/Components/Assistant/index.js +16 -0
- package/dist/esm/Components/Assistant/launcher/AssistantLauncher.js +40 -0
- package/dist/esm/Components/Assistant/launcher/AssistantLauncherProps.js +1 -0
- package/dist/esm/Components/Assistant/markdown/AssistantMarkdown.js +141 -0
- package/dist/esm/Components/Assistant/markdown/AssistantMarkdownProps.js +1 -0
- package/dist/esm/Components/Assistant/markdown/parseMarkdown.js +322 -0
- package/dist/esm/Components/Assistant/markdown/safeHref.js +23 -0
- package/dist/esm/Components/Assistant/message/AssistantMessage.js +126 -0
- package/dist/esm/Components/Assistant/message/AssistantMessageProps.js +1 -0
- package/dist/esm/Components/Assistant/message/MessageActions.js +16 -0
- package/dist/esm/Components/Assistant/panel/AssistantPanel.js +82 -0
- package/dist/esm/Components/Assistant/panel/AssistantPanelProps.js +1 -0
- package/dist/esm/Components/Assistant/panel/ResizeHandle.js +68 -0
- package/dist/esm/Components/Assistant/sources/AssistantSources.js +58 -0
- package/dist/esm/Components/Assistant/sources/AssistantSourcesProps.js +1 -0
- package/dist/esm/Components/Assistant/steps/AssistantToolSteps.js +36 -0
- package/dist/esm/Components/Assistant/steps/AssistantToolStepsProps.js +1 -0
- package/dist/esm/Components/Assistant/suggestions/AssistantSuggestions.js +13 -0
- package/dist/esm/Components/Assistant/suggestions/AssistantSuggestionsProps.js +1 -0
- package/dist/esm/Components/Assistant/thread/AssistantThread.js +107 -0
- package/dist/esm/Components/Assistant/thread/AssistantThreadProps.js +1 -0
- package/dist/esm/Components/Assistant/typing/AssistantTypingIndicator.js +28 -0
- package/dist/esm/Components/Assistant/typing/AssistantTypingIndicatorProps.js +1 -0
- package/dist/esm/Components/Assistant/welcome/AssistantWelcome.js +25 -0
- package/dist/esm/Components/Assistant/welcome/AssistantWelcomeProps.js +1 -0
- package/dist/esm/Components/Table/components/TableBody.js +5 -1
- package/dist/esm/index.js +2 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +20 -1
- package/package.json +1 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { AssistantChange, AssistantIcon } from "../assistantTypes";
|
|
3
|
+
/** Where an approval is in its life; Approve and Deny show only while "pending", and "failed" offers a retry. */
|
|
4
|
+
export type AssistantApprovalStatus = "pending" | "approving" | "approved" | "denied" | "expired" | "failed";
|
|
5
|
+
/** How much an approval can break; "high" also turns Approve red. */
|
|
6
|
+
export type AssistantApprovalRisk = "low" | "medium" | "high";
|
|
7
|
+
/** Visible and spoken text of `AssistantApprovalCard`; omitted keys keep the English default. */
|
|
8
|
+
export interface AssistantApprovalCardLabels {
|
|
9
|
+
/** Default "Approve". */
|
|
10
|
+
approve?: string;
|
|
11
|
+
/** Default "Deny". */
|
|
12
|
+
deny?: string;
|
|
13
|
+
/** Default "Undo". */
|
|
14
|
+
undo?: string;
|
|
15
|
+
/** The retry button on a failed approval. Default "Try again". */
|
|
16
|
+
retry?: string;
|
|
17
|
+
/** Name of the change list. Default "Changes". */
|
|
18
|
+
changes?: string;
|
|
19
|
+
/** Spoken between a change's old and new value. Default "changes to". */
|
|
20
|
+
changesTo?: string;
|
|
21
|
+
/** Shown for a change with no `before`. Default "Not set". */
|
|
22
|
+
empty?: string;
|
|
23
|
+
/** Risk badge text. */
|
|
24
|
+
risk?: {
|
|
25
|
+
low?: string;
|
|
26
|
+
medium?: string;
|
|
27
|
+
high?: string;
|
|
28
|
+
};
|
|
29
|
+
/** Status badge text per state; "pending" shows no badge. */
|
|
30
|
+
status?: {
|
|
31
|
+
approving?: string;
|
|
32
|
+
approved?: string;
|
|
33
|
+
denied?: string;
|
|
34
|
+
expired?: string;
|
|
35
|
+
failed?: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** A compact yes/no card for an action the assistant wants to run. */
|
|
39
|
+
export interface AssistantApprovalCardProps {
|
|
40
|
+
/** What will happen, e.g. "Close 3 duplicate tickets". */
|
|
41
|
+
title: string;
|
|
42
|
+
/** Extra context under the title. */
|
|
43
|
+
summary?: ReactNode;
|
|
44
|
+
/** Fields that change, shown as `label: before → after`. */
|
|
45
|
+
changes?: AssistantChange[];
|
|
46
|
+
/** Adds a risk badge; "high" turns Approve red. */
|
|
47
|
+
risk?: AssistantApprovalRisk;
|
|
48
|
+
/** Default "pending". "approving" spins Approve and disables Deny. */
|
|
49
|
+
status?: AssistantApprovalStatus;
|
|
50
|
+
/** Shown in error ink while `status` is "failed". */
|
|
51
|
+
error?: string;
|
|
52
|
+
/** With `status="approved"` and `onUndo`, shows an Undo button. */
|
|
53
|
+
undoable?: boolean;
|
|
54
|
+
/** Approve button; also the retry on a failed approval. */
|
|
55
|
+
onApprove?: () => void;
|
|
56
|
+
/** Deny button. */
|
|
57
|
+
onDeny?: () => void;
|
|
58
|
+
/** Undo button, shown only once approved and `undoable`. */
|
|
59
|
+
onUndo?: () => void;
|
|
60
|
+
/** Decorative icon before the title. Default ShieldCheck. */
|
|
61
|
+
icon?: AssistantIcon;
|
|
62
|
+
/** Translated button, badge and change text. */
|
|
63
|
+
labels?: AssistantApprovalCardLabels;
|
|
64
|
+
/** data-testid on the root. */
|
|
65
|
+
"data-testid"?: string;
|
|
66
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AssistantProposalCardProps } from "./AssistantProposalCardProps";
|
|
2
|
+
declare const _default: import("react").MemoExoticComponent<({ title, summary, fields, status, error, primaryLabel, onPrimary, onEdit, onDismiss, children, icon, labels, "data-testid": testId, }: AssistantProposalCardProps) => import("react/jsx-runtime").JSX.Element>;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const react_2 = require("@chakra-ui/react");
|
|
9
|
+
const lucide_react_1 = require("lucide-react");
|
|
10
|
+
const useCustomTheme_1 = require("../../../Theme/useCustomTheme");
|
|
11
|
+
const Button_1 = __importDefault(require("../../Button/Button"));
|
|
12
|
+
const DescriptionList_1 = __importDefault(require("../../DescriptionList/DescriptionList"));
|
|
13
|
+
const CardShell_1 = require("./CardShell");
|
|
14
|
+
const DEFAULT_STATUS = { applying: "Applying", applied: "Applied", dismissed: "Dismissed", failed: "Failed" };
|
|
15
|
+
const DEFAULT_LABELS = { edit: "Edit", dismiss: "Dismiss", retry: "Try again" };
|
|
16
|
+
const BADGE_TONE = {
|
|
17
|
+
applying: "info",
|
|
18
|
+
applied: "success",
|
|
19
|
+
dismissed: "neutral",
|
|
20
|
+
failed: "error",
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* A proposal to apply, edit or dismiss (the web twin of mobile's `ProposalCard`). Applied, dismissed and
|
|
24
|
+
* failed each look different — a green edge and badge, a dimmed title, an error edge and message — and
|
|
25
|
+
* the buttons go away once the proposal is settled.
|
|
26
|
+
*/
|
|
27
|
+
const AssistantProposalCard = ({ title, summary, fields, status = "pending", error, primaryLabel = "Apply", onPrimary, onEdit, onDismiss, children, icon = lucide_react_1.Sparkles, labels, "data-testid": testId = "assistant-proposal", }) => {
|
|
28
|
+
const { colors } = (0, useCustomTheme_1.useCustomTheme)();
|
|
29
|
+
const text = { ...DEFAULT_LABELS, ...labels };
|
|
30
|
+
const statusText = { ...DEFAULT_STATUS, ...labels === null || labels === void 0 ? void 0 : labels.status };
|
|
31
|
+
const busy = status === "applying";
|
|
32
|
+
const open = status === "pending" || busy || status === "failed";
|
|
33
|
+
const badge = status === "pending" ? undefined : { label: statusText[status], tone: BADGE_TONE[status] };
|
|
34
|
+
return ((0, jsx_runtime_1.jsxs)(CardShell_1.CardShell, { title: title, icon: icon, badge: badge, edgeTone: status === "applied" ? "success" : status === "failed" ? "error" : undefined, quiet: status === "dismissed", isBusy: busy, status: status, testId: testId, children: [summary ? ((0, jsx_runtime_1.jsx)(react_2.Box, { fontSize: "sm", color: status === "dismissed" ? colors.textMuted : colors.text[800], children: summary })) : null, (fields === null || fields === void 0 ? void 0 : fields.length) && status !== "dismissed" ? ((0, jsx_runtime_1.jsx)(DescriptionList_1.default, { items: fields, layout: "inline", columns: { base: 1 } })) : null, open ? children : null, status === "failed" && error ? (0, jsx_runtime_1.jsx)(CardShell_1.CardError, { message: error }) : null, open && (onPrimary || onEdit || onDismiss) ? ((0, jsx_runtime_1.jsxs)(CardShell_1.CardActions, { children: [onDismiss ? ((0, jsx_runtime_1.jsx)(Button_1.default, { size: "sm", variant: "ghost", colorScheme: "gray", label: text.dismiss, onClick: onDismiss, isDisabled: busy })) : null, onEdit ? ((0, jsx_runtime_1.jsx)(Button_1.default, { size: "sm", variant: "outline", colorScheme: "gray", label: text.edit, onClick: onEdit, isDisabled: busy })) : null, onPrimary ? ((0, jsx_runtime_1.jsx)(Button_1.default, { size: "sm", variant: "solid", colorScheme: "primary", label: status === "failed" ? text.retry : primaryLabel, onClick: onPrimary, isLoading: busy })) : null] })) : null] }));
|
|
35
|
+
};
|
|
36
|
+
exports.default = (0, react_1.memo)(AssistantProposalCard);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { AssistantIcon } from "../assistantTypes";
|
|
3
|
+
/** Where a proposal is in its life; actions show only while "pending", and "failed" offers a retry. */
|
|
4
|
+
export type AssistantProposalStatus = "pending" | "applying" | "applied" | "dismissed" | "failed";
|
|
5
|
+
/** One label/value pair in a proposal's preview. */
|
|
6
|
+
export interface AssistantProposalField {
|
|
7
|
+
/** Field name, e.g. "Priority". */
|
|
8
|
+
label: ReactNode;
|
|
9
|
+
/** Proposed value; a node (e.g. a `Tag`) is fine. */
|
|
10
|
+
value: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
/** Visible text of `AssistantProposalCard`; omitted keys keep the English default. */
|
|
13
|
+
export interface AssistantProposalCardLabels {
|
|
14
|
+
/** The edit button. Default "Edit". */
|
|
15
|
+
edit?: string;
|
|
16
|
+
/** The dismiss button. Default "Dismiss". */
|
|
17
|
+
dismiss?: string;
|
|
18
|
+
/** The retry button on a failed proposal. Default "Try again". */
|
|
19
|
+
retry?: string;
|
|
20
|
+
/** Status badge text per state; "pending" shows no badge. */
|
|
21
|
+
status?: {
|
|
22
|
+
applying?: string;
|
|
23
|
+
applied?: string;
|
|
24
|
+
dismissed?: string;
|
|
25
|
+
failed?: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** A proposal the assistant drafted for the person to apply, edit or dismiss. */
|
|
29
|
+
export interface AssistantProposalCardProps {
|
|
30
|
+
/** What is proposed, e.g. "Create issue: Login fails on Android". */
|
|
31
|
+
title: string;
|
|
32
|
+
/** Summary under the title; never clamped, because the person is approving it. */
|
|
33
|
+
summary?: ReactNode;
|
|
34
|
+
/** Label/value preview of what will be created or changed. */
|
|
35
|
+
fields?: AssistantProposalField[];
|
|
36
|
+
/** Default "pending". "applying" spins the primary button; "applied" and "dismissed" drop every action. */
|
|
37
|
+
status?: AssistantProposalStatus;
|
|
38
|
+
/** Shown in error ink while `status` is "failed". */
|
|
39
|
+
error?: string;
|
|
40
|
+
/** Label of the primary button. Default "Apply". */
|
|
41
|
+
primaryLabel?: string;
|
|
42
|
+
/** Primary action; also the retry on a failed proposal. Without it there is no primary button. */
|
|
43
|
+
onPrimary?: () => void;
|
|
44
|
+
/** Adds an Edit button (usually opens the app's own form, or reveals `children`). */
|
|
45
|
+
onEdit?: () => void;
|
|
46
|
+
/** Adds a Dismiss button. */
|
|
47
|
+
onDismiss?: () => void;
|
|
48
|
+
/** App-supplied body between the preview and the actions, e.g. an inline edit form. */
|
|
49
|
+
children?: ReactNode;
|
|
50
|
+
/** Decorative icon before the title. Default Sparkles. */
|
|
51
|
+
icon?: AssistantIcon;
|
|
52
|
+
/** Translated button and status text. */
|
|
53
|
+
labels?: AssistantProposalCardLabels;
|
|
54
|
+
/** data-testid on the root. */
|
|
55
|
+
"data-testid"?: string;
|
|
56
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { Tone } from "../../../Theme/tokens/builders/tone";
|
|
3
|
+
import type { AssistantIcon } from "../assistantTypes";
|
|
4
|
+
export interface CardShellBadge {
|
|
5
|
+
label: string;
|
|
6
|
+
tone: Tone;
|
|
7
|
+
}
|
|
8
|
+
interface CardShellProps {
|
|
9
|
+
title: string;
|
|
10
|
+
icon: AssistantIcon;
|
|
11
|
+
badge?: CardShellBadge;
|
|
12
|
+
/** Tints the card edge for a settled state; the badge carries the meaning in words. */
|
|
13
|
+
edgeTone?: Tone;
|
|
14
|
+
/** Dims the title for a closed card (dismissed, denied, expired). */
|
|
15
|
+
quiet?: boolean;
|
|
16
|
+
isBusy?: boolean;
|
|
17
|
+
testId: string;
|
|
18
|
+
status: string;
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
}
|
|
21
|
+
/** The bordered card both action cards share; a rule, not a lifted card, so it never nests a card in the panel. */
|
|
22
|
+
export declare const CardShell: ({ title, icon: Icon, badge, edgeTone, quiet, isBusy, testId, status, children }: CardShellProps) => import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
/** The end-aligned action row under a card. */
|
|
24
|
+
export declare const CardActions: ({ children }: {
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
/** Error line shown on a failed card. */
|
|
28
|
+
export declare const CardError: ({ message }: {
|
|
29
|
+
message: string;
|
|
30
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CardError = exports.CardActions = exports.CardShell = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const react_2 = require("@chakra-ui/react");
|
|
10
|
+
const useCustomTheme_1 = require("../../../Theme/useCustomTheme");
|
|
11
|
+
const borderWidths_1 = require("../../../Theme/tokens/primitives/borderWidths");
|
|
12
|
+
const radii_1 = require("../../../Theme/tokens/primitives/radii");
|
|
13
|
+
const Tag_1 = __importDefault(require("../../Tag/Tag"));
|
|
14
|
+
const assistantStyles_1 = require("../assistantStyles");
|
|
15
|
+
/** The bordered card both action cards share; a rule, not a lifted card, so it never nests a card in the panel. */
|
|
16
|
+
const CardShell = ({ title, icon: Icon, badge, edgeTone, quiet, isBusy, testId, status, children }) => {
|
|
17
|
+
const { colors } = (0, useCustomTheme_1.useCustomTheme)();
|
|
18
|
+
const tokens = (0, assistantStyles_1.assistantTokens)(colors);
|
|
19
|
+
const titleId = (0, react_1.useId)();
|
|
20
|
+
const edge = edgeTone ? (0, assistantStyles_1.assistantTone)(colors, edgeTone).border : tokens.rule;
|
|
21
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.Box, { as: "section", "aria-labelledby": titleId, "aria-busy": isBusy || undefined, borderWidth: borderWidths_1.BORDER_WIDTHS.hairline, borderColor: edge, borderRadius: radii_1.RADIUS_ROLE.card, p: 3, "data-testid": testId, "data-status": status, children: [(0, jsx_runtime_1.jsxs)(react_2.Flex, { align: "flex-start", gap: 2.5, children: [(0, jsx_runtime_1.jsx)(react_2.Flex, { "aria-hidden": "true", boxSize: 7, flexShrink: 0, align: "center", justify: "center", borderRadius: radii_1.RADIUS_ROLE.control, bg: colors.primary.opacity[8], color: quiet ? tokens.muted : colors.accentText, children: (0, jsx_runtime_1.jsx)(Icon, { size: 16 }) }), (0, jsx_runtime_1.jsx)(react_2.Text, { id: titleId, as: "h4", flex: "1", minW: 0, pt: 1, fontSize: "sm", fontWeight: 600, lineHeight: 1.43, color: quiet ? tokens.muted : tokens.heading, noOfLines: 2, children: title }), badge ? (0, jsx_runtime_1.jsx)(Tag_1.default, { label: badge.label, tone: badge.tone, size: "xs", "data-testid": `${testId}-status` }) : null] }), (0, jsx_runtime_1.jsx)(react_2.Flex, { direction: "column", gap: 2.5, mt: 2.5, children: children })] }));
|
|
22
|
+
};
|
|
23
|
+
exports.CardShell = CardShell;
|
|
24
|
+
/** The end-aligned action row under a card. */
|
|
25
|
+
const CardActions = ({ children }) => ((0, jsx_runtime_1.jsx)(react_2.Flex, { justify: "flex-end", wrap: "wrap", gap: 2, children: children }));
|
|
26
|
+
exports.CardActions = CardActions;
|
|
27
|
+
/** Error line shown on a failed card. */
|
|
28
|
+
const CardError = ({ message }) => {
|
|
29
|
+
const { colors } = (0, useCustomTheme_1.useCustomTheme)();
|
|
30
|
+
return ((0, jsx_runtime_1.jsx)(react_2.Text, { role: "alert", fontSize: "sm", color: colors.semanticText.error, children: message }));
|
|
31
|
+
};
|
|
32
|
+
exports.CardError = CardError;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AssistantComposerProps } from "./AssistantComposerProps";
|
|
2
|
+
declare const _default: import("react").MemoExoticComponent<({ value, onChange, onSubmit, onStop, isStreaming, disabled, placeholder, maxLength, maxRows, autoFocus, attachments, onAttach, accept, onRemoveAttachment, commands, onCommand, onMentionQuery, onMentionSelect, formatMention, voice, header, footer, inputRef, labels, "data-testid": testId, }: AssistantComposerProps) => import("react/jsx-runtime").JSX.Element>;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const react_2 = require("@chakra-ui/react");
|
|
9
|
+
const lucide_react_1 = require("lucide-react");
|
|
10
|
+
const useCustomTheme_1 = require("../../../Theme/useCustomTheme");
|
|
11
|
+
const focusRing_styles_1 = require("../../../Theme/chakra/focusRing.styles");
|
|
12
|
+
const placeholderInk_1 = require("../../../Theme/tokens/builders/placeholderInk");
|
|
13
|
+
const borderWidths_1 = require("../../../Theme/tokens/primitives/borderWidths");
|
|
14
|
+
const radii_1 = require("../../../Theme/tokens/primitives/radii");
|
|
15
|
+
const typography_1 = require("../../../Theme/tokens/primitives/typography");
|
|
16
|
+
const scrollbar_1 = require("../../../Theme/tokens/builders/scrollbar");
|
|
17
|
+
const fieldStyles_1 = require("../../Common/fieldStyles");
|
|
18
|
+
const mergeRefs_1 = require("../../../Utils/mergeRefs");
|
|
19
|
+
const IconButton_1 = __importDefault(require("../../IconButton/IconButton"));
|
|
20
|
+
const ToolTip_1 = __importDefault(require("../../ToolTip/ToolTip"));
|
|
21
|
+
const VisuallyHidden_1 = __importDefault(require("../../VisuallyHidden/VisuallyHidden"));
|
|
22
|
+
const assistantStyles_1 = require("../assistantStyles");
|
|
23
|
+
const ComposerMenu_1 = require("./ComposerMenu");
|
|
24
|
+
const composerLogic_1 = require("./composerLogic");
|
|
25
|
+
const DEFAULT_LABELS = {
|
|
26
|
+
input: "Message the assistant",
|
|
27
|
+
send: "Send message",
|
|
28
|
+
stop: "Stop generating",
|
|
29
|
+
attach: "Attach files",
|
|
30
|
+
removeAttachment: (name) => `Remove ${name}`,
|
|
31
|
+
attachments: "Attachments",
|
|
32
|
+
commands: "Commands",
|
|
33
|
+
mentions: "Mentions",
|
|
34
|
+
mentionLoading: "Searching…",
|
|
35
|
+
mentionEmpty: "No matches",
|
|
36
|
+
voiceStart: "Start voice input",
|
|
37
|
+
voiceStop: "Stop voice input",
|
|
38
|
+
counter: (length, max) => `${length} of ${max} characters`,
|
|
39
|
+
dropHint: "Drop files to attach",
|
|
40
|
+
};
|
|
41
|
+
const MENTION_DEBOUNCE_MS = 150;
|
|
42
|
+
const COUNTER_FROM = 0.8;
|
|
43
|
+
const FALLBACK_LINE_PX = 20;
|
|
44
|
+
const ATTACHMENT_ICON = { image: lucide_react_1.Image, document: lucide_react_1.FileText, audio: lucide_react_1.FileAudio, video: lucide_react_1.FileVideo, file: lucide_react_1.FileText };
|
|
45
|
+
const hasFiles = (event) => { var _a, _b; return Array.from((_b = (_a = event.dataTransfer) === null || _a === void 0 ? void 0 : _a.types) !== null && _b !== void 0 ? _b : []).includes("Files"); };
|
|
46
|
+
/**
|
|
47
|
+
* The assistant's message box. Enter sends and Shift+Enter breaks the line (never mid-IME composition);
|
|
48
|
+
* while a reply streams Send turns into Stop. Files arrive from the paperclip, a paste or a drop. Typing
|
|
49
|
+
* "/" opens the command menu and "@" the mention menu; both keep focus in the field and are driven with
|
|
50
|
+
* ↑ ↓ Enter Tab Esc.
|
|
51
|
+
*/
|
|
52
|
+
const AssistantComposer = ({ value, onChange, onSubmit, onStop, isStreaming = false, disabled = false, placeholder = "Ask anything", maxLength, maxRows = 8, autoFocus, attachments = [], onAttach, accept, onRemoveAttachment, commands, onCommand, onMentionQuery, onMentionSelect, formatMention, voice, header, footer, inputRef, labels, "data-testid": testId = "assistant-composer", }) => {
|
|
53
|
+
const { colors } = (0, useCustomTheme_1.useCustomTheme)();
|
|
54
|
+
const tokens = (0, assistantStyles_1.assistantTokens)(colors);
|
|
55
|
+
const text = { ...DEFAULT_LABELS, ...labels };
|
|
56
|
+
const baseId = (0, react_1.useId)();
|
|
57
|
+
const menuId = `${baseId}-menu`;
|
|
58
|
+
const counterId = `${baseId}-counter`;
|
|
59
|
+
const textareaRef = (0, react_1.useRef)(null);
|
|
60
|
+
const fileRef = (0, react_1.useRef)(null);
|
|
61
|
+
const composing = (0, react_1.useRef)(false);
|
|
62
|
+
const pendingCaret = (0, react_1.useRef)(null);
|
|
63
|
+
const mentionToken = (0, react_1.useRef)(0);
|
|
64
|
+
const ref = (0, react_1.useMemo)(() => (0, mergeRefs_1.mergeRefs)(textareaRef, inputRef), [inputRef]);
|
|
65
|
+
const [caret, setCaret] = (0, react_1.useState)(value.length);
|
|
66
|
+
const [dismissedFor, setDismissedFor] = (0, react_1.useState)(null);
|
|
67
|
+
const [activeIndex, setActiveIndex] = (0, react_1.useState)(0);
|
|
68
|
+
const [mention, setMention] = (0, react_1.useState)(null);
|
|
69
|
+
const [dragging, setDragging] = (0, react_1.useState)(false);
|
|
70
|
+
// Autosize: the height changes per keystroke, so it is written to inline style, never a Chakra prop.
|
|
71
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
72
|
+
const el = textareaRef.current;
|
|
73
|
+
if (!el)
|
|
74
|
+
return;
|
|
75
|
+
const style = getComputedStyle(el);
|
|
76
|
+
const line = Number.parseFloat(style.lineHeight) || FALLBACK_LINE_PX;
|
|
77
|
+
const padding = (Number.parseFloat(style.paddingTop) || 0) + (Number.parseFloat(style.paddingBottom) || 0);
|
|
78
|
+
const max = line * maxRows + padding;
|
|
79
|
+
el.style.height = "auto";
|
|
80
|
+
const next = Math.min(el.scrollHeight, max);
|
|
81
|
+
el.style.height = next > 0 ? `${next}px` : "";
|
|
82
|
+
el.style.overflowY = el.scrollHeight > max ? "auto" : "hidden";
|
|
83
|
+
}, [value, maxRows]);
|
|
84
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
85
|
+
if (pendingCaret.current === null)
|
|
86
|
+
return;
|
|
87
|
+
const el = textareaRef.current;
|
|
88
|
+
const at = pendingCaret.current;
|
|
89
|
+
pendingCaret.current = null;
|
|
90
|
+
if (!el)
|
|
91
|
+
return;
|
|
92
|
+
el.focus();
|
|
93
|
+
el.setSelectionRange(at, at);
|
|
94
|
+
setCaret(at);
|
|
95
|
+
}, [value]);
|
|
96
|
+
const slash = (commands === null || commands === void 0 ? void 0 : commands.length) ? (0, composerLogic_1.commandQuery)(value) : null;
|
|
97
|
+
const commandOptions = (0, react_1.useMemo)(() => (slash === null || !commands ? [] : (0, composerLogic_1.filterCommands)(commands, slash)), [commands, slash]);
|
|
98
|
+
const mentionMatch = onMentionQuery ? (0, composerLogic_1.mentionAt)(value, caret) : null;
|
|
99
|
+
const dismissed = dismissedFor === value;
|
|
100
|
+
const commandOpen = !dismissed && slash !== null && commandOptions.length > 0;
|
|
101
|
+
const mentionOpen = !dismissed && !commandOpen && mentionMatch !== null;
|
|
102
|
+
// Debounced, stale-safe mention lookup.
|
|
103
|
+
const mentionQuery = mentionOpen ? mentionMatch.query : null;
|
|
104
|
+
(0, react_1.useEffect)(() => {
|
|
105
|
+
if (mentionQuery === null || !onMentionQuery) {
|
|
106
|
+
setMention(null);
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
const token = ++mentionToken.current;
|
|
110
|
+
setMention((prev) => { var _a; return ({ query: mentionQuery, items: (_a = prev === null || prev === void 0 ? void 0 : prev.items) !== null && _a !== void 0 ? _a : [], loading: true }); });
|
|
111
|
+
const timer = setTimeout(() => {
|
|
112
|
+
onMentionQuery(mentionQuery)
|
|
113
|
+
.then((items) => {
|
|
114
|
+
if (token === mentionToken.current)
|
|
115
|
+
setMention({ query: mentionQuery, items, loading: false });
|
|
116
|
+
})
|
|
117
|
+
.catch(() => {
|
|
118
|
+
if (token === mentionToken.current)
|
|
119
|
+
setMention({ query: mentionQuery, items: [], loading: false });
|
|
120
|
+
});
|
|
121
|
+
}, MENTION_DEBOUNCE_MS);
|
|
122
|
+
return () => clearTimeout(timer);
|
|
123
|
+
}, [mentionQuery, onMentionQuery]);
|
|
124
|
+
const options = commandOpen
|
|
125
|
+
? commandOptions.map((c) => ({
|
|
126
|
+
key: c.command,
|
|
127
|
+
label: c.label,
|
|
128
|
+
prefix: (0, composerLogic_1.commandText)(c).trim(),
|
|
129
|
+
description: c.description,
|
|
130
|
+
icon: c.icon,
|
|
131
|
+
}))
|
|
132
|
+
: mentionOpen && mention
|
|
133
|
+
? mention.items.map((m) => ({ key: m.id, label: m.label, description: m.description, trailing: m.kind }))
|
|
134
|
+
: [];
|
|
135
|
+
const menuOpen = commandOpen || (mentionOpen && mention !== null);
|
|
136
|
+
const optionsKey = options.map((o) => o.key).join("|");
|
|
137
|
+
(0, react_1.useEffect)(() => setActiveIndex(0), [optionsKey]);
|
|
138
|
+
const active = Math.min(activeIndex, Math.max(0, options.length - 1));
|
|
139
|
+
const canSend = !disabled && !isStreaming && (value.trim().length > 0 || attachments.length > 0);
|
|
140
|
+
const submit = () => {
|
|
141
|
+
if (canSend)
|
|
142
|
+
onSubmit(value);
|
|
143
|
+
};
|
|
144
|
+
const pick = (index) => {
|
|
145
|
+
if (commandOpen) {
|
|
146
|
+
const command = commandOptions[index];
|
|
147
|
+
if (!command)
|
|
148
|
+
return;
|
|
149
|
+
const next = (0, composerLogic_1.commandText)(command);
|
|
150
|
+
pendingCaret.current = next.length;
|
|
151
|
+
onChange(next);
|
|
152
|
+
onCommand === null || onCommand === void 0 ? void 0 : onCommand(command);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (mentionOpen && mentionMatch && mention) {
|
|
156
|
+
const item = mention.items[index];
|
|
157
|
+
if (!item)
|
|
158
|
+
return;
|
|
159
|
+
const insert = formatMention ? formatMention(item) : `@${item.label}`;
|
|
160
|
+
const next = (0, composerLogic_1.applyMention)(value, mentionMatch.start, caret, insert);
|
|
161
|
+
pendingCaret.current = next.caret;
|
|
162
|
+
onChange(next.value);
|
|
163
|
+
onMentionSelect === null || onMentionSelect === void 0 ? void 0 : onMentionSelect(item);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const syncCaret = () => { var _a, _b; return setCaret((_b = (_a = textareaRef.current) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : value.length); };
|
|
167
|
+
const onKeyDown = (event) => {
|
|
168
|
+
if (composing.current || event.nativeEvent.isComposing || event.keyCode === 229)
|
|
169
|
+
return;
|
|
170
|
+
if (menuOpen) {
|
|
171
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
172
|
+
if (options.length === 0)
|
|
173
|
+
return;
|
|
174
|
+
event.preventDefault();
|
|
175
|
+
const step = event.key === "ArrowDown" ? 1 : -1;
|
|
176
|
+
setActiveIndex((active + step + options.length) % options.length);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if ((event.key === "Enter" && !event.shiftKey) || event.key === "Tab") {
|
|
180
|
+
if (options.length > 0) {
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
pick(active);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (event.key === "Escape") {
|
|
187
|
+
event.preventDefault();
|
|
188
|
+
event.stopPropagation();
|
|
189
|
+
setDismissedFor(value);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
194
|
+
event.preventDefault();
|
|
195
|
+
submit();
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
const passFiles = (list) => {
|
|
199
|
+
if (!onAttach || disabled)
|
|
200
|
+
return false;
|
|
201
|
+
const files = Array.from(list !== null && list !== void 0 ? list : []).filter((file) => (0, composerLogic_1.matchesAccept)(file, accept));
|
|
202
|
+
if (files.length)
|
|
203
|
+
onAttach(files);
|
|
204
|
+
return files.length > 0;
|
|
205
|
+
};
|
|
206
|
+
const onPaste = (event) => {
|
|
207
|
+
var _a;
|
|
208
|
+
const files = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.files;
|
|
209
|
+
if (!files || files.length === 0)
|
|
210
|
+
return;
|
|
211
|
+
const passed = passFiles(files);
|
|
212
|
+
if (passed && !event.clipboardData.getData("text/plain"))
|
|
213
|
+
event.preventDefault();
|
|
214
|
+
};
|
|
215
|
+
const dropHandlers = onAttach
|
|
216
|
+
? {
|
|
217
|
+
onDragOver: (event) => {
|
|
218
|
+
if (!hasFiles(event) || disabled)
|
|
219
|
+
return;
|
|
220
|
+
event.preventDefault();
|
|
221
|
+
setDragging(true);
|
|
222
|
+
},
|
|
223
|
+
onDragLeave: (event) => {
|
|
224
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
225
|
+
setDragging(false);
|
|
226
|
+
},
|
|
227
|
+
onDrop: (event) => {
|
|
228
|
+
if (!hasFiles(event))
|
|
229
|
+
return;
|
|
230
|
+
event.preventDefault();
|
|
231
|
+
setDragging(false);
|
|
232
|
+
passFiles(event.dataTransfer.files);
|
|
233
|
+
},
|
|
234
|
+
}
|
|
235
|
+
: {};
|
|
236
|
+
const showCounter = maxLength !== undefined && value.length >= maxLength * COUNTER_FROM;
|
|
237
|
+
const counterInk = maxLength !== undefined && value.length >= maxLength ? colors.semanticText.error : tokens.muted;
|
|
238
|
+
const brand = (0, assistantStyles_1.assistantTone)(colors, "info");
|
|
239
|
+
const attachmentChip = (attachment) => {
|
|
240
|
+
var _a;
|
|
241
|
+
const kind = (_a = attachment.kind) !== null && _a !== void 0 ? _a : (attachment.previewUrl ? "image" : "file");
|
|
242
|
+
const Icon = ATTACHMENT_ICON[kind];
|
|
243
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.Flex, { as: "li", align: "center", gap: 1.5, maxW: "14rem", pl: attachment.previewUrl ? 1 : 2, pr: onRemoveAttachment ? 0.5 : 2, py: 1, borderWidth: borderWidths_1.BORDER_WIDTHS.hairline, borderColor: tokens.rule, borderRadius: radii_1.RADIUS_ROLE.control, "data-testid": `${testId}-attachment`, children: [attachment.previewUrl ? ((0, jsx_runtime_1.jsx)(react_2.Image, { src: attachment.previewUrl, alt: "", boxSize: 7, objectFit: "cover", borderRadius: radii_1.RADIUS_ROLE.option, flexShrink: 0 })) : ((0, jsx_runtime_1.jsx)(react_2.Box, { as: Icon, "aria-hidden": "true", boxSize: 4, flexShrink: 0, color: tokens.muted })), (0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "xs", color: tokens.body, noOfLines: 1, title: attachment.name, children: attachment.name }), onRemoveAttachment ? ((0, jsx_runtime_1.jsx)(IconButton_1.default, { "aria-label": text.removeAttachment(attachment.name), icon: (0, jsx_runtime_1.jsx)(lucide_react_1.X, { size: 12 }), size: "xs", variant: "ghost", colorScheme: "gray", isDisabled: disabled, onClick: () => onRemoveAttachment(attachment.id) })) : null] }, attachment.id));
|
|
244
|
+
};
|
|
245
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.Box, { "data-testid": testId, children: [(0, jsx_runtime_1.jsxs)(react_2.Box, { position: "relative", children: [menuOpen ? ((0, jsx_runtime_1.jsx)(ComposerMenu_1.ComposerMenu, { id: menuId, label: commandOpen ? text.commands : text.mentions, options: options, activeIndex: active, onActiveChange: setActiveIndex, onPick: pick, isLoading: !commandOpen && Boolean(mention === null || mention === void 0 ? void 0 : mention.loading) && options.length === 0, status: !commandOpen && mention && options.length === 0
|
|
246
|
+
? mention.loading
|
|
247
|
+
? text.mentionLoading
|
|
248
|
+
: text.mentionEmpty
|
|
249
|
+
: undefined })) : null, (0, jsx_runtime_1.jsxs)(react_2.Box, { ...(0, fieldStyles_1.fieldBoxStyles)(colors), position: "relative", borderRadius: radii_1.RADIUS_ROLE.card, bg: disabled ? colors.background[100] : colors.background[50], _focusWithin: { borderColor: colors.primary[500], ...(0, focusRing_styles_1.fieldFocusVisible)(colors) }, ...dropHandlers, "data-dragging": dragging || undefined, children: [header ? (0, jsx_runtime_1.jsx)(react_2.Box, { px: 3, pt: 2.5, children: header }) : null, attachments.length ? ((0, jsx_runtime_1.jsx)(react_2.Flex, { as: "ul", "aria-label": text.attachments, listStyleType: "none", wrap: "wrap", gap: 1.5, px: 3, pt: 2.5, m: 0, children: attachments.map(attachmentChip) })) : null, (0, jsx_runtime_1.jsx)(react_2.Textarea, { ref: ref, variant: "unstyled", value: value, rows: 1, resize: "none", minH: 0, px: 3, pt: 2.5, pb: 1, fontSize: "sm", lineHeight: 1.43, color: colors.text[900], placeholder: placeholder, maxLength: maxLength, autoFocus: autoFocus, isDisabled: disabled, "aria-label": text.input, "aria-autocomplete": (commands === null || commands === void 0 ? void 0 : commands.length) || onMentionQuery ? "list" : undefined, "aria-controls": menuOpen && options.length ? menuId : undefined, "aria-activedescendant": menuOpen && options.length ? (0, ComposerMenu_1.optionId)(menuId, active) : undefined, "aria-describedby": showCounter ? counterId : undefined, _placeholder: { color: (0, placeholderInk_1.placeholderInk)(colors), opacity: 1 },
|
|
250
|
+
// The composer box draws the focus state (focus-within), so the bare field draws none of its own.
|
|
251
|
+
sx: { ...(0, scrollbar_1.scrollbarStyles)(colors), "&:focus, &:focus-visible": { outline: "none", boxShadow: "none" } }, onChange: (event) => {
|
|
252
|
+
var _a;
|
|
253
|
+
setCaret((_a = event.target.selectionStart) !== null && _a !== void 0 ? _a : event.target.value.length);
|
|
254
|
+
onChange(event.target.value);
|
|
255
|
+
}, onKeyDown: onKeyDown, onKeyUp: syncCaret, onClick: syncCaret, onSelect: syncCaret, onPaste: onPaste, onCompositionStart: () => {
|
|
256
|
+
composing.current = true;
|
|
257
|
+
}, onCompositionEnd: () => {
|
|
258
|
+
composing.current = false;
|
|
259
|
+
} }), (0, jsx_runtime_1.jsxs)(react_2.Flex, { align: "center", gap: 1, px: 2, pb: 2, children: [onAttach ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(ToolTip_1.default, { label: text.attach, children: (0, jsx_runtime_1.jsx)(IconButton_1.default, { "aria-label": text.attach, icon: (0, jsx_runtime_1.jsx)(lucide_react_1.Paperclip, { size: 16 }), size: "sm", variant: "ghost", colorScheme: "gray", isDisabled: disabled, onClick: () => { var _a; return (_a = fileRef.current) === null || _a === void 0 ? void 0 : _a.click(); } }) }), (0, jsx_runtime_1.jsx)("input", { ref: fileRef, type: "file", multiple: true, hidden: true, accept: accept, tabIndex: -1, "aria-hidden": "true", "data-testid": `${testId}-file-input`, onChange: (event) => {
|
|
260
|
+
passFiles(event.target.files);
|
|
261
|
+
event.target.value = "";
|
|
262
|
+
} })] })) : null, (voice === null || voice === void 0 ? void 0 : voice.supported) ? ((0, jsx_runtime_1.jsx)(ToolTip_1.default, { label: voice.listening ? text.voiceStop : text.voiceStart, children: (0, jsx_runtime_1.jsx)(IconButton_1.default, { "aria-label": voice.listening ? text.voiceStop : text.voiceStart, "aria-pressed": voice.listening, icon: voice.listening ? (0, jsx_runtime_1.jsx)(lucide_react_1.MicOff, { size: 16 }) : (0, jsx_runtime_1.jsx)(lucide_react_1.Mic, { size: 16 }), size: "sm", variant: voice.listening ? "solid" : "ghost", colorScheme: voice.listening ? "red" : "gray", isDisabled: disabled, onClick: voice.onToggle }) })) : null, (0, jsx_runtime_1.jsx)(react_2.Box, { flex: "1" }), showCounter && maxLength !== undefined ? ((0, jsx_runtime_1.jsxs)(react_2.Text, { id: counterId, fontSize: "xs", color: counterInk, sx: typography_1.NUMERIC_TEXT, "data-testid": `${testId}-counter`, children: [(0, jsx_runtime_1.jsxs)("span", { "aria-hidden": "true", children: [value.length, "/", maxLength] }), (0, jsx_runtime_1.jsx)(VisuallyHidden_1.default, { children: text.counter(value.length, maxLength) })] })) : null, isStreaming ? ((0, jsx_runtime_1.jsx)(ToolTip_1.default, { label: text.stop, children: (0, jsx_runtime_1.jsx)(IconButton_1.default, { "aria-label": text.stop, icon: (0, jsx_runtime_1.jsx)(lucide_react_1.Square, { size: 14, fill: "currentColor" }), size: "sm", variant: "outline", colorScheme: "gray", isDisabled: disabled || !onStop, onClick: onStop }) })) : ((0, jsx_runtime_1.jsx)(ToolTip_1.default, { label: text.send, children: (0, jsx_runtime_1.jsx)(IconButton_1.default, { "aria-label": text.send, icon: (0, jsx_runtime_1.jsx)(lucide_react_1.ArrowUp, { size: 16 }), size: "sm", variant: "solid", colorScheme: "primary", isDisabled: !canSend, onClick: submit }) }))] }), dragging ? ((0, jsx_runtime_1.jsx)(react_2.Flex, { position: "absolute", inset: 0, align: "center", justify: "center", borderRadius: radii_1.RADIUS_ROLE.card, bg: brand.bg, borderWidth: borderWidths_1.BORDER_WIDTHS.thick, borderStyle: "dashed", borderColor: brand.ink, color: brand.ink, fontSize: "sm", fontWeight: 600, pointerEvents: "none", children: text.dropHint })) : null] })] }), footer ? ((0, jsx_runtime_1.jsx)(react_2.Box, { mt: 1.5, px: 1, fontSize: "xs", color: tokens.muted, children: footer })) : null] }));
|
|
263
|
+
};
|
|
264
|
+
exports.default = (0, react_1.memo)(AssistantComposer);
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { ReactNode, Ref } from "react";
|
|
2
|
+
import type { AssistantIcon } from "../assistantTypes";
|
|
3
|
+
/** A file staged on the composer until the message is sent. */
|
|
4
|
+
export interface AssistantComposerAttachment {
|
|
5
|
+
/** Handed back to `onRemoveAttachment`. */
|
|
6
|
+
id: string;
|
|
7
|
+
/** File name; truncated in the middle of the chip. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** Thumbnail URL (e.g. an object URL) for an image; app-owned, so it may be shown. */
|
|
10
|
+
previewUrl?: string;
|
|
11
|
+
/** Picks the chip's icon when there is no preview. Default "file". */
|
|
12
|
+
kind?: "image" | "document" | "audio" | "video" | "file";
|
|
13
|
+
}
|
|
14
|
+
/** One slash command in the "/" menu. */
|
|
15
|
+
export interface AssistantComposerCommand {
|
|
16
|
+
/** The word after the slash, e.g. "summarize" (a leading "/" is ignored). */
|
|
17
|
+
command: string;
|
|
18
|
+
/** Visible name, e.g. "Summarize". */
|
|
19
|
+
label: string;
|
|
20
|
+
/** Muted line under the label. */
|
|
21
|
+
description?: string;
|
|
22
|
+
/** Decorative icon before the label. */
|
|
23
|
+
icon?: AssistantIcon;
|
|
24
|
+
}
|
|
25
|
+
/** One result in the "@" mention menu. */
|
|
26
|
+
export interface AssistantMentionItem {
|
|
27
|
+
/** Stable key. */
|
|
28
|
+
id: string;
|
|
29
|
+
/** Inserted after "@" by default, and shown in the menu. */
|
|
30
|
+
label: string;
|
|
31
|
+
/** Muted second line, e.g. an email or a record key. */
|
|
32
|
+
description?: string;
|
|
33
|
+
/** Short type word shown at the end of the row, e.g. "Person" or "Ticket". */
|
|
34
|
+
kind?: string;
|
|
35
|
+
}
|
|
36
|
+
/** Speech-input wiring; the app owns the recogniser. */
|
|
37
|
+
export interface AssistantComposerVoice {
|
|
38
|
+
/** False hides the mic button (no Web Speech API, or not permitted). */
|
|
39
|
+
supported: boolean;
|
|
40
|
+
/** Pressed state of the mic button. */
|
|
41
|
+
listening: boolean;
|
|
42
|
+
/** Called from the mic button to start or stop listening. */
|
|
43
|
+
onToggle: () => void;
|
|
44
|
+
}
|
|
45
|
+
/** Visible and spoken text of `AssistantComposer`; omitted keys keep the English default. */
|
|
46
|
+
export interface AssistantComposerLabels {
|
|
47
|
+
/** Accessible name of the text field. Default "Message the assistant". */
|
|
48
|
+
input?: string;
|
|
49
|
+
/** Default "Send message". */
|
|
50
|
+
send?: string;
|
|
51
|
+
/** Default "Stop generating". */
|
|
52
|
+
stop?: string;
|
|
53
|
+
/** Default "Attach files". */
|
|
54
|
+
attach?: string;
|
|
55
|
+
/** Accessible name of an attachment's remove button. Default "Remove <name>". */
|
|
56
|
+
removeAttachment?: (name: string) => string;
|
|
57
|
+
/** Name of the attachment list. Default "Attachments". */
|
|
58
|
+
attachments?: string;
|
|
59
|
+
/** Name of the slash-command menu. Default "Commands". */
|
|
60
|
+
commands?: string;
|
|
61
|
+
/** Name of the mention menu. Default "Mentions". */
|
|
62
|
+
mentions?: string;
|
|
63
|
+
/** Shown while mention results load. Default "Searching…". */
|
|
64
|
+
mentionLoading?: string;
|
|
65
|
+
/** Shown when a mention query has no results. Default "No matches". */
|
|
66
|
+
mentionEmpty?: string;
|
|
67
|
+
/** Default "Start voice input". */
|
|
68
|
+
voiceStart?: string;
|
|
69
|
+
/** Default "Stop voice input". */
|
|
70
|
+
voiceStop?: string;
|
|
71
|
+
/** Spoken character count once the counter shows. Default "<n> of <max> characters". */
|
|
72
|
+
counter?: (length: number, max: number) => string;
|
|
73
|
+
/** Shown over the composer while files are dragged onto it. Default "Drop files to attach". */
|
|
74
|
+
dropHint?: string;
|
|
75
|
+
}
|
|
76
|
+
/** The assistant's message box: autosizing field, send/stop, attachments, slash commands, mentions and voice. */
|
|
77
|
+
export interface AssistantComposerProps {
|
|
78
|
+
/** Controlled text. The app clears it after `onSubmit`. */
|
|
79
|
+
value: string;
|
|
80
|
+
/** Called with the full new text on every edit, command pick and mention insert. */
|
|
81
|
+
onChange: (value: string) => void;
|
|
82
|
+
/** Enter (without Shift, outside IME composition) or the Send button; only with trimmed text or an attachment. */
|
|
83
|
+
onSubmit: (value: string) => void;
|
|
84
|
+
/** While `isStreaming`, Send becomes Stop and calls this. */
|
|
85
|
+
onStop?: () => void;
|
|
86
|
+
/** A reply is streaming: Send becomes Stop and Enter no longer submits. */
|
|
87
|
+
isStreaming?: boolean;
|
|
88
|
+
/** Disables the field and every button. */
|
|
89
|
+
disabled?: boolean;
|
|
90
|
+
/** Default "Ask anything". */
|
|
91
|
+
placeholder?: string;
|
|
92
|
+
/** Hard cap (native `maxLength`); a counter appears from 80% of it. */
|
|
93
|
+
maxLength?: number;
|
|
94
|
+
/** Lines the field grows to before it scrolls. Default 8. */
|
|
95
|
+
maxRows?: number;
|
|
96
|
+
/** Focuses the field on mount. */
|
|
97
|
+
autoFocus?: boolean;
|
|
98
|
+
/** Staged files, shown as chips above the field. */
|
|
99
|
+
attachments?: AssistantComposerAttachment[];
|
|
100
|
+
/** Adds the paperclip and accepts pasted and dropped files; only files matching `accept` are passed on. */
|
|
101
|
+
onAttach?: (files: File[]) => void;
|
|
102
|
+
/** `accept` list, as for `<input type="file">`, e.g. "image/*,.pdf". */
|
|
103
|
+
accept?: string;
|
|
104
|
+
/** Adds a remove button to each attachment chip. */
|
|
105
|
+
onRemoveAttachment?: (id: string) => void;
|
|
106
|
+
/** Opens a command menu while the whole text is "/" plus a word; ↑ ↓ move, Enter or Tab picks, Esc closes. */
|
|
107
|
+
commands?: AssistantComposerCommand[];
|
|
108
|
+
/** Called with the picked command after the text becomes "/command ". */
|
|
109
|
+
onCommand?: (command: AssistantComposerCommand) => void;
|
|
110
|
+
/** Turns on "@" mentions: called (debounced) with the text after "@"; resolve the matches. Stale results are ignored. */
|
|
111
|
+
onMentionQuery?: (query: string) => Promise<AssistantMentionItem[]>;
|
|
112
|
+
/** Called with the picked mention after it is inserted. */
|
|
113
|
+
onMentionSelect?: (item: AssistantMentionItem) => void;
|
|
114
|
+
/** Text that replaces "@query". Default "@" + the item's label. A trailing space is added. */
|
|
115
|
+
formatMention?: (item: AssistantMentionItem) => string;
|
|
116
|
+
/** Adds a mic button when `supported`. */
|
|
117
|
+
voice?: AssistantComposerVoice;
|
|
118
|
+
/** Content above the field, inside the composer, e.g. an `AssistantContextBar`. */
|
|
119
|
+
header?: ReactNode;
|
|
120
|
+
/** Muted content under the composer, e.g. "AI can make mistakes". */
|
|
121
|
+
footer?: ReactNode;
|
|
122
|
+
/** Ref to the `<textarea>`, to focus it from outside. */
|
|
123
|
+
inputRef?: Ref<HTMLTextAreaElement>;
|
|
124
|
+
/** Translated text. */
|
|
125
|
+
labels?: AssistantComposerLabels;
|
|
126
|
+
/** data-testid on the root. */
|
|
127
|
+
"data-testid"?: string;
|
|
128
|
+
}
|