rdesign/frontend/node_modules/@copilotkitnext/react/dist/components/chat/CopilotChatSuggestionView.cjs

71 lines
2.9 KiB
JavaScript

const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
const require_utils = require('../../lib/utils.cjs');
const require_slots = require('../../lib/slots.cjs');
const require_CopilotChatSuggestionPill = require('./CopilotChatSuggestionPill.cjs');
let react = require("react");
react = require_runtime.__toESM(react);
let react_jsx_runtime = require("react/jsx-runtime");
//#region src/components/chat/CopilotChatSuggestionView.tsx
const DefaultContainer = react.default.forwardRef(function DefaultContainer({ className, ...props }, ref) {
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
ref,
"data-copilotkit": true,
"data-testid": "copilot-suggestions",
className: require_utils.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.default.forwardRef(function CopilotChatSuggestionView({ suggestions, onSelectSuggestion, loadingIndexes, container, suggestion: suggestionSlot, className, children, ...restProps }, ref) {
const loadingSet = react.default.useMemo(() => {
if (!loadingIndexes || loadingIndexes.length === 0) return /* @__PURE__ */ new Set();
return new Set(loadingIndexes);
}, [loadingIndexes]);
const ContainerElement = require_slots.renderSlot(container, DefaultContainer, {
ref,
className,
...restProps
});
const suggestionElements = suggestions.map((suggestion, index) => {
const isLoading = loadingSet.has(index) || suggestion.isLoading === true;
const pill = require_slots.renderSlot(suggestionSlot, require_CopilotChatSuggestionPill.default, {
children: suggestion.title,
isLoading,
type: "button",
onClick: () => onSelectSuggestion?.(suggestion, index)
});
return react.default.cloneElement(pill, { key: `${suggestion.title}-${index}` });
});
const boundContainer = react.default.cloneElement(ContainerElement, void 0, suggestionElements);
if (typeof children === "function") {
const sampleSuggestion = require_slots.renderSlot(suggestionSlot, require_CopilotChatSuggestionPill.default, {
children: suggestions[0]?.title ?? "",
isLoading: suggestions.length > 0 ? loadingSet.has(0) || suggestions[0]?.isLoading === true : false,
type: "button"
});
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
"data-copilotkit": true,
style: { display: "contents" },
children: children({
container: boundContainer,
suggestion: sampleSuggestion,
suggestions,
onSelectSuggestion,
loadingIndexes,
className,
...restProps
})
});
}
if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
"data-copilotkit": true,
style: { display: "contents" },
children: [boundContainer, children]
});
return boundContainer;
});
CopilotChatSuggestionView.displayName = "CopilotChatSuggestionView";
//#endregion
exports.default = CopilotChatSuggestionView;
//# sourceMappingURL=CopilotChatSuggestionView.cjs.map