@langchain/macaw-components 1.4.0 → 1.5.1

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.
Files changed (55) hide show
  1. package/dist/catalog.json +740 -548
  2. package/dist/components/Breadcrumb/Breadcrumb.d.ts +4 -0
  3. package/dist/components/Breadcrumb/Breadcrumb.js +160 -42
  4. package/dist/components/Breadcrumb/Breadcrumb.js.map +1 -1
  5. package/dist/components/ChatComposer/ChatComposer.d.ts +31 -0
  6. package/dist/components/ChatComposer/ChatComposer.js +142 -0
  7. package/dist/components/ChatComposer/ChatComposer.js.map +1 -0
  8. package/dist/components/ChatComposer/ChatComposerAttachments.d.ts +17 -0
  9. package/dist/components/ChatComposer/ChatComposerAttachments.js +117 -0
  10. package/dist/components/ChatComposer/ChatComposerAttachments.js.map +1 -0
  11. package/dist/components/ChatComposer/ChatComposerCodeBlock.d.ts +2 -0
  12. package/dist/components/ChatComposer/ChatComposerCodeBlock.js +100 -0
  13. package/dist/components/ChatComposer/ChatComposerCodeBlock.js.map +1 -0
  14. package/dist/components/ChatComposer/ChatComposerCodeBlockAdapter.d.ts +19 -0
  15. package/dist/components/ChatComposer/ChatComposerCodeBlockAdapter.js +107 -0
  16. package/dist/components/ChatComposer/ChatComposerCodeBlockAdapter.js.map +1 -0
  17. package/dist/components/ChatComposer/ChatComposerCodeBlockView.d.ts +5 -0
  18. package/dist/components/ChatComposer/ChatComposerCodeBlockView.js +104 -0
  19. package/dist/components/ChatComposer/ChatComposerCodeBlockView.js.map +1 -0
  20. package/dist/components/ChatComposer/ChatComposerContext.d.ts +15 -0
  21. package/dist/components/ChatComposer/ChatComposerContext.js +16 -0
  22. package/dist/components/ChatComposer/ChatComposerContext.js.map +1 -0
  23. package/dist/components/ChatComposer/ChatComposerInput.d.ts +19 -0
  24. package/dist/components/ChatComposer/ChatComposerInput.js +38 -0
  25. package/dist/components/ChatComposer/ChatComposerInput.js.map +1 -0
  26. package/dist/components/ChatComposer/ChatComposerModelSelect.d.ts +3 -0
  27. package/dist/components/ChatComposer/ChatComposerModelSelect.js +56 -0
  28. package/dist/components/ChatComposer/ChatComposerModelSelect.js.map +1 -0
  29. package/dist/components/ChatComposer/ChatComposerPlainInput.d.ts +8 -0
  30. package/dist/components/ChatComposer/ChatComposerPlainInput.js +48 -0
  31. package/dist/components/ChatComposer/ChatComposerPlainInput.js.map +1 -0
  32. package/dist/components/ChatComposer/ChatComposerRichInput.d.ts +7 -0
  33. package/dist/components/ChatComposer/ChatComposerRichInput.js +53 -0
  34. package/dist/components/ChatComposer/ChatComposerRichInput.js.map +1 -0
  35. package/dist/components/ChatComposer/index.d.ts +10 -0
  36. package/dist/components/ChatComposer/index.js +6 -0
  37. package/dist/components/ChatComposer/useChatComposerEditor.d.ts +21 -0
  38. package/dist/components/ChatComposer/useChatComposerEditor.js +113 -0
  39. package/dist/components/ChatComposer/useChatComposerEditor.js.map +1 -0
  40. package/dist/components/ChatMessage/ChatMessage.js +1 -1
  41. package/dist/components/Code/CodeLite.js +1 -1
  42. package/dist/components/Code/index.js +7 -8
  43. package/dist/components/Code/index.js.map +1 -1
  44. package/dist/components/Input/Input.js +1 -1
  45. package/dist/components/Select/Select.d.ts +5 -0
  46. package/dist/components/Select/Select.js +2 -1
  47. package/dist/components/Select/Select.js.map +1 -1
  48. package/dist/components/TextWithLinks.js +1 -1
  49. package/dist/components/index.d.ts +2 -0
  50. package/dist/components/index.js +7 -2
  51. package/dist/components.css +2 -0
  52. package/dist/index.js +7 -2
  53. package/dist/utilities.css +1 -1
  54. package/docs/DESIGN.md +49 -15
  55. package/package.json +13 -2
@@ -3,6 +3,8 @@ import type { IconComponent } from '../../utils/icon-types.js';
3
3
  import type { LinkProps } from '../Link/index.js';
4
4
  type BreadcrumbProps = ComponentPropsWithoutRef<'nav'> & {
5
5
  separator?: ReactNode;
6
+ /** Cap labels at 148px instead of 200px. The consuming layout chooses when. */
7
+ condensed?: boolean;
6
8
  };
7
9
  type BreadcrumbLinkProps = LinkProps;
