impact-ui 5.0.4-alpha.3 → 5.0.4-chatbot.2
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/dist/_virtual/ArrowBack.js +4 -0
- package/dist/_virtual/AttachFileOutlined.js +4 -0
- package/dist/_virtual/ContentCopyOutlined.js +4 -0
- package/dist/_virtual/Menu.js +4 -0
- package/dist/_virtual/NorthRounded.js +4 -0
- package/dist/_virtual/RefreshOutlined.js +4 -0
- package/dist/_virtual/StopRounded.js +4 -0
- package/dist/_virtual/VolumeUpOutlined.js +4 -0
- package/dist/_virtual/index2.js +2 -2
- package/dist/_virtual/index3.js +2 -2
- package/dist/components/AccordionModern/index.js +1 -1
- package/dist/components/Badge/index.js +1 -1
- package/dist/components/Breadcrumbs/index.js +1 -1
- package/dist/components/Button/index.js +1 -1
- package/dist/components/ButtonGroup/index.js +1 -1
- package/dist/components/Chatbot/Chatbot.types.d.ts +253 -186
- package/dist/components/Chatbot/Chatbot.types.d.ts.map +1 -1
- package/dist/components/Chatbot/chatBotFooter.d.ts +1 -1
- package/dist/components/Chatbot/chatBotFooter.d.ts.map +1 -1
- package/dist/components/Chatbot/chatBotFooter.js +21 -4
- package/dist/components/Chatbot/chatbotComposer.d.ts +4 -0
- package/dist/components/Chatbot/chatbotComposer.d.ts.map +1 -0
- package/dist/components/Chatbot/chatbotComposer.js +328 -0
- package/dist/components/Chatbot/chatbotGreetingHeader.d.ts +4 -0
- package/dist/components/Chatbot/chatbotGreetingHeader.d.ts.map +1 -0
- package/dist/components/Chatbot/chatbotGreetingHeader.js +226 -0
- package/dist/components/Chatbot/greetingWeather.d.ts +23 -0
- package/dist/components/Chatbot/greetingWeather.d.ts.map +1 -0
- package/dist/components/Chatbot/greetingWeather.js +81 -0
- package/dist/components/Chatbot/greetingWeather.test.d.ts +2 -0
- package/dist/components/Chatbot/greetingWeather.test.d.ts.map +1 -0
- package/dist/components/Chatbot/index.d.ts +5 -2
- package/dist/components/Chatbot/index.d.ts.map +1 -1
- package/dist/components/Chatbot/index.js +390 -421
- package/dist/components/Chatbot/irisConversationThread.d.ts +24 -0
- package/dist/components/Chatbot/irisConversationThread.d.ts.map +1 -0
- package/dist/components/Chatbot/irisConversationThread.js +511 -0
- package/dist/components/Chatbot/irisGreetingBackdrop.d.ts +5 -0
- package/dist/components/Chatbot/irisGreetingBackdrop.d.ts.map +1 -0
- package/dist/components/Chatbot/irisGreetingBackdrop.js +62 -0
- package/dist/components/Chatbot/irisMenuListItem.d.ts +11 -0
- package/dist/components/Chatbot/irisMenuListItem.d.ts.map +1 -0
- package/dist/components/Chatbot/irisMenuListItem.js +126 -0
- package/dist/components/Chatbot/irisMenuScreen.d.ts +4 -0
- package/dist/components/Chatbot/irisMenuScreen.d.ts.map +1 -0
- package/dist/components/Chatbot/irisMenuScreen.js +357 -0
- package/dist/components/Chatbot/irisThinking.d.ts +7 -0
- package/dist/components/Chatbot/irisThinking.d.ts.map +1 -0
- package/dist/components/Chatbot/irisThinking.js +219 -0
- package/dist/components/Chatbot/newChatComponent.d.ts +1 -1
- package/dist/components/Chatbot/newChatComponent.d.ts.map +1 -1
- package/dist/components/Chatbot/newChatComponent.js +497 -72
- package/dist/components/Chips/index.js +1 -1
- package/dist/components/CommentsPanel/CommentsPanel.impl.js +1 -1
- package/dist/components/DatePicker/DatePicker.types.d.ts +0 -4
- package/dist/components/DatePicker/DatePicker.types.d.ts.map +1 -1
- package/dist/components/DatePicker/datePickerInput.d.ts +0 -2
- package/dist/components/DatePicker/datePickerInput.d.ts.map +1 -1
- package/dist/components/DatePicker/datePickerInput.js +2 -32
- package/dist/components/DatePicker/index.d.ts.map +1 -1
- package/dist/components/DatePicker/index.js +1 -5
- package/dist/components/DatePicker/showMonthYearSelect.d.ts.map +1 -1
- package/dist/components/DatePicker/showMonthYearSelect.js +0 -2
- package/dist/components/DateRangePicker/index.js +1 -1
- package/dist/components/DateRangePicker/showMonthYearSelect.d.ts.map +1 -1
- package/dist/components/DateRangePicker/showMonthYearSelect.js +0 -2
- package/dist/components/FileUpload/index.js +1 -1
- package/dist/components/FilterPanel/index.js +1 -1
- package/dist/components/FiltersStrip/FilterSlider.js +1 -1
- package/dist/components/FiltersStrip/index.js +1 -1
- package/dist/components/Input/index.js +1 -1
- package/dist/components/KeyboardShortCuts/ShortcutLandingPage.js +1 -1
- package/dist/components/KeyboardShortCuts/ShortcutModal.js +1 -1
- package/dist/components/KeyboardShortCuts/allSetBox.js +1 -1
- package/dist/components/KeyboardShortCuts/index.js +1 -1
- package/dist/components/KeyboardShortCuts/tutorial.js +1 -1
- package/dist/components/Menu/IconMenuItem.js +1 -1
- package/dist/components/Menu/NestedMenuItem.js +1 -1
- package/dist/components/Menu/index.js +1 -1
- package/dist/components/Menu/nestedMenuItemsFromObject.js +1 -1
- package/dist/components/Modal/index.js +1 -1
- package/dist/components/MonthPicker/index.js +1 -1
- package/dist/components/MonthRangePicker/index.js +1 -1
- package/dist/components/NewCreateItemFlow/index.js +1 -1
- package/dist/components/NewDynamicLayout/index.js +1 -1
- package/dist/components/OnboardingTour/index.js +1 -1
- package/dist/components/OnboardingTour/productTourList.js +1 -1
- package/dist/components/OnboardingTour/tooltipCard.js +1 -1
- package/dist/components/Panel/index.js +1 -1
- package/dist/components/Popover/index.js +1 -1
- package/dist/components/Prompt/index.js +1 -1
- package/dist/components/Select/Select.types.d.ts +0 -7
- package/dist/components/Select/Select.types.d.ts.map +1 -1
- package/dist/components/Select/index.d.ts.map +1 -1
- package/dist/components/Select/index.js +26 -44
- package/dist/components/Stepper/index.js +1 -1
- package/dist/components/TableChat/EmptyContainer.js +1 -1
- package/dist/components/TableChat/TableChatSidePanel.js +1 -1
- package/dist/components/TableChat/components/TableChatLeftSection/AddChatContainer/AddChatContainer.js +1 -1
- package/dist/components/TableChat/components/TableChatLeftSection/ChatFilterChips/ChatFilterChips.js +1 -1
- package/dist/components/TableChat/components/TableChatLeftSection/TableChatChannelHeader.js +1 -1
- package/dist/components/TableChat/components/TableChatRightSection/AvatarGroup/AvatarGroup.js +1 -1
- package/dist/components/TableChat/components/TableChatRightSection/ChatDefaultMessageType/ChatDefaultMessageType.js +1 -1
- package/dist/components/TableChat/components/TableChatRightSection/ChatDeleteMessageType/ChatDeletedMessageType.js +1 -1
- package/dist/components/TableChat/components/TableChatRightSection/ChatHeader/ChatHeader.js +1 -1
- package/dist/components/TableChat/components/TableChatRightSection/ChatInlineEdit/ChatInlineEdit.js +1 -1
- package/dist/components/TableChat/components/TableChatRightSection/ChatInput/ChatInput.js +1 -1
- package/dist/components/TableChat/components/TableChatRightSection/ChatMessages/ChatMessage.js +1 -1
- package/dist/components/TableChat/components/TableChatRightSection/ChatNotificationSettings/ChatNotificationSettings.js +1 -1
- package/dist/components/TableChat/components/TableChatRightSection/TableChatRightSection.js +1 -1
- package/dist/components/TableChat/components/TextEditor/EditorToolbar.js +1 -1
- package/dist/components/TableChat/components/TextEditor/Mention.js +1 -1
- package/dist/components/TableChat/components/TextEditor/MentionList.js +1 -1
- package/dist/components/TableV36/AgGridHeader.d.ts.map +1 -1
- package/dist/components/TableV36/AgGridHeader.js +115 -107
- package/dist/components/TableV36/index.js +1 -1
- package/dist/components/Tag/index.js +1 -1
- package/dist/components/TextArea/index.js +1 -1
- package/dist/components/common/MentionEditor/MentionList/index.js +1 -1
- package/dist/components/common/MentionEditor/index.js +1 -1
- package/dist/components/index.d.ts +3 -2
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +3 -0
- package/dist/hooks/useDraggableResizable.d.ts +11 -1
- package/dist/hooks/useDraggableResizable.d.ts.map +1 -1
- package/dist/hooks/useDraggableResizable.js +73 -59
- package/dist/locales/de-DE.json.d.ts +50 -30
- package/dist/locales/de-DE.json.js +50 -30
- package/dist/locales/en-US.json.d.ts +50 -30
- package/dist/locales/en-US.json.js +50 -30
- package/dist/locales/es-ES.json.d.ts +50 -30
- package/dist/locales/es-ES.json.js +50 -30
- package/dist/mcp-component-registry.json +65 -263
- package/dist/node_modules/@impactsmartsuite/impact-icons/dist/index.js +43 -15
- package/dist/node_modules/@mui/icons-material/ArrowBack.js +17 -0
- package/dist/node_modules/@mui/icons-material/AttachFileOutlined.js +17 -0
- package/dist/node_modules/@mui/icons-material/ContentCopyOutlined.js +17 -0
- package/dist/node_modules/@mui/icons-material/Menu.js +17 -0
- package/dist/node_modules/@mui/icons-material/NorthRounded.js +17 -0
- package/dist/node_modules/@mui/icons-material/RefreshOutlined.js +17 -0
- package/dist/node_modules/@mui/icons-material/StopRounded.js +17 -0
- package/dist/node_modules/@mui/icons-material/VolumeUpOutlined.js +17 -0
- package/dist/node_modules/prop-types/index.js +1 -1
- package/dist/node_modules/react-is/index.js +1 -1
- package/dist/stories/chatBotApiMock.d.ts +91 -0
- package/dist/stories/chatBotApiMock.d.ts.map +1 -0
- package/dist/styles/style.css +1 -1
- package/package.json +2 -2
- package/dist/_virtual/MoreVert.js +0 -4
- package/dist/_virtual/RemoveRounded.js +0 -4
- package/dist/_virtual/SaveOutlined.js +0 -4
- package/dist/components/Chatbot/bookMarkPanel.d.ts +0 -4
- package/dist/components/Chatbot/bookMarkPanel.d.ts.map +0 -1
- package/dist/components/Chatbot/bookMarkPanel.js +0 -64
- package/dist/components/Chatbot/chatBotLandingScreen.d.ts +0 -4
- package/dist/components/Chatbot/chatBotLandingScreen.d.ts.map +0 -1
- package/dist/components/Chatbot/chatBotLandingScreen.js +0 -24
- package/dist/components/Chatbot/chatInput.d.ts +0 -4
- package/dist/components/Chatbot/chatInput.d.ts.map +0 -1
- package/dist/components/Chatbot/chatInput.js +0 -198
- package/dist/components/Chatbot/chatbotModuleMenu.d.ts +0 -4
- package/dist/components/Chatbot/chatbotModuleMenu.d.ts.map +0 -1
- package/dist/components/Chatbot/chatbotModuleMenu.js +0 -248
- package/dist/components/Chatbot/constant.d.ts +0 -6
- package/dist/components/Chatbot/constant.d.ts.map +0 -1
- package/dist/components/Chatbot/constant.js +0 -27
- package/dist/components/Chatbot/conversationScreen.d.ts +0 -4
- package/dist/components/Chatbot/conversationScreen.d.ts.map +0 -1
- package/dist/components/Chatbot/conversationScreen.js +0 -207
- package/dist/components/Chatbot/customScreen.d.ts +0 -4
- package/dist/components/Chatbot/customScreen.d.ts.map +0 -1
- package/dist/components/Chatbot/customScreen.js +0 -66
- package/dist/components/Chatbot/historyPanel.d.ts +0 -4
- package/dist/components/Chatbot/historyPanel.d.ts.map +0 -1
- package/dist/components/Chatbot/historyPanel.js +0 -374
- package/dist/components/Chatbot/utils.d.ts +0 -5
- package/dist/components/Chatbot/utils.d.ts.map +0 -1
- package/dist/components/Chatbot/utils.js +0 -29
- package/dist/node_modules/@mui/icons-material/MoreVert.js +0 -17
- package/dist/node_modules/@mui/icons-material/RemoveRounded.js +0 -17
- package/dist/node_modules/@mui/icons-material/SaveOutlined.js +0 -17
- package/dist/utils/onResize.js +0 -28
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState, useEffect } from "react";
|
|
3
|
+
import default_1 from "../../node_modules/@mui/icons-material/Add.js";
|
|
4
|
+
import default_1$1 from "../../node_modules/@mui/icons-material/AttachFileOutlined.js";
|
|
5
|
+
import default_1$3 from "../../node_modules/@mui/icons-material/KeyboardArrowDown.js";
|
|
6
|
+
import default_1$2 from "../../node_modules/@mui/icons-material/KeyboardArrowUp.js";
|
|
7
|
+
import { ChatbotFloating as ChatbotFloating_default, ChatbotSidebar as ChatbotSidebar_default, ChatbotCollapse as ChatbotCollapse_default, ChatbotFullScreen as ChatbotFullScreen_default, ChatBotMicIcon as ChatBotMicIcon_default } from "../../node_modules/@impactsmartsuite/impact-icons/dist/index.js";
|
|
8
|
+
import default_1$4 from "../../node_modules/@mui/icons-material/StopRounded.js";
|
|
9
|
+
import default_1$5 from "../../node_modules/@mui/icons-material/NorthRounded.js";
|
|
10
|
+
import TextareaAutosize from "react-textarea-autosize";
|
|
11
|
+
import { Button } from "../Button/index.js";
|
|
12
|
+
import { Menu } from "../Menu/index.js";
|
|
13
|
+
import { Tooltip } from "../Tooltip/index.js";
|
|
14
|
+
import { useTranslation } from "../../i18n/useTranslation.js";
|
|
15
|
+
const DEFAULT_MODEL = { label: "Auto", value: "auto" };
|
|
16
|
+
const COMPOSER_ACTION_SELECTOR = 'button, a, input, textarea, select, label, [role="button"], [role="menuitem"]';
|
|
17
|
+
const FLOATING_STACK_LINE_HEIGHT = 28;
|
|
18
|
+
function ChatbotComposer({
|
|
19
|
+
inputValue,
|
|
20
|
+
setInputValue,
|
|
21
|
+
handleMicClick,
|
|
22
|
+
customInputComponent,
|
|
23
|
+
modelOptions,
|
|
24
|
+
selectedModel,
|
|
25
|
+
onModelChange,
|
|
26
|
+
onAddClick,
|
|
27
|
+
onAttachClick,
|
|
28
|
+
onSend,
|
|
29
|
+
onStop,
|
|
30
|
+
isStopIcon = false,
|
|
31
|
+
placeholder,
|
|
32
|
+
isFloating = false,
|
|
33
|
+
onFloatingLayoutChange
|
|
34
|
+
}) {
|
|
35
|
+
const { t } = useTranslation();
|
|
36
|
+
const composerRef = useRef(null);
|
|
37
|
+
const textareaRef = useRef(null);
|
|
38
|
+
const [modelAnchorEl, setModelAnchorEl] = useState(null);
|
|
39
|
+
const [layoutAnchorEl, setLayoutAnchorEl] = useState(null);
|
|
40
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
41
|
+
const [isStacked, setIsStacked] = useState(false);
|
|
42
|
+
const isModelOpen = Boolean(modelAnchorEl);
|
|
43
|
+
const isLayoutMenuOpen = Boolean(layoutAnchorEl);
|
|
44
|
+
const hasContent = inputValue.trim().length > 0;
|
|
45
|
+
const isActive = isFocused || hasContent;
|
|
46
|
+
const options = (modelOptions == null ? void 0 : modelOptions.length) ? modelOptions : [DEFAULT_MODEL];
|
|
47
|
+
const activeOption = options.find((option) => option.value === selectedModel) ?? options[0] ?? DEFAULT_MODEL;
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!inputValue.trim()) {
|
|
50
|
+
setIsStacked(false);
|
|
51
|
+
}
|
|
52
|
+
}, [inputValue]);
|
|
53
|
+
const handleModelClose = () => {
|
|
54
|
+
setModelAnchorEl(null);
|
|
55
|
+
};
|
|
56
|
+
const handleLayoutMenuClose = () => {
|
|
57
|
+
setLayoutAnchorEl(null);
|
|
58
|
+
};
|
|
59
|
+
const handleLayoutSelect = (mode) => {
|
|
60
|
+
onFloatingLayoutChange == null ? void 0 : onFloatingLayoutChange(mode);
|
|
61
|
+
handleLayoutMenuClose();
|
|
62
|
+
};
|
|
63
|
+
const handleSend = () => {
|
|
64
|
+
if (!hasContent || isStopIcon) return;
|
|
65
|
+
onSend == null ? void 0 : onSend();
|
|
66
|
+
};
|
|
67
|
+
const handleBoxMouseDown = (event) => {
|
|
68
|
+
var _a;
|
|
69
|
+
const target = event.target;
|
|
70
|
+
if (target == null ? void 0 : target.closest(COMPOSER_ACTION_SELECTOR)) return;
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
73
|
+
};
|
|
74
|
+
if (customInputComponent) {
|
|
75
|
+
return /* @__PURE__ */ jsx("div", { className: "chatbot-composer", children: customInputComponent });
|
|
76
|
+
}
|
|
77
|
+
return /* @__PURE__ */ jsx(
|
|
78
|
+
"form",
|
|
79
|
+
{
|
|
80
|
+
ref: composerRef,
|
|
81
|
+
className: "chatbot-composer",
|
|
82
|
+
onSubmit: (event) => {
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
handleSend();
|
|
85
|
+
},
|
|
86
|
+
children: /* @__PURE__ */ jsxs(
|
|
87
|
+
"div",
|
|
88
|
+
{
|
|
89
|
+
className: [
|
|
90
|
+
"chatbot-composer-box",
|
|
91
|
+
isActive ? "is-active" : "",
|
|
92
|
+
hasContent ? "has-content" : "",
|
|
93
|
+
isStopIcon ? "is-stopping" : "",
|
|
94
|
+
isFloating ? "is-floating" : "",
|
|
95
|
+
isFloating && isStacked ? "is-stacked" : ""
|
|
96
|
+
].filter(Boolean).join(" "),
|
|
97
|
+
onMouseDown: handleBoxMouseDown,
|
|
98
|
+
children: [
|
|
99
|
+
/* @__PURE__ */ jsx(
|
|
100
|
+
TextareaAutosize,
|
|
101
|
+
{
|
|
102
|
+
ref: textareaRef,
|
|
103
|
+
"aria-label": placeholder ?? t("chatBot.irisInputPlaceholder"),
|
|
104
|
+
className: "chatbot-composer-textarea",
|
|
105
|
+
maxRows: 6,
|
|
106
|
+
minRows: 1,
|
|
107
|
+
id: "chatbot-composer-textarea",
|
|
108
|
+
name: "chatbot-composer-textarea",
|
|
109
|
+
placeholder: placeholder ?? t("chatBot.irisInputPlaceholder"),
|
|
110
|
+
value: inputValue,
|
|
111
|
+
onBlur: () => {
|
|
112
|
+
setIsFocused(false);
|
|
113
|
+
},
|
|
114
|
+
onChange: (event) => {
|
|
115
|
+
setInputValue(event.target.value);
|
|
116
|
+
},
|
|
117
|
+
onFocus: () => {
|
|
118
|
+
setIsFocused(true);
|
|
119
|
+
},
|
|
120
|
+
onHeightChange: (height) => {
|
|
121
|
+
if (!isFloating || !inputValue.trim()) return;
|
|
122
|
+
if (height > FLOATING_STACK_LINE_HEIGHT) {
|
|
123
|
+
setIsStacked(true);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
onKeyDown: (event) => {
|
|
127
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
128
|
+
event.preventDefault();
|
|
129
|
+
handleSend();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
),
|
|
134
|
+
/* @__PURE__ */ jsxs("div", { className: "chatbot-composer-toolbar", children: [
|
|
135
|
+
/* @__PURE__ */ jsxs("div", { className: "chatbot-composer-toolbar-left", children: [
|
|
136
|
+
/* @__PURE__ */ jsx(Tooltip, { title: t("chatBot.composer.add"), variant: "tertiary", children: /* @__PURE__ */ jsx(
|
|
137
|
+
Button,
|
|
138
|
+
{
|
|
139
|
+
"aria-label": t("chatBot.composer.add"),
|
|
140
|
+
className: "chatbot-composer-icon-button",
|
|
141
|
+
icon: /* @__PURE__ */ jsx(default_1, { fontSize: "small" }),
|
|
142
|
+
type: "default",
|
|
143
|
+
variant: "text",
|
|
144
|
+
onClick: onAddClick
|
|
145
|
+
}
|
|
146
|
+
) }),
|
|
147
|
+
/* @__PURE__ */ jsx(Tooltip, { title: t("chatBot.composer.attach"), variant: "tertiary", children: /* @__PURE__ */ jsx(
|
|
148
|
+
Button,
|
|
149
|
+
{
|
|
150
|
+
"aria-label": t("chatBot.composer.attach"),
|
|
151
|
+
className: "chatbot-composer-icon-button",
|
|
152
|
+
icon: /* @__PURE__ */ jsx(default_1$1, { fontSize: "small" }),
|
|
153
|
+
type: "default",
|
|
154
|
+
variant: "text",
|
|
155
|
+
onClick: onAttachClick
|
|
156
|
+
}
|
|
157
|
+
) })
|
|
158
|
+
] }),
|
|
159
|
+
/* @__PURE__ */ jsxs("div", { className: "chatbot-composer-toolbar-right", children: [
|
|
160
|
+
/* @__PURE__ */ jsxs("div", { className: "chatbot-composer-model", children: [
|
|
161
|
+
/* @__PURE__ */ jsx(Tooltip, { title: t("chatBot.composer.model"), variant: "tertiary", children: /* @__PURE__ */ jsx(
|
|
162
|
+
Button,
|
|
163
|
+
{
|
|
164
|
+
"aria-controls": isModelOpen ? "chatbot-composer-model-menu" : void 0,
|
|
165
|
+
"aria-expanded": isModelOpen,
|
|
166
|
+
"aria-haspopup": "true",
|
|
167
|
+
"aria-label": t("chatBot.composer.model"),
|
|
168
|
+
className: "chatbot-composer-model-trigger",
|
|
169
|
+
icon: isModelOpen ? /* @__PURE__ */ jsx(default_1$2, { fontSize: "small" }) : /* @__PURE__ */ jsx(default_1$3, { fontSize: "small" }),
|
|
170
|
+
iconPlacement: "right",
|
|
171
|
+
variant: "text",
|
|
172
|
+
onClick: (event) => {
|
|
173
|
+
setModelAnchorEl(isModelOpen ? null : event.currentTarget);
|
|
174
|
+
},
|
|
175
|
+
children: activeOption.label
|
|
176
|
+
}
|
|
177
|
+
) }),
|
|
178
|
+
/* @__PURE__ */ jsx(
|
|
179
|
+
Menu,
|
|
180
|
+
{
|
|
181
|
+
MenuProps: {
|
|
182
|
+
anchorOrigin: {
|
|
183
|
+
vertical: "top",
|
|
184
|
+
horizontal: "left"
|
|
185
|
+
},
|
|
186
|
+
transformOrigin: {
|
|
187
|
+
vertical: "bottom",
|
|
188
|
+
horizontal: "left"
|
|
189
|
+
},
|
|
190
|
+
PaperProps: {
|
|
191
|
+
style: {
|
|
192
|
+
width: 200
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
anchorEl: modelAnchorEl,
|
|
197
|
+
id: "chatbot-composer-model-menu",
|
|
198
|
+
open: isModelOpen,
|
|
199
|
+
options: options.map((option) => ({
|
|
200
|
+
label: option.label,
|
|
201
|
+
value: option.value,
|
|
202
|
+
onClick: () => {
|
|
203
|
+
onModelChange == null ? void 0 : onModelChange(option.value);
|
|
204
|
+
handleModelClose();
|
|
205
|
+
}
|
|
206
|
+
})),
|
|
207
|
+
selected: { value: activeOption.value },
|
|
208
|
+
onClose: handleModelClose
|
|
209
|
+
}
|
|
210
|
+
)
|
|
211
|
+
] }),
|
|
212
|
+
isFloating && onFloatingLayoutChange && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
213
|
+
/* @__PURE__ */ jsx(Tooltip, { title: t("chatBot.greeting.window"), variant: "tertiary", children: /* @__PURE__ */ jsx(
|
|
214
|
+
Button,
|
|
215
|
+
{
|
|
216
|
+
"aria-controls": isLayoutMenuOpen ? "chatbot-floating-layout-menu" : void 0,
|
|
217
|
+
"aria-expanded": isLayoutMenuOpen,
|
|
218
|
+
"aria-haspopup": "true",
|
|
219
|
+
"aria-label": t("chatBot.greeting.window"),
|
|
220
|
+
className: "chatbot-composer-icon-button chatbot-composer-float-toggle",
|
|
221
|
+
icon: /* @__PURE__ */ jsx(ChatbotFloating_default, { height: 16, width: 16 }),
|
|
222
|
+
type: "default",
|
|
223
|
+
variant: "text",
|
|
224
|
+
onClick: (event) => {
|
|
225
|
+
setLayoutAnchorEl(isLayoutMenuOpen ? null : event.currentTarget);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
) }),
|
|
229
|
+
/* @__PURE__ */ jsx(
|
|
230
|
+
Menu,
|
|
231
|
+
{
|
|
232
|
+
MenuProps: {
|
|
233
|
+
anchorOrigin: {
|
|
234
|
+
vertical: "top",
|
|
235
|
+
horizontal: "right"
|
|
236
|
+
},
|
|
237
|
+
transformOrigin: {
|
|
238
|
+
vertical: "bottom",
|
|
239
|
+
horizontal: "right"
|
|
240
|
+
},
|
|
241
|
+
slotProps: {
|
|
242
|
+
root: {
|
|
243
|
+
sx: { zIndex: 2e3 }
|
|
244
|
+
},
|
|
245
|
+
paper: {
|
|
246
|
+
style: {
|
|
247
|
+
width: 182,
|
|
248
|
+
minWidth: 180,
|
|
249
|
+
maxWidth: 240
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
anchorEl: layoutAnchorEl,
|
|
255
|
+
id: "chatbot-floating-layout-menu",
|
|
256
|
+
open: isLayoutMenuOpen,
|
|
257
|
+
options: [
|
|
258
|
+
{
|
|
259
|
+
label: t("chatBot.greeting.layout.sidebar"),
|
|
260
|
+
value: "sidebar",
|
|
261
|
+
icon: /* @__PURE__ */ jsx(ChatbotSidebar_default, { height: 14, width: 14 }),
|
|
262
|
+
onClick: () => handleLayoutSelect("sidebar")
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
label: t("chatBot.greeting.layout.collapse"),
|
|
266
|
+
value: "collapse",
|
|
267
|
+
icon: /* @__PURE__ */ jsx(ChatbotCollapse_default, { height: 14, width: 14 }),
|
|
268
|
+
onClick: () => handleLayoutSelect("collapse")
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
label: t("chatBot.greeting.layout.floating"),
|
|
272
|
+
value: "floating",
|
|
273
|
+
icon: /* @__PURE__ */ jsx(ChatbotFloating_default, { height: 14, width: 14 }),
|
|
274
|
+
onClick: () => handleLayoutSelect("floating")
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
label: t("chatBot.greeting.layout.fullScreen"),
|
|
278
|
+
value: "fullScreen",
|
|
279
|
+
icon: /* @__PURE__ */ jsx(ChatbotFullScreen_default, { height: 14, width: 14 }),
|
|
280
|
+
onClick: () => handleLayoutSelect("fullScreen")
|
|
281
|
+
}
|
|
282
|
+
],
|
|
283
|
+
selected: { value: "floating" },
|
|
284
|
+
onClose: handleLayoutMenuClose
|
|
285
|
+
}
|
|
286
|
+
)
|
|
287
|
+
] }),
|
|
288
|
+
handleMicClick && /* @__PURE__ */ jsx(Tooltip, { title: t("chatBot.composer.mic"), variant: "tertiary", children: /* @__PURE__ */ jsx(
|
|
289
|
+
Button,
|
|
290
|
+
{
|
|
291
|
+
"aria-label": t("chatBot.composer.mic"),
|
|
292
|
+
className: "chatbot-composer-icon-button",
|
|
293
|
+
icon: /* @__PURE__ */ jsx(ChatBotMicIcon_default, { height: 16, width: 16 }),
|
|
294
|
+
type: "default",
|
|
295
|
+
variant: "text",
|
|
296
|
+
onClick: handleMicClick
|
|
297
|
+
}
|
|
298
|
+
) }),
|
|
299
|
+
isStopIcon ? /* @__PURE__ */ jsx(Tooltip, { title: t("chatBot.composer.stop"), variant: "tertiary", children: /* @__PURE__ */ jsx(
|
|
300
|
+
Button,
|
|
301
|
+
{
|
|
302
|
+
"aria-label": t("chatBot.composer.stop"),
|
|
303
|
+
icon: /* @__PURE__ */ jsx(default_1$4, { height: 16, width: 16 }),
|
|
304
|
+
type: "default",
|
|
305
|
+
variant: "primary",
|
|
306
|
+
onClick: onStop
|
|
307
|
+
}
|
|
308
|
+
) }) : hasContent && /* @__PURE__ */ jsx(Tooltip, { title: t("chatBot.composer.send"), variant: "tertiary", children: /* @__PURE__ */ jsx(
|
|
309
|
+
Button,
|
|
310
|
+
{
|
|
311
|
+
"aria-label": t("chatBot.composer.send"),
|
|
312
|
+
htmlType: "submit",
|
|
313
|
+
icon: /* @__PURE__ */ jsx(default_1$5, { fontSize: "small" }),
|
|
314
|
+
type: "default",
|
|
315
|
+
variant: "primary"
|
|
316
|
+
}
|
|
317
|
+
) })
|
|
318
|
+
] })
|
|
319
|
+
] })
|
|
320
|
+
]
|
|
321
|
+
}
|
|
322
|
+
)
|
|
323
|
+
}
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
export {
|
|
327
|
+
ChatbotComposer
|
|
328
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ChatbotGreetingHeaderProps } from './Chatbot.types';
|
|
2
|
+
|
|
3
|
+
export declare function ChatbotGreetingHeader({ title, variant, onClose, onMenuClick, onBackClick, onNewChatClick, onToggleCollapse, onMinimiseChatBot, onEnterFloating, onEnterFullScreen, onExitFullScreen, isCollapsed, isFloating, isFullScreen, isFullWidth, dragHandleProps, }: ChatbotGreetingHeaderProps): import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
//# sourceMappingURL=chatbotGreetingHeader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatbotGreetingHeader.d.ts","sourceRoot":"","sources":["../../../src/components/Chatbot/chatbotGreetingHeader.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAKlE,wBAAgB,qBAAqB,CAAC,EACpC,KAAK,EACL,OAAoB,EACpB,OAAO,EACP,WAAW,EACX,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,WAAmB,EACnB,UAAkB,EAClB,YAAoB,EACpB,WAAmB,EACnB,eAAe,GAChB,EAAE,0BAA0B,2CAmO5B"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import default_1 from "../../node_modules/@mui/icons-material/ArrowBack.js";
|
|
4
|
+
import default_1$2 from "../../node_modules/@mui/icons-material/Clear.js";
|
|
5
|
+
import default_1$1 from "../../node_modules/@mui/icons-material/Menu.js";
|
|
6
|
+
import { ChatbotNewChat as ChatbotNewChat_default, ChatbotFullScreen as ChatbotFullScreen_default, ChatbotCollapse as ChatbotCollapse_default, ChatbotWindow as ChatbotWindow_default, ChatbotSidebar as ChatbotSidebar_default, ChatbotFloating as ChatbotFloating_default } from "../../node_modules/@impactsmartsuite/impact-icons/dist/index.js";
|
|
7
|
+
import { getAssetUrl } from "../../utils/assetBase.js";
|
|
8
|
+
import { Button } from "../Button/index.js";
|
|
9
|
+
import { Menu } from "../Menu/index.js";
|
|
10
|
+
import { Tooltip } from "../Tooltip/index.js";
|
|
11
|
+
import { useTranslation } from "../../i18n/useTranslation.js";
|
|
12
|
+
const IrisMark = getAssetUrl("icons/smartBotAlan.svg");
|
|
13
|
+
const HEADER_ICON_SIZE = 16;
|
|
14
|
+
function ChatbotGreetingHeader({
|
|
15
|
+
title,
|
|
16
|
+
variant = "greeting",
|
|
17
|
+
onClose,
|
|
18
|
+
onMenuClick,
|
|
19
|
+
onBackClick,
|
|
20
|
+
onNewChatClick,
|
|
21
|
+
onToggleCollapse,
|
|
22
|
+
onMinimiseChatBot,
|
|
23
|
+
onEnterFloating,
|
|
24
|
+
onEnterFullScreen,
|
|
25
|
+
onExitFullScreen,
|
|
26
|
+
isCollapsed = false,
|
|
27
|
+
isFloating = false,
|
|
28
|
+
isFullScreen = false,
|
|
29
|
+
isFullWidth = false,
|
|
30
|
+
dragHandleProps
|
|
31
|
+
}) {
|
|
32
|
+
const { t } = useTranslation();
|
|
33
|
+
const [windowAnchorEl, setWindowAnchorEl] = useState(null);
|
|
34
|
+
const isWindowMenuOpen = Boolean(windowAnchorEl);
|
|
35
|
+
const selectedLayout = isFullScreen ? "fullScreen" : isFloating ? "floating" : isCollapsed ? "collapse" : "sidebar";
|
|
36
|
+
const isConversation = variant === "conversation";
|
|
37
|
+
const isMenuOrList = variant === "menu" || variant === "list";
|
|
38
|
+
const showNewChat = (isConversation || isMenuOrList) && Boolean(onNewChatClick);
|
|
39
|
+
const handleToggleLayout = () => {
|
|
40
|
+
onToggleCollapse == null ? void 0 : onToggleCollapse();
|
|
41
|
+
onMinimiseChatBot == null ? void 0 : onMinimiseChatBot();
|
|
42
|
+
};
|
|
43
|
+
const handleWindowMenuClose = () => {
|
|
44
|
+
setWindowAnchorEl(null);
|
|
45
|
+
};
|
|
46
|
+
const showWindowControls = Boolean(onToggleCollapse) && !isFullWidth;
|
|
47
|
+
const handleHeaderPointerDown = (event) => {
|
|
48
|
+
var _a;
|
|
49
|
+
if (isWindowMenuOpen) return;
|
|
50
|
+
(_a = dragHandleProps == null ? void 0 : dragHandleProps.onPointerDown) == null ? void 0 : _a.call(dragHandleProps, event);
|
|
51
|
+
};
|
|
52
|
+
return /* @__PURE__ */ jsxs(
|
|
53
|
+
"header",
|
|
54
|
+
{
|
|
55
|
+
className: `chatbot-greeting-header ${dragHandleProps && !isWindowMenuOpen ? "is-draggable" : ""}${isConversation || isMenuOrList ? " is-conversation" : ""}`,
|
|
56
|
+
onPointerDown: handleHeaderPointerDown,
|
|
57
|
+
children: [
|
|
58
|
+
/* @__PURE__ */ jsxs("div", { className: "chatbot-greeting-header-left", children: [
|
|
59
|
+
isMenuOrList ? /* @__PURE__ */ jsx(Tooltip, { title: t("chatBot.irisMenu.back"), variant: "tertiary", children: /* @__PURE__ */ jsx(
|
|
60
|
+
Button,
|
|
61
|
+
{
|
|
62
|
+
"aria-label": t("chatBot.irisMenu.back"),
|
|
63
|
+
className: "chatbot-greeting-header-button-ghost",
|
|
64
|
+
icon: /* @__PURE__ */ jsx(default_1, { fontSize: "small" }),
|
|
65
|
+
size: isCollapsed ? "small" : "large",
|
|
66
|
+
type: "default",
|
|
67
|
+
variant: "text",
|
|
68
|
+
onClick: onBackClick,
|
|
69
|
+
onPointerDown: (event) => event.stopPropagation()
|
|
70
|
+
}
|
|
71
|
+
) }) : /* @__PURE__ */ jsx(Tooltip, { title: t("chatBot.greeting.menu"), variant: "tertiary", children: /* @__PURE__ */ jsx(
|
|
72
|
+
Button,
|
|
73
|
+
{
|
|
74
|
+
"aria-label": t("chatBot.greeting.menu"),
|
|
75
|
+
className: "chatbot-greeting-header-button-ghost",
|
|
76
|
+
icon: /* @__PURE__ */ jsx(default_1$1, { fontSize: "small" }),
|
|
77
|
+
size: isCollapsed ? "small" : "large",
|
|
78
|
+
type: "default",
|
|
79
|
+
variant: "text",
|
|
80
|
+
onClick: onMenuClick,
|
|
81
|
+
onPointerDown: (event) => event.stopPropagation()
|
|
82
|
+
}
|
|
83
|
+
) }),
|
|
84
|
+
isConversation || isMenuOrList ? /* @__PURE__ */ jsx("h1", { className: "chatbot-greeting-conversation-title", children: title ?? (isMenuOrList ? t("chatBot.irisMenu.title") : t("chatBot.greeting.brand")) }) : /* @__PURE__ */ jsxs("div", { className: "chatbot-greeting-brand", children: [
|
|
85
|
+
/* @__PURE__ */ jsx("img", { alt: "", className: "chatbot-greeting-brand-mark", src: IrisMark }),
|
|
86
|
+
/* @__PURE__ */ jsx("span", { className: "chatbot-greeting-brand-title", children: title ?? t("chatBot.greeting.brand") })
|
|
87
|
+
] })
|
|
88
|
+
] }),
|
|
89
|
+
/* @__PURE__ */ jsxs("div", { className: "chatbot-greeting-header-right", children: [
|
|
90
|
+
showNewChat && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
91
|
+
/* @__PURE__ */ jsx(Tooltip, { title: t("chatBot.menu.newChat"), variant: "tertiary", children: /* @__PURE__ */ jsx(
|
|
92
|
+
Button,
|
|
93
|
+
{
|
|
94
|
+
"aria-label": t("chatBot.menu.newChat"),
|
|
95
|
+
icon: /* @__PURE__ */ jsx(ChatbotNewChat_default, {}),
|
|
96
|
+
type: "default",
|
|
97
|
+
variant: "tertiary",
|
|
98
|
+
onClick: onNewChatClick,
|
|
99
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
100
|
+
size: isCollapsed ? "medium" : "large"
|
|
101
|
+
}
|
|
102
|
+
) }),
|
|
103
|
+
showWindowControls && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "chatbot-greeting-header-divider" })
|
|
104
|
+
] }),
|
|
105
|
+
showWindowControls && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
106
|
+
/* @__PURE__ */ jsx(Tooltip, { title: t("chatBot.greeting.window"), variant: "tertiary", children: /* @__PURE__ */ jsx(
|
|
107
|
+
Button,
|
|
108
|
+
{
|
|
109
|
+
"aria-controls": isWindowMenuOpen ? "chatbot-greeting-window-menu" : void 0,
|
|
110
|
+
"aria-expanded": isWindowMenuOpen,
|
|
111
|
+
"aria-haspopup": "true",
|
|
112
|
+
"aria-label": t("chatBot.greeting.window"),
|
|
113
|
+
className: [
|
|
114
|
+
"chatbot-greeting-header-window",
|
|
115
|
+
isFullScreen ? "chatbot-greeting-header-exit-fullscreen" : "",
|
|
116
|
+
isWindowMenuOpen ? "chatbot-greeting-header-button-active" : ""
|
|
117
|
+
].filter(Boolean).join(" "),
|
|
118
|
+
icon: isFullScreen ? /* @__PURE__ */ jsx(ChatbotFullScreen_default, { height: HEADER_ICON_SIZE, width: HEADER_ICON_SIZE }) : isCollapsed ? /* @__PURE__ */ jsx(ChatbotCollapse_default, { height: HEADER_ICON_SIZE, width: HEADER_ICON_SIZE }) : /* @__PURE__ */ jsx(ChatbotWindow_default, { height: HEADER_ICON_SIZE, width: HEADER_ICON_SIZE }),
|
|
119
|
+
size: isCollapsed ? "medium" : "large",
|
|
120
|
+
type: "default",
|
|
121
|
+
variant: "text",
|
|
122
|
+
onClick: (event) => {
|
|
123
|
+
setWindowAnchorEl(isWindowMenuOpen ? null : event.currentTarget);
|
|
124
|
+
},
|
|
125
|
+
onPointerDown: (event) => event.stopPropagation()
|
|
126
|
+
}
|
|
127
|
+
) }),
|
|
128
|
+
/* @__PURE__ */ jsx(
|
|
129
|
+
Menu,
|
|
130
|
+
{
|
|
131
|
+
MenuProps: {
|
|
132
|
+
anchorOrigin: {
|
|
133
|
+
vertical: "bottom",
|
|
134
|
+
horizontal: "right"
|
|
135
|
+
},
|
|
136
|
+
transformOrigin: {
|
|
137
|
+
vertical: "top",
|
|
138
|
+
horizontal: "right"
|
|
139
|
+
},
|
|
140
|
+
// Chatbot shell is z-index 1300; keep the menu above so collapsed-drag
|
|
141
|
+
// hits don't steal clicks from menu items / backdrop.
|
|
142
|
+
slotProps: {
|
|
143
|
+
root: {
|
|
144
|
+
sx: { zIndex: 2e3 }
|
|
145
|
+
},
|
|
146
|
+
paper: {
|
|
147
|
+
className: "chatbot-greeting-window-menu-paper",
|
|
148
|
+
style: {
|
|
149
|
+
width: 182,
|
|
150
|
+
minWidth: 180,
|
|
151
|
+
maxWidth: 240
|
|
152
|
+
},
|
|
153
|
+
onPointerDown: (event) => {
|
|
154
|
+
event.stopPropagation();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
anchorEl: windowAnchorEl,
|
|
160
|
+
id: "chatbot-greeting-window-menu",
|
|
161
|
+
open: isWindowMenuOpen,
|
|
162
|
+
options: [
|
|
163
|
+
{
|
|
164
|
+
label: t("chatBot.greeting.layout.sidebar"),
|
|
165
|
+
value: "sidebar",
|
|
166
|
+
icon: /* @__PURE__ */ jsx(ChatbotSidebar_default, { height: 14, width: 14 }),
|
|
167
|
+
onClick: () => {
|
|
168
|
+
if (isFullScreen) onExitFullScreen == null ? void 0 : onExitFullScreen();
|
|
169
|
+
else if (isCollapsed) handleToggleLayout();
|
|
170
|
+
handleWindowMenuClose();
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
label: t("chatBot.greeting.layout.collapse"),
|
|
175
|
+
value: "collapse",
|
|
176
|
+
icon: /* @__PURE__ */ jsx(ChatbotCollapse_default, { height: 14, width: 14 }),
|
|
177
|
+
onClick: () => {
|
|
178
|
+
if (isFullScreen || !isCollapsed) handleToggleLayout();
|
|
179
|
+
handleWindowMenuClose();
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
label: t("chatBot.greeting.layout.floating"),
|
|
184
|
+
value: "floating",
|
|
185
|
+
icon: /* @__PURE__ */ jsx(ChatbotFloating_default, { height: 14, width: 14 }),
|
|
186
|
+
onClick: () => {
|
|
187
|
+
onEnterFloating == null ? void 0 : onEnterFloating();
|
|
188
|
+
handleWindowMenuClose();
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
label: t("chatBot.greeting.layout.fullScreen"),
|
|
193
|
+
value: "fullScreen",
|
|
194
|
+
icon: /* @__PURE__ */ jsx(ChatbotFullScreen_default, { height: 14, width: 14 }),
|
|
195
|
+
onClick: () => {
|
|
196
|
+
if (!isFullScreen) onEnterFullScreen == null ? void 0 : onEnterFullScreen();
|
|
197
|
+
handleWindowMenuClose();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
],
|
|
201
|
+
selected: { value: selectedLayout },
|
|
202
|
+
onClose: handleWindowMenuClose
|
|
203
|
+
}
|
|
204
|
+
)
|
|
205
|
+
] }),
|
|
206
|
+
(isFullScreen || !isFullWidth) && onClose && /* @__PURE__ */ jsx(Tooltip, { title: t("chatBot.closeAlt"), variant: "tertiary", children: /* @__PURE__ */ jsx(
|
|
207
|
+
Button,
|
|
208
|
+
{
|
|
209
|
+
"aria-label": t("chatBot.closeAlt"),
|
|
210
|
+
className: "chatbot-greeting-header-close",
|
|
211
|
+
icon: /* @__PURE__ */ jsx(default_1$2, { fontSize: "small" }),
|
|
212
|
+
size: isCollapsed ? "medium" : "large",
|
|
213
|
+
type: "default",
|
|
214
|
+
variant: "text",
|
|
215
|
+
onClick: onClose,
|
|
216
|
+
onPointerDown: (event) => event.stopPropagation()
|
|
217
|
+
}
|
|
218
|
+
) })
|
|
219
|
+
] })
|
|
220
|
+
]
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
export {
|
|
225
|
+
ChatbotGreetingHeader
|
|
226
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { GreetingWeather } from './Chatbot.types';
|
|
2
|
+
|
|
3
|
+
export interface GreetingWeatherLocation {
|
|
4
|
+
latitude: number;
|
|
5
|
+
longitude: number;
|
|
6
|
+
}
|
|
7
|
+
export interface FetchGreetingWeatherOptions {
|
|
8
|
+
/** Skip browser geolocation and use these coordinates. */
|
|
9
|
+
location?: GreetingWeatherLocation;
|
|
10
|
+
/** Called when geolocation is unavailable / denied; fetch is skipped unless `location` is set. */
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Map WMO weather interpretation codes (Open-Meteo) → Iris greeting weather.
|
|
15
|
+
* @see https://open-meteo.com/en/docs
|
|
16
|
+
*/
|
|
17
|
+
export declare function mapWeatherCodeToGreetingWeather(code: number): GreetingWeather;
|
|
18
|
+
/**
|
|
19
|
+
* Resolve local weather for the Iris greeting icon via Open-Meteo (no API key).
|
|
20
|
+
* Uses browser geolocation unless `location` is provided.
|
|
21
|
+
*/
|
|
22
|
+
export declare function fetchGreetingWeather(options?: FetchGreetingWeatherOptions): Promise<GreetingWeather>;
|
|
23
|
+
//# sourceMappingURL=greetingWeather.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"greetingWeather.d.ts","sourceRoot":"","sources":["../../../src/components/Chatbot/greetingWeather.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAMvD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,2BAA2B;IAC1C,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,uBAAuB,CAAC;IACnC,kGAAkG;IAClG,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAQ7E;AAuCD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,eAAe,CAAC,CAmC1B"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const OPEN_METEO_FORECAST = "https://api.open-meteo.com/v1/forecast";
|
|
2
|
+
const GEO_TIMEOUT_MS = 8e3;
|
|
3
|
+
const FETCH_TIMEOUT_MS = 8e3;
|
|
4
|
+
function mapWeatherCodeToGreetingWeather(code) {
|
|
5
|
+
if (code === 0) return "clear";
|
|
6
|
+
if (code === 1 || code === 2) return "partlyCloudy";
|
|
7
|
+
if (code === 3 || code === 45 || code === 48) return "cloudy";
|
|
8
|
+
if (code >= 71 && code <= 77 || code === 85 || code === 86) return "snow";
|
|
9
|
+
if (code >= 95 && code <= 99) return "storm";
|
|
10
|
+
if (code >= 51 && code <= 67 || code >= 80 && code <= 82) return "rain";
|
|
11
|
+
return "cloudy";
|
|
12
|
+
}
|
|
13
|
+
function getCurrentPosition(signal) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
if (typeof navigator === "undefined" || !navigator.geolocation) {
|
|
16
|
+
reject(new Error("Geolocation is not available"));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const onAbort = () => {
|
|
20
|
+
reject(new DOMException("Geolocation aborted", "AbortError"));
|
|
21
|
+
};
|
|
22
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
23
|
+
onAbort();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
signal == null ? void 0 : signal.addEventListener("abort", onAbort, { once: true });
|
|
27
|
+
navigator.geolocation.getCurrentPosition(
|
|
28
|
+
(pos) => {
|
|
29
|
+
signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
|
|
30
|
+
resolve({
|
|
31
|
+
latitude: pos.coords.latitude,
|
|
32
|
+
longitude: pos.coords.longitude
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
(err) => {
|
|
36
|
+
signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
|
|
37
|
+
reject(err);
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
enableHighAccuracy: false,
|
|
41
|
+
timeout: GEO_TIMEOUT_MS,
|
|
42
|
+
maximumAge: 30 * 60 * 1e3
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
async function fetchGreetingWeather(options = {}) {
|
|
48
|
+
var _a, _b, _c;
|
|
49
|
+
const location = options.location ?? await getCurrentPosition(options.signal);
|
|
50
|
+
const url = new URL(OPEN_METEO_FORECAST);
|
|
51
|
+
url.searchParams.set("latitude", String(location.latitude));
|
|
52
|
+
url.searchParams.set("longitude", String(location.longitude));
|
|
53
|
+
url.searchParams.set("current", "weather_code");
|
|
54
|
+
url.searchParams.set("timezone", "auto");
|
|
55
|
+
const controller = new AbortController();
|
|
56
|
+
const timeoutId = window.setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
57
|
+
const onOuterAbort = () => controller.abort();
|
|
58
|
+
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", onOuterAbort);
|
|
59
|
+
try {
|
|
60
|
+
const response = await fetch(url.toString(), {
|
|
61
|
+
signal: controller.signal,
|
|
62
|
+
headers: { Accept: "application/json" }
|
|
63
|
+
});
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
throw new Error(`Weather request failed (${response.status})`);
|
|
66
|
+
}
|
|
67
|
+
const data = await response.json();
|
|
68
|
+
const code = (_b = data.current) == null ? void 0 : _b.weather_code;
|
|
69
|
+
if (typeof code !== "number") {
|
|
70
|
+
throw new Error("Weather response missing weather_code");
|
|
71
|
+
}
|
|
72
|
+
return mapWeatherCodeToGreetingWeather(code);
|
|
73
|
+
} finally {
|
|
74
|
+
window.clearTimeout(timeoutId);
|
|
75
|
+
(_c = options.signal) == null ? void 0 : _c.removeEventListener("abort", onOuterAbort);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
fetchGreetingWeather,
|
|
80
|
+
mapWeatherCodeToGreetingWeather
|
|
81
|
+
};
|