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,24 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { AssistantIcon } from "../assistantTypes";
|
|
3
|
+
export interface ComposerMenuOption {
|
|
4
|
+
key: string;
|
|
5
|
+
label: string;
|
|
6
|
+
prefix?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
trailing?: string;
|
|
9
|
+
icon?: AssistantIcon;
|
|
10
|
+
}
|
|
11
|
+
interface ComposerMenuProps {
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
options: ComposerMenuOption[];
|
|
15
|
+
activeIndex: number;
|
|
16
|
+
onActiveChange: (index: number) => void;
|
|
17
|
+
onPick: (index: number) => void;
|
|
18
|
+
status?: ReactNode;
|
|
19
|
+
isLoading?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare const optionId: (menuId: string, index: number) => string;
|
|
22
|
+
/** The listbox the composer opens above its field; focus stays in the field (aria-activedescendant). */
|
|
23
|
+
export declare const ComposerMenu: ({ id, label, options, activeIndex, onActiveChange, onPick, status, isLoading }: ComposerMenuProps) => import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
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.ComposerMenu = exports.optionId = 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 rowStates_1 = require("../../../Theme/tokens/builders/rowStates");
|
|
12
|
+
const scrollbar_1 = require("../../../Theme/tokens/builders/scrollbar");
|
|
13
|
+
const borderWidths_1 = require("../../../Theme/tokens/primitives/borderWidths");
|
|
14
|
+
const radii_1 = require("../../../Theme/tokens/primitives/radii");
|
|
15
|
+
const zIndices_1 = __importDefault(require("../../../Theme/tokens/primitives/zIndices"));
|
|
16
|
+
const Spinner_1 = __importDefault(require("../../Spinner/Spinner"));
|
|
17
|
+
const optionRowInk_1 = require("../../Select/optionRowInk");
|
|
18
|
+
const assistantStyles_1 = require("../assistantStyles");
|
|
19
|
+
const optionId = (menuId, index) => `${menuId}-option-${index}`;
|
|
20
|
+
exports.optionId = optionId;
|
|
21
|
+
/** The listbox the composer opens above its field; focus stays in the field (aria-activedescendant). */
|
|
22
|
+
const ComposerMenu = ({ id, label, options, activeIndex, onActiveChange, onPick, status, isLoading }) => {
|
|
23
|
+
const { colors } = (0, useCustomTheme_1.useCustomTheme)();
|
|
24
|
+
const tokens = (0, assistantStyles_1.assistantTokens)(colors);
|
|
25
|
+
const rows = (0, rowStates_1.listRowBackgrounds)(colors);
|
|
26
|
+
const listRef = (0, react_1.useRef)(null);
|
|
27
|
+
(0, react_1.useEffect)(() => {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
const active = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument.getElementById((0, exports.optionId)(id, activeIndex));
|
|
30
|
+
(_b = active === null || active === void 0 ? void 0 : active.scrollIntoView) === null || _b === void 0 ? void 0 : _b.call(active, { block: "nearest" });
|
|
31
|
+
}, [id, activeIndex]);
|
|
32
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.Box, { position: "absolute", left: 0, right: 0, bottom: "100%", mb: 2, zIndex: zIndices_1.default.dropdown, bg: tokens.surface, borderWidth: borderWidths_1.BORDER_WIDTHS.hairline, borderColor: tokens.rule, borderRadius: radii_1.RADIUS_ROLE.float, boxShadow: "md", overflow: "hidden", "data-testid": `${id}-menu`, children: [status || isLoading ? ((0, jsx_runtime_1.jsxs)(react_2.Flex, { align: "center", gap: 2, px: 3, py: 2, fontSize: "sm", color: tokens.muted, role: "status", children: [isLoading ? (0, jsx_runtime_1.jsx)(Spinner_1.default, { size: "xs", label: "", "aria-hidden": "true" }) : null, status] })) : null, options.length ? ((0, jsx_runtime_1.jsx)(react_2.Box, { ref: listRef, id: id, role: "listbox", "aria-label": label, maxH: "16rem", overflowY: "auto", p: 1, sx: (0, scrollbar_1.scrollbarStyles)(colors), children: options.map((option, index) => {
|
|
33
|
+
const Icon = option.icon;
|
|
34
|
+
const active = index === activeIndex;
|
|
35
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.Flex, { id: (0, exports.optionId)(id, index), role: "option", "aria-selected": active, align: "center", gap: 2.5, px: 2.5, py: 1.5, cursor: "pointer", borderRadius: radii_1.RADIUS_ROLE.option, bg: (0, optionRowInk_1.optionRowFill)(rows, active), onMouseDown: (event) => event.preventDefault(), onMouseMove: () => (active ? undefined : onActiveChange(index)), onClick: () => onPick(index), children: [Icon ? (0, jsx_runtime_1.jsx)(react_2.Box, { as: Icon, "aria-hidden": "true", boxSize: 4, flexShrink: 0, color: tokens.muted }) : null, (0, jsx_runtime_1.jsxs)(react_2.Box, { flex: "1", minW: 0, children: [(0, jsx_runtime_1.jsxs)(react_2.Text, { fontSize: "sm", color: colors.text[800], noOfLines: 1, children: [option.prefix ? ((0, jsx_runtime_1.jsx)(react_2.Text, { as: "span", fontFamily: "mono", color: tokens.muted, mr: 1.5, children: option.prefix })) : null, option.label] }), option.description ? ((0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "xs", color: (0, optionRowInk_1.optionRowDescriptionInk)(colors), noOfLines: 1, children: option.description })) : null] }), option.trailing ? ((0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "xs", color: tokens.muted, flexShrink: 0, children: option.trailing })) : null] }, option.key));
|
|
36
|
+
}) })) : null] }));
|
|
37
|
+
};
|
|
38
|
+
exports.ComposerMenu = ComposerMenu;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AssistantComposerCommand } from "./AssistantComposerProps";
|
|
2
|
+
/** True when `file` passes an `<input accept>`-style list (".pdf", "image/*", "text/plain"). Empty accepts all. */
|
|
3
|
+
export declare const matchesAccept: (file: Pick<File, "name" | "type">, accept?: string) => boolean;
|
|
4
|
+
/** The text after "/" while the whole value is a slash plus one word, else null. */
|
|
5
|
+
export declare const commandQuery: (value: string) => string | null;
|
|
6
|
+
/** Commands whose word or label starts with (then contains) the query, prefix matches first. */
|
|
7
|
+
export declare const filterCommands: (commands: readonly AssistantComposerCommand[], query: string) => AssistantComposerCommand[];
|
|
8
|
+
/** The text a picked command leaves in the field. */
|
|
9
|
+
export declare const commandText: (command: AssistantComposerCommand) => string;
|
|
10
|
+
/** The "@query" being typed right before the caret, with where it starts, else null. */
|
|
11
|
+
export declare const mentionAt: (value: string, caret: number) => {
|
|
12
|
+
query: string;
|
|
13
|
+
start: number;
|
|
14
|
+
} | null;
|
|
15
|
+
/** Replaces "@query" (from `start` up to `caret`) with `insert` plus a space; returns the text and the new caret. */
|
|
16
|
+
export declare const applyMention: (value: string, start: number, caret: number, insert: string) => {
|
|
17
|
+
value: string;
|
|
18
|
+
caret: number;
|
|
19
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyMention = exports.mentionAt = exports.commandText = exports.filterCommands = exports.commandQuery = exports.matchesAccept = void 0;
|
|
4
|
+
/** True when `file` passes an `<input accept>`-style list (".pdf", "image/*", "text/plain"). Empty accepts all. */
|
|
5
|
+
const matchesAccept = (file, accept) => {
|
|
6
|
+
const tokens = (accept !== null && accept !== void 0 ? accept : "")
|
|
7
|
+
.split(",")
|
|
8
|
+
.map((t) => t.trim().toLowerCase())
|
|
9
|
+
.filter(Boolean);
|
|
10
|
+
if (tokens.length === 0)
|
|
11
|
+
return true;
|
|
12
|
+
const name = file.name.toLowerCase();
|
|
13
|
+
const type = (file.type || "").toLowerCase();
|
|
14
|
+
return tokens.some((token) => {
|
|
15
|
+
if (token.startsWith("."))
|
|
16
|
+
return name.endsWith(token);
|
|
17
|
+
if (token.endsWith("/*"))
|
|
18
|
+
return type.startsWith(token.slice(0, -1));
|
|
19
|
+
return type === token;
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
exports.matchesAccept = matchesAccept;
|
|
23
|
+
const normalise = (command) => command.replace(/^\/+/, "");
|
|
24
|
+
/** The text after "/" while the whole value is a slash plus one word, else null. */
|
|
25
|
+
const commandQuery = (value) => {
|
|
26
|
+
const match = /^\/(\S*)$/.exec(value);
|
|
27
|
+
return match ? match[1] : null;
|
|
28
|
+
};
|
|
29
|
+
exports.commandQuery = commandQuery;
|
|
30
|
+
/** Commands whose word or label starts with (then contains) the query, prefix matches first. */
|
|
31
|
+
const filterCommands = (commands, query) => {
|
|
32
|
+
const q = query.toLowerCase();
|
|
33
|
+
const scored = commands
|
|
34
|
+
.map((command) => {
|
|
35
|
+
const word = normalise(command.command).toLowerCase();
|
|
36
|
+
const label = command.label.toLowerCase();
|
|
37
|
+
if (word.startsWith(q) || label.startsWith(q))
|
|
38
|
+
return { command, rank: 0 };
|
|
39
|
+
if (word.includes(q) || label.includes(q))
|
|
40
|
+
return { command, rank: 1 };
|
|
41
|
+
return null;
|
|
42
|
+
})
|
|
43
|
+
.filter((x) => x !== null);
|
|
44
|
+
return scored.sort((a, b) => a.rank - b.rank).map((x) => x.command);
|
|
45
|
+
};
|
|
46
|
+
exports.filterCommands = filterCommands;
|
|
47
|
+
/** The text a picked command leaves in the field. */
|
|
48
|
+
const commandText = (command) => `/${normalise(command.command)} `;
|
|
49
|
+
exports.commandText = commandText;
|
|
50
|
+
/** The "@query" being typed right before the caret, with where it starts, else null. */
|
|
51
|
+
const mentionAt = (value, caret) => {
|
|
52
|
+
const before = value.slice(0, Math.max(0, Math.min(caret, value.length)));
|
|
53
|
+
const match = /(^|\s)@([^\s@]{0,40})$/.exec(before);
|
|
54
|
+
if (!match)
|
|
55
|
+
return null;
|
|
56
|
+
return { query: match[2], start: before.length - match[2].length - 1 };
|
|
57
|
+
};
|
|
58
|
+
exports.mentionAt = mentionAt;
|
|
59
|
+
/** Replaces "@query" (from `start` up to `caret`) with `insert` plus a space; returns the text and the new caret. */
|
|
60
|
+
const applyMention = (value, start, caret, insert) => {
|
|
61
|
+
const head = `${value.slice(0, start)}${insert} `;
|
|
62
|
+
const tail = value.slice(caret).replace(/^ /, "");
|
|
63
|
+
return { value: head + tail, caret: head.length };
|
|
64
|
+
};
|
|
65
|
+
exports.applyMention = applyMention;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AssistantContextBarProps } from "./AssistantContextBarProps";
|
|
2
|
+
declare const _default: import("react").MemoExoticComponent<({ items, onRemove, onAdd, labels, "data-testid": testId, }: AssistantContextBarProps) => import("react/jsx-runtime").JSX.Element | null>;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,27 @@
|
|
|
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 Tag_1 = __importDefault(require("../../Tag/Tag"));
|
|
11
|
+
const Button_1 = __importDefault(require("../../Button/Button"));
|
|
12
|
+
const DEFAULT_LABELS = {
|
|
13
|
+
group: "Context",
|
|
14
|
+
add: "Add context",
|
|
15
|
+
remove: (label) => `Remove ${label}`,
|
|
16
|
+
};
|
|
17
|
+
/** Removable context chips (built on `Tag`) plus an optional Add button. */
|
|
18
|
+
const AssistantContextBar = ({ items, onRemove, onAdd, labels, "data-testid": testId = "assistant-context-bar", }) => {
|
|
19
|
+
const text = { ...DEFAULT_LABELS, ...labels };
|
|
20
|
+
if (items.length === 0 && !onAdd)
|
|
21
|
+
return null;
|
|
22
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.Flex, { role: "group", "aria-label": text.group, wrap: "wrap", align: "center", gap: 1.5, "data-testid": testId, children: [items.map((item) => {
|
|
23
|
+
const removable = Boolean(onRemove) && item.removable !== false;
|
|
24
|
+
return ((0, jsx_runtime_1.jsx)(Tag_1.default, { label: item.label, size: "sm", variant: "outline", colorScheme: "gray", maxW: "14rem", leadingIcon: item.icon, icon: removable ? lucide_react_1.X : undefined, onIconClick: removable ? () => onRemove === null || onRemove === void 0 ? void 0 : onRemove(item.id) : undefined, removeLabel: text.remove, "data-testid": `${testId}-item` }, item.id));
|
|
25
|
+
}), onAdd ? ((0, jsx_runtime_1.jsx)(Button_1.default, { size: "xs", variant: "ghost", colorScheme: "gray", leftIcon: (0, jsx_runtime_1.jsx)(lucide_react_1.Plus, { size: 14 }), label: text.add, onClick: onAdd })) : null] }));
|
|
26
|
+
};
|
|
27
|
+
exports.default = (0, react_1.memo)(AssistantContextBar);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AssistantIcon } from "../assistantTypes";
|
|
2
|
+
/** One piece of context the next message will carry, e.g. the open ticket or a selected file. */
|
|
3
|
+
export interface AssistantContextItem {
|
|
4
|
+
/** Handed back to `onRemove`. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** Chip text. */
|
|
7
|
+
label: string;
|
|
8
|
+
/** Decorative icon before the label. */
|
|
9
|
+
icon?: AssistantIcon;
|
|
10
|
+
/** Default true; false hides this chip's remove button even when `onRemove` is set (e.g. the current page). */
|
|
11
|
+
removable?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** Visible and spoken text of `AssistantContextBar`; omitted keys keep the English default. */
|
|
14
|
+
export interface AssistantContextBarLabels {
|
|
15
|
+
/** Name of the chip group. Default "Context". */
|
|
16
|
+
group?: string;
|
|
17
|
+
/** The add button. Default "Add context". */
|
|
18
|
+
add?: string;
|
|
19
|
+
/** Accessible name of a chip's remove button. Default "Remove <label>". */
|
|
20
|
+
remove?: (label: string) => string;
|
|
21
|
+
}
|
|
22
|
+
/** A row of removable context chips above the composer, with an optional Add button. */
|
|
23
|
+
export interface AssistantContextBarProps {
|
|
24
|
+
/** Chips in display order; with no items and no `onAdd` nothing renders. */
|
|
25
|
+
items: AssistantContextItem[];
|
|
26
|
+
/** Adds a remove button to every removable chip. */
|
|
27
|
+
onRemove?: (id: string) => void;
|
|
28
|
+
/** Adds an "Add context" button after the chips. */
|
|
29
|
+
onAdd?: () => void;
|
|
30
|
+
/** Translated group name and button text. */
|
|
31
|
+
labels?: AssistantContextBarLabels;
|
|
32
|
+
/** data-testid on the root. */
|
|
33
|
+
"data-testid"?: string;
|
|
34
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AssistantHistoryListProps } from "./AssistantHistoryListProps";
|
|
2
|
+
declare const _default: import("react").MemoExoticComponent<({ conversations, activeId, onSelect, onRename, onTogglePin, onDelete, now, isLoading, searchable, groupHeadingAs, labels, "data-testid": testId, }: AssistantHistoryListProps) => import("react/jsx-runtime").JSX.Element>;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,123 @@
|
|
|
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 rowStates_1 = require("../../../Theme/tokens/builders/rowStates");
|
|
13
|
+
const motion_1 = require("../../../Theme/tokens/primitives/motion");
|
|
14
|
+
const radii_1 = require("../../../Theme/tokens/primitives/radii");
|
|
15
|
+
const AlertDialog_1 = __importDefault(require("../../AlertDialog/AlertDialog"));
|
|
16
|
+
const EmptyState_1 = __importDefault(require("../../EmptyState/EmptyState"));
|
|
17
|
+
const IconButton_1 = __importDefault(require("../../IconButton/IconButton"));
|
|
18
|
+
const TextInput_1 = __importDefault(require("../../Input/TextInput"));
|
|
19
|
+
const Skeletons_1 = __importDefault(require("../../Skeletons/Skeletons"));
|
|
20
|
+
const VisuallyHidden_1 = __importDefault(require("../../VisuallyHidden/VisuallyHidden"));
|
|
21
|
+
const assistantStyles_1 = require("../assistantStyles");
|
|
22
|
+
const groupConversations_1 = require("./groupConversations");
|
|
23
|
+
const DEFAULT_GROUPS = { pinned: "Pinned", today: "Today", yesterday: "Yesterday", week: "Previous 7 days", older: "Older" };
|
|
24
|
+
const DEFAULT_LABELS = {
|
|
25
|
+
region: "Conversation history",
|
|
26
|
+
search: "Search conversations",
|
|
27
|
+
actions: (title) => `Actions for ${title}`,
|
|
28
|
+
rename: "Rename",
|
|
29
|
+
pin: "Pin",
|
|
30
|
+
unpin: "Unpin",
|
|
31
|
+
delete: "Delete",
|
|
32
|
+
renameField: "Conversation title",
|
|
33
|
+
deleteTitle: "Delete conversation?",
|
|
34
|
+
deleteBody: (title) => `“${title}” will be deleted. This can't be undone.`,
|
|
35
|
+
deleteConfirm: "Delete",
|
|
36
|
+
cancel: "Cancel",
|
|
37
|
+
empty: "No conversations yet",
|
|
38
|
+
emptyDescription: "Your conversations with the assistant show up here.",
|
|
39
|
+
noMatches: (query) => `No conversations match “${query}”`,
|
|
40
|
+
loading: "Loading conversations",
|
|
41
|
+
untitled: "Untitled conversation",
|
|
42
|
+
};
|
|
43
|
+
const ROW_TRANSITION = (0, motion_1.transitionFor)(["background-color"]);
|
|
44
|
+
const LOADING_ROWS = [0, 1, 2, 3, 4];
|
|
45
|
+
/** Recency-grouped conversation list with local search, inline rename, pin and confirmed delete. */
|
|
46
|
+
const AssistantHistoryList = ({ conversations, activeId, onSelect, onRename, onTogglePin, onDelete, now, isLoading = false, searchable = true, groupHeadingAs = "h3", labels, "data-testid": testId = "assistant-history", }) => {
|
|
47
|
+
const { colors } = (0, useCustomTheme_1.useCustomTheme)();
|
|
48
|
+
const tokens = (0, assistantStyles_1.assistantTokens)(colors);
|
|
49
|
+
const rows = (0, rowStates_1.listRowBackgrounds)(colors);
|
|
50
|
+
const text = { ...DEFAULT_LABELS, ...labels };
|
|
51
|
+
const groupText = { ...DEFAULT_GROUPS, ...labels === null || labels === void 0 ? void 0 : labels.groups };
|
|
52
|
+
const baseId = (0, react_1.useId)();
|
|
53
|
+
const [query, setQuery] = (0, react_1.useState)("");
|
|
54
|
+
const [editingId, setEditingId] = (0, react_1.useState)(null);
|
|
55
|
+
const [draft, setDraft] = (0, react_1.useState)("");
|
|
56
|
+
const [pendingDelete, setPendingDelete] = (0, react_1.useState)(null);
|
|
57
|
+
const [deleting, setDeleting] = (0, react_1.useState)(false);
|
|
58
|
+
const cancelRef = (0, react_1.useRef)(null);
|
|
59
|
+
const [nowAtMount] = (0, react_1.useState)(() => Date.now());
|
|
60
|
+
const trimmed = query.trim().toLowerCase();
|
|
61
|
+
const filtered = (0, react_1.useMemo)(() => (trimmed ? conversations.filter((c) => (c.title || "").toLowerCase().includes(trimmed)) : conversations), [conversations, trimmed]);
|
|
62
|
+
const groups = (0, react_1.useMemo)(() => (0, groupConversations_1.groupConversations)(filtered, now !== null && now !== void 0 ? now : nowAtMount), [filtered, now, nowAtMount]);
|
|
63
|
+
const hasMenu = Boolean(onRename || onTogglePin || onDelete);
|
|
64
|
+
const titleOf = (c) => c.title.trim() || text.untitled;
|
|
65
|
+
const startRename = (c) => {
|
|
66
|
+
setEditingId(c.id);
|
|
67
|
+
setDraft(c.title);
|
|
68
|
+
};
|
|
69
|
+
const commitRename = (c) => {
|
|
70
|
+
const next = draft.trim();
|
|
71
|
+
setEditingId(null);
|
|
72
|
+
if (next && next !== c.title.trim())
|
|
73
|
+
onRename === null || onRename === void 0 ? void 0 : onRename(c.id, next);
|
|
74
|
+
};
|
|
75
|
+
const onRenameKey = (c) => (event) => {
|
|
76
|
+
if (event.key === "Enter") {
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
commitRename(c);
|
|
79
|
+
}
|
|
80
|
+
else if (event.key === "Escape") {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
event.stopPropagation();
|
|
83
|
+
setEditingId(null);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const confirmDelete = async () => {
|
|
87
|
+
if (!pendingDelete)
|
|
88
|
+
return;
|
|
89
|
+
setDeleting(true);
|
|
90
|
+
try {
|
|
91
|
+
await (onDelete === null || onDelete === void 0 ? void 0 : onDelete(pendingDelete.id));
|
|
92
|
+
setPendingDelete(null);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// The app reports the failure; the dialog stays open so the person can retry or cancel.
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
setDeleting(false);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const renderRow = (c) => {
|
|
102
|
+
const isActive = c.id === activeId;
|
|
103
|
+
const title = titleOf(c);
|
|
104
|
+
return ((0, jsx_runtime_1.jsx)("li", { children: (0, jsx_runtime_1.jsxs)(react_2.Flex, { align: "center", gap: 1, pl: editingId === c.id ? 1 : 0, pr: 1, borderRadius: radii_1.RADIUS_ROLE.option, bg: isActive ? rows.selected : "transparent", transition: ROW_TRANSITION, _hover: { bg: isActive ? rows.selectedActive : rows.active }, "data-testid": `${testId}-row`, "data-active": isActive || undefined, children: [editingId === c.id ? ((0, jsx_runtime_1.jsx)(react_2.Box, { flex: "1", minW: 0, py: 1, children: (0, jsx_runtime_1.jsx)(TextInput_1.default, { "aria-label": text.renameField, value: draft, size: "xs", autoFocus: true, onChange: (e) => setDraft(e.target.value), onKeyDown: onRenameKey(c), onBlur: () => commitRename(c) }) })) : ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "button", type: "button", flex: "1", minW: 0, textAlign: "start", px: 2.5, py: 2, borderRadius: radii_1.RADIUS_ROLE.option, fontSize: "sm", fontWeight: isActive ? 500 : 400, color: isActive ? tokens.heading : tokens.body, "aria-current": isActive ? "true" : undefined, sx: (0, focusRing_styles_1.focusVisibleStyles)(colors), onClick: () => onSelect(c.id), children: (0, jsx_runtime_1.jsx)(react_2.Text, { as: "span", display: "block", noOfLines: 1, children: title }) })), c.pinned ? ((0, jsx_runtime_1.jsx)(react_2.Box, { as: lucide_react_1.Pin, "aria-hidden": "true", boxSize: 3.5, flexShrink: 0, color: tokens.muted })) : null, hasMenu && editingId !== c.id ? ((0, jsx_runtime_1.jsxs)(react_2.Menu, { isLazy: true, placement: "bottom-end", children: [(0, jsx_runtime_1.jsx)(react_2.MenuButton, { as: IconButton_1.default, "aria-label": text.actions(title), icon: (0, jsx_runtime_1.jsx)(lucide_react_1.MoreHorizontal, { size: 16 }), size: "xs", variant: "ghost", colorScheme: "gray", flexShrink: 0 }), (0, jsx_runtime_1.jsx)(react_2.Portal, { children: (0, jsx_runtime_1.jsxs)(react_2.MenuList, { minW: "10rem", fontSize: "sm", children: [onRename ? ((0, jsx_runtime_1.jsx)(react_2.MenuItem, { icon: (0, jsx_runtime_1.jsx)(lucide_react_1.Pencil, { size: 14 }), onClick: () => startRename(c), children: text.rename })) : null, onTogglePin ? ((0, jsx_runtime_1.jsx)(react_2.MenuItem, { icon: c.pinned ? (0, jsx_runtime_1.jsx)(lucide_react_1.PinOff, { size: 14 }) : (0, jsx_runtime_1.jsx)(lucide_react_1.Pin, { size: 14 }), onClick: () => onTogglePin(c.id), children: c.pinned ? text.unpin : text.pin })) : null, onDelete ? ((0, jsx_runtime_1.jsx)(react_2.MenuItem, { icon: (0, jsx_runtime_1.jsx)(lucide_react_1.Trash2, { size: 14 }), color: colors.semanticText.error, onClick: () => setPendingDelete(c), children: text.delete })) : null] }) })] })) : null] }) }, c.id));
|
|
105
|
+
};
|
|
106
|
+
const body = () => {
|
|
107
|
+
if (isLoading) {
|
|
108
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.Flex, { direction: "column", gap: 2, px: 1, "aria-busy": "true", "data-testid": `${testId}-loading`, children: [(0, jsx_runtime_1.jsx)(VisuallyHidden_1.default, { role: "status", children: text.loading }), LOADING_ROWS.map((row) => ((0, jsx_runtime_1.jsx)(Skeletons_1.default, { type: "skeleton", height: "2rem", width: row % 2 ? "70%" : "90%", borderRadius: radii_1.RADIUS_ROLE.option }, row)))] }));
|
|
109
|
+
}
|
|
110
|
+
if (conversations.length === 0) {
|
|
111
|
+
return (0, jsx_runtime_1.jsx)(EmptyState_1.default, { size: "sm", icon: lucide_react_1.MessageSquare, title: text.empty, description: text.emptyDescription, titleAs: "p" });
|
|
112
|
+
}
|
|
113
|
+
if (groups.length === 0) {
|
|
114
|
+
return (0, jsx_runtime_1.jsx)(EmptyState_1.default, { size: "sm", icon: lucide_react_1.Search, title: text.noMatches(query.trim()), titleAs: "p" });
|
|
115
|
+
}
|
|
116
|
+
return groups.map((group) => {
|
|
117
|
+
const headingId = `${baseId}-${group.key}`;
|
|
118
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.Box, { role: "group", "aria-labelledby": headingId, children: [(0, jsx_runtime_1.jsx)(react_2.Text, { id: headingId, as: groupHeadingAs, px: 2.5, pt: 3, pb: 1, fontSize: "xs", fontWeight: 600, color: tokens.muted, children: groupText[group.key] }), (0, jsx_runtime_1.jsx)(react_2.Box, { as: "ul", listStyleType: "none", m: 0, p: 0, children: group.items.map(renderRow) })] }, group.key));
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.Box, { as: "nav", "aria-label": text.region, "data-testid": testId, p: 2, children: [searchable && !isLoading && conversations.length > 0 ? ((0, jsx_runtime_1.jsx)(react_2.Box, { px: 1, pb: 1, children: (0, jsx_runtime_1.jsx)(TextInput_1.default, { "aria-label": text.search, placeholder: text.search, value: query, size: "sm", isClearable: true, inputLeftIcon: (0, jsx_runtime_1.jsx)(lucide_react_1.Search, { size: 14 }), onChange: (e) => setQuery(e.target.value) }) })) : null, body(), (0, jsx_runtime_1.jsx)(AlertDialog_1.default, { isOpen: pendingDelete !== null, onClose: () => (deleting ? undefined : setPendingDelete(null)), leastDestructiveRef: cancelRef, isCentered: true, tone: "danger", title: text.deleteTitle, content: (0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "sm", children: pendingDelete ? text.deleteBody(titleOf(pendingDelete)) : null }), confirmButtonText: text.deleteConfirm, cancelButtonText: text.cancel, isConfirmLoading: deleting, onConfirm: () => void confirmDelete() })] }));
|
|
122
|
+
};
|
|
123
|
+
exports.default = (0, react_1.memo)(AssistantHistoryList);
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/** One past conversation in the history list. */
|
|
2
|
+
export interface AssistantConversation {
|
|
3
|
+
/** Handed back to every callback. */
|
|
4
|
+
id: string;
|
|
5
|
+
/** Row text; an empty title shows the `untitled` label. */
|
|
6
|
+
title: string;
|
|
7
|
+
/** Last activity (epoch ms, Date or ISO string); decides the date group. Missing means "Older". */
|
|
8
|
+
updatedAt?: number | string | Date;
|
|
9
|
+
/** Pinned conversations sit in their own group at the top. */
|
|
10
|
+
pinned?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** Visible and spoken text of `AssistantHistoryList`; omitted keys keep the English default. */
|
|
13
|
+
export interface AssistantHistoryListLabels {
|
|
14
|
+
/** Name of the navigation landmark. Default "Conversation history". */
|
|
15
|
+
region?: string;
|
|
16
|
+
/** Search field name and placeholder. Default "Search conversations". */
|
|
17
|
+
search?: string;
|
|
18
|
+
/** Group headings. */
|
|
19
|
+
groups?: {
|
|
20
|
+
pinned?: string;
|
|
21
|
+
today?: string;
|
|
22
|
+
yesterday?: string;
|
|
23
|
+
week?: string;
|
|
24
|
+
older?: string;
|
|
25
|
+
};
|
|
26
|
+
/** Accessible name of a row's menu button. Default "Actions for <title>". */
|
|
27
|
+
actions?: (title: string) => string;
|
|
28
|
+
/** Default "Rename". */
|
|
29
|
+
rename?: string;
|
|
30
|
+
/** Default "Pin". */
|
|
31
|
+
pin?: string;
|
|
32
|
+
/** Default "Unpin". */
|
|
33
|
+
unpin?: string;
|
|
34
|
+
/** Default "Delete". */
|
|
35
|
+
delete?: string;
|
|
36
|
+
/** Accessible name of the inline rename field. Default "Conversation title". */
|
|
37
|
+
renameField?: string;
|
|
38
|
+
/** Confirm dialog title. Default "Delete conversation?". */
|
|
39
|
+
deleteTitle?: string;
|
|
40
|
+
/** Confirm dialog body. Default "“<title>” will be deleted. This can't be undone.". */
|
|
41
|
+
deleteBody?: (title: string) => string;
|
|
42
|
+
/** Confirm dialog's destructive button. Default "Delete". */
|
|
43
|
+
deleteConfirm?: string;
|
|
44
|
+
/** Confirm dialog's cancel button. Default "Cancel". */
|
|
45
|
+
cancel?: string;
|
|
46
|
+
/** Title of the empty state. Default "No conversations yet". */
|
|
47
|
+
empty?: string;
|
|
48
|
+
/** Line under the empty title. Default "Your conversations with the assistant show up here.". */
|
|
49
|
+
emptyDescription?: string;
|
|
50
|
+
/** Title when the search matches nothing. Default "No conversations match “<query>”". */
|
|
51
|
+
noMatches?: (query: string) => string;
|
|
52
|
+
/** Spoken while loading. Default "Loading conversations". */
|
|
53
|
+
loading?: string;
|
|
54
|
+
/** Shown for a conversation with an empty title. Default "Untitled conversation". */
|
|
55
|
+
untitled?: string;
|
|
56
|
+
}
|
|
57
|
+
/** Past conversations grouped by recency, with search, inline rename, pin and delete-with-confirm. */
|
|
58
|
+
export interface AssistantHistoryListProps {
|
|
59
|
+
/** Every conversation; grouping, sorting (newest first) and search happen here. */
|
|
60
|
+
conversations: AssistantConversation[];
|
|
61
|
+
/** The open conversation; its row is marked `aria-current`. */
|
|
62
|
+
activeId?: string;
|
|
63
|
+
/** Called when a row is chosen. */
|
|
64
|
+
onSelect: (id: string) => void;
|
|
65
|
+
/** Adds Rename to the row menu; called with the trimmed new title when it is non-empty and changed. */
|
|
66
|
+
onRename?: (id: string, title: string) => void;
|
|
67
|
+
/** Adds Pin / Unpin to the row menu. */
|
|
68
|
+
onTogglePin?: (id: string) => void;
|
|
69
|
+
/** Adds Delete, behind a confirm dialog; a returned promise keeps the dialog busy until it settles. */
|
|
70
|
+
onDelete?: (id: string) => void | Promise<unknown>;
|
|
71
|
+
/** "Now" for the date groups; inject it in tests and stories. Default the current time. */
|
|
72
|
+
now?: number | Date;
|
|
73
|
+
/** Shows skeleton rows instead of the list. */
|
|
74
|
+
isLoading?: boolean;
|
|
75
|
+
/** Shows the local search field. Default true. */
|
|
76
|
+
searchable?: boolean;
|
|
77
|
+
/** Heading level of the group titles. Default "h3". */
|
|
78
|
+
groupHeadingAs?: "h2" | "h3" | "h4";
|
|
79
|
+
/** Translated text. */
|
|
80
|
+
labels?: AssistantHistoryListLabels;
|
|
81
|
+
/** data-testid on the root. */
|
|
82
|
+
"data-testid"?: string;
|
|
83
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AssistantConversation } from "./AssistantHistoryListProps";
|
|
2
|
+
export type ConversationGroupKey = "pinned" | "today" | "yesterday" | "week" | "older";
|
|
3
|
+
export interface ConversationGroup {
|
|
4
|
+
key: ConversationGroupKey;
|
|
5
|
+
items: AssistantConversation[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Buckets conversations into Pinned / Today / Yesterday / Previous 7 days / Older, by local calendar day
|
|
9
|
+
* relative to `now`. Each bucket is newest first; a conversation without a parseable `updatedAt` is Older.
|
|
10
|
+
* Empty buckets are left out.
|
|
11
|
+
*/
|
|
12
|
+
export declare const groupConversations: (conversations: readonly AssistantConversation[], now: number | Date) => ConversationGroup[];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.groupConversations = void 0;
|
|
4
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
5
|
+
const toTime = (value) => {
|
|
6
|
+
if (value === undefined || value === null)
|
|
7
|
+
return null;
|
|
8
|
+
const time = value instanceof Date ? value.getTime() : typeof value === "number" ? value : Date.parse(value);
|
|
9
|
+
return Number.isFinite(time) ? time : null;
|
|
10
|
+
};
|
|
11
|
+
const startOfDay = (time) => {
|
|
12
|
+
const d = new Date(time);
|
|
13
|
+
d.setHours(0, 0, 0, 0);
|
|
14
|
+
return d.getTime();
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Buckets conversations into Pinned / Today / Yesterday / Previous 7 days / Older, by local calendar day
|
|
18
|
+
* relative to `now`. Each bucket is newest first; a conversation without a parseable `updatedAt` is Older.
|
|
19
|
+
* Empty buckets are left out.
|
|
20
|
+
*/
|
|
21
|
+
const groupConversations = (conversations, now) => {
|
|
22
|
+
const today = startOfDay(now instanceof Date ? now.getTime() : now);
|
|
23
|
+
// Noon offsets keep a 23- or 25-hour DST day from shifting a boundary by a day.
|
|
24
|
+
const yesterday = startOfDay(today - DAY_MS / 2);
|
|
25
|
+
const weekStart = startOfDay(today - 7 * DAY_MS + DAY_MS / 2);
|
|
26
|
+
const buckets = {
|
|
27
|
+
pinned: [],
|
|
28
|
+
today: [],
|
|
29
|
+
yesterday: [],
|
|
30
|
+
week: [],
|
|
31
|
+
older: [],
|
|
32
|
+
};
|
|
33
|
+
const byRecency = [...conversations].sort((a, b) => { var _a, _b; return ((_a = toTime(b.updatedAt)) !== null && _a !== void 0 ? _a : -Infinity) - ((_b = toTime(a.updatedAt)) !== null && _b !== void 0 ? _b : -Infinity); });
|
|
34
|
+
byRecency.forEach((conversation) => {
|
|
35
|
+
if (conversation.pinned) {
|
|
36
|
+
buckets.pinned.push(conversation);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const time = toTime(conversation.updatedAt);
|
|
40
|
+
if (time === null)
|
|
41
|
+
buckets.older.push(conversation);
|
|
42
|
+
else if (time >= today)
|
|
43
|
+
buckets.today.push(conversation);
|
|
44
|
+
else if (time >= yesterday)
|
|
45
|
+
buckets.yesterday.push(conversation);
|
|
46
|
+
else if (time >= weekStart)
|
|
47
|
+
buckets.week.push(conversation);
|
|
48
|
+
else
|
|
49
|
+
buckets.older.push(conversation);
|
|
50
|
+
});
|
|
51
|
+
return Object.keys(buckets)
|
|
52
|
+
.filter((key) => buckets[key].length > 0)
|
|
53
|
+
.map((key) => ({ key, items: buckets[key] }));
|
|
54
|
+
};
|
|
55
|
+
exports.groupConversations = groupConversations;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { default as AssistantPanel } from "./panel/AssistantPanel";
|
|
2
|
+
export { default as AssistantLauncher } from "./launcher/AssistantLauncher";
|
|
3
|
+
export { default as AssistantThread } from "./thread/AssistantThread";
|
|
4
|
+
export { default as AssistantMessage } from "./message/AssistantMessage";
|
|
5
|
+
export { default as AssistantMarkdown } from "./markdown/AssistantMarkdown";
|
|
6
|
+
export { default as AssistantToolSteps } from "./steps/AssistantToolSteps";
|
|
7
|
+
export { default as AssistantProposalCard } from "./cards/AssistantProposalCard";
|
|
8
|
+
export { default as AssistantApprovalCard } from "./cards/AssistantApprovalCard";
|
|
9
|
+
export { default as AssistantSuggestions } from "./suggestions/AssistantSuggestions";
|
|
10
|
+
export { default as AssistantComposer } from "./composer/AssistantComposer";
|
|
11
|
+
export { default as AssistantWelcome } from "./welcome/AssistantWelcome";
|
|
12
|
+
export { default as AssistantHistoryList } from "./history/AssistantHistoryList";
|
|
13
|
+
export { default as AssistantContextBar } from "./context/AssistantContextBar";
|
|
14
|
+
export { default as AssistantSources } from "./sources/AssistantSources";
|
|
15
|
+
export { default as AssistantStatusBanner } from "./banner/AssistantStatusBanner";
|
|
16
|
+
export { default as AssistantTypingIndicator } from "./typing/AssistantTypingIndicator";
|
|
@@ -0,0 +1,38 @@
|
|
|
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.AssistantTypingIndicator = exports.AssistantStatusBanner = exports.AssistantSources = exports.AssistantContextBar = exports.AssistantHistoryList = exports.AssistantWelcome = exports.AssistantComposer = exports.AssistantSuggestions = exports.AssistantApprovalCard = exports.AssistantProposalCard = exports.AssistantToolSteps = exports.AssistantMarkdown = exports.AssistantMessage = exports.AssistantThread = exports.AssistantLauncher = exports.AssistantPanel = void 0;
|
|
7
|
+
var AssistantPanel_1 = require("./panel/AssistantPanel");
|
|
8
|
+
Object.defineProperty(exports, "AssistantPanel", { enumerable: true, get: function () { return __importDefault(AssistantPanel_1).default; } });
|
|
9
|
+
var AssistantLauncher_1 = require("./launcher/AssistantLauncher");
|
|
10
|
+
Object.defineProperty(exports, "AssistantLauncher", { enumerable: true, get: function () { return __importDefault(AssistantLauncher_1).default; } });
|
|
11
|
+
var AssistantThread_1 = require("./thread/AssistantThread");
|
|
12
|
+
Object.defineProperty(exports, "AssistantThread", { enumerable: true, get: function () { return __importDefault(AssistantThread_1).default; } });
|
|
13
|
+
var AssistantMessage_1 = require("./message/AssistantMessage");
|
|
14
|
+
Object.defineProperty(exports, "AssistantMessage", { enumerable: true, get: function () { return __importDefault(AssistantMessage_1).default; } });
|
|
15
|
+
var AssistantMarkdown_1 = require("./markdown/AssistantMarkdown");
|
|
16
|
+
Object.defineProperty(exports, "AssistantMarkdown", { enumerable: true, get: function () { return __importDefault(AssistantMarkdown_1).default; } });
|
|
17
|
+
var AssistantToolSteps_1 = require("./steps/AssistantToolSteps");
|
|
18
|
+
Object.defineProperty(exports, "AssistantToolSteps", { enumerable: true, get: function () { return __importDefault(AssistantToolSteps_1).default; } });
|
|
19
|
+
var AssistantProposalCard_1 = require("./cards/AssistantProposalCard");
|
|
20
|
+
Object.defineProperty(exports, "AssistantProposalCard", { enumerable: true, get: function () { return __importDefault(AssistantProposalCard_1).default; } });
|
|
21
|
+
var AssistantApprovalCard_1 = require("./cards/AssistantApprovalCard");
|
|
22
|
+
Object.defineProperty(exports, "AssistantApprovalCard", { enumerable: true, get: function () { return __importDefault(AssistantApprovalCard_1).default; } });
|
|
23
|
+
var AssistantSuggestions_1 = require("./suggestions/AssistantSuggestions");
|
|
24
|
+
Object.defineProperty(exports, "AssistantSuggestions", { enumerable: true, get: function () { return __importDefault(AssistantSuggestions_1).default; } });
|
|
25
|
+
var AssistantComposer_1 = require("./composer/AssistantComposer");
|
|
26
|
+
Object.defineProperty(exports, "AssistantComposer", { enumerable: true, get: function () { return __importDefault(AssistantComposer_1).default; } });
|
|
27
|
+
var AssistantWelcome_1 = require("./welcome/AssistantWelcome");
|
|
28
|
+
Object.defineProperty(exports, "AssistantWelcome", { enumerable: true, get: function () { return __importDefault(AssistantWelcome_1).default; } });
|
|
29
|
+
var AssistantHistoryList_1 = require("./history/AssistantHistoryList");
|
|
30
|
+
Object.defineProperty(exports, "AssistantHistoryList", { enumerable: true, get: function () { return __importDefault(AssistantHistoryList_1).default; } });
|
|
31
|
+
var AssistantContextBar_1 = require("./context/AssistantContextBar");
|
|
32
|
+
Object.defineProperty(exports, "AssistantContextBar", { enumerable: true, get: function () { return __importDefault(AssistantContextBar_1).default; } });
|
|
33
|
+
var AssistantSources_1 = require("./sources/AssistantSources");
|
|
34
|
+
Object.defineProperty(exports, "AssistantSources", { enumerable: true, get: function () { return __importDefault(AssistantSources_1).default; } });
|
|
35
|
+
var AssistantStatusBanner_1 = require("./banner/AssistantStatusBanner");
|
|
36
|
+
Object.defineProperty(exports, "AssistantStatusBanner", { enumerable: true, get: function () { return __importDefault(AssistantStatusBanner_1).default; } });
|
|
37
|
+
var AssistantTypingIndicator_1 = require("./typing/AssistantTypingIndicator");
|
|
38
|
+
Object.defineProperty(exports, "AssistantTypingIndicator", { enumerable: true, get: function () { return __importDefault(AssistantTypingIndicator_1).default; } });
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AssistantLauncherProps } from "./AssistantLauncherProps";
|
|
2
|
+
declare const _default: import("react").MemoExoticComponent<({ onClick, label, icon: Icon, isOpen, "aria-controls": controls, busy, badge, badgeLabel, shortcut, variant, positioning, placement, offset, "data-testid": testId, }: AssistantLauncherProps) => import("react/jsx-runtime").JSX.Element>;
|
|
3
|
+
export default _default;
|