8
10
  type BreadcrumbPageProps = ComponentPropsWithoutRef<'span'> & {
@@ -10,6 +12,8 @@ type BreadcrumbPageProps = ComponentPropsWithoutRef<'span'> & {
10
12
  };
11
13
  declare const Breadcrumb: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & {
12
14
  separator?: ReactNode;
15
+ /** Cap labels at 148px instead of 200px. The consuming layout chooses when. */
16
+ condensed?: boolean;
13
17
  } & import("react").RefAttributes<HTMLElement>>;
14
18
  declare const BreadcrumbLink: import("react").ForwardRefExoticComponent<LinkProps & import("react").RefAttributes<HTMLAnchorElement>>;
15
19
  declare const BreadcrumbPage: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
@@ -1,37 +1,137 @@
1
1
  import { cn } from "../../utils/cn.js";
2
2
  import { Text } from "../Text/Text.js";
3
- import { Children, cloneElement, forwardRef } from "react";
3
+ import { Tooltip } from "../Tooltip/Tooltip.js";
4
+ import { Children, cloneElement, createContext, forwardRef, useContext, useLayoutEffect, useRef, useState } from "react";
4
5
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
6
+ import { TooltipProvider } from "@radix-ui/react-tooltip";
5
7
  //#region packages/components/src/components/Breadcrumb/Breadcrumb.tsx
6
- var Breadcrumb = forwardRef(({ children, className, separator = "/", ...props }, ref) => {
8
+ var BreadcrumbContext = createContext({
9
+ condensed: false,
10
+ hasTooltipProvider: false
11
+ });
12
+ function SlashSeparator() {
13
+ return /* @__PURE__ */ jsx("svg", {
14
+ "aria-hidden": "true",
15
+ width: 10,
16
+ height: 10,
17
+ viewBox: "0 0 24 24",
18
+ fill: "none",
19
+ children: /* @__PURE__ */ jsx("path", {
20
+ d: "M7 22 17 2",
21
+ stroke: "currentColor",
22
+ strokeWidth: 2,
23
+ strokeLinecap: "round"
24
+ })
25
+ });
26
+ }
27
+ var Breadcrumb = forwardRef(({ children, className, separator = /* @__PURE__ */ jsx(SlashSeparator, {}), condensed = false, ...props }, ref) => {
7
28
  const items = Children.toArray(children).filter((item) => item !== "");
29
+ const listRef = useRef(null);
30
+ const [scrollable, setScrollable] = useState(false);
31
+ useLayoutEffect(() => {
32
+ const list = listRef.current;
33
+ if (!list) {
34
+ setScrollable(false);
35
+ return;
36
+ }
37
+ const measure = () => setScrollable(list.scrollWidth > list.clientWidth);
38
+ measure();
39
+ const observer = new ResizeObserver(measure);
40
+ observer.observe(list);
41
+ for (const item of list.children) observer.observe(item);
42
+ return () => observer.disconnect();
43
+ }, [children, condensed]);
8
44
  if (!items.length) return null;
9
- return /* @__PURE__ */ jsx("nav", {
10
- ref,
11
- "aria-label": "Breadcrumb",
12
- className: cn("min-w-0", className),
13
- ...props,
14
- children: /* @__PURE__ */ jsx("ol", {
15
- role: "list",
16
- className: "flex flex-wrap items-center gap-space-2",
17
- children: items.map((item, index) => /* @__PURE__ */ jsxs("li", {
18
- className: "flex min-w-0 max-w-full items-center gap-space-2",
19
- children: [index > 0 && /* @__PURE__ */ jsx("span", {
20
- "aria-hidden": "true",
21
- className: "shrink-0 text-xxs text-quaternary",
22
- children: separator
23
- }), item]
24
- }, typeof item === "object" && "key" in item ? item.key : index))
25
- })
45
+ return /* @__PURE__ */ jsx(BreadcrumbContext.Provider, {
46
+ value: {
47
+ condensed,
48
+ hasTooltipProvider: true
49
+ },
50
+ children: /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx("nav", {
51
+ ref,
52
+ "aria-label": "Breadcrumb",
53
+ className: cn("min-w-0", className),
54
+ ...props,
55
+ children: /* @__PURE__ */ jsx("ol", {
56
+ ref: listRef,
57
+ role: "list",
58
+ tabIndex: scrollable ? 0 : -1,
59
+ className: "flex flex-nowrap items-center gap-space-2 overflow-x-auto rounded-sm focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus",
60
+ children: items.map((item, index) => /* @__PURE__ */ jsxs("li", {
61
+ className: "flex min-w-0 max-w-full shrink-0 items-center gap-space-2",
62
+ children: [index > 0 && /* @__PURE__ */ jsx("span", {
63
+ "aria-hidden": "true",
64
+ className: "flex shrink-0 items-center text-xxs text-quaternary",
65
+ children: separator
66
+ }), item]
67
+ }, typeof item === "object" && "key" in item ? item.key : index))
68
+ })
69
+ }) })
26
70
  });
27
71
  });
28
72
  Breadcrumb.displayName = "Breadcrumb";
73
+ function useBreadcrumbLabel(children) {
74
+ const { condensed } = useContext(BreadcrumbContext);
75
+ const labelRef = useRef(null);
76
+ const [text, setText] = useState("");
77
+ const [clipped, setClipped] = useState(false);
78
+ const [open, setOpen] = useState(false);
79
+ useLayoutEffect(() => {
80
+ const label = labelRef.current;
81
+ if (!label) return;
82
+ let active = true;
83
+ function measure() {
84
+ if (!active || !label) return;
85
+ const isClipped = label.scrollWidth > label.clientWidth;
86
+ setText(label.textContent ?? "");
87
+ setClipped(isClipped);
88
+ if (!isClipped) setOpen(false);
89
+ }
90
+ measure();
91
+ const resizeObserver = new ResizeObserver(measure);
92
+ resizeObserver.observe(label);
93
+ const mutationObserver = new MutationObserver(measure);
94
+ mutationObserver.observe(label, {
95
+ childList: true,
96
+ characterData: true,
97
+ subtree: true
98
+ });
99
+ const fonts = label.ownerDocument.fonts;
100
+ fonts?.ready.then(measure);
101
+ fonts?.addEventListener("loadingdone", measure);
102
+ return () => {
103
+ active = false;
104
+ resizeObserver.disconnect();
105
+ mutationObserver.disconnect();
106
+ fonts?.removeEventListener("loadingdone", measure);
107
+ };
108
+ }, [children, condensed]);
109
+ return {
110
+ labelRef,
111
+ clipped,
112
+ labelClassName: cn("min-w-0 max-w-50 truncate", condensed && "max-w-37"),
113
+ tooltipProps: {
114
+ title: /* @__PURE__ */ jsx(Text, {
115
+ variant: "sm",
116
+ className: "text-primary",
117
+ children: text
118
+ }),
119
+ open: clipped && open,
120
+ onOpenChange: (nextOpen) => setOpen(clipped && nextOpen)
121
+ }
122
+ };
123
+ }
124
+ function BreadcrumbTooltip(props) {
125
+ const { hasTooltipProvider } = useContext(BreadcrumbContext);
126
+ const tooltip = /* @__PURE__ */ jsx(Tooltip, { ...props });
127
+ return hasTooltipProvider ? tooltip : /* @__PURE__ */ jsx(TooltipProvider, { children: tooltip });
128
+ }
29
129
  var BreadcrumbLink = forwardRef(({ children, className, as, leftDecorator: LeftIcon, rightDecorator: RightIcon, iconWeight = "regular", variant = "xs", ...props }, ref) => {
130
+ const { labelRef, labelClassName, tooltipProps } = useBreadcrumbLabel(children);
30
131
  const linkProps = {
31
- ...typeof children === "string" && as?.props.title === void 0 ? { title: children } : {},
32
132
  ...props,
33
133
  ref,
34
- className: cn("inline-flex min-w-0 items-center gap-space-1 rounded-sm text-quaternary hover:text-secondary hover:underline underline-offset-2 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-focus", as?.props.className, className),
134
+ className: cn("inline-flex min-w-0 items-center gap-space-1 rounded-sm text-quaternary hover:underline underline-offset-2 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus", as?.props.className, className),
35
135
  children: /* @__PURE__ */ jsxs(Fragment$1, { children: [
36
136
  LeftIcon && /* @__PURE__ */ jsx(LeftIcon, {
37
137
  "aria-hidden": true,
@@ -40,10 +140,11 @@ var BreadcrumbLink = forwardRef(({ children, className, as, leftDecorator: LeftI
40
140
  className: "shrink-0"
41
141
  }),
42
142
  /* @__PURE__ */ jsx(Text, {
143
+ ref: labelRef,
43
144
  as: "span",
44
145
  variant,
45
146
  weight: "medium",
46
- className: "min-w-0 max-w-50 truncate",
147
+ className: labelClassName,
47
148
  children
48
149
  }),
49
150
  RightIcon && /* @__PURE__ */ jsx(RightIcon, {
@@ -54,28 +155,45 @@ var BreadcrumbLink = forwardRef(({ children, className, as, leftDecorator: LeftI
54
155
  })
55
156
  ] })
56
157
  };
57
- return as ? cloneElement(as, linkProps) : /* @__PURE__ */ jsx("a", { ...linkProps });
158
+ return /* @__PURE__ */ jsx(BreadcrumbTooltip, {
159
+ ...tooltipProps,
160
+ children: as ? cloneElement(as, linkProps) : /* @__PURE__ */ jsx("a", { ...linkProps })
161
+ });
58
162
  });
59
163
  BreadcrumbLink.displayName = "BreadcrumbLink";
60
- var BreadcrumbPage = forwardRef(({ children, className, leftDecorator: LeftIcon, ...props }, ref) => /* @__PURE__ */ jsxs("span", {
61
- ref,
62
- "aria-current": "page",
63
- title: typeof children === "string" ? children : void 0,
64
- className: cn("inline-flex min-w-0 items-center gap-space-1 text-secondary", className),
65
- ...props,
66
- children: [LeftIcon && /* @__PURE__ */ jsx(LeftIcon, {
67
- "aria-hidden": true,
68
- size: 12,
69
- weight: "regular",
70
- className: "shrink-0"
71
- }), /* @__PURE__ */ jsx(Text, {
72
- as: "span",
73
- variant: "xs",
74
- weight: "medium",
75
- className: "min-w-0 max-w-50 truncate",
76
- children
77
- })]
78
- }));
164
+ var BreadcrumbPage = forwardRef(({ children, className, leftDecorator: LeftIcon, tabIndex, onFocus, ...props }, ref) => {
165
+ const { labelRef, labelClassName, clipped, tooltipProps } = useBreadcrumbLabel(children);
166
+ return /* @__PURE__ */ jsx(BreadcrumbTooltip, {
167
+ ...tooltipProps,
168
+ children: /* @__PURE__ */ jsxs("span", {
169
+ ref,
170
+ "aria-current": "page",
171
+ tabIndex: tabIndex ?? (clipped ? 0 : -1),
172
+ onFocus: (event) => {
173
+ onFocus?.(event);
174
+ if (!event.defaultPrevented) event.currentTarget.scrollIntoView({
175
+ block: "nearest",
176
+ inline: "nearest"
177
+ });
178
+ },
179
+ className: cn("inline-flex min-w-0 items-center gap-space-1 rounded-sm text-secondary focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus", className),
180
+ ...props,
181
+ children: [LeftIcon && /* @__PURE__ */ jsx(LeftIcon, {
182
+ "aria-hidden": true,
183
+ size: 12,
184
+ weight: "regular",
185
+ className: "shrink-0"
186
+ }), /* @__PURE__ */ jsx(Text, {
187
+ ref: labelRef,
188
+ as: "span",
189
+ variant: "xs",
190
+ weight: "medium",
191
+ className: labelClassName,
192
+ children
193
+ })]
194
+ })
195
+ });
196
+ });
79
197
  BreadcrumbPage.displayName = "BreadcrumbPage";
80
198
  //#endregion
81
199
  export { Breadcrumb, BreadcrumbLink, BreadcrumbPage };
@@ -1 +1 @@
1
- {"version":3,"file":"Breadcrumb.js","names":[],"sources":["../../../src/components/Breadcrumb/Breadcrumb.tsx"],"sourcesContent":["import {\n Children,\n cloneElement,\n forwardRef,\n type ComponentPropsWithoutRef,\n type ReactNode,\n} from 'react';\n\nimport { cn } from '../../utils/cn';\nimport type { IconComponent } from '../../utils/icon-types';\nimport type { LinkProps } from '../Link';\nimport { Text } from '../Text';\n\ntype BreadcrumbProps = ComponentPropsWithoutRef<'nav'> & {\n separator?: ReactNode;\n};\n\ntype BreadcrumbLinkProps = LinkProps;\n\ntype BreadcrumbPageProps = ComponentPropsWithoutRef<'span'> & {\n leftDecorator?: IconComponent;\n};\n\nconst Breadcrumb = forwardRef<HTMLElement, BreadcrumbProps>(\n ({ children, className, separator = '/', ...props }, ref) => {\n const items = Children.toArray(children).filter((item) => item !== '');\n if (!items.length) return null;\n\n return (\n <nav\n ref={ref}\n aria-label=\"Breadcrumb\"\n className={cn('min-w-0', className)}\n {...props}\n >\n <ol role=\"list\" className=\"flex flex-wrap items-center gap-space-2\">\n {items.map((item, index) => (\n <li\n key={typeof item === 'object' && 'key' in item ? item.key : index}\n className=\"flex min-w-0 max-w-full items-center gap-space-2\"\n >\n {index > 0 && (\n <span\n aria-hidden=\"true\"\n className=\"shrink-0 text-xxs text-quaternary\"\n >\n {separator}\n </span>\n )}\n {item}\n </li>\n ))}\n </ol>\n </nav>\n );\n }\n);\nBreadcrumb.displayName = 'Breadcrumb';\n\nconst BreadcrumbLink = forwardRef<HTMLAnchorElement, BreadcrumbLinkProps>(\n (\n {\n children,\n className,\n as,\n leftDecorator: LeftIcon,\n rightDecorator: RightIcon,\n iconWeight = 'regular',\n variant = 'xs',\n ...props\n },\n ref\n ) => {\n const linkProps = {\n ...(typeof children === 'string' && as?.props.title === undefined\n ? { title: children }\n : {}),\n ...props,\n ref,\n className: cn(\n 'inline-flex min-w-0 items-center gap-space-1 rounded-sm text-quaternary hover:text-secondary hover:underline underline-offset-2 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-focus',\n as?.props.className,\n className\n ),\n children: (\n <>\n {LeftIcon && (\n <LeftIcon\n aria-hidden\n size={12}\n weight={iconWeight}\n className=\"shrink-0\"\n />\n )}\n <Text\n as=\"span\"\n variant={variant}\n weight=\"medium\"\n className=\"min-w-0 max-w-50 truncate\"\n >\n {children}\n </Text>\n {RightIcon && (\n <RightIcon\n aria-hidden\n size={12}\n weight={iconWeight}\n className=\"shrink-0\"\n />\n )}\n </>\n ),\n };\n\n return as ? cloneElement(as, linkProps) : <a {...linkProps} />;\n }\n);\nBreadcrumbLink.displayName = 'BreadcrumbLink';\n\nconst BreadcrumbPage = forwardRef<HTMLSpanElement, BreadcrumbPageProps>(\n ({ children, className, leftDecorator: LeftIcon, ...props }, ref) => (\n <span\n ref={ref}\n aria-current=\"page\"\n title={typeof children === 'string' ? children : undefined}\n className={cn(\n 'inline-flex min-w-0 items-center gap-space-1 text-secondary',\n className\n )}\n {...props}\n >\n {LeftIcon && (\n <LeftIcon aria-hidden size={12} weight=\"regular\" className=\"shrink-0\" />\n )}\n <Text\n as=\"span\"\n variant=\"xs\"\n weight=\"medium\"\n className=\"min-w-0 max-w-50 truncate\"\n >\n {children}\n </Text>\n </span>\n )\n);\nBreadcrumbPage.displayName = 'BreadcrumbPage';\n\nexport { Breadcrumb, BreadcrumbLink, BreadcrumbPage };\nexport type { BreadcrumbProps, BreadcrumbLinkProps, BreadcrumbPageProps };\n"],"mappings":";;;;;AAuBA,IAAM,aAAa,YAChB,EAAE,UAAU,WAAW,YAAY,KAAK,GAAG,SAAS,QAAQ;CAC3D,MAAM,QAAQ,SAAS,QAAQ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S,QAC3D,qBAAC,QAAD;CACO;CACL,gBAAa;CACb,OAAO,OAAO,aAAa,WAAW,WAAW,KAAA;CACjD,WAAW,GACT,+DACA,SACF;CACA,GAAI;CARN,UAAA,CAUG,YACC,oBAAC,UAAD;EAAU,eAAA;EAAY,MAAM;EAAI,QAAO;EAAU,WAAU;CAAY,CAAA,GAEzE,oBAAC,MAAD;EACE,IAAG;EACH,SAAQ;EACR,QAAO;EACP,WAAU;EAET;CACG,CAAA,CACF;AAEV,CAAA,CAAA;AACA,eAAe,cAAc"}
1
+ {"version":3,"file":"Breadcrumb.js","names":[],"sources":["../../../src/components/Breadcrumb/Breadcrumb.tsx"],"sourcesContent":["import {\n Children,\n cloneElement,\n createContext,\n forwardRef,\n useContext,\n useLayoutEffect,\n useRef,\n useState,\n type ComponentPropsWithoutRef,\n type ReactNode,\n} from 'react';\n\nimport { TooltipProvider } from '@radix-ui/react-tooltip';\n\nimport { cn } from '../../utils/cn';\nimport type { IconComponent } from '../../utils/icon-types';\nimport type { LinkProps } from '../Link';\nimport { Text } from '../Text';\nimport { Tooltip, type TooltipProps } from '../Tooltip';\n\ntype BreadcrumbProps = ComponentPropsWithoutRef<'nav'> & {\n separator?: ReactNode;\n /** Cap labels at 148px instead of 200px. The consuming layout chooses when. */\n condensed?: boolean;\n};\n\ntype BreadcrumbLinkProps = LinkProps;\n\ntype BreadcrumbPageProps = ComponentPropsWithoutRef<'span'> & {\n leftDecorator?: IconComponent;\n};\n\nconst BreadcrumbContext = createContext({\n condensed: false,\n hasTooltipProvider: false,\n});\n\nfunction SlashSeparator() {\n return (\n <svg\n aria-hidden=\"true\"\n width={10}\n height={10}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n >\n <path\n d=\"M7 22 17 2\"\n stroke=\"currentColor\"\n strokeWidth={2}\n strokeLinecap=\"round\"\n />\n </svg>\n );\n}\n\nconst Breadcrumb = forwardRef<HTMLElement, BreadcrumbProps>(\n (\n {\n children,\n className,\n separator = <SlashSeparator />,\n condensed = false,\n ...props\n },\n ref\n ) => {\n const items = Children.toArray(children).filter((item) => item !== '');\n const listRef = useRef<HTMLOListElement>(null);\n const [scrollable, setScrollable] = useState(false);\n\n useLayoutEffect(() => {\n const list = listRef.current;\n if (!list) {\n setScrollable(false);\n return;\n }\n const measure = () => setScrollable(list.scrollWidth > list.clientWidth);\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(list);\n for (const item of list.children) observer.observe(item);\n return () => observer.disconnect();\n }, [children, condensed]);\n\n if (!items.length) return null;\n\n return (\n <BreadcrumbContext.Provider\n value={{ condensed, hasTooltipProvider: true }}\n >\n <TooltipProvider>\n <nav\n ref={ref}\n aria-label=\"Breadcrumb\"\n className={cn('min-w-0', className)}\n {...props}\n >\n <ol\n ref={listRef}\n role=\"list\"\n tabIndex={scrollable ? 0 : -1}\n className=\"flex flex-nowrap items-center gap-space-2 overflow-x-auto rounded-sm focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus\"\n >\n {items.map((item, index) => (\n <li\n key={\n typeof item === 'object' && 'key' in item ? item.key : index\n }\n className=\"flex min-w-0 max-w-full shrink-0 items-center gap-space-2\"\n >\n {index > 0 && (\n <span\n aria-hidden=\"true\"\n className=\"flex shrink-0 items-center text-xxs text-quaternary\"\n >\n {separator}\n </span>\n )}\n {item}\n </li>\n ))}\n </ol>\n </nav>\n </TooltipProvider>\n </BreadcrumbContext.Provider>\n );\n }\n);\nBreadcrumb.displayName = 'Breadcrumb';\n\nfunction useBreadcrumbLabel(children: ReactNode) {\n const { condensed } = useContext(BreadcrumbContext);\n const labelRef = useRef<HTMLElement>(null);\n const [text, setText] = useState('');\n const [clipped, setClipped] = useState(false);\n const [open, setOpen] = useState(false);\n\n useLayoutEffect(() => {\n const label = labelRef.current;\n if (!label) return;\n let active = true;\n function measure() {\n if (!active || !label) return;\n const isClipped = label.scrollWidth > label.clientWidth;\n setText(label.textContent ?? '');\n setClipped(isClipped);\n if (!isClipped) setOpen(false);\n }\n\n measure();\n const resizeObserver = new ResizeObserver(measure);\n resizeObserver.observe(label);\n const mutationObserver = new MutationObserver(measure);\n mutationObserver.observe(label, {\n childList: true,\n characterData: true,\n subtree: true,\n });\n // A font change can change scrollWidth without changing the capped width.\n const fonts = label.ownerDocument.fonts;\n void fonts?.ready.then(measure);\n fonts?.addEventListener('loadingdone', measure);\n return () => {\n active = false;\n resizeObserver.disconnect();\n mutationObserver.disconnect();\n fonts?.removeEventListener('loadingdone', measure);\n };\n }, [children, condensed]);\n\n return {\n labelRef,\n clipped,\n labelClassName: cn('min-w-0 max-w-50 truncate', condensed && 'max-w-37'),\n tooltipProps: {\n // Keep the trigger mounted when clipping changes, preserving keyboard focus.\n title: (\n <Text variant=\"sm\" className=\"text-primary\">\n {text}\n </Text>\n ),\n open: clipped && open,\n onOpenChange: (nextOpen: boolean) => setOpen(clipped && nextOpen),\n },\n };\n}\n\nfunction BreadcrumbTooltip(props: TooltipProps) {\n const { hasTooltipProvider } = useContext(BreadcrumbContext);\n const tooltip = <Tooltip {...props} />;\n // Exported links/pages also work on their own, without an application provider.\n return hasTooltipProvider ? (\n tooltip\n ) : (\n <TooltipProvider>{tooltip}</TooltipProvider>\n );\n}\n\nconst BreadcrumbLink = forwardRef<HTMLAnchorElement, BreadcrumbLinkProps>(\n (\n {\n children,\n className,\n as,\n leftDecorator: LeftIcon,\n rightDecorator: RightIcon,\n iconWeight = 'regular',\n variant = 'xs',\n ...props\n },\n ref\n ) => {\n const { labelRef, labelClassName, tooltipProps } =\n useBreadcrumbLabel(children);\n const linkProps = {\n ...props,\n ref,\n className: cn(\n 'inline-flex min-w-0 items-center gap-space-1 rounded-sm text-quaternary hover:underline underline-offset-2 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus',\n as?.props.className,\n className\n ),\n children: (\n <>\n {LeftIcon && (\n <LeftIcon\n aria-hidden\n size={12}\n weight={iconWeight}\n className=\"shrink-0\"\n />\n )}\n <Text\n ref={labelRef}\n as=\"span\"\n variant={variant}\n weight=\"medium\"\n className={labelClassName}\n >\n {children}\n </Text>\n {RightIcon && (\n <RightIcon\n aria-hidden\n size={12}\n weight={iconWeight}\n className=\"shrink-0\"\n />\n )}\n </>\n ),\n };\n\n return (\n <BreadcrumbTooltip {...tooltipProps}>\n {as ? cloneElement(as, linkProps) : <a {...linkProps} />}\n </BreadcrumbTooltip>\n );\n }\n);\nBreadcrumbLink.displayName = 'BreadcrumbLink';\n\nconst BreadcrumbPage = forwardRef<HTMLSpanElement, BreadcrumbPageProps>(\n (\n {\n children,\n className,\n leftDecorator: LeftIcon,\n tabIndex,\n onFocus,\n ...props\n },\n ref\n ) => {\n const { labelRef, labelClassName, clipped, tooltipProps } =\n useBreadcrumbLabel(children);\n return (\n <BreadcrumbTooltip {...tooltipProps}>\n <span\n ref={ref}\n aria-current=\"page\"\n tabIndex={tabIndex ?? (clipped ? 0 : -1)}\n onFocus={(event) => {\n onFocus?.(event);\n if (!event.defaultPrevented) {\n event.currentTarget.scrollIntoView({\n block: 'nearest',\n inline: 'nearest',\n });\n }\n }}\n className={cn(\n 'inline-flex min-w-0 items-center gap-space-1 rounded-sm text-secondary focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus',\n className\n )}\n {...props}\n >\n {LeftIcon && (\n <LeftIcon\n aria-hidden\n size={12}\n weight=\"regular\"\n className=\"shrink-0\"\n />\n )}\n <Text\n ref={labelRef}\n as=\"span\"\n variant=\"xs\"\n weight=\"medium\"\n className={labelClassName}\n >\n {children}\n </Text>\n </span>\n </BreadcrumbTooltip>\n );\n }\n);\nBreadcrumbPage.displayName = 'BreadcrumbPage';\n\nexport { Breadcrumb, BreadcrumbLink, BreadcrumbPage };\nexport type { BreadcrumbProps, BreadcrumbLinkProps, BreadcrumbPageProps };\n"],"mappings":";;;;;;;AAiCA,IAAM,oBAAoB,cAAc;CACtC,WAAW;CACX,oBAAoB;AACtB,CAAC;AAED,SAAS,iBAAiB;CACxB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,IAAI,CAAC,MAAM,kBACT,MAAM,cAAc,eAAe;KACjC,OAAO;KACP,QAAQ;IACV,CAAC;GAEL;GACA,WAAW,GACT,8KACA,SACF;GACA,GAAI;GAjBN,UAAA,CAmBG,YACC,oBAAC,UAAD;IACE,eAAA;IACA,MAAM;IACN,QAAO;IACP,WAAU;GACX,CAAA,GAEH,oBAAC,MAAD;IACE,KAAK;IACL,IAAG;IACH,SAAQ;IACR,QAAO;IACP,WAAW;IAEV;GACG,CAAA,CACF;;CACW,CAAA;AAEvB,CACF;AACA,eAAe,cAAc"}
@@ -0,0 +1,31 @@
1
+ import type { ComponentPropsWithRef, ReactNode } from 'react';
2
+ import type { IconButtonProps } from '../IconButton/index.js';
3
+ export type ChatComposerDrawerIntent = 'neutral' | 'info' | 'warning' | 'error';
4
+ export type ChatComposerProps = ComponentPropsWithRef<'form'> & {
5
+ /** Supplementary content attached above the editor, inside the composer form. */
6
+ drawer?: ReactNode;
7
+ /**
8
+ * Drawer surface color. Color alone doesn't convey severity, so the drawer
9
+ * content should also say it in text or with an icon.
10
+ */
11
+ drawerIntent?: ChatComposerDrawerIntent;
12
+ disabled?: boolean;
13
+ submitDisabled?: boolean;
14
+ onFilesSelected?: (files: File[]) => void;
15
+ } & ({
16
+ action?: 'send' | 'sending';
17
+ onStop?: never;
18
+ } | {
19
+ action: 'stop';
20
+ onStop: () => void;
21
+ });
22
+ export declare function ChatComposer({ children, drawer, drawerIntent, className, ref, disabled, submitDisabled, action, onStop, onSubmit, onFilesSelected, onDragOver, onDragLeave, onDropCapture, onPasteCapture, noValidate, ...props }: ChatComposerProps): import("react").JSX.Element;
23
+ export interface ChatComposerToolbarProps extends ComponentPropsWithRef<'div'> {
24
+ modelSelector?: ReactNode;
25
+ actions?: ReactNode;
26
+ }
27
+ export declare function ChatComposerToolbar({ children, modelSelector, actions, className, ...props }: ChatComposerToolbarProps): import("react").JSX.Element;
28
+ export type ChatComposerActionProps = Omit<IconButtonProps, 'icon' | 'type' | 'onClick' | 'asChild' | 'label' | 'loading'> & {
29
+ label?: string;
30
+ };
31
+ export declare function ChatComposerAction({ disabled, label, ...props }: ChatComposerActionProps): import("react").JSX.Element;
@@ -0,0 +1,142 @@
1
+ import { cn } from "../../utils/cn.js";
2
+ import { IconButton } from "../IconButton/IconButton.js";
3
+ import { mergeRefs } from "../../utils/merge-refs.js";
4
+ import { ChatComposerContext, useChatComposerContext } from "./ChatComposerContext.js";
5
+ import { useRef, useState } from "react";
6
+ import { ArrowUpIcon } from "@phosphor-icons/react/dist/ssr/ArrowUp";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ import { StopIcon } from "@phosphor-icons/react/dist/ssr/Stop";
9
+ //#region packages/components/src/components/ChatComposer/ChatComposer.tsx
10
+ var DRAWER_INTENT_CLASSES = {
11
+ neutral: "border-subtle bg-surface-level-2",
12
+ info: "border-brand-subtle bg-brand-subtle",
13
+ warning: "border-warning bg-warning",
14
+ error: "border-error bg-error"
15
+ };
16
+ function isAttachmentTargetBlocked(target) {
17
+ return target instanceof Element && target.closest(":disabled, [readonly], [aria-disabled=\"true\"], [aria-readonly=\"true\"]") !== null;
18
+ }
19
+ function reportFieldsetValidity(fieldset) {
20
+ for (const element of fieldset?.elements ?? []) if ((element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement) && !element.reportValidity()) return false;
21
+ return true;
22
+ }
23
+ function ChatComposer({ children, drawer, drawerIntent = "neutral", className, ref, disabled = false, submitDisabled = false, action = "send", onStop, onSubmit, onFilesSelected, onDragOver, onDragLeave, onDropCapture, onPasteCapture, noValidate, ...props }) {
24
+ const formRef = useRef(null);
25
+ const [isDropTarget, setIsDropTarget] = useState(false);
26
+ const canSubmit = !disabled && !submitDisabled && action === "send" && !!onSubmit;
27
+ const hasDrawer = Boolean(drawer);
28
+ const fieldsetRef = useRef(null);
29
+ const inputFocusRef = useRef(null);
30
+ const validatesFieldsetOnly = noValidate === void 0 && hasDrawer;
31
+ return /* @__PURE__ */ jsx(ChatComposerContext.Provider, {
32
+ value: {
33
+ disabled,
34
+ canSubmit,
35
+ action,
36
+ onStop,
37
+ onFilesSelected,
38
+ inputFocusRef,
39
+ submit: onSubmit ? () => {
40
+ if (canSubmit) formRef.current?.requestSubmit();
41
+ } : void 0
42
+ },
43
+ children: /* @__PURE__ */ jsxs("form", {
44
+ ...props,
45
+ ref: mergeRefs([formRef, ref]),
46
+ noValidate: noValidate ?? hasDrawer,
47
+ className: cn("isolate w-full min-w-0 @container/composer", className),
48
+ onSubmit: (event) => {
49
+ event.preventDefault();
50
+ if (!canSubmit) return;
51
+ if (validatesFieldsetOnly && !reportFieldsetValidity(fieldsetRef.current)) return;
52
+ onSubmit?.(event);
53
+ },
54
+ onDragOver: (event) => {
55
+ onDragOver?.(event);
56
+ if (event.defaultPrevented || !onFilesSelected) return;
57
+ if (!event.dataTransfer.types.includes("Files")) return;
58
+ event.preventDefault();
59
+ const canAttach = !disabled && !isAttachmentTargetBlocked(event.target);
60
+ event.dataTransfer.dropEffect = canAttach ? "copy" : "none";
61
+ setIsDropTarget(canAttach);
62
+ },
63
+ onDragLeave: (event) => {
64
+ onDragLeave?.(event);
65
+ if (!(event.relatedTarget instanceof Node) || !event.currentTarget.contains(event.relatedTarget)) setIsDropTarget(false);
66
+ },
67
+ onDropCapture: (event) => {
68
+ onDropCapture?.(event);
69
+ setIsDropTarget(false);
70
+ if (event.defaultPrevented || !onFilesSelected) return;
71
+ const files = Array.from(event.dataTransfer.files);
72
+ if (!files.length) return;
73
+ event.preventDefault();
74
+ if (!disabled && !isAttachmentTargetBlocked(event.target)) onFilesSelected(files);
75
+ },
76
+ onPasteCapture: (event) => {
77
+ onPasteCapture?.(event);
78
+ if (event.defaultPrevented || !onFilesSelected) return;
79
+ const files = Array.from(event.clipboardData.files);
80
+ if (!files.length) return;
81
+ if (disabled || isAttachmentTargetBlocked(event.target)) {
82
+ event.preventDefault();
83
+ return;
84
+ }
85
+ if (!event.clipboardData.getData("text/plain")) event.preventDefault();
86
+ onFilesSelected(files);
87
+ },
88
+ children: [hasDrawer && /* @__PURE__ */ jsx("fieldset", {
89
+ disabled,
90
+ className: cn("mx-space-3 -mb-space-3 max-h-[50dvh] min-w-0 overflow-y-auto overscroll-contain rounded-t-xl border border-b-0 pb-space-3 duration-normal ease-out animate-in fade-in slide-in-from-bottom-2 motion-reduce:animate-none", DRAWER_INTENT_CLASSES[drawerIntent], disabled && "border-disabled"),
91
+ children: drawer
92
+ }), /* @__PURE__ */ jsx("fieldset", {
93
+ ref: fieldsetRef,
94
+ disabled,
95
+ className: cn("relative m-0 flex w-full min-w-0 flex-col gap-space-2 rounded-xl border border-subtle bg-elevated p-space-2 transition-[border-color,box-shadow,background-color] duration-normal motion-reduce:transition-none", "has-[:is(textarea,[contenteditable=true]):focus]:border-focus has-[:is(textarea,[contenteditable=true]):focus]:shadow-[0_0_0_1px_var(--border-focus)]", disabled && "border-disabled bg-input-disabled", isDropTarget && !disabled && "border-focus bg-surface-level-2 shadow-[0_0_0_1px_var(--border-focus)]"),
96
+ children
97
+ })]
98
+ })
99
+ });
100
+ }
101
+ function ChatComposerToolbar({ children, modelSelector, actions = /* @__PURE__ */ jsx(ChatComposerAction, {}), className, ...props }) {
102
+ return /* @__PURE__ */ jsxs("div", {
103
+ ...props,
104
+ className: cn("flex min-w-0 items-center gap-space-2", className),
105
+ children: [/* @__PURE__ */ jsxs("div", {
106
+ className: "flex min-w-0 flex-1 flex-wrap items-center gap-space-1 @[440px]/composer:gap-space-2",
107
+ children: [children, modelSelector != null && /* @__PURE__ */ jsx("div", {
108
+ className: "min-w-0 max-w-full [&>*]:max-w-full",
109
+ children: modelSelector
110
+ })]
111
+ }), /* @__PURE__ */ jsx("div", {
112
+ className: "flex shrink-0 items-center gap-space-1",
113
+ children: actions
114
+ })]
115
+ });
116
+ }
117
+ var ACTION_LABELS = {
118
+ send: "Send message",
119
+ sending: "Sending message",
120
+ stop: "Stop response"
121
+ };
122
+ function ChatComposerAction({ disabled, label, ...props }) {
123
+ const composer = useChatComposerContext();
124
+ const isStop = composer.action === "stop";
125
+ return /* @__PURE__ */ jsx(IconButton, {
126
+ size: "sm",
127
+ round: true,
128
+ color: "primary",
129
+ iconWeight: "regular",
130
+ ...props,
131
+ type: isStop ? "button" : "submit",
132
+ icon: isStop ? StopIcon : ArrowUpIcon,
133
+ label: label ?? ACTION_LABELS[composer.action],
134
+ disabled: composer.disabled || disabled || !isStop && !composer.canSubmit,
135
+ loading: composer.action === "sending",
136
+ onClick: isStop ? composer.onStop : void 0
137
+ });
138
+ }
139
+ //#endregion
140
+ export { ChatComposer, ChatComposerAction, ChatComposerToolbar };
141
+
142
+ //# sourceMappingURL=ChatComposer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatComposer.js","names":[],"sources":["../../../src/components/ChatComposer/ChatComposer.tsx"],"sourcesContent":["import type { ComponentPropsWithRef, ReactNode } from 'react';\nimport { useRef, useState } from 'react';\n\nimport { ArrowUpIcon } from '@phosphor-icons/react/dist/ssr/ArrowUp';\nimport { StopIcon } from '@phosphor-icons/react/dist/ssr/Stop';\n\nimport { cn } from '../../utils/cn';\nimport { mergeRefs } from '../../utils/merge-refs';\nimport { IconButton } from '../IconButton';\nimport type { IconButtonProps } from '../IconButton';\nimport {\n ChatComposerContext,\n type ChatComposerContextValue,\n useChatComposerContext,\n} from './ChatComposerContext';\n\nexport type ChatComposerDrawerIntent = 'neutral' | 'info' | 'warning' | 'error';\n\nconst DRAWER_INTENT_CLASSES: Record<ChatComposerDrawerIntent, string> = {\n neutral: 'border-subtle bg-surface-level-2',\n info: 'border-brand-subtle bg-brand-subtle',\n warning: 'border-warning bg-warning',\n error: 'border-error bg-error',\n};\n\nexport type ChatComposerProps = ComponentPropsWithRef<'form'> & {\n /** Supplementary content attached above the editor, inside the composer form. */\n drawer?: ReactNode;\n /**\n * Drawer surface color. Color alone doesn't convey severity, so the drawer\n * content should also say it in text or with an icon.\n */\n drawerIntent?: ChatComposerDrawerIntent;\n disabled?: boolean;\n submitDisabled?: boolean;\n onFilesSelected?: (files: File[]) => void;\n} & (\n | { action?: 'send' | 'sending'; onStop?: never }\n | { action: 'stop'; onStop: () => void }\n );\n\n// A disabled or read-only part of the composer, such as a read-only message\n// input, does not accept input, so files dropped or pasted onto it are not\n// attached either.\nfunction isAttachmentTargetBlocked(target: EventTarget) {\n return (\n target instanceof Element &&\n target.closest(\n ':disabled, [readonly], [aria-disabled=\"true\"], [aria-readonly=\"true\"]'\n ) !== null\n );\n}\n\n// A fieldset is barred from constraint validation, so its own\n// reportValidity() never inspects the controls inside it.\nfunction reportFieldsetValidity(fieldset: HTMLFieldSetElement | null) {\n for (const element of fieldset?.elements ?? []) {\n if (\n (element instanceof HTMLInputElement ||\n element instanceof HTMLSelectElement ||\n element instanceof HTMLTextAreaElement) &&\n !element.reportValidity()\n )\n return false;\n }\n return true;\n}\n\nexport function ChatComposer({\n children,\n drawer,\n drawerIntent = 'neutral',\n className,\n ref,\n disabled = false,\n submitDisabled = false,\n action = 'send',\n onStop,\n onSubmit,\n onFilesSelected,\n onDragOver,\n onDragLeave,\n onDropCapture,\n onPasteCapture,\n noValidate,\n ...props\n}: ChatComposerProps) {\n const formRef = useRef<HTMLFormElement>(null);\n const [isDropTarget, setIsDropTarget] = useState(false);\n const canSubmit =\n !disabled && !submitDisabled && action === 'send' && !!onSubmit;\n const hasDrawer = Boolean(drawer);\n const fieldsetRef = useRef<HTMLFieldSetElement>(null);\n const inputFocusRef = useRef<(() => boolean) | null>(null);\n // Inert drawer fields cannot be focused to report errors, so the drawer's\n // host validates them; fields outside the drawer keep native checks.\n const validatesFieldsetOnly = noValidate === undefined && hasDrawer;\n\n return (\n <ChatComposerContext.Provider\n value={{\n disabled,\n canSubmit,\n action,\n onStop,\n onFilesSelected,\n inputFocusRef,\n submit: onSubmit\n ? () => {\n if (canSubmit) formRef.current?.requestSubmit();\n }\n : undefined,\n }}\n >\n <form\n {...props}\n ref={mergeRefs([formRef, ref])}\n noValidate={noValidate ?? hasDrawer}\n className={cn('isolate w-full min-w-0 @container/composer', className)}\n onSubmit={(event) => {\n event.preventDefault();\n if (!canSubmit) return;\n if (\n validatesFieldsetOnly &&\n !reportFieldsetValidity(fieldsetRef.current)\n )\n return;\n onSubmit?.(event);\n }}\n onDragOver={(event) => {\n onDragOver?.(event);\n if (event.defaultPrevented || !onFilesSelected) return;\n if (!event.dataTransfer.types.includes('Files')) return;\n event.preventDefault();\n const canAttach =\n !disabled && !isAttachmentTargetBlocked(event.target);\n event.dataTransfer.dropEffect = canAttach ? 'copy' : 'none';\n setIsDropTarget(canAttach);\n }}\n onDragLeave={(event) => {\n onDragLeave?.(event);\n if (\n !(event.relatedTarget instanceof Node) ||\n !event.currentTarget.contains(event.relatedTarget)\n ) {\n setIsDropTarget(false);\n }\n }}\n onDropCapture={(event) => {\n onDropCapture?.(event);\n setIsDropTarget(false);\n if (event.defaultPrevented || !onFilesSelected) return;\n const files = Array.from(event.dataTransfer.files);\n if (!files.length) return;\n event.preventDefault();\n if (!disabled && !isAttachmentTargetBlocked(event.target)) {\n onFilesSelected(files);\n }\n }}\n onPasteCapture={(event) => {\n onPasteCapture?.(event);\n if (event.defaultPrevented || !onFilesSelected) return;\n const files = Array.from(event.clipboardData.files);\n if (!files.length) return;\n if (disabled || isAttachmentTargetBlocked(event.target)) {\n event.preventDefault();\n return;\n }\n // Let the focused editor preserve mixed-paste text and its selection.\n if (!event.clipboardData.getData('text/plain')) {\n event.preventDefault();\n }\n onFilesSelected(files);\n }}\n >\n {hasDrawer && (\n <fieldset\n disabled={disabled}\n className={cn(\n // Extends under the composer's rounded top so the seam stays hidden.\n 'mx-space-3 -mb-space-3 max-h-[50dvh] min-w-0 overflow-y-auto overscroll-contain rounded-t-xl border border-b-0 pb-space-3 duration-normal ease-out animate-in fade-in slide-in-from-bottom-2 motion-reduce:animate-none',\n DRAWER_INTENT_CLASSES[drawerIntent],\n disabled && 'border-disabled'\n )}\n >\n {drawer}\n </fieldset>\n )}\n <fieldset\n ref={fieldsetRef}\n disabled={disabled}\n className={cn(\n 'relative m-0 flex w-full min-w-0 flex-col gap-space-2 rounded-xl border border-subtle bg-elevated p-space-2 transition-[border-color,box-shadow,background-color] duration-normal motion-reduce:transition-none',\n // Toolbar menus portal out, so focus-within would flash as focus\n // moves from their trigger to the menu; only typing shows focus.\n 'has-[:is(textarea,[contenteditable=true]):focus]:border-focus has-[:is(textarea,[contenteditable=true]):focus]:shadow-[0_0_0_1px_var(--border-focus)]',\n disabled && 'border-disabled bg-input-disabled',\n isDropTarget &&\n !disabled &&\n 'border-focus bg-surface-level-2 shadow-[0_0_0_1px_var(--border-focus)]'\n )}\n >\n {children}\n </fieldset>\n </form>\n </ChatComposerContext.Provider>\n );\n}\n\nexport interface ChatComposerToolbarProps extends ComponentPropsWithRef<'div'> {\n modelSelector?: ReactNode;\n actions?: ReactNode;\n}\n\nexport function ChatComposerToolbar({\n children,\n modelSelector,\n actions = <ChatComposerAction />,\n className,\n ...props\n}: ChatComposerToolbarProps) {\n return (\n <div\n {...props}\n className={cn('flex min-w-0 items-center gap-space-2', className)}\n >\n <div className=\"flex min-w-0 flex-1 flex-wrap items-center gap-space-1 @[440px]/composer:gap-space-2\">\n {children}\n {modelSelector != null && (\n <div className=\"min-w-0 max-w-full [&>*]:max-w-full\">\n {modelSelector}\n </div>\n )}\n </div>\n <div className=\"flex shrink-0 items-center gap-space-1\">{actions}</div>\n </div>\n );\n}\n\nconst ACTION_LABELS = {\n send: 'Send message',\n sending: 'Sending message',\n stop: 'Stop response',\n} satisfies Record<ChatComposerContextValue['action'], string>;\n\n// Pending sends use the composer's action=\"sending\", which also blocks the\n// send shortcuts; a button-level loading state would only block clicks.\nexport type ChatComposerActionProps = Omit<\n IconButtonProps,\n 'icon' | 'type' | 'onClick' | 'asChild' | 'label' | 'loading'\n> & { label?: string };\n\nexport function ChatComposerAction({\n disabled,\n label,\n ...props\n}: ChatComposerActionProps) {\n const composer = useChatComposerContext();\n const isStop = composer.action === 'stop';\n return (\n <IconButton\n size=\"sm\"\n round\n color=\"primary\"\n iconWeight=\"regular\"\n {...props}\n type={isStop ? 'button' : 'submit'}\n icon={isStop ? StopIcon : ArrowUpIcon}\n label={label ?? ACTION_LABELS[composer.action]}\n disabled={\n composer.disabled || disabled || (!isStop && !composer.canSubmit)\n }\n loading={composer.action === 'sending'}\n onClick={isStop ? composer.onStop : undefined}\n />\n );\n}\n"],"mappings":";;;;;;;;;AAkBA,IAAM,wBAAkE;CACtE,SAAS;CACT,MAAM;CACN,SAAS;CACT,OAAO;AACT;AAqBA,SAAS,0BAA0B,QAAqB;CACtD,OACE,kBAAkB,WAClB,OAAO,QACL,2EACF,MAAM;AAEV;AAIA,SAAS,uBAAuB,UAAsC;CACpE,KAAK,MAAM,WAAW,UAAU,YAAY,CAAC,GAC3C,KACG,mBAAmB,oBAClB,mBAAmB,qBACnB,mBAAmB,wBACrB,CAAC,QAAQ,eAAe,GAExB,OAAO;CAEX,OAAO;AACT;AAEA,SAAgB,aAAa,EAC3B,UACA,QACA,eAAe,WACf,WACA,KACA,WAAW,OACX,iBAAiB,OACjB,SAAS,QACT,QACA,UACA,iBACA,YACA,aACA,eACA,gBACA,YACA,GAAG,SACiB;CACpB,MAAM,UAAU,OAAwB,IAAI;CAC5C,MAAM,CAAC,cAAc,mBAAmB,SAAS,KAAK;CACtD,MAAM,YACJ,CAAC,YAAY,CAAC,kBAAkB,WAAW,UAAU,CAAC,CAAC;CACzD,MAAM,YAAY,QAAQ,MAAM;CAChC,MAAM,cAAc,OAA4B,IAAI;CACpD,MAAM,gBAAgB,OAA+B,IAAI;CAGzD,MAAM,wBAAwB,eAAe,KAAA,KAAa;CAE1D,OACE,oBAAC,oBAAoB,UAArB;EACE,OAAO;GACL;GACA;GACA;GACA;GACA;GACA;GACA,QAAQ,iBACE;IACJ,IAAI,WAAW,QAAQ,SAAS,cAAc;GAChD,IACA,KAAA;EACN;EAEA,UAAA,qBAAC,QAAD;GACE,GAAI;GACJ,KAA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F,UAAA,CA6DG,aACC,oBAAC,YAAD;IACY;IACV,WAAW,GAET,2NACA,sBAAsB,eACtB,YAAY,iBACd;IAEC,UAAA;GACO,CAAA,GAEZ,oBAAC,YAAD;IACE,KAAK;IACK;IACV,WAAW,GACT,mNAGA,yJACA,YAAY,qCACZ,gBACE,CAAC,YACD,wEACJ;IAEC;GACO,CAAA,CACN;;CACsB,CAAA;AAElC;AAOA,SAAgB,oBAAoB,EAClC,UACA,eACA,UAAU,oBAAC,oBAAD,CAAqB,CAAA,GAC/B,WACA,GAAG,SACwB;CAC3B,OACE,qBAAC,OAAD;EACE,GAAI;EACJ,WAAW,GAAG,yCAAyC,SAAS;EAFlE,UAAA,CAIE,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACG,UACA,iBAAiB,QAChB,oBAAC,OAAD;IAAK,WAAU;IACZ,UAAA;GACE,CAAA,CAEJ;EACL,CAAA,GAAA,oBAAC,OAAD;GAAK,WAAU;GAA0C,UAAA;EAAa,CAAA,CACnE;;AAET;AAEA,IAAM,gBAAgB;CACpB,MAAM;CACN,SAAS;CACT,MAAM;AACR;AASA,SAAgB,mBAAmB,EACjC,UACA,OACA,GAAG,SACuB;CAC1B,MAAM,WAAW,uBAAuB;CACxC,MAAM,SAAS,SAAS,WAAW;CACnC,OACE,oBAAC,YAAD;EACE,MAAK;EACL,OAAA;EACA,OAAM;EACN,YAAW;EACX,GAAI;EACJ,MAAM,SAAS,WAAW;EAC1B,MAAM,SAAS,WAAW;EAC1B,OAAO,SAAS,cAAc,SAAS;EACvC,UACE,SAAS,YAAY,YAAa,CAAC,UAAU,CAAC,SAAS;EAEzD,SAAS,SAAS,WAAW;EAC7B,SAAS,SAAS,SAAS,SAAS,KAAA;CACrC,CAAA;AAEL"}
@@ -0,0 +1,17 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { AttachmentProps, AttachmentListProps } from '../Attachment/index.js';
3
+ import type { IconButtonProps } from '../IconButton/index.js';
4
+ export interface ChatComposerAttachmentMenuProps {
5
+ accept?: string;
6
+ size?: IconButtonProps['size'];
7
+ multiple?: boolean;
8
+ disabled?: boolean;
9
+ label?: string;
10
+ children?: ReactNode;
11
+ }
12
+ export declare function ChatComposerAttachmentMenu({ accept, size, multiple, disabled, label, children, }: ChatComposerAttachmentMenuProps): import("react").JSX.Element;
13
+ export interface ChatComposerAttachmentsProps extends AttachmentListProps, Pick<AttachmentProps, 'size' | 'variant'> {
14
+ }
15
+ export declare function ChatComposerAttachments({ className, layout, size, variant, ...props }: ChatComposerAttachmentsProps): import("react").JSX.Element;
16
+ export type ChatComposerAttachmentProps = AttachmentProps;
17
+ export declare function ChatComposerAttachment({ disabled, size, variant, ...props }: ChatComposerAttachmentProps): import("react").JSX.Element;
@@ -0,0 +1,117 @@
1
+ import { cn } from "../../utils/cn.js";
2
+ import { Text } from "../Text/Text.js";
3
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "../DropdownMenu/DropdownMenu.js";
4
+ import { IconButton } from "../IconButton/IconButton.js";
5
+ import { Attachment } from "../Attachment/Attachment.js";
6
+ import { AttachmentList } from "../Attachment/AttachmentList.js";
7
+ import { useChatComposerContext } from "./ChatComposerContext.js";
8
+ import { createContext, useContext, useRef, useState } from "react";
9
+ import { PlusIcon } from "@phosphor-icons/react/dist/ssr/Plus";
10
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
11
+ import { PaperclipIcon } from "@phosphor-icons/react/dist/ssr/Paperclip";
12
+ //#region packages/components/src/components/ChatComposer/ChatComposerAttachments.tsx
13
+ function ChatComposerAttachmentMenu({ accept, size = "sm", multiple = true, disabled = false, label = "Add attachments", children }) {
14
+ const composer = useChatComposerContext();
15
+ const fileInputRef = useRef(null);
16
+ const isDisabled = composer.disabled || disabled;
17
+ const [menuOpen, setMenuOpen] = useState(false);
18
+ const [tooltipOpen, setTooltipOpen] = useState(false);
19
+ const pointerOverTrigger = useRef(false);
20
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs(DropdownMenu, {
21
+ modal: false,
22
+ open: menuOpen,
23
+ onOpenChange: (open) => {
24
+ setMenuOpen(open);
25
+ setTooltipOpen(false);
26
+ },
27
+ children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
28
+ asChild: true,
29
+ disabled: isDisabled,
30
+ children: /* @__PURE__ */ jsx(IconButton, {
31
+ type: "button",
32
+ icon: PlusIcon,
33
+ iconWeight: "regular",
34
+ label,
35
+ size,
36
+ color: "secondary",
37
+ variant: "plain",
38
+ disabled: isDisabled,
39
+ onPointerEnter: () => {
40
+ pointerOverTrigger.current = true;
41
+ },
42
+ onPointerLeave: () => {
43
+ pointerOverTrigger.current = false;
44
+ },
45
+ tooltipProps: {
46
+ open: tooltipOpen,
47
+ onOpenChange: (open) => setTooltipOpen(open && pointerOverTrigger.current && !menuOpen)
48
+ }
49
+ })
50
+ }), /* @__PURE__ */ jsxs(DropdownMenuContent, {
51
+ side: "top",
52
+ align: "start",
53
+ collisionPadding: 16,
54
+ className: "max-w-[var(--radix-dropdown-menu-content-available-width)]",
55
+ children: [/* @__PURE__ */ jsxs(DropdownMenuItem, {
56
+ disabled: isDisabled || !composer.onFilesSelected,
57
+ className: "gap-space-2",
58
+ onSelect: () => {
59
+ if (!isDisabled) fileInputRef.current?.click();
60
+ },
61
+ children: [/* @__PURE__ */ jsx(PaperclipIcon, {
62
+ size: 16,
63
+ weight: "regular",
64
+ "aria-hidden": true
65
+ }), /* @__PURE__ */ jsx(Text, {
66
+ as: "span",
67
+ variant: "sm",
68
+ children: "Upload files"
69
+ })]
70
+ }), children]
71
+ })]
72
+ }), /* @__PURE__ */ jsx("input", {
73
+ ref: fileInputRef,
74
+ type: "file",
75
+ "aria-label": "Upload files",
76
+ className: "hidden",
77
+ accept,
78
+ multiple,
79
+ disabled: isDisabled,
80
+ onChange: (event) => {
81
+ const files = Array.from(event.currentTarget.files ?? []);
82
+ event.currentTarget.value = "";
83
+ if (!isDisabled && files.length) composer.onFilesSelected?.(files);
84
+ }
85
+ })] });
86
+ }
87
+ var AttachmentAppearanceContext = createContext({
88
+ size: "md",
89
+ variant: "file"
90
+ });
91
+ function ChatComposerAttachments({ className, layout = "scroll", size = "md", variant = "file", ...props }) {
92
+ return /* @__PURE__ */ jsx(AttachmentAppearanceContext.Provider, {
93
+ value: {
94
+ size,
95
+ variant
96
+ },
97
+ children: /* @__PURE__ */ jsx(AttachmentList, {
98
+ ...props,
99
+ layout,
100
+ className: cn("no-scrollbar scroll-mask-l scroll-mask-r", className)
101
+ })
102
+ });
103
+ }
104
+ function ChatComposerAttachment({ disabled, size, variant, ...props }) {
105
+ const composer = useChatComposerContext();
106
+ const appearance = useContext(AttachmentAppearanceContext);
107
+ return /* @__PURE__ */ jsx(Attachment, {
108
+ ...props,
109
+ size: size ?? appearance.size,
110
+ variant: variant ?? appearance.variant,
111
+ disabled: composer.disabled || disabled
112
+ });
113
+ }
114
+ //#endregion
115
+ export { ChatComposerAttachment, ChatComposerAttachmentMenu, ChatComposerAttachments };
116
+
117
+ //# sourceMappingURL=ChatComposerAttachments.js.map