pixelize-design-library 3.1.1 → 3.3.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 +25 -0
- package/COMPONENT-GOTCHAS.md +33 -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 +158 -0
- package/dist/Components/Assistant/thread/AssistantThreadProps.d.ts +39 -0
- package/dist/Components/Assistant/thread/AssistantThreadProps.js +2 -0
- package/dist/Components/Assistant/thread/replyStartScroll.d.ts +8 -0
- package/dist/Components/Assistant/thread/replyStartScroll.js +6 -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/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 +153 -0
- package/dist/esm/Components/Assistant/thread/AssistantThreadProps.js +1 -0
- package/dist/esm/Components/Assistant/thread/replyStartScroll.js +2 -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/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,45 @@
|
|
|
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 filledSurface_1 = require("../../../Theme/tokens/builders/filledSurface");
|
|
13
|
+
const borderWidths_1 = require("../../../Theme/tokens/primitives/borderWidths");
|
|
14
|
+
const controlSizes_1 = require("../../../Theme/tokens/primitives/controlSizes");
|
|
15
|
+
const motion_1 = require("../../../Theme/tokens/primitives/motion");
|
|
16
|
+
const typography_1 = require("../../../Theme/tokens/primitives/typography");
|
|
17
|
+
const zIndices_1 = __importDefault(require("../../../Theme/tokens/primitives/zIndices"));
|
|
18
|
+
const Kbd_1 = require("../../Kbd/Kbd");
|
|
19
|
+
const Spinner_1 = __importDefault(require("../../Spinner/Spinner"));
|
|
20
|
+
const ToolTip_1 = __importDefault(require("../../ToolTip/ToolTip"));
|
|
21
|
+
const assistantStyles_1 = require("../assistantStyles");
|
|
22
|
+
const cssLength = (value) => (typeof value === "number" ? `${value}px` : value);
|
|
23
|
+
const PRESS = (0, motion_1.transitionFor)(["background-color", "color"]);
|
|
24
|
+
/** Round floating button that opens the assistant, with a busy ring, an unread badge and a shortcut hint. */
|
|
25
|
+
const AssistantLauncher = ({ onClick, label = "Open assistant", icon: Icon = lucide_react_1.Sparkles, isOpen, "aria-controls": controls, busy = false, badge, badgeLabel = (b) => (b === true ? "new activity" : `${b} new`), shortcut, variant = "surface", positioning = "fixed", placement = "bottom-end", offset, "data-testid": testId = "assistant-launcher", }) => {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
const { colors } = (0, useCustomTheme_1.useCustomTheme)();
|
|
28
|
+
const tokens = (0, assistantStyles_1.assistantTokens)(colors);
|
|
29
|
+
const filled = (0, filledSurface_1.resolveFilledSurface)(colors.primary, colors);
|
|
30
|
+
const danger = (0, filledSurface_1.resolveFilledSurface)(colors.semantic.error, colors);
|
|
31
|
+
const hasBadge = badge === true || (typeof badge === "number" && badge > 0);
|
|
32
|
+
const count = typeof badge === "number" ? (badge > 99 ? "99+" : String(badge)) : "";
|
|
33
|
+
const name = hasBadge ? `${label}, ${badgeLabel(badge)}` : label;
|
|
34
|
+
const solid = variant === "solid";
|
|
35
|
+
const placed = positioning === "static"
|
|
36
|
+
? {}
|
|
37
|
+
: {
|
|
38
|
+
position: positioning,
|
|
39
|
+
bottom: cssLength((_a = offset === null || offset === void 0 ? void 0 : offset.y) !== null && _a !== void 0 ? _a : "1.5rem"),
|
|
40
|
+
[placement === "bottom-end" ? "right" : "left"]: cssLength((_b = offset === null || offset === void 0 ? void 0 : offset.x) !== null && _b !== void 0 ? _b : "1.5rem"),
|
|
41
|
+
zIndex: zIndices_1.default.sticky,
|
|
42
|
+
};
|
|
43
|
+
return ((0, jsx_runtime_1.jsx)(react_2.Box, { ...placed, display: "inline-flex", "data-testid": `${testId}-root`, children: (0, jsx_runtime_1.jsx)(ToolTip_1.default, { placement: placement === "bottom-end" ? "left" : "right", label: shortcut ? ((0, jsx_runtime_1.jsxs)(react_2.Flex, { align: "center", gap: 2, children: [(0, jsx_runtime_1.jsx)(react_2.Text, { as: "span", children: label }), (0, jsx_runtime_1.jsx)(Kbd_1.KbdShortcut, { shortcut: shortcut, size: "xs" })] })) : (label), children: (0, jsx_runtime_1.jsxs)(react_2.Flex, { as: "button", type: "button", position: "relative", align: "center", justify: "center", boxSize: controlSizes_1.BUTTON_SIZES.lg.height, borderRadius: "full", bg: solid ? filled.fill : tokens.surface, color: solid ? filled.color : colors.accentText, borderWidth: solid ? 0 : borderWidths_1.BORDER_WIDTHS.hairline, borderColor: tokens.rule, boxShadow: "lg", transition: PRESS, _hover: { bg: solid ? filled.hoverFill : colors.background[100], color: solid ? filled.hoverColor : undefined }, sx: (0, focusRing_styles_1.focusVisibleStyles)(colors), "aria-label": name, "aria-expanded": isOpen, "aria-controls": controls, "aria-busy": busy || undefined, onClick: onClick, "data-testid": testId, "data-open": isOpen || undefined, children: [(0, jsx_runtime_1.jsx)(Icon, { size: 22, "aria-hidden": "true" }), busy ? ((0, jsx_runtime_1.jsx)(Spinner_1.default, { size: "xl", color: solid ? filled.color : colors.accentText, label: "", "aria-hidden": "true", position: "absolute", inset: 0, boxSize: "100%", thickness: "0.125rem", "data-testid": `${testId}-busy` })) : null, hasBadge ? ((0, jsx_runtime_1.jsx)(react_2.Flex, { "aria-hidden": "true", position: "absolute", top: 0, right: 0, minW: count ? 5 : 3, h: count ? 5 : 3, px: count ? 1 : 0, align: "center", justify: "center", borderRadius: "full", bg: danger.fill, color: danger.color, borderWidth: borderWidths_1.BORDER_WIDTHS.thick, borderColor: solid ? colors.background[50] : tokens.surface, fontSize: "xs-minus", fontWeight: 700, lineHeight: 1, sx: typography_1.NUMERIC_TEXT, "data-testid": `${testId}-badge`, children: count })) : null] }) }) }));
|
|
44
|
+
};
|
|
45
|
+
exports.default = (0, react_1.memo)(AssistantLauncher);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AssistantIcon } from "../assistantTypes";
|
|
2
|
+
/** The round floating button that opens the assistant; placement is the app's (no drag logic here). */
|
|
3
|
+
export interface AssistantLauncherProps {
|
|
4
|
+
/** Toggles the assistant. */
|
|
5
|
+
onClick: () => void;
|
|
6
|
+
/** Tooltip text and accessible name. Default "Open assistant". */
|
|
7
|
+
label?: string;
|
|
8
|
+
/** Glyph. Default Sparkles. */
|
|
9
|
+
icon?: AssistantIcon;
|
|
10
|
+
/** Sets `aria-expanded`; pair with `aria-controls` naming the panel's id. */
|
|
11
|
+
isOpen?: boolean;
|
|
12
|
+
/** Id of the panel it opens, for `aria-controls`. */
|
|
13
|
+
"aria-controls"?: string;
|
|
14
|
+
/** Spins a ring around the button and sets `aria-busy`, e.g. while a reply streams with the panel closed. */
|
|
15
|
+
busy?: boolean;
|
|
16
|
+
/** A count (shown, 99+ past 99) or `true` for a dot; also added to the accessible name. */
|
|
17
|
+
badge?: number | boolean;
|
|
18
|
+
/** Spoken badge text. Default "<n> new" for a count, "new activity" for a dot. */
|
|
19
|
+
badgeLabel?: (badge: number | true) => string;
|
|
20
|
+
/** Key chord in `KbdShortcut` notation (e.g. "mod+shift+a"), shown in the tooltip. The app binds the key itself. */
|
|
21
|
+
shortcut?: string;
|
|
22
|
+
/** "surface" (default) is a raised neutral disc with a brand glyph; "solid" fills it with the brand colour. */
|
|
23
|
+
variant?: "surface" | "solid";
|
|
24
|
+
/** "fixed" (default) pins it to the viewport; "absolute" to the nearest positioned ancestor; "static" leaves layout to the app. */
|
|
25
|
+
positioning?: "fixed" | "absolute" | "static";
|
|
26
|
+
/** Corner it sits in when not static. Default "bottom-end". */
|
|
27
|
+
placement?: "bottom-end" | "bottom-start";
|
|
28
|
+
/** Distance from the edges; numbers are px, strings any CSS length. Default 1.5rem each. */
|
|
29
|
+
offset?: {
|
|
30
|
+
/** Gap from the side edge. */
|
|
31
|
+
x?: number | string;
|
|
32
|
+
/** Gap from the bottom edge. */
|
|
33
|
+
y?: number | string;
|
|
34
|
+
};
|
|
35
|
+
/** data-testid on the button. */
|
|
36
|
+
"data-testid"?: string;
|
|
37
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AssistantMarkdownProps } from "./AssistantMarkdownProps";
|
|
2
|
+
declare const _default: import("react").MemoExoticComponent<({ content, onLinkClick, showCaret, headingLevel, labels, "data-testid": testId, }: AssistantMarkdownProps) => import("react/jsx-runtime").JSX.Element>;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,146 @@
|
|
|
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 scrollbar_1 = require("../../../Theme/tokens/builders/scrollbar");
|
|
13
|
+
const planeStep_1 = require("../../../Theme/tokens/builders/planeStep");
|
|
14
|
+
const borderWidths_1 = require("../../../Theme/tokens/primitives/borderWidths");
|
|
15
|
+
const radii_1 = require("../../../Theme/tokens/primitives/radii");
|
|
16
|
+
const useScrollableRegion_1 = require("../../../Hooks/useScrollableRegion");
|
|
17
|
+
const CopyButton_1 = __importDefault(require("../../CopyButton/CopyButton"));
|
|
18
|
+
const VisuallyHidden_1 = __importDefault(require("../../VisuallyHidden/VisuallyHidden"));
|
|
19
|
+
const ScrollbarBox_1 = __importDefault(require("../../ScrollbarBox/ScrollbarBox"));
|
|
20
|
+
const assistantStyles_1 = require("../assistantStyles");
|
|
21
|
+
const parseMarkdown_1 = require("./parseMarkdown");
|
|
22
|
+
const safeHref_1 = require("./safeHref");
|
|
23
|
+
const DEFAULT_LABELS = {
|
|
24
|
+
copyCode: "Copy code",
|
|
25
|
+
copied: "Copied",
|
|
26
|
+
image: (alt) => (alt ? `[image: ${alt}]` : "[image]"),
|
|
27
|
+
newTab: "opens in a new tab",
|
|
28
|
+
table: "Table",
|
|
29
|
+
taskDone: "Done",
|
|
30
|
+
taskOpen: "Not done",
|
|
31
|
+
code: (lang) => (lang ? `${lang} code` : "Code"),
|
|
32
|
+
};
|
|
33
|
+
const renderInline = (nodes, ctx, keyPrefix = "i") => nodes.map((node, i) => {
|
|
34
|
+
const key = `${keyPrefix}-${i}`;
|
|
35
|
+
switch (node.type) {
|
|
36
|
+
case "text":
|
|
37
|
+
return (0, jsx_runtime_1.jsx)(react_1.Fragment, { children: node.content }, key);
|
|
38
|
+
case "break":
|
|
39
|
+
return (0, jsx_runtime_1.jsx)("br", {}, key);
|
|
40
|
+
case "code":
|
|
41
|
+
return ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "code", fontFamily: "mono", fontSize: "0.9em", px: 1, py: "0.0625em", borderRadius: "base", bg: ctx.tokens.inset, color: ctx.tokens.heading, overflowWrap: "anywhere", children: node.content }, key));
|
|
42
|
+
case "strong":
|
|
43
|
+
return ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "strong", fontWeight: 600, color: ctx.tokens.heading, children: renderInline(node.children, ctx, key) }, key));
|
|
44
|
+
case "em":
|
|
45
|
+
return ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "em", fontStyle: "italic", children: renderInline(node.children, ctx, key) }, key));
|
|
46
|
+
case "strike":
|
|
47
|
+
return ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "del", textDecoration: "line-through", children: renderInline(node.children, ctx, key) }, key));
|
|
48
|
+
case "image":
|
|
49
|
+
return ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "span", color: ctx.tokens.muted, "data-testid": "assistant-md-image", children: ctx.labels.image(node.alt) }, key));
|
|
50
|
+
case "link": {
|
|
51
|
+
const safe = (0, safeHref_1.resolveSafeHref)(node.href);
|
|
52
|
+
const children = renderInline(node.children, ctx, key);
|
|
53
|
+
if (!safe) {
|
|
54
|
+
return ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "span", "data-unsafe-link": "true", children: children }, key));
|
|
55
|
+
}
|
|
56
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.Box, { as: "a", href: safe.href, ...(0, safeHref_1.anchorAttributes)(safe), color: ctx.tokens.link, textDecoration: "underline", textUnderlineOffset: "0.15em", borderRadius: "sm", overflowWrap: "anywhere", sx: ctx.focusRing, onClick: (event) => { var _a; return (_a = ctx.onLinkClick) === null || _a === void 0 ? void 0 : _a.call(ctx, safe.href, event); }, children: [children, safe.external ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_2.Box, { as: lucide_react_1.ExternalLink, "aria-hidden": "true", display: "inline", boxSize: "0.8em", ml: "0.15em", verticalAlign: "baseline" }), (0, jsx_runtime_1.jsxs)(VisuallyHidden_1.default, { children: ["(", ctx.labels.newTab, ")"] })] })) : null] }, key));
|
|
57
|
+
}
|
|
58
|
+
default:
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const HEADING_SIZE = {
|
|
63
|
+
1: "md",
|
|
64
|
+
2: "md",
|
|
65
|
+
3: "sm",
|
|
66
|
+
4: "sm",
|
|
67
|
+
5: "sm",
|
|
68
|
+
6: "sm",
|
|
69
|
+
};
|
|
70
|
+
const CodeBlock = ({ lang, content, ctx, }) => {
|
|
71
|
+
const { colors } = (0, useCustomTheme_1.useCustomTheme)();
|
|
72
|
+
const region = (0, useScrollableRegion_1.useScrollableRegion)({
|
|
73
|
+
label: ctx.labels.code(lang),
|
|
74
|
+
});
|
|
75
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.Box, { position: "relative", borderWidth: borderWidths_1.BORDER_WIDTHS.hairline, borderColor: ctx.tokens.rule, borderRadius: radii_1.RADIUS_ROLE.media, bg: ctx.tokens.inset, overflow: "hidden", "data-testid": "assistant-md-code", children: [(0, jsx_runtime_1.jsxs)(react_2.Flex, { align: "center", justify: "space-between", pl: 3, pr: 1, py: 0.5, borderBottomWidth: borderWidths_1.BORDER_WIDTHS.hairline, borderColor: ctx.tokens.rule, children: [(0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "xs", fontFamily: "mono", color: ctx.tokens.muted, children: lang || " " }), (0, jsx_runtime_1.jsx)(CopyButton_1.default, { value: content, size: "xs", iconSize: 14, tooltip: ctx.labels.copyCode, copiedLabel: ctx.labels.copied })] }), (0, jsx_runtime_1.jsx)(react_2.Box, { as: "pre", ref: region.ref, ...region.props, m: 0, px: 3, py: 2.5, overflowX: "auto", fontFamily: "mono", fontSize: "xs-plus", lineHeight: 1.6, color: ctx.tokens.heading, sx: { ...(0, scrollbar_1.scrollbarStyles)(colors, "overlay"), ...ctx.focusRing }, children: (0, jsx_runtime_1.jsx)("code", { children: content }) })] }));
|
|
76
|
+
};
|
|
77
|
+
const renderBlocks = (blocks, ctx, caret, keyPrefix = "b") => blocks.map((block, i) => {
|
|
78
|
+
const key = `${keyPrefix}-${i}`;
|
|
79
|
+
const isLast = i === blocks.length - 1;
|
|
80
|
+
const withCaret = caret && isLast ? (0, jsx_runtime_1.jsx)(assistantStyles_1.StreamingCaret, {}) : null;
|
|
81
|
+
switch (block.type) {
|
|
82
|
+
case "heading": {
|
|
83
|
+
const level = Math.min(6, ctx.headingLevel + block.level - 1);
|
|
84
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.Text, { as: `h${level}`, fontSize: HEADING_SIZE[block.level], fontWeight: 600, lineHeight: 1.4, color: ctx.tokens.heading, children: [renderInline(block.children, ctx, key), withCaret] }, key));
|
|
85
|
+
}
|
|
86
|
+
case "paragraph":
|
|
87
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.Text, { as: "p", children: [renderInline(block.children, ctx, key), withCaret] }, key));
|
|
88
|
+
case "code":
|
|
89
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(CodeBlock, { lang: block.lang, content: block.content, ctx: ctx }), withCaret] }, key));
|
|
90
|
+
case "blockquote":
|
|
91
|
+
return ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "blockquote", pl: 3, borderInlineStartWidth: borderWidths_1.BORDER_WIDTHS.thick, borderInlineStartColor: ctx.tokens.rule, color: ctx.tokens.muted, className: "assistant-md-flow", children: renderBlocks(block.blocks, ctx, caret && isLast, key) }, key));
|
|
92
|
+
case "list": {
|
|
93
|
+
const isTaskList = block.items.some((item) => item.checked !== null);
|
|
94
|
+
const listProps = {
|
|
95
|
+
pl: isTaskList ? 0 : 5,
|
|
96
|
+
listStyleType: isTaskList ? "none" : undefined,
|
|
97
|
+
sx: { "& > li + li": { mt: 1 } },
|
|
98
|
+
};
|
|
99
|
+
const items = block.items.map((item, j) => {
|
|
100
|
+
const itemKey = `${key}-${j}`;
|
|
101
|
+
const lastItem = caret && isLast && j === block.items.length - 1;
|
|
102
|
+
const body = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [renderInline(item.children, ctx, itemKey), lastItem && item.blocks.length === 0 ? (0, jsx_runtime_1.jsx)(assistantStyles_1.StreamingCaret, {}) : null, item.blocks.length ? ((0, jsx_runtime_1.jsx)(react_2.Box, { mt: 1, className: "assistant-md-flow", children: renderBlocks(item.blocks, ctx, lastItem, itemKey) })) : null] }));
|
|
103
|
+
if (item.checked === null) {
|
|
104
|
+
return (0, jsx_runtime_1.jsx)("li", { children: body }, itemKey);
|
|
105
|
+
}
|
|
106
|
+
const Icon = item.checked ? lucide_react_1.CheckSquare : lucide_react_1.Square;
|
|
107
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.Flex, { as: "li", gap: 2, align: "flex-start", children: [(0, jsx_runtime_1.jsx)(react_2.Box, { as: Icon, "aria-hidden": "true", boxSize: "1em", mt: "0.2em", flexShrink: 0, color: item.checked ? ctx.tokens.link : ctx.tokens.muted }), (0, jsx_runtime_1.jsxs)(VisuallyHidden_1.default, { children: [item.checked ? ctx.labels.taskDone : ctx.labels.taskOpen, ":", " "] }), (0, jsx_runtime_1.jsx)(react_2.Box, { minW: 0, textDecoration: item.checked ? "line-through" : undefined, color: item.checked ? ctx.tokens.muted : undefined, children: body })] }, itemKey));
|
|
108
|
+
});
|
|
109
|
+
return block.ordered ? ((0, jsx_runtime_1.jsx)(react_2.chakra.ol, { start: block.start !== 1 ? block.start : undefined, ...listProps, children: items }, key)) : ((0, jsx_runtime_1.jsx)(react_2.chakra.ul, { ...listProps, children: items }, key));
|
|
110
|
+
}
|
|
111
|
+
case "rule":
|
|
112
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_2.Box, { as: "hr", borderTopWidth: borderWidths_1.BORDER_WIDTHS.hairline, borderColor: ctx.tokens.rule }), withCaret] }, key));
|
|
113
|
+
case "table":
|
|
114
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_2.Box, { borderWidth: borderWidths_1.BORDER_WIDTHS.hairline, borderColor: ctx.tokens.rule, borderRadius: radii_1.RADIUS_ROLE.media, overflow: "hidden", children: (0, jsx_runtime_1.jsx)(ScrollbarBox_1.default, { overflowX: "auto", overflowY: "hidden", variant: "overlay", "aria-label": ctx.labels.table, children: (0, jsx_runtime_1.jsxs)(react_2.Box, { as: "table", w: "100%", fontSize: "xs-plus", sx: { borderCollapse: "collapse" }, children: [(0, jsx_runtime_1.jsx)("thead", { children: (0, jsx_runtime_1.jsx)("tr", { children: block.header.map((cell, c) => {
|
|
115
|
+
var _a;
|
|
116
|
+
return ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "th", px: 3, py: 1.5, textAlign: (_a = block.align[c]) !== null && _a !== void 0 ? _a : "start", fontWeight: 600, color: ctx.tokens.heading, bg: ctx.tableHeader, borderBottomWidth: borderWidths_1.BORDER_WIDTHS.hairline, borderColor: ctx.tokens.rule, whiteSpace: "nowrap", children: renderInline(cell, ctx, `${key}-h-${c}`) }, `${key}-h-${c}`));
|
|
117
|
+
}) }) }), (0, jsx_runtime_1.jsx)("tbody", { children: block.rows.map((row, r) => ((0, jsx_runtime_1.jsx)("tr", { children: row.map((cell, c) => {
|
|
118
|
+
var _a;
|
|
119
|
+
return ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "td", px: 3, py: 1.5, textAlign: (_a = block.align[c]) !== null && _a !== void 0 ? _a : "start", verticalAlign: "top", borderTopWidth: r === 0 ? 0 : borderWidths_1.BORDER_WIDTHS.hairline, borderColor: ctx.tokens.rule, children: renderInline(cell, ctx, `${key}-r-${r}-${c}`) }, `${key}-r-${r}-${c}`));
|
|
120
|
+
}) }, `${key}-r-${r}`))) })] }) }) }), withCaret] }, key));
|
|
121
|
+
default:
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
const FLOW = { "& > * + *": { mt: 3 } };
|
|
126
|
+
/**
|
|
127
|
+
* Renders model markdown safely: headings, emphasis, inline and fenced code (with Copy), ordered, unordered
|
|
128
|
+
* and task lists, quotes, pipe tables, rules and links. Never renders HTML or an element that loads a
|
|
129
|
+
* remote resource — an image becomes `[image: alt]` text — and only http(s), mailto and app-relative
|
|
130
|
+
* links become anchors. External links open a new tab with `rel="noopener noreferrer nofollow"`.
|
|
131
|
+
*/
|
|
132
|
+
const AssistantMarkdown = ({ content, onLinkClick, showCaret = false, headingLevel = 3, labels, "data-testid": testId = "assistant-markdown", }) => {
|
|
133
|
+
const { colors } = (0, useCustomTheme_1.useCustomTheme)();
|
|
134
|
+
const blocks = (0, react_1.useMemo)(() => (0, parseMarkdown_1.parseMarkdown)(content), [content]);
|
|
135
|
+
const tokens = (0, assistantStyles_1.assistantTokens)(colors);
|
|
136
|
+
const ctx = {
|
|
137
|
+
tokens,
|
|
138
|
+
labels: { ...DEFAULT_LABELS, ...labels },
|
|
139
|
+
headingLevel,
|
|
140
|
+
onLinkClick,
|
|
141
|
+
focusRing: (0, focusRing_styles_1.focusVisibleStyles)(colors),
|
|
142
|
+
tableHeader: (0, planeStep_1.bandOn)(colors.backgroundColor.tableHeader, tokens.surface),
|
|
143
|
+
};
|
|
144
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.Box, { "data-testid": testId, className: "assistant-md-flow", color: tokens.body, fontSize: "sm", lineHeight: 1.6, overflowWrap: "break-word", minW: 0, sx: { ...FLOW, "& .assistant-md-flow": FLOW }, children: [renderBlocks(blocks, ctx, showCaret), showCaret && blocks.length === 0 ? (0, jsx_runtime_1.jsx)(assistantStyles_1.StreamingCaret, {}) : null] }));
|
|
145
|
+
};
|
|
146
|
+
exports.default = (0, react_1.memo)(AssistantMarkdown);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { MouseEvent } from "react";
|
|
2
|
+
/** Visible and spoken text of `AssistantMarkdown`; omitted keys keep the English default. */
|
|
3
|
+
export interface AssistantMarkdownLabels {
|
|
4
|
+
/** Copy button on a code block. Default "Copy code". */
|
|
5
|
+
copyCode?: string;
|
|
6
|
+
/** Shown briefly after a copy. Default "Copied". */
|
|
7
|
+
copied?: string;
|
|
8
|
+
/** Inert text that replaces an image. Default `[image: alt]`, or `[image]` without alt text. */
|
|
9
|
+
image?: (alt: string) => string;
|
|
10
|
+
/** Appended, visually hidden, to every link that opens a new tab. Default "opens in a new tab". */
|
|
11
|
+
newTab?: string;
|
|
12
|
+
/** Name of a wide table's scroll region. Default "Table". */
|
|
13
|
+
table?: string;
|
|
14
|
+
/** Spoken state of a checked task item. Default "Done". */
|
|
15
|
+
taskDone?: string;
|
|
16
|
+
/** Spoken state of an unchecked task item. Default "Not done". */
|
|
17
|
+
taskOpen?: string;
|
|
18
|
+
/** Name of a code block's scroll region. Default "<lang> code", or "Code". */
|
|
19
|
+
code?: (lang: string) => string;
|
|
20
|
+
}
|
|
21
|
+
/** Safe, dependency-free markdown for model output: no HTML, no images, only allowlisted links. */
|
|
22
|
+
export interface AssistantMarkdownProps {
|
|
23
|
+
/** Markdown source. Malformed input renders as text; an unclosed code fence swallows the rest (a half-streamed answer). */
|
|
24
|
+
content: string;
|
|
25
|
+
/**
|
|
26
|
+
* Called for every link click with the already-vetted href. Call `event.preventDefault()` to route an
|
|
27
|
+
* app-relative link in-app instead of letting the browser follow it.
|
|
28
|
+
*/
|
|
29
|
+
onLinkClick?: (href: string, event: MouseEvent<HTMLAnchorElement>) => void;
|
|
30
|
+
/** Draws a blinking caret after the last word, for a message that is still streaming. */
|
|
31
|
+
showCaret?: boolean;
|
|
32
|
+
/** HTML level a `#` heading renders at, so model headings never outrank the page's own. Default 3 (`#` → h3, `##` → h4…, capped at h6). */
|
|
33
|
+
headingLevel?: 2 | 3 | 4 | 5 | 6;
|
|
34
|
+
/** Translated text for the copy button, image placeholder and screen-reader hints. */
|
|
35
|
+
labels?: AssistantMarkdownLabels;
|
|
36
|
+
/** data-testid on the root. */
|
|
37
|
+
"data-testid"?: string;
|
|
38
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small hand-rolled markdown parser for model output: no dependencies, no HTML, never throws.
|
|
3
|
+
* Ported from Mobile-Components `src/modules/markdown/parseMarkdown.ts` and extended with nesting
|
|
4
|
+
* (lists and quotes), images (as inert alt text), autolinks, escapes, ordered-list starts, table
|
|
5
|
+
* alignment and hard line breaks. Malformed input degrades to literal text; an unclosed fence swallows
|
|
6
|
+
* the rest of the input as code, which is what a half-streamed answer looks like.
|
|
7
|
+
*/
|
|
8
|
+
export type MarkdownInline = {
|
|
9
|
+
type: "text";
|
|
10
|
+
content: string;
|
|
11
|
+
} | {
|
|
12
|
+
type: "break";
|
|
13
|
+
} | {
|
|
14
|
+
type: "code";
|
|
15
|
+
content: string;
|
|
16
|
+
} | {
|
|
17
|
+
type: "strong";
|
|
18
|
+
children: MarkdownInline[];
|
|
19
|
+
} | {
|
|
20
|
+
type: "em";
|
|
21
|
+
children: MarkdownInline[];
|
|
22
|
+
} | {
|
|
23
|
+
type: "strike";
|
|
24
|
+
children: MarkdownInline[];
|
|
25
|
+
} | {
|
|
26
|
+
type: "link";
|
|
27
|
+
href: string;
|
|
28
|
+
children: MarkdownInline[];
|
|
29
|
+
} | {
|
|
30
|
+
type: "image";
|
|
31
|
+
alt: string;
|
|
32
|
+
};
|
|
33
|
+
export type TableAlign = "left" | "center" | "right" | null;
|
|
34
|
+
export interface MarkdownListItem {
|
|
35
|
+
/** First line of the item. */
|
|
36
|
+
children: MarkdownInline[];
|
|
37
|
+
/** `true`/`false` for a `[x]`/`[ ]` task item, `null` for a plain one. */
|
|
38
|
+
checked: boolean | null;
|
|
39
|
+
/** Indented content under the item (nested lists, paragraphs, code). */
|
|
40
|
+
blocks: MarkdownBlock[];
|
|
41
|
+
}
|
|
42
|
+
export type MarkdownBlock = {
|
|
43
|
+
type: "heading";
|
|
44
|
+
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
45
|
+
children: MarkdownInline[];
|
|
46
|
+
} | {
|
|
47
|
+
type: "paragraph";
|
|
48
|
+
children: MarkdownInline[];
|
|
49
|
+
} | {
|
|
50
|
+
type: "code";
|
|
51
|
+
lang: string;
|
|
52
|
+
content: string;
|
|
53
|
+
} | {
|
|
54
|
+
type: "blockquote";
|
|
55
|
+
blocks: MarkdownBlock[];
|
|
56
|
+
} | {
|
|
57
|
+
type: "list";
|
|
58
|
+
ordered: boolean;
|
|
59
|
+
start: number;
|
|
60
|
+
items: MarkdownListItem[];
|
|
61
|
+
} | {
|
|
62
|
+
type: "rule";
|
|
63
|
+
} | {
|
|
64
|
+
type: "table";
|
|
65
|
+
align: TableAlign[];
|
|
66
|
+
header: MarkdownInline[][];
|
|
67
|
+
rows: MarkdownInline[][][];
|
|
68
|
+
};
|
|
69
|
+
/** Inline markdown of one paragraph's lines; a line break between lines is kept as a `break` node. */
|
|
70
|
+
export declare const parseInline: (text: string, depth?: number) => MarkdownInline[];
|
|
71
|
+
/** Parses markdown into blocks; never throws — on an internal failure the input comes back as one paragraph. */
|
|
72
|
+
export declare const parseMarkdown: (content: string) => MarkdownBlock[];
|
|
73
|
+
/** Markdown reduced to readable text (no markers), e.g. for a screen-reader announcement. */
|
|
74
|
+
export declare const markdownToPlainText: (content: string) => string;
|