69 lines
2.6 KiB
JavaScript
69 lines
2.6 KiB
JavaScript
import { cn } from "../../lib/utils.mjs";
|
|
import { renderSlot } from "../../lib/slots.mjs";
|
|
import CopilotChatSuggestionPill from "./CopilotChatSuggestionPill.mjs";
|
|
import React from "react";
|
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
|
//#region src/components/chat/CopilotChatSuggestionView.tsx
|
|
const DefaultContainer = React.forwardRef(function DefaultContainer({ className, ...props }, ref) {
|
|
return /* @__PURE__ */ jsx("div", {
|
|
ref,
|
|
"data-copilotkit": true,
|
|
"data-testid": "copilot-suggestions",
|
|
className: cn("cpk:flex cpk:flex-wrap cpk:items-center cpk:gap-1.5 cpk:sm:gap-2 cpk:pl-0 cpk:pr-4 cpk:sm:px-0 cpk:pointer-events-none", className),
|
|
...props
|
|
});
|
|
});
|
|
const CopilotChatSuggestionView = React.forwardRef(function CopilotChatSuggestionView({ suggestions, onSelectSuggestion, loadingIndexes, container, suggestion: suggestionSlot, className, children, ...restProps }, ref) {
|
|
const loadingSet = React.useMemo(() => {
|
|
if (!loadingIndexes || loadingIndexes.length === 0) return /* @__PURE__ */ new Set();
|
|
return new Set(loadingIndexes);
|
|
}, [loadingIndexes]);
|
|
const ContainerElement = renderSlot(container, DefaultContainer, {
|
|
ref,
|
|
className,
|
|
...restProps
|
|
});
|
|
const suggestionElements = suggestions.map((suggestion, index) => {
|
|
const isLoading = loadingSet.has(index) || suggestion.isLoading === true;
|
|
const pill = renderSlot(suggestionSlot, CopilotChatSuggestionPill, {
|
|
children: suggestion.title,
|
|
isLoading,
|
|
type: "button",
|
|
onClick: () => onSelectSuggestion?.(suggestion, index)
|
|
});
|
|
return React.cloneElement(pill, { key: `${suggestion.title}-${index}` });
|
|
});
|
|
const boundContainer = React.cloneElement(ContainerElement, void 0, suggestionElements);
|
|
if (typeof children === "function") {
|
|
const sampleSuggestion = renderSlot(suggestionSlot, CopilotChatSuggestionPill, {
|
|
children: suggestions[0]?.title ?? "",
|
|
isLoading: suggestions.length > 0 ? loadingSet.has(0) || suggestions[0]?.isLoading === true : false,
|
|
type: "button"
|
|
});
|
|
return /* @__PURE__ */ jsx("div", {
|
|
"data-copilotkit": true,
|
|
style: { display: "contents" },
|
|
children: children({
|
|
container: boundContainer,
|
|
suggestion: sampleSuggestion,
|
|
suggestions,
|
|
onSelectSuggestion,
|
|
loadingIndexes,
|
|
className,
|
|
...restProps
|
|
})
|
|
});
|
|
}
|
|
if (children) return /* @__PURE__ */ jsxs("div", {
|
|
"data-copilotkit": true,
|
|
style: { display: "contents" },
|
|
children: [boundContainer, children]
|
|
});
|
|
return boundContainer;
|
|
});
|
|
CopilotChatSuggestionView.displayName = "CopilotChatSuggestionView";
|
|
|
|
//#endregion
|
|
export { CopilotChatSuggestionView as default };
|
|
//# sourceMappingURL=CopilotChatSuggestionView.mjs.map
|