@telia-ace/widget-conversation 1.0.12 → 1.0.13
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/{lib-esm → dist}/agent.d.ts +0 -0
- package/{lib-esm → dist}/conversation-controller.d.ts +0 -0
- package/{lib-esm → dist}/conversation-form-adapter.d.ts +0 -0
- package/{lib-esm → dist}/conversation-platform.d.ts +0 -0
- package/{lib-esm → dist}/conversation-provider.d.ts +0 -0
- package/dist/conversation.js +1357 -0
- package/dist/conversation.js.map +1 -0
- package/{lib-esm → dist}/index.d.ts +0 -0
- package/dist/index.js +867 -0
- package/dist/index.js.map +1 -0
- package/{lib-esm → dist}/resolve-entity-value.d.ts +0 -0
- package/dist/return-button.js +174 -0
- package/dist/return-button.js.map +1 -0
- package/{lib-esm → dist}/types.d.ts +0 -0
- package/{lib-esm → dist}/ui/conversation/conversation-component.d.ts +0 -0
- package/{lib-esm → dist}/ui/conversation/conversation-content.d.ts +0 -0
- package/{lib-esm → dist}/ui/conversation/conversation-input.d.ts +0 -0
- package/{lib-esm → dist}/ui/conversation/conversation-loader.d.ts +0 -0
- package/{lib-esm → dist}/ui/conversation/conversation-message.d.ts +0 -0
- package/{lib-esm → dist}/ui/conversation/conversation-styles.d.ts +0 -0
- package/{lib-esm → dist}/ui/conversation/conversation.d.ts +0 -0
- package/{lib-esm → dist}/ui/conversation/index.d.ts +0 -0
- package/{lib-esm → dist}/ui/conversation/message-types/agent.d.ts +0 -0
- package/{lib-esm → dist}/ui/conversation/message-types/custom-message-list-item.d.ts +0 -0
- package/{lib-esm → dist}/ui/conversation/message-types/custom.d.ts +0 -0
- package/{lib-esm → dist}/ui/conversation/message-types/index.d.ts +0 -0
- package/{lib-esm → dist}/ui/conversation/message-types/system.d.ts +0 -0
- package/{lib-esm → dist}/ui/conversation/message-types/timestamp.d.ts +0 -0
- package/{lib-esm → dist}/ui/conversation/message-types/user.d.ts +0 -0
- package/{lib-esm → dist}/ui/index.d.ts +0 -0
- package/{lib-esm → dist}/ui/return-button/index.d.ts +0 -0
- package/{lib-esm → dist}/ui/return-button/return-button-component.d.ts +0 -0
- package/{lib-esm → dist}/ui/return-button/return-button.d.ts +0 -0
- package/{lib-esm → dist}/user.d.ts +0 -0
- package/{lib-esm → dist}/utils/custom-message.d.ts +0 -0
- package/{lib-esm → dist}/utils/index.d.ts +0 -0
- package/{lib-esm → dist}/utils/open-chat-widget.d.ts +0 -0
- package/package.json +14 -15
- package/lib/agent.d.ts +0 -17
- package/lib/agent.js +0 -37
- package/lib/conversation-controller.d.ts +0 -88
- package/lib/conversation-controller.js +0 -318
- package/lib/conversation-form-adapter.d.ts +0 -7
- package/lib/conversation-form-adapter.js +0 -88
- package/lib/conversation-platform.d.ts +0 -49
- package/lib/conversation-platform.js +0 -295
- package/lib/conversation-provider.d.ts +0 -22
- package/lib/conversation-provider.js +0 -73
- package/lib/index.d.ts +0 -9
- package/lib/index.js +0 -17
- package/lib/resolve-entity-value.d.ts +0 -10
- package/lib/resolve-entity-value.js +0 -22
- package/lib/types.d.ts +0 -110
- package/lib/types.js +0 -19
- package/lib/ui/conversation/conversation-component.d.ts +0 -37
- package/lib/ui/conversation/conversation-component.js +0 -152
- package/lib/ui/conversation/conversation-content.d.ts +0 -11
- package/lib/ui/conversation/conversation-content.js +0 -240
- package/lib/ui/conversation/conversation-input.d.ts +0 -6
- package/lib/ui/conversation/conversation-input.js +0 -163
- package/lib/ui/conversation/conversation-loader.d.ts +0 -8
- package/lib/ui/conversation/conversation-loader.js +0 -18
- package/lib/ui/conversation/conversation-message.d.ts +0 -7
- package/lib/ui/conversation/conversation-message.js +0 -141
- package/lib/ui/conversation/conversation-styles.d.ts +0 -11
- package/lib/ui/conversation/conversation-styles.js +0 -65
- package/lib/ui/conversation/conversation.d.ts +0 -6
- package/lib/ui/conversation/conversation.js +0 -139
- package/lib/ui/conversation/index.d.ts +0 -2
- package/lib/ui/conversation/index.js +0 -7
- package/lib/ui/conversation/message-types/agent.d.ts +0 -11
- package/lib/ui/conversation/message-types/agent.js +0 -54
- package/lib/ui/conversation/message-types/custom-message-list-item.d.ts +0 -9
- package/lib/ui/conversation/message-types/custom-message-list-item.js +0 -27
- package/lib/ui/conversation/message-types/custom.d.ts +0 -9
- package/lib/ui/conversation/message-types/custom.js +0 -50
- package/lib/ui/conversation/message-types/index.d.ts +0 -5
- package/lib/ui/conversation/message-types/index.js +0 -16
- package/lib/ui/conversation/message-types/system.d.ts +0 -12
- package/lib/ui/conversation/message-types/system.js +0 -26
- package/lib/ui/conversation/message-types/timestamp.d.ts +0 -8
- package/lib/ui/conversation/message-types/timestamp.js +0 -36
- package/lib/ui/conversation/message-types/user.d.ts +0 -8
- package/lib/ui/conversation/message-types/user.js +0 -24
- package/lib/ui/index.d.ts +0 -2
- package/lib/ui/index.js +0 -10
- package/lib/ui/return-button/index.d.ts +0 -2
- package/lib/ui/return-button/index.js +0 -7
- package/lib/ui/return-button/return-button-component.d.ts +0 -19
- package/lib/ui/return-button/return-button-component.js +0 -70
- package/lib/ui/return-button/return-button.d.ts +0 -6
- package/lib/ui/return-button/return-button.js +0 -82
- package/lib/user.d.ts +0 -7
- package/lib/user.js +0 -16
- package/lib/utils/custom-message.d.ts +0 -3
- package/lib/utils/custom-message.js +0 -56
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +0 -7
- package/lib/utils/open-chat-widget.d.ts +0 -4
- package/lib/utils/open-chat-widget.js +0 -148
- package/lib-esm/agent.js +0 -34
- package/lib-esm/conversation-controller.js +0 -314
- package/lib-esm/conversation-form-adapter.js +0 -85
- package/lib-esm/conversation-platform.js +0 -292
- package/lib-esm/conversation-provider.js +0 -70
- package/lib-esm/index.js +0 -6
- package/lib-esm/resolve-entity-value.js +0 -18
- package/lib-esm/types.js +0 -16
- package/lib-esm/ui/conversation/conversation-component.js +0 -127
- package/lib-esm/ui/conversation/conversation-content.js +0 -212
- package/lib-esm/ui/conversation/conversation-input.js +0 -138
- package/lib-esm/ui/conversation/conversation-loader.js +0 -13
- package/lib-esm/ui/conversation/conversation-message.js +0 -113
- package/lib-esm/ui/conversation/conversation-styles.js +0 -39
- package/lib-esm/ui/conversation/conversation.js +0 -111
- package/lib-esm/ui/conversation/index.js +0 -2
- package/lib-esm/ui/conversation/message-types/agent.js +0 -25
- package/lib-esm/ui/conversation/message-types/custom-message-list-item.js +0 -22
- package/lib-esm/ui/conversation/message-types/custom.js +0 -25
- package/lib-esm/ui/conversation/message-types/index.js +0 -5
- package/lib-esm/ui/conversation/message-types/system.js +0 -20
- package/lib-esm/ui/conversation/message-types/timestamp.js +0 -31
- package/lib-esm/ui/conversation/message-types/user.js +0 -19
- package/lib-esm/ui/index.js +0 -2
- package/lib-esm/ui/return-button/index.js +0 -2
- package/lib-esm/ui/return-button/return-button-component.js +0 -44
- package/lib-esm/ui/return-button/return-button.js +0 -54
- package/lib-esm/user.js +0 -13
- package/lib-esm/utils/custom-message.js +0 -52
- package/lib-esm/utils/index.js +0 -1
- package/lib-esm/utils/open-chat-widget.js +0 -142
|
@@ -0,0 +1,1357 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
import { Input, Button, borderTabStyle, SymbolBadge, useDispatch, useProperties, useScroll, Typography, useComponent, invertedHoverButton, Html, List, buttonCss, Icon, Lightbox, useTransitionEnd, headingElement } from "@telia-ace/widget-ui";
|
|
33
|
+
import { appendClassNames, uuid } from "@telia-ace/widget-utilities";
|
|
34
|
+
import React, { useState, useEffect, Suspense, Fragment, useRef, useCallback } from "react";
|
|
35
|
+
import styled, { css, keyframes } from "styled-components";
|
|
36
|
+
import { FormComponent } from "@telia-ace/widget-forms";
|
|
37
|
+
import { ConversationMessageListItemType, ConversationMessageType } from "./index.js";
|
|
38
|
+
import "@telia-ace/widget-core";
|
|
39
|
+
import "@telia-ace/widget-services";
|
|
40
|
+
import "@telia-ace/widget-plugins";
|
|
41
|
+
const ConversationInput = ({ className }) => {
|
|
42
|
+
const [inputText, setInputText] = useState("");
|
|
43
|
+
const [inputFocus, setInputFocus] = useState(false);
|
|
44
|
+
const [calculatedLineHeight, setCalculatedLineHeight] = useState(0);
|
|
45
|
+
const [textareaMaxHeight, setTextareaMaxHeight] = useState(0);
|
|
46
|
+
const dispatch = useDispatch();
|
|
47
|
+
const {
|
|
48
|
+
inputPlaceholder = "Type your message",
|
|
49
|
+
inputHidden = false,
|
|
50
|
+
inputDisabled = false,
|
|
51
|
+
sendButtonLabel = "Send message",
|
|
52
|
+
inputMultiline: multiline = true,
|
|
53
|
+
secondaryAction
|
|
54
|
+
} = useProperties();
|
|
55
|
+
const [scrollableCss, inputRef] = useScroll(true);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (inputRef.current) {
|
|
58
|
+
const { lineHeight, maxHeight } = getComputedStyle(inputRef.current);
|
|
59
|
+
if (lineHeight && lineHeight.indexOf("px") > -1) {
|
|
60
|
+
const lineHeightNumber = lineHeight.split("px");
|
|
61
|
+
const calcLH = parseInt(lineHeightNumber[0], 10);
|
|
62
|
+
setCalculatedLineHeight(calcLH);
|
|
63
|
+
const maxHeightNumber = maxHeight.split("px");
|
|
64
|
+
setTextareaMaxHeight(parseInt(maxHeightNumber[0], 10));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}, [inputRef.current]);
|
|
68
|
+
const submit = (e) => {
|
|
69
|
+
if (!e.shiftKey || !multiline) {
|
|
70
|
+
e.preventDefault();
|
|
71
|
+
if (inputText && inputText.length > 0) {
|
|
72
|
+
dispatch("user-submit", { text: inputText });
|
|
73
|
+
setInputText("");
|
|
74
|
+
onChange("");
|
|
75
|
+
}
|
|
76
|
+
} else if (inputText.length < 1) {
|
|
77
|
+
e.preventDefault();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const onSecondaryActionButtonClick = (e) => {
|
|
81
|
+
if (!secondaryAction) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
dispatch("action", secondaryAction.action);
|
|
86
|
+
};
|
|
87
|
+
const calculateHeight = (value) => {
|
|
88
|
+
if (multiline && inputRef.current) {
|
|
89
|
+
const scrollHeight = inputRef.current.scrollHeight;
|
|
90
|
+
if (scrollHeight > calculatedLineHeight) {
|
|
91
|
+
inputRef.current.style.height = "auto";
|
|
92
|
+
let areaHeight = scrollHeight;
|
|
93
|
+
if (value.length < 1) {
|
|
94
|
+
areaHeight = calculatedLineHeight;
|
|
95
|
+
}
|
|
96
|
+
inputRef.current.style.height = `${areaHeight}px`;
|
|
97
|
+
if (areaHeight >= textareaMaxHeight) {
|
|
98
|
+
inputRef.current.style.overflowY = "scroll";
|
|
99
|
+
} else {
|
|
100
|
+
inputRef.current.style.overflowY = "hidden";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const onChange = (value) => {
|
|
106
|
+
calculateHeight(value);
|
|
107
|
+
setInputText(value);
|
|
108
|
+
if (value && value.length > 0) {
|
|
109
|
+
dispatch("user-typing", { textLength: value.length });
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
if (inputHidden) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
return /* @__PURE__ */ React.createElement(Wrapper$1, {
|
|
116
|
+
grow: multiline,
|
|
117
|
+
className: appendClassNames("humany-conversation-input", className),
|
|
118
|
+
"data-has-focus": inputFocus,
|
|
119
|
+
scrollableCss
|
|
120
|
+
}, secondaryAction && /* @__PURE__ */ React.createElement(StyledButton, {
|
|
121
|
+
disabled: inputDisabled,
|
|
122
|
+
onClick: onSecondaryActionButtonClick,
|
|
123
|
+
title: secondaryAction.label,
|
|
124
|
+
"aria-label": secondaryAction.label
|
|
125
|
+
}, /* @__PURE__ */ React.createElement(SymbolBadge, {
|
|
126
|
+
size: 22,
|
|
127
|
+
symbol: { type: "Svg", content: secondaryAction.icon || "browse" }
|
|
128
|
+
})), multiline ? /* @__PURE__ */ React.createElement(StyledTextArea, {
|
|
129
|
+
value: inputText,
|
|
130
|
+
onChange,
|
|
131
|
+
onEnter: submit,
|
|
132
|
+
disabled: inputDisabled,
|
|
133
|
+
"aria-label": inputPlaceholder,
|
|
134
|
+
placeholder: inputPlaceholder,
|
|
135
|
+
onFocusChange: setInputFocus,
|
|
136
|
+
type: "textarea",
|
|
137
|
+
rows: 1,
|
|
138
|
+
ref: inputRef
|
|
139
|
+
}) : /* @__PURE__ */ React.createElement(StyledInput, {
|
|
140
|
+
value: inputText,
|
|
141
|
+
onChange,
|
|
142
|
+
onEnter: submit,
|
|
143
|
+
disabled: inputDisabled,
|
|
144
|
+
"aria-label": inputPlaceholder,
|
|
145
|
+
placeholder: inputPlaceholder,
|
|
146
|
+
onFocusChange: setInputFocus
|
|
147
|
+
}), /* @__PURE__ */ React.createElement(StyledButton, {
|
|
148
|
+
disabled: inputDisabled,
|
|
149
|
+
onClick: submit,
|
|
150
|
+
title: sendButtonLabel,
|
|
151
|
+
"aria-label": sendButtonLabel
|
|
152
|
+
}, /* @__PURE__ */ React.createElement(SendSymbol, {
|
|
153
|
+
size: 22,
|
|
154
|
+
symbol: { type: "Svg", content: "send" },
|
|
155
|
+
hasContent: inputText && inputText.length
|
|
156
|
+
})));
|
|
157
|
+
};
|
|
158
|
+
const StyledTextArea = styled(Input)`
|
|
159
|
+
resize: none;
|
|
160
|
+
flex: 1;
|
|
161
|
+
flex-shrink: 1;
|
|
162
|
+
min-height: 1.2em;
|
|
163
|
+
max-height: 148px;
|
|
164
|
+
line-height: 1.2em;
|
|
165
|
+
height: 1.2em;
|
|
166
|
+
padding: 0;
|
|
167
|
+
margin: ${(p) => {
|
|
168
|
+
var _a;
|
|
169
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.small;
|
|
170
|
+
}} ${(p) => {
|
|
171
|
+
var _a;
|
|
172
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.medium;
|
|
173
|
+
}};
|
|
174
|
+
font-size: ${(p) => {
|
|
175
|
+
var _a;
|
|
176
|
+
return (_a = p.theme.fonts) == null ? void 0 : _a.normal;
|
|
177
|
+
}};
|
|
178
|
+
border: none;
|
|
179
|
+
transition: height 200ms linear;
|
|
180
|
+
outline: none;
|
|
181
|
+
`;
|
|
182
|
+
const StyledInput = styled(Input)`
|
|
183
|
+
flex: 1;
|
|
184
|
+
border: none;
|
|
185
|
+
background-color: transparent;
|
|
186
|
+
font-weight: 300;
|
|
187
|
+
font-size: ${(p) => {
|
|
188
|
+
var _a;
|
|
189
|
+
return (_a = p.theme.fonts) == null ? void 0 : _a.normal;
|
|
190
|
+
}};
|
|
191
|
+
line-height: 1.2em;
|
|
192
|
+
outline: none;
|
|
193
|
+
padding-left: ${(p) => {
|
|
194
|
+
var _a;
|
|
195
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.large;
|
|
196
|
+
}};
|
|
197
|
+
color: ${(p) => {
|
|
198
|
+
var _a;
|
|
199
|
+
return (_a = p.theme.colors) == null ? void 0 : _a.text;
|
|
200
|
+
}};
|
|
201
|
+
&::placeholder {
|
|
202
|
+
color: ${(p) => {
|
|
203
|
+
var _a;
|
|
204
|
+
return (_a = p.theme.colors) == null ? void 0 : _a.textLight;
|
|
205
|
+
}};
|
|
206
|
+
font-style: italic;
|
|
207
|
+
}
|
|
208
|
+
`;
|
|
209
|
+
const StyledButton = styled(Button)`
|
|
210
|
+
flex: 0 0 50px;
|
|
211
|
+
align-self: stretch;
|
|
212
|
+
background-color: transparent;
|
|
213
|
+
display: flex;
|
|
214
|
+
align-items: center;
|
|
215
|
+
justify-content: center;
|
|
216
|
+
border: none;
|
|
217
|
+
color: #a6a6a6;
|
|
218
|
+
&:focus {
|
|
219
|
+
${(p) => {
|
|
220
|
+
var _a;
|
|
221
|
+
return ((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && borderTabStyle;
|
|
222
|
+
}};
|
|
223
|
+
}
|
|
224
|
+
`;
|
|
225
|
+
const Wrapper$1 = styled.div`
|
|
226
|
+
${(p) => p.grow ? css`
|
|
227
|
+
min-height: 50px;
|
|
228
|
+
max-height: 150px;
|
|
229
|
+
` : css`
|
|
230
|
+
height: 50px;
|
|
231
|
+
`}
|
|
232
|
+
flex: 0 0 auto;
|
|
233
|
+
display: flex;
|
|
234
|
+
align-items: center;
|
|
235
|
+
background-color: ${(p) => {
|
|
236
|
+
var _a;
|
|
237
|
+
return (_a = p.theme.colors) == null ? void 0 : _a.accent;
|
|
238
|
+
}};
|
|
239
|
+
border-top: ${(p) => p.theme.inputBorder};
|
|
240
|
+
${(p) => p["data-has-focus"] && css`
|
|
241
|
+
${(p2) => {
|
|
242
|
+
var _a;
|
|
243
|
+
return ((_a = p2.theme.accessibility) == null ? void 0 : _a.isTabbing) && borderTabStyle;
|
|
244
|
+
}};
|
|
245
|
+
`}
|
|
246
|
+
${StyledTextArea} {
|
|
247
|
+
${(p) => !!p.scrollableCss && p.scrollableCss}
|
|
248
|
+
}
|
|
249
|
+
`;
|
|
250
|
+
const SendSymbol = styled((_a) => {
|
|
251
|
+
var _b = _a, { hasContent } = _b, other = __objRest(_b, ["hasContent"]);
|
|
252
|
+
return /* @__PURE__ */ React.createElement(SymbolBadge, __spreadValues({}, other));
|
|
253
|
+
})`
|
|
254
|
+
line,
|
|
255
|
+
path {
|
|
256
|
+
stroke: ${(p) => {
|
|
257
|
+
var _a;
|
|
258
|
+
return p.hasContent ? (_a = p.theme.colors) == null ? void 0 : _a.primary : "#a6a6a6";
|
|
259
|
+
}};
|
|
260
|
+
fill: ${(p) => {
|
|
261
|
+
var _a;
|
|
262
|
+
return p.hasContent ? (_a = p.theme.colors) == null ? void 0 : _a.primary : "#a6a6a6";
|
|
263
|
+
}};
|
|
264
|
+
}
|
|
265
|
+
`;
|
|
266
|
+
const Avatar = styled.div`
|
|
267
|
+
width: ${(p) => p.avatarSize || "32px"};
|
|
268
|
+
height: ${(p) => p.avatarSize || "32px"};
|
|
269
|
+
border-radius: 50%;
|
|
270
|
+
background-color: ${(p) => {
|
|
271
|
+
var _a;
|
|
272
|
+
return (_a = p.theme.colors) == null ? void 0 : _a.accent;
|
|
273
|
+
}};
|
|
274
|
+
border: ${(p) => p.theme.border};
|
|
275
|
+
grid-area: avatar;
|
|
276
|
+
align-self: flex-end;
|
|
277
|
+
justify-self: center;
|
|
278
|
+
overflow: hidden;
|
|
279
|
+
margin-right: ${(p) => {
|
|
280
|
+
var _a;
|
|
281
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
282
|
+
}};
|
|
283
|
+
display: flex;
|
|
284
|
+
justify-content: center;
|
|
285
|
+
align-items: center;
|
|
286
|
+
color: ${(p) => {
|
|
287
|
+
var _a;
|
|
288
|
+
return (_a = p.theme.colors) == null ? void 0 : _a.text;
|
|
289
|
+
}};
|
|
290
|
+
|
|
291
|
+
> img {
|
|
292
|
+
height: 100%;
|
|
293
|
+
width: 100%;
|
|
294
|
+
object-fit: cover;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
> svg {
|
|
298
|
+
width: 90%;
|
|
299
|
+
height: 90%;
|
|
300
|
+
padding: 10%;
|
|
301
|
+
color: ${(p) => {
|
|
302
|
+
var _a;
|
|
303
|
+
return (_a = p.theme.colors) == null ? void 0 : _a.text;
|
|
304
|
+
}};
|
|
305
|
+
|
|
306
|
+
line,
|
|
307
|
+
path,
|
|
308
|
+
circle,
|
|
309
|
+
fill {
|
|
310
|
+
stroke: ${(p) => {
|
|
311
|
+
var _a;
|
|
312
|
+
return (_a = p.theme.colors) == null ? void 0 : _a.text;
|
|
313
|
+
}};
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
`;
|
|
317
|
+
const LoaderAnimation = keyframes`
|
|
318
|
+
0% {
|
|
319
|
+
opacity: 0;
|
|
320
|
+
}
|
|
321
|
+
75% {
|
|
322
|
+
opacity: 1;
|
|
323
|
+
}
|
|
324
|
+
100% {
|
|
325
|
+
opacity: 0;
|
|
326
|
+
}
|
|
327
|
+
`;
|
|
328
|
+
const Loader = styled.div`
|
|
329
|
+
display: flex;
|
|
330
|
+
justify-content: center;
|
|
331
|
+
> div {
|
|
332
|
+
height: 10px;
|
|
333
|
+
width: 10px;
|
|
334
|
+
border-radius: 50%;
|
|
335
|
+
margin: 5px;
|
|
336
|
+
background-color: ${(p) => {
|
|
337
|
+
var _a;
|
|
338
|
+
return (_a = p.theme.colors) == null ? void 0 : _a.text;
|
|
339
|
+
}};
|
|
340
|
+
animation: ${LoaderAnimation} 1s infinite;
|
|
341
|
+
}
|
|
342
|
+
> div:nth-child(2) {
|
|
343
|
+
animation-delay: 100ms;
|
|
344
|
+
}
|
|
345
|
+
> div:nth-child(3) {
|
|
346
|
+
animation-delay: 200ms;
|
|
347
|
+
}
|
|
348
|
+
`;
|
|
349
|
+
const ContentBundle = styled.div`
|
|
350
|
+
grid-area: content;
|
|
351
|
+
max-width: 100%;
|
|
352
|
+
overflow: hidden;
|
|
353
|
+
`;
|
|
354
|
+
const MessageTitle = styled(Typography)`
|
|
355
|
+
font-size: ${(p) => {
|
|
356
|
+
var _a;
|
|
357
|
+
return (_a = p.theme.fonts) == null ? void 0 : _a.normal;
|
|
358
|
+
}};
|
|
359
|
+
font-weight: normal;
|
|
360
|
+
margin: 0;
|
|
361
|
+
`;
|
|
362
|
+
const MessageContainer = styled.div`
|
|
363
|
+
display: flex;
|
|
364
|
+
`;
|
|
365
|
+
const MessageContent = styled.div`
|
|
366
|
+
background-color: ${(p) => {
|
|
367
|
+
var _a, _b;
|
|
368
|
+
return p.user ? (_a = p.theme.colors) == null ? void 0 : _a.primary : (_b = p.theme.colors) == null ? void 0 : _b.accent;
|
|
369
|
+
}};
|
|
370
|
+
color: ${(p) => {
|
|
371
|
+
var _a, _b;
|
|
372
|
+
return p.user ? (_a = p.theme.colors) == null ? void 0 : _a.accent : (_b = p.theme.colors) == null ? void 0 : _b.text;
|
|
373
|
+
}};
|
|
374
|
+
border-radius: 5px; // TODO: prop?
|
|
375
|
+
border: 1px solid rgb(231, 231, 231);
|
|
376
|
+
padding-top: calc(${(p) => {
|
|
377
|
+
var _a;
|
|
378
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.medium;
|
|
379
|
+
}} - ${(p) => {
|
|
380
|
+
var _a;
|
|
381
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
382
|
+
}});
|
|
383
|
+
padding-bottom: calc(${(p) => {
|
|
384
|
+
var _a;
|
|
385
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.medium;
|
|
386
|
+
}} - ${(p) => {
|
|
387
|
+
var _a;
|
|
388
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
389
|
+
}});
|
|
390
|
+
margin-top: ${(p) => {
|
|
391
|
+
var _a;
|
|
392
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
393
|
+
}};
|
|
394
|
+
display: inline-block;
|
|
395
|
+
&& > * {
|
|
396
|
+
overflow-wrap: break-word;
|
|
397
|
+
word-wrap: break-word;
|
|
398
|
+
word-break: break-all;
|
|
399
|
+
word-break: break-word;
|
|
400
|
+
hyphens: auto;
|
|
401
|
+
}
|
|
402
|
+
max-width: 100%;
|
|
403
|
+
${(p) => p.fullWidth && "width: 100%;"}
|
|
404
|
+
|
|
405
|
+
${(p) => !p.user && css`
|
|
406
|
+
border: ${p.theme.border};
|
|
407
|
+
`}
|
|
408
|
+
${(p) => p.user && "margin-left: auto"};
|
|
409
|
+
|
|
410
|
+
${(p) => p.stacked === "first" && p.user && css`
|
|
411
|
+
border-bottom-right-radius: 1px; // TODO: Prop?
|
|
412
|
+
`}
|
|
413
|
+
${(p) => p.stacked === "middle" && p.user && css`
|
|
414
|
+
border-bottom-right-radius: 1px;
|
|
415
|
+
border-top-right-radius: 1px;
|
|
416
|
+
`}
|
|
417
|
+
${(p) => p.stacked === "last" && p.user && css`
|
|
418
|
+
border-top-right-radius: 1px;
|
|
419
|
+
`}
|
|
420
|
+
${(p) => p.stacked === "first" && !p.user && css`
|
|
421
|
+
border-bottom-left-radius: 1px;
|
|
422
|
+
`}
|
|
423
|
+
${(p) => p.stacked === "middle" && !p.user && css`
|
|
424
|
+
border-bottom-left-radius: 1px;
|
|
425
|
+
border-top-left-radius: 1px;
|
|
426
|
+
`}
|
|
427
|
+
${(p) => p.stacked === "last" && !p.user && css`
|
|
428
|
+
border-top-left-radius: 1px;
|
|
429
|
+
`};
|
|
430
|
+
|
|
431
|
+
${(p) => !p.stacked && css`
|
|
432
|
+
${p.user ? "border-bottom-right-radius: 1px;" : "border-bottom-left-radius: 1px;"}
|
|
433
|
+
`};
|
|
434
|
+
|
|
435
|
+
transition: border-radius 500ms linear;
|
|
436
|
+
`;
|
|
437
|
+
const MessageContentPart = styled.div`
|
|
438
|
+
padding: ${(p) => {
|
|
439
|
+
var _a;
|
|
440
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
441
|
+
}} ${(p) => {
|
|
442
|
+
var _a;
|
|
443
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.medium;
|
|
444
|
+
}};
|
|
445
|
+
|
|
446
|
+
${(p) => p.noPadding && css`
|
|
447
|
+
padding: 0;
|
|
448
|
+
`}
|
|
449
|
+
|
|
450
|
+
margin-bottom: ${(p) => {
|
|
451
|
+
var _a;
|
|
452
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
453
|
+
}};
|
|
454
|
+
&:last-child {
|
|
455
|
+
margin-bottom: 0;
|
|
456
|
+
}
|
|
457
|
+
`;
|
|
458
|
+
const ConversationLoader = ({ className, agentData }) => {
|
|
459
|
+
return /* @__PURE__ */ React.createElement(ContentBundle, null, /* @__PURE__ */ React.createElement(MessageContainer, null, /* @__PURE__ */ React.createElement(MessageContent, null, /* @__PURE__ */ React.createElement(Loader, null, /* @__PURE__ */ React.createElement("div", null), /* @__PURE__ */ React.createElement("div", null), /* @__PURE__ */ React.createElement("div", null)))));
|
|
460
|
+
};
|
|
461
|
+
const StyledTimestamp = styled.p`
|
|
462
|
+
&& {
|
|
463
|
+
font-size: ${(p) => {
|
|
464
|
+
var _a;
|
|
465
|
+
return (_a = p.theme.fonts) == null ? void 0 : _a.small;
|
|
466
|
+
}};
|
|
467
|
+
font-weight: 300;
|
|
468
|
+
}
|
|
469
|
+
padding-top: ${(p) => {
|
|
470
|
+
var _a;
|
|
471
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.small;
|
|
472
|
+
}};
|
|
473
|
+
margin: 0;
|
|
474
|
+
line-height: 1.5em;
|
|
475
|
+
grid-area: info;
|
|
476
|
+
color: ${(p) => {
|
|
477
|
+
var _a;
|
|
478
|
+
return (_a = p.theme.colors) == null ? void 0 : _a.text;
|
|
479
|
+
}};
|
|
480
|
+
`;
|
|
481
|
+
const getTimestamp = (raw) => {
|
|
482
|
+
return new Date(raw).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
|
483
|
+
};
|
|
484
|
+
const Timestamp = ({ className, name, timestamp }) => {
|
|
485
|
+
if (!name && !timestamp) {
|
|
486
|
+
return null;
|
|
487
|
+
}
|
|
488
|
+
let output = "";
|
|
489
|
+
if (name) {
|
|
490
|
+
if (timestamp) {
|
|
491
|
+
output = `${name}: ${getTimestamp(timestamp)}`;
|
|
492
|
+
} else {
|
|
493
|
+
output = name;
|
|
494
|
+
}
|
|
495
|
+
} else if (timestamp) {
|
|
496
|
+
output = getTimestamp(timestamp);
|
|
497
|
+
}
|
|
498
|
+
return /* @__PURE__ */ React.createElement(StyledTimestamp, null, output);
|
|
499
|
+
};
|
|
500
|
+
const AgentMessage = ({ className, children, sender, timestamp }) => {
|
|
501
|
+
const { avatar, name } = sender;
|
|
502
|
+
const { avatarSize } = useProperties();
|
|
503
|
+
return /* @__PURE__ */ React.createElement(StyledAgentMessage, {
|
|
504
|
+
hasAvatar: !!avatar,
|
|
505
|
+
className: appendClassNames(className, "humany-conversation-agent-message")
|
|
506
|
+
}, avatar && /* @__PURE__ */ React.createElement(Avatar, {
|
|
507
|
+
avatarSize
|
|
508
|
+
}, typeof avatar === "string" ? /* @__PURE__ */ React.createElement("img", {
|
|
509
|
+
src: avatar
|
|
510
|
+
}) : /* @__PURE__ */ React.createElement(SymbolBadge, {
|
|
511
|
+
symbol: avatar
|
|
512
|
+
})), children, /* @__PURE__ */ React.createElement(Timestamp, {
|
|
513
|
+
name,
|
|
514
|
+
timestamp
|
|
515
|
+
}));
|
|
516
|
+
};
|
|
517
|
+
const StyledAgentMessage = styled.div`
|
|
518
|
+
display: grid;
|
|
519
|
+
margin-right: 10%;
|
|
520
|
+
width: 90%;
|
|
521
|
+
${(p) => p.hasAvatar ? css`
|
|
522
|
+
grid-template-columns: auto 1fr;
|
|
523
|
+
grid-template-rows: 1fr auto;
|
|
524
|
+
grid-template-areas:
|
|
525
|
+
'avatar content'
|
|
526
|
+
'. info';
|
|
527
|
+
` : css`
|
|
528
|
+
grid-template-columns: 1fr;
|
|
529
|
+
grid-template-rows: 1fr auto;
|
|
530
|
+
grid-template-areas:
|
|
531
|
+
'content'
|
|
532
|
+
'info';
|
|
533
|
+
`};
|
|
534
|
+
`;
|
|
535
|
+
const CustomMessage = (props) => {
|
|
536
|
+
const CustomComponent = useComponent(props.type);
|
|
537
|
+
if (!CustomComponent) {
|
|
538
|
+
return null;
|
|
539
|
+
}
|
|
540
|
+
return /* @__PURE__ */ React.createElement(Suspense, {
|
|
541
|
+
fallback: null
|
|
542
|
+
}, /* @__PURE__ */ React.createElement(MessageContent, {
|
|
543
|
+
user: props.isUser,
|
|
544
|
+
stacked: !!props.stacked && props.stacked,
|
|
545
|
+
fullWidth: !!props.content.form || !!props.content.actions
|
|
546
|
+
}, /* @__PURE__ */ React.createElement(MessageContentPart, {
|
|
547
|
+
noPadding: !!props.content.noPadding && props.content.noPadding
|
|
548
|
+
}, /* @__PURE__ */ React.createElement(CustomComponent, __spreadValues({}, props.content)))));
|
|
549
|
+
};
|
|
550
|
+
const SystemMessage = ({
|
|
551
|
+
className,
|
|
552
|
+
children,
|
|
553
|
+
timestamp,
|
|
554
|
+
discrete,
|
|
555
|
+
fullWidth
|
|
556
|
+
}) => {
|
|
557
|
+
return /* @__PURE__ */ React.createElement(StyledSystemMessage, {
|
|
558
|
+
className: appendClassNames(className, "humany-conversation-system-message"),
|
|
559
|
+
fullWidth
|
|
560
|
+
}, discrete ? /* @__PURE__ */ React.createElement(Discrete, {
|
|
561
|
+
className: "humany-conversation-discrete-message"
|
|
562
|
+
}, children, /* @__PURE__ */ React.createElement(Timestamp, {
|
|
563
|
+
timestamp
|
|
564
|
+
})) : /* @__PURE__ */ React.createElement(React.Fragment, null, children, /* @__PURE__ */ React.createElement(Timestamp, {
|
|
565
|
+
timestamp
|
|
566
|
+
})));
|
|
567
|
+
};
|
|
568
|
+
const StyledSystemMessage = styled.div`
|
|
569
|
+
${(p) => p.fullWidth && "width: 100%"};
|
|
570
|
+
padding: 0 ${(p) => {
|
|
571
|
+
var _a;
|
|
572
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.large;
|
|
573
|
+
}};
|
|
574
|
+
overflow: auto;
|
|
575
|
+
`;
|
|
576
|
+
const Discrete = styled.div`
|
|
577
|
+
text-align: center;
|
|
578
|
+
word-wrap: break-word;
|
|
579
|
+
font-size: ${(p) => {
|
|
580
|
+
var _a;
|
|
581
|
+
return (_a = p.theme.fonts) == null ? void 0 : _a.normal;
|
|
582
|
+
}};
|
|
583
|
+
color: ${(p) => {
|
|
584
|
+
var _a;
|
|
585
|
+
return (_a = p.theme.colors) == null ? void 0 : _a.text;
|
|
586
|
+
}};
|
|
587
|
+
> p {
|
|
588
|
+
margin: 0;
|
|
589
|
+
}
|
|
590
|
+
`;
|
|
591
|
+
const UserMessage = ({ className, children, timestamp }) => {
|
|
592
|
+
const { userLabel = "" } = useProperties();
|
|
593
|
+
return /* @__PURE__ */ React.createElement(StyledUserMessage, {
|
|
594
|
+
className: appendClassNames(className, "humany-conversation-user-message")
|
|
595
|
+
}, children, /* @__PURE__ */ React.createElement(Timestamp, {
|
|
596
|
+
name: userLabel,
|
|
597
|
+
timestamp
|
|
598
|
+
}));
|
|
599
|
+
};
|
|
600
|
+
const StyledUserMessage = styled.div`
|
|
601
|
+
margin-left: 10%;
|
|
602
|
+
width: 90%;
|
|
603
|
+
display: flex;
|
|
604
|
+
flex-direction: column;
|
|
605
|
+
align-items: flex-end;
|
|
606
|
+
`;
|
|
607
|
+
const CustomMessageListItem = ({ type, content = {} }) => {
|
|
608
|
+
const Component = useComponent(type);
|
|
609
|
+
if (!Component || !type) {
|
|
610
|
+
return null;
|
|
611
|
+
}
|
|
612
|
+
return /* @__PURE__ */ React.createElement(Component, __spreadValues({}, content));
|
|
613
|
+
};
|
|
614
|
+
const imageLightboxRenderer$1 = (attrs) => /* @__PURE__ */ React.createElement(Lightbox, {
|
|
615
|
+
attrs
|
|
616
|
+
});
|
|
617
|
+
const htmlParseInstructions$1 = {
|
|
618
|
+
transform: {
|
|
619
|
+
img: imageLightboxRenderer$1
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
const ConversationContent = ({ content, isUser, stacked }) => {
|
|
623
|
+
const dispatch = useDispatch();
|
|
624
|
+
const { title, body, actions, form, type, items } = content;
|
|
625
|
+
if (type)
|
|
626
|
+
return /* @__PURE__ */ React.createElement(CustomMessage, {
|
|
627
|
+
type,
|
|
628
|
+
content,
|
|
629
|
+
isUser,
|
|
630
|
+
stacked
|
|
631
|
+
});
|
|
632
|
+
return /* @__PURE__ */ React.createElement(MessageContent, {
|
|
633
|
+
noPadding: true,
|
|
634
|
+
user: isUser,
|
|
635
|
+
stacked: !!stacked && stacked,
|
|
636
|
+
fullWidth: !!form || !!actions
|
|
637
|
+
}, title && /* @__PURE__ */ React.createElement(MessageContentPart, null, /* @__PURE__ */ React.createElement(MessageTitle, {
|
|
638
|
+
variant: "h2"
|
|
639
|
+
}, title)), body && /* @__PURE__ */ React.createElement(MessageContentPart, null, /* @__PURE__ */ React.createElement(StyledHtml, {
|
|
640
|
+
html: body,
|
|
641
|
+
htmlParseInstruction: htmlParseInstructions$1
|
|
642
|
+
})), form && /* @__PURE__ */ React.createElement(MessageContentPart, null, /* @__PURE__ */ React.createElement(StyledForm, __spreadProps(__spreadValues({}, form), {
|
|
643
|
+
onChange: (key, data) => {
|
|
644
|
+
dispatch("form", {
|
|
645
|
+
data,
|
|
646
|
+
formKey: form.schema.id,
|
|
647
|
+
actionKey: key
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
}))), actions && /* @__PURE__ */ React.createElement(MessageContentPart, null, /* @__PURE__ */ React.createElement(StyledActionList, {
|
|
651
|
+
items: Object.keys(actions).map((i) => {
|
|
652
|
+
return { label: actions[i], actionKey: i };
|
|
653
|
+
}),
|
|
654
|
+
renderItem: (item) => {
|
|
655
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
656
|
+
key: item.actionKey
|
|
657
|
+
}, /* @__PURE__ */ React.createElement(StyledActionButton, {
|
|
658
|
+
onClick: () => {
|
|
659
|
+
dispatch("action", item.actionKey);
|
|
660
|
+
}
|
|
661
|
+
}, item.label));
|
|
662
|
+
}
|
|
663
|
+
})), items && /* @__PURE__ */ React.createElement(Fragment, null, /* @__PURE__ */ React.createElement(MessageContentPart, {
|
|
664
|
+
key: uuid(),
|
|
665
|
+
noPadding: true
|
|
666
|
+
}, /* @__PURE__ */ React.createElement(StyledActionList, {
|
|
667
|
+
items: items.map(([type2, content2]) => {
|
|
668
|
+
return { type: type2, content: content2 };
|
|
669
|
+
}),
|
|
670
|
+
renderItem: (item) => {
|
|
671
|
+
const itemKey = uuid();
|
|
672
|
+
switch (item.type) {
|
|
673
|
+
case ConversationMessageListItemType.Header: {
|
|
674
|
+
return /* @__PURE__ */ React.createElement(ConversationListItem, {
|
|
675
|
+
key: itemKey
|
|
676
|
+
}, /* @__PURE__ */ React.createElement(HeaderText, null, item.content));
|
|
677
|
+
}
|
|
678
|
+
case ConversationMessageListItemType.Text: {
|
|
679
|
+
return /* @__PURE__ */ React.createElement(ConversationListItem, {
|
|
680
|
+
key: itemKey
|
|
681
|
+
}, /* @__PURE__ */ React.createElement("span", null, item.content));
|
|
682
|
+
}
|
|
683
|
+
case ConversationMessageListItemType.HTML: {
|
|
684
|
+
return /* @__PURE__ */ React.createElement(ConversationListItem, {
|
|
685
|
+
key: itemKey
|
|
686
|
+
}, /* @__PURE__ */ React.createElement(StyledHtml, {
|
|
687
|
+
html: item.content.body,
|
|
688
|
+
htmlParseInstruction: htmlParseInstructions$1
|
|
689
|
+
}));
|
|
690
|
+
}
|
|
691
|
+
case ConversationMessageListItemType.Separator: {
|
|
692
|
+
return /* @__PURE__ */ React.createElement(ConversationListItem, {
|
|
693
|
+
key: itemKey,
|
|
694
|
+
noPadding: true
|
|
695
|
+
}, /* @__PURE__ */ React.createElement(SeparatorPadding, null, /* @__PURE__ */ React.createElement(Separator, null)));
|
|
696
|
+
}
|
|
697
|
+
case ConversationMessageListItemType.LinkList: {
|
|
698
|
+
return /* @__PURE__ */ React.createElement(ConversationListItem, {
|
|
699
|
+
key: itemKey
|
|
700
|
+
}, /* @__PURE__ */ React.createElement(StyledLinkList, {
|
|
701
|
+
items: Object.keys(item.content.actions).map((i) => {
|
|
702
|
+
return {
|
|
703
|
+
label: item.content.actions[i],
|
|
704
|
+
actionKey: i
|
|
705
|
+
};
|
|
706
|
+
}),
|
|
707
|
+
renderItem: (item2) => {
|
|
708
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
709
|
+
key: item2.actionKey
|
|
710
|
+
}, /* @__PURE__ */ React.createElement(StyledLinkButton, {
|
|
711
|
+
help: item2.actionKey === "help",
|
|
712
|
+
onClick: () => {
|
|
713
|
+
dispatch("action", item2.actionKey);
|
|
714
|
+
}
|
|
715
|
+
}, item2.label, item2.actionKey === "help" && /* @__PURE__ */ React.createElement(SymbolBadge, {
|
|
716
|
+
size: 14,
|
|
717
|
+
symbol: {
|
|
718
|
+
type: "Svg",
|
|
719
|
+
content: "caret-down"
|
|
720
|
+
}
|
|
721
|
+
})));
|
|
722
|
+
}
|
|
723
|
+
}));
|
|
724
|
+
}
|
|
725
|
+
case ConversationMessageListItemType.ButtonList: {
|
|
726
|
+
return /* @__PURE__ */ React.createElement(ConversationListItem, {
|
|
727
|
+
key: itemKey
|
|
728
|
+
}, /* @__PURE__ */ React.createElement(StyledButtonList, {
|
|
729
|
+
items: Object.keys(item.content.actions).map((i) => {
|
|
730
|
+
return {
|
|
731
|
+
label: item.content.actions[i],
|
|
732
|
+
actionKey: i
|
|
733
|
+
};
|
|
734
|
+
}),
|
|
735
|
+
renderItem: (item2) => {
|
|
736
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
737
|
+
key: item2.actionKey
|
|
738
|
+
}, /* @__PURE__ */ React.createElement(StyledButtonListButton, {
|
|
739
|
+
onClick: () => {
|
|
740
|
+
dispatch("action", item2.actionKey);
|
|
741
|
+
}
|
|
742
|
+
}, item2.label));
|
|
743
|
+
}
|
|
744
|
+
}));
|
|
745
|
+
}
|
|
746
|
+
case ConversationMessageListItemType.NoGoodAlternative: {
|
|
747
|
+
return /* @__PURE__ */ React.createElement(ConversationListItem, {
|
|
748
|
+
key: itemKey
|
|
749
|
+
}, /* @__PURE__ */ React.createElement(NoGoodAlternativeWrapper, {
|
|
750
|
+
onClick: () => {
|
|
751
|
+
dispatch("action", "help");
|
|
752
|
+
}
|
|
753
|
+
}, /* @__PURE__ */ React.createElement(SymbolBadge, {
|
|
754
|
+
size: 14,
|
|
755
|
+
symbol: {
|
|
756
|
+
type: "FontAwesome",
|
|
757
|
+
content: "meh-o"
|
|
758
|
+
}
|
|
759
|
+
}), /* @__PURE__ */ React.createElement("span", null, item.content.body)));
|
|
760
|
+
}
|
|
761
|
+
case ConversationMessageListItemType.FeedbackList: {
|
|
762
|
+
return /* @__PURE__ */ React.createElement(ConversationListItem, {
|
|
763
|
+
key: itemKey
|
|
764
|
+
}, /* @__PURE__ */ React.createElement(StyledButtonList, {
|
|
765
|
+
items: Object.keys(item.content.actions).map((i) => {
|
|
766
|
+
return {
|
|
767
|
+
label: item.content.actions[i],
|
|
768
|
+
actionKey: i
|
|
769
|
+
};
|
|
770
|
+
}),
|
|
771
|
+
renderItem: (item2) => {
|
|
772
|
+
return /* @__PURE__ */ React.createElement(FeedbackItem, {
|
|
773
|
+
key: item2.actionKey
|
|
774
|
+
}, /* @__PURE__ */ React.createElement(FeedbackButton, {
|
|
775
|
+
className: "humany-feedback-button",
|
|
776
|
+
disabled: false,
|
|
777
|
+
"aria-pressed": true,
|
|
778
|
+
"data-selected": true,
|
|
779
|
+
"data-direction": "vertical",
|
|
780
|
+
onClick: () => {
|
|
781
|
+
dispatch("action", item2.actionKey);
|
|
782
|
+
}
|
|
783
|
+
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
784
|
+
faIcon: item2.actionKey == "yes" ? "smile-o" : "frown-o"
|
|
785
|
+
}), /* @__PURE__ */ React.createElement("span", null, item2.label)));
|
|
786
|
+
}
|
|
787
|
+
}));
|
|
788
|
+
}
|
|
789
|
+
default: {
|
|
790
|
+
return /* @__PURE__ */ React.createElement(ConversationListItem, {
|
|
791
|
+
key: itemKey,
|
|
792
|
+
noPadding: true
|
|
793
|
+
}, /* @__PURE__ */ React.createElement(CustomMessageListItem, {
|
|
794
|
+
type: item.type,
|
|
795
|
+
content: item.content
|
|
796
|
+
}));
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}))));
|
|
801
|
+
};
|
|
802
|
+
const StyledForm = styled(FormComponent)`
|
|
803
|
+
& button.humany-form-component-button {
|
|
804
|
+
${(p) => {
|
|
805
|
+
var _a, _b;
|
|
806
|
+
return invertedHoverButton({
|
|
807
|
+
active: false,
|
|
808
|
+
primaryColor: (_a = p.theme.colors) == null ? void 0 : _a.primary,
|
|
809
|
+
secondaryColor: (_b = p.theme.colors) == null ? void 0 : _b.accent
|
|
810
|
+
});
|
|
811
|
+
}};
|
|
812
|
+
display: block;
|
|
813
|
+
width: 100%;
|
|
814
|
+
margin-bottom: ${(p) => {
|
|
815
|
+
var _a;
|
|
816
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
817
|
+
}};
|
|
818
|
+
}
|
|
819
|
+
& button.humany-form-component-submit {
|
|
820
|
+
width: 100%;
|
|
821
|
+
margin: 0;
|
|
822
|
+
:not(:last-child) {
|
|
823
|
+
margin-bottom: ${(p) => {
|
|
824
|
+
var _a;
|
|
825
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
826
|
+
}};
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
`;
|
|
830
|
+
const StyledHtml = styled(Html)`
|
|
831
|
+
white-space: pre-wrap;
|
|
832
|
+
a {
|
|
833
|
+
color: ${(p) => p.theme.colors.link};
|
|
834
|
+
&:focus {
|
|
835
|
+
${(p) => {
|
|
836
|
+
var _a;
|
|
837
|
+
return ((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && borderTabStyle;
|
|
838
|
+
}};
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
`;
|
|
842
|
+
const StyledActionList = styled(List)`
|
|
843
|
+
padding: 0;
|
|
844
|
+
list-style: none;
|
|
845
|
+
margin: 0 -${(p) => {
|
|
846
|
+
var _a;
|
|
847
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
848
|
+
}};
|
|
849
|
+
> li {
|
|
850
|
+
margin: ${(p) => {
|
|
851
|
+
var _a;
|
|
852
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
853
|
+
}};
|
|
854
|
+
}
|
|
855
|
+
`;
|
|
856
|
+
const StyledButtonList = styled(List)`
|
|
857
|
+
padding: 0;
|
|
858
|
+
list-style: none;
|
|
859
|
+
> li {
|
|
860
|
+
margin: ${(p) => {
|
|
861
|
+
var _a;
|
|
862
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.small;
|
|
863
|
+
}} ${(p) => {
|
|
864
|
+
var _a;
|
|
865
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
866
|
+
}};
|
|
867
|
+
margin-left: 0;
|
|
868
|
+
display: inline-block;
|
|
869
|
+
}
|
|
870
|
+
`;
|
|
871
|
+
const StyledButtonListButton = styled.button`
|
|
872
|
+
${buttonCss};
|
|
873
|
+
display: block;
|
|
874
|
+
text-align: left;
|
|
875
|
+
background-color: ${(p) => {
|
|
876
|
+
var _a;
|
|
877
|
+
return (_a = p.theme.colors) == null ? void 0 : _a.primary;
|
|
878
|
+
}};
|
|
879
|
+
width: 100%;
|
|
880
|
+
color: #fff;
|
|
881
|
+
&:focus {
|
|
882
|
+
${(p) => {
|
|
883
|
+
var _a;
|
|
884
|
+
return ((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && css`
|
|
885
|
+
${borderTabStyle}
|
|
886
|
+
background-color: transparent;
|
|
887
|
+
`;
|
|
888
|
+
}}
|
|
889
|
+
}
|
|
890
|
+
`;
|
|
891
|
+
const StyledLinkList = styled(List)`
|
|
892
|
+
padding: 0;
|
|
893
|
+
list-style: none;
|
|
894
|
+
> li {
|
|
895
|
+
margin-bottom: ${(p) => {
|
|
896
|
+
var _a;
|
|
897
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
898
|
+
}};
|
|
899
|
+
|
|
900
|
+
&:last-child {
|
|
901
|
+
margin-bottom: 0;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
`;
|
|
905
|
+
const HeaderText = styled.strong`
|
|
906
|
+
font-size: ${(p) => {
|
|
907
|
+
var _a;
|
|
908
|
+
return (_a = p.theme.fonts) == null ? void 0 : _a.huge;
|
|
909
|
+
}};
|
|
910
|
+
`;
|
|
911
|
+
const StyledLinkButton = styled.button`
|
|
912
|
+
display: block;
|
|
913
|
+
background-color: transparent;
|
|
914
|
+
text-align: left;
|
|
915
|
+
border: none;
|
|
916
|
+
padding: 0;
|
|
917
|
+
font-weight: 300;
|
|
918
|
+
font-family: inherit;
|
|
919
|
+
cursor: pointer;
|
|
920
|
+
color: ${(p) => {
|
|
921
|
+
var _a;
|
|
922
|
+
return (_a = p.theme.colors) == null ? void 0 : _a.primary;
|
|
923
|
+
}};
|
|
924
|
+
|
|
925
|
+
${(p) => {
|
|
926
|
+
var _a, _b;
|
|
927
|
+
return p.help && css`
|
|
928
|
+
color: ${(_a = p.theme.colors) == null ? void 0 : _a.text};
|
|
929
|
+
text-decoration: underline;
|
|
930
|
+
|
|
931
|
+
i,
|
|
932
|
+
svg {
|
|
933
|
+
margin-left: ${(_b = p.theme.sizes) == null ? void 0 : _b.small};
|
|
934
|
+
}
|
|
935
|
+
`;
|
|
936
|
+
}}
|
|
937
|
+
`;
|
|
938
|
+
const StyledActionButton = styled.button`
|
|
939
|
+
${buttonCss};
|
|
940
|
+
display: block;
|
|
941
|
+
background-color: ${(p) => {
|
|
942
|
+
var _a;
|
|
943
|
+
return (_a = p.theme.colors) == null ? void 0 : _a.primary;
|
|
944
|
+
}};
|
|
945
|
+
width: 100%;
|
|
946
|
+
color: #fff;
|
|
947
|
+
font-family: Lato;
|
|
948
|
+
font-size: ${(p) => {
|
|
949
|
+
var _a;
|
|
950
|
+
return (_a = p.theme.fonts) == null ? void 0 : _a.huge;
|
|
951
|
+
}};
|
|
952
|
+
font-weight: 300;
|
|
953
|
+
&:focus {
|
|
954
|
+
${(p) => {
|
|
955
|
+
var _a;
|
|
956
|
+
return ((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && css`
|
|
957
|
+
${borderTabStyle}
|
|
958
|
+
background-color: transparent;
|
|
959
|
+
`;
|
|
960
|
+
}}
|
|
961
|
+
}
|
|
962
|
+
`;
|
|
963
|
+
const SeparatorPadding = styled.div`
|
|
964
|
+
padding-top: calc(${(p) => {
|
|
965
|
+
var _a;
|
|
966
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.medium;
|
|
967
|
+
}} - ${(p) => {
|
|
968
|
+
var _a;
|
|
969
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
970
|
+
}});
|
|
971
|
+
padding-bottom: calc(${(p) => {
|
|
972
|
+
var _a;
|
|
973
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.medium;
|
|
974
|
+
}} - ${(p) => {
|
|
975
|
+
var _a;
|
|
976
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
977
|
+
}});
|
|
978
|
+
`;
|
|
979
|
+
const Separator = styled.div`
|
|
980
|
+
background-color: #efefef;
|
|
981
|
+
height: 1px;
|
|
982
|
+
width: 100%;
|
|
983
|
+
`;
|
|
984
|
+
const NoGoodAlternativeWrapper = styled.div`
|
|
985
|
+
display: flex;
|
|
986
|
+
align-items: center;
|
|
987
|
+
justify-content: center;
|
|
988
|
+
cursor: pointer;
|
|
989
|
+
|
|
990
|
+
> i,
|
|
991
|
+
svg {
|
|
992
|
+
margin-right: ${(p) => {
|
|
993
|
+
var _a;
|
|
994
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.small;
|
|
995
|
+
}};
|
|
996
|
+
}
|
|
997
|
+
`;
|
|
998
|
+
const ConversationListItem = styled.li`
|
|
999
|
+
padding-left: ${(p) => {
|
|
1000
|
+
var _a;
|
|
1001
|
+
return p.noPadding ? 0 : (_a = p.theme.sizes) == null ? void 0 : _a.medium;
|
|
1002
|
+
}};
|
|
1003
|
+
padding-right: ${(p) => {
|
|
1004
|
+
var _a;
|
|
1005
|
+
return p.noPadding ? 0 : (_a = p.theme.sizes) == null ? void 0 : _a.medium;
|
|
1006
|
+
}};
|
|
1007
|
+
`;
|
|
1008
|
+
const FeedbackItem = styled.li`
|
|
1009
|
+
@media (min-width: 768px) {
|
|
1010
|
+
display: list-item !important;
|
|
1011
|
+
margin-right: 0 !important;
|
|
1012
|
+
margin-top: ${(p) => {
|
|
1013
|
+
var _a;
|
|
1014
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
1015
|
+
}} !important;
|
|
1016
|
+
}
|
|
1017
|
+
`;
|
|
1018
|
+
const FeedbackButton = styled.button`
|
|
1019
|
+
@media (min-width: 768px) {
|
|
1020
|
+
min-width: 100%;
|
|
1021
|
+
margin-right: 0;
|
|
1022
|
+
}
|
|
1023
|
+
display: inline-block;
|
|
1024
|
+
font-size: ${(p) => {
|
|
1025
|
+
var _a;
|
|
1026
|
+
return (_a = p.theme.fonts) == null ? void 0 : _a.normal;
|
|
1027
|
+
}};
|
|
1028
|
+
border-color: ${(p) => {
|
|
1029
|
+
var _a;
|
|
1030
|
+
return (_a = p.theme.colors) == null ? void 0 : _a.primary;
|
|
1031
|
+
}} !important;
|
|
1032
|
+
font-weight: 300;
|
|
1033
|
+
&& {
|
|
1034
|
+
margin-right: ${(p) => {
|
|
1035
|
+
var _a;
|
|
1036
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.small;
|
|
1037
|
+
}};
|
|
1038
|
+
}
|
|
1039
|
+
${(p) => {
|
|
1040
|
+
var _a, _b;
|
|
1041
|
+
return p["data-direction"] === "horizontal" && css`
|
|
1042
|
+
width: 225px;
|
|
1043
|
+
max-width: calc(50% - ${(_a = p.theme.sizes) == null ? void 0 : _a.large} - ${(_b = p.theme.sizes) == null ? void 0 : _b.small});
|
|
1044
|
+
`;
|
|
1045
|
+
}}
|
|
1046
|
+
${(p) => p["data-direction"] === "vertical" && css`
|
|
1047
|
+
min-width: 150px;
|
|
1048
|
+
`}
|
|
1049
|
+
${(p) => {
|
|
1050
|
+
var _a;
|
|
1051
|
+
return invertedHoverButton({
|
|
1052
|
+
primaryColor: `${(_a = p.theme.colors) == null ? void 0 : _a.primary}`,
|
|
1053
|
+
secondaryColor: "#FFFFFF"
|
|
1054
|
+
});
|
|
1055
|
+
}}
|
|
1056
|
+
i {
|
|
1057
|
+
margin: 0 ${(p) => {
|
|
1058
|
+
var _a;
|
|
1059
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.small;
|
|
1060
|
+
}} 0 0;
|
|
1061
|
+
}
|
|
1062
|
+
span {
|
|
1063
|
+
}
|
|
1064
|
+
`;
|
|
1065
|
+
const imageLightboxRenderer = (attrs) => /* @__PURE__ */ React.createElement(Lightbox, {
|
|
1066
|
+
attrs
|
|
1067
|
+
});
|
|
1068
|
+
const htmlParseInstructions = {
|
|
1069
|
+
transform: {
|
|
1070
|
+
img: imageLightboxRenderer
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
const ConversationMessageComponent = ({
|
|
1074
|
+
className,
|
|
1075
|
+
timestamp,
|
|
1076
|
+
sender,
|
|
1077
|
+
type,
|
|
1078
|
+
content
|
|
1079
|
+
}) => {
|
|
1080
|
+
useDispatch();
|
|
1081
|
+
const getMessageStackPosition = (index) => {
|
|
1082
|
+
let messageOrder = void 0;
|
|
1083
|
+
if (content.length > 1) {
|
|
1084
|
+
messageOrder = index === 0 ? "first" : index + 1 === content.length ? "last" : "middle";
|
|
1085
|
+
}
|
|
1086
|
+
return messageOrder;
|
|
1087
|
+
};
|
|
1088
|
+
const createSystemMessage = () => {
|
|
1089
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, content.map((item) => {
|
|
1090
|
+
const { key, body, title, form, actions } = item;
|
|
1091
|
+
const discrete = !!body && !title && !form && !actions;
|
|
1092
|
+
return /* @__PURE__ */ React.createElement(SystemMessage, {
|
|
1093
|
+
className,
|
|
1094
|
+
key,
|
|
1095
|
+
discrete,
|
|
1096
|
+
timestamp,
|
|
1097
|
+
fullWidth: !!form || !!actions
|
|
1098
|
+
}, discrete && body ? /* @__PURE__ */ React.createElement(Html, {
|
|
1099
|
+
html: body,
|
|
1100
|
+
htmlParseInstruction: htmlParseInstructions
|
|
1101
|
+
}) : /* @__PURE__ */ React.createElement(ConversationContent, {
|
|
1102
|
+
content: item,
|
|
1103
|
+
isUser: false
|
|
1104
|
+
}));
|
|
1105
|
+
}));
|
|
1106
|
+
};
|
|
1107
|
+
const createAgentMessage = () => {
|
|
1108
|
+
return /* @__PURE__ */ React.createElement(AgentMessage, {
|
|
1109
|
+
sender,
|
|
1110
|
+
timestamp,
|
|
1111
|
+
className
|
|
1112
|
+
}, /* @__PURE__ */ React.createElement(ContentBundle, null, content.map((item, index) => {
|
|
1113
|
+
return /* @__PURE__ */ React.createElement(MessageContainer, {
|
|
1114
|
+
key: item.key
|
|
1115
|
+
}, /* @__PURE__ */ React.createElement(ConversationContent, {
|
|
1116
|
+
content: item,
|
|
1117
|
+
isUser: false,
|
|
1118
|
+
stacked: getMessageStackPosition(index)
|
|
1119
|
+
}));
|
|
1120
|
+
})));
|
|
1121
|
+
};
|
|
1122
|
+
const createUserMessage = () => {
|
|
1123
|
+
return /* @__PURE__ */ React.createElement(UserMessage, {
|
|
1124
|
+
timestamp,
|
|
1125
|
+
className
|
|
1126
|
+
}, /* @__PURE__ */ React.createElement(ContentBundle, null, content.map((item, index) => {
|
|
1127
|
+
return /* @__PURE__ */ React.createElement(MessageContainer, {
|
|
1128
|
+
key: item.key
|
|
1129
|
+
}, /* @__PURE__ */ React.createElement(ConversationContent, {
|
|
1130
|
+
content: item,
|
|
1131
|
+
isUser: true,
|
|
1132
|
+
stacked: getMessageStackPosition(index)
|
|
1133
|
+
}));
|
|
1134
|
+
})));
|
|
1135
|
+
};
|
|
1136
|
+
switch (type) {
|
|
1137
|
+
case ConversationMessageType.System:
|
|
1138
|
+
return createSystemMessage();
|
|
1139
|
+
case ConversationMessageType.Agent:
|
|
1140
|
+
return createAgentMessage();
|
|
1141
|
+
case ConversationMessageType.User:
|
|
1142
|
+
return createUserMessage();
|
|
1143
|
+
default:
|
|
1144
|
+
return null;
|
|
1145
|
+
}
|
|
1146
|
+
};
|
|
1147
|
+
styled(FormComponent)`
|
|
1148
|
+
& button.humany-form-component-button {
|
|
1149
|
+
${(p) => {
|
|
1150
|
+
var _a, _b;
|
|
1151
|
+
return invertedHoverButton({
|
|
1152
|
+
active: false,
|
|
1153
|
+
primaryColor: (_a = p.theme.colors) == null ? void 0 : _a.primary,
|
|
1154
|
+
secondaryColor: (_b = p.theme.colors) == null ? void 0 : _b.accent
|
|
1155
|
+
});
|
|
1156
|
+
}};
|
|
1157
|
+
display: block;
|
|
1158
|
+
width: 100%;
|
|
1159
|
+
margin-bottom: ${(p) => {
|
|
1160
|
+
var _a;
|
|
1161
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
1162
|
+
}};
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
& button.humany-form-component-submit {
|
|
1166
|
+
width: 100%;
|
|
1167
|
+
margin: 0;
|
|
1168
|
+
:not(:last-child) {
|
|
1169
|
+
margin-bottom: ${(p) => {
|
|
1170
|
+
var _a;
|
|
1171
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
1172
|
+
}};
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
`;
|
|
1176
|
+
styled(Html)`
|
|
1177
|
+
white-space: pre-wrap;
|
|
1178
|
+
|
|
1179
|
+
a {
|
|
1180
|
+
color: ${(p) => p.theme.colors.link};
|
|
1181
|
+
&:focus {
|
|
1182
|
+
${(p) => {
|
|
1183
|
+
var _a;
|
|
1184
|
+
return ((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && borderTabStyle;
|
|
1185
|
+
}};
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
`;
|
|
1189
|
+
styled(List)`
|
|
1190
|
+
padding: 0;
|
|
1191
|
+
list-style: none;
|
|
1192
|
+
margin: 0 -${(p) => {
|
|
1193
|
+
var _a;
|
|
1194
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
1195
|
+
}};
|
|
1196
|
+
> li {
|
|
1197
|
+
margin: ${(p) => {
|
|
1198
|
+
var _a;
|
|
1199
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
1200
|
+
}};
|
|
1201
|
+
}
|
|
1202
|
+
`;
|
|
1203
|
+
styled.button`
|
|
1204
|
+
${buttonCss};
|
|
1205
|
+
display: block;
|
|
1206
|
+
background-color: ${(p) => {
|
|
1207
|
+
var _a;
|
|
1208
|
+
return (_a = p.theme.colors) == null ? void 0 : _a.primary;
|
|
1209
|
+
}};
|
|
1210
|
+
width: 100%;
|
|
1211
|
+
color: #fff;
|
|
1212
|
+
&:focus {
|
|
1213
|
+
${(p) => {
|
|
1214
|
+
var _a;
|
|
1215
|
+
return ((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && css`
|
|
1216
|
+
${borderTabStyle}
|
|
1217
|
+
background-color: transparent;
|
|
1218
|
+
`;
|
|
1219
|
+
}}
|
|
1220
|
+
}
|
|
1221
|
+
`;
|
|
1222
|
+
const Conversation = ({ className }) => {
|
|
1223
|
+
const lastEntry = useRef(document.createElement("div"));
|
|
1224
|
+
const [scrollableCss, viewElem] = useScroll(true);
|
|
1225
|
+
const { messages, loading, typingActors } = useProperties();
|
|
1226
|
+
const [canSmooth, setCanSmooth] = useState(false);
|
|
1227
|
+
const scrollView = useCallback((lastEntry2, smooth = true) => {
|
|
1228
|
+
if (lastEntry2 !== null && lastEntry2.current !== null) {
|
|
1229
|
+
if (messages && messages.length === 1) {
|
|
1230
|
+
lastEntry2.current.focus();
|
|
1231
|
+
}
|
|
1232
|
+
if (lastEntry2.current.id.indexOf("typing_") !== -1 && viewElem.current.scrollTopMax - viewElem.current.scrollTop > lastEntry2.current.clientHeight + 100) {
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1235
|
+
setTimeout(() => {
|
|
1236
|
+
if (lastEntry2.current) {
|
|
1237
|
+
lastEntry2.current.scrollIntoView({
|
|
1238
|
+
block: "end",
|
|
1239
|
+
behavior: smooth ? "smooth" : "auto"
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
}, 0);
|
|
1243
|
+
}
|
|
1244
|
+
}, [lastEntry]);
|
|
1245
|
+
useEffect(() => {
|
|
1246
|
+
if (canSmooth) {
|
|
1247
|
+
scrollView(lastEntry);
|
|
1248
|
+
}
|
|
1249
|
+
}, [messages, typingActors]);
|
|
1250
|
+
useTransitionEnd(() => {
|
|
1251
|
+
setCanSmooth(true);
|
|
1252
|
+
scrollView(lastEntry, false);
|
|
1253
|
+
});
|
|
1254
|
+
const renderTypingActors = () => {
|
|
1255
|
+
if (typingActors && typingActors.length) {
|
|
1256
|
+
return typingActors.map((actor, index) => {
|
|
1257
|
+
return /* @__PURE__ */ React.createElement(MessageEntry, {
|
|
1258
|
+
id: `typing_${actor.name}`,
|
|
1259
|
+
ref: typingActors.length ? lastEntry : null,
|
|
1260
|
+
key: `typing_${actor.name}`
|
|
1261
|
+
}, /* @__PURE__ */ React.createElement(AgentMessage, {
|
|
1262
|
+
timestamp: Date.now(),
|
|
1263
|
+
sender: actor
|
|
1264
|
+
}, /* @__PURE__ */ React.createElement(ConversationLoader, null)));
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
return null;
|
|
1268
|
+
};
|
|
1269
|
+
return /* @__PURE__ */ React.createElement(Wrapper, {
|
|
1270
|
+
className: appendClassNames(className, "humany-conversation-component")
|
|
1271
|
+
}, /* @__PURE__ */ React.createElement(Scrollable, {
|
|
1272
|
+
tabIndex: 0,
|
|
1273
|
+
scrollableCss,
|
|
1274
|
+
ref: viewElem
|
|
1275
|
+
}, messages && messages.length ? messages.map((message, index) => {
|
|
1276
|
+
const { type, timestamp, sender, content } = message;
|
|
1277
|
+
return /* @__PURE__ */ React.createElement(MessageEntry, {
|
|
1278
|
+
className: "humany-conversation-entry",
|
|
1279
|
+
tabIndex: -1,
|
|
1280
|
+
key: `${type}_${sender == null ? void 0 : sender.name}_${timestamp}_${content[0].key}`,
|
|
1281
|
+
ref: index + 1 < messages.length ? null : typingActors.length ? null : lastEntry
|
|
1282
|
+
}, /* @__PURE__ */ React.createElement(ConversationMessageComponent, __spreadValues({}, message)));
|
|
1283
|
+
}) : null, renderTypingActors(), loading && /* @__PURE__ */ React.createElement(MessageEntry, null, /* @__PURE__ */ React.createElement(ConversationLoader, null))), /* @__PURE__ */ React.createElement(ConversationInput, null));
|
|
1284
|
+
};
|
|
1285
|
+
const Wrapper = styled.div`
|
|
1286
|
+
position: absolute;
|
|
1287
|
+
right: 0;
|
|
1288
|
+
left: 0;
|
|
1289
|
+
bottom: 0;
|
|
1290
|
+
top: 0;
|
|
1291
|
+
overflow: hidden;
|
|
1292
|
+
display: flex;
|
|
1293
|
+
flex-direction: column;
|
|
1294
|
+
`;
|
|
1295
|
+
const Scrollable = styled.div`
|
|
1296
|
+
display: flex;
|
|
1297
|
+
flex-direction: column;
|
|
1298
|
+
align-items: stretch;
|
|
1299
|
+
flex: 0 1 100%;
|
|
1300
|
+
padding: 0 ${(p) => {
|
|
1301
|
+
var _a;
|
|
1302
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
1303
|
+
}};
|
|
1304
|
+
${(p) => !!p.scrollableCss && p.scrollableCss};
|
|
1305
|
+
&:focus {
|
|
1306
|
+
${(p) => {
|
|
1307
|
+
var _a;
|
|
1308
|
+
return ((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && borderTabStyle;
|
|
1309
|
+
}};
|
|
1310
|
+
}
|
|
1311
|
+
`;
|
|
1312
|
+
const MessageEntry = styled.div`
|
|
1313
|
+
margin: 0;
|
|
1314
|
+
margin-bottom: ${(p) => {
|
|
1315
|
+
var _a;
|
|
1316
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.medium;
|
|
1317
|
+
}};
|
|
1318
|
+
|
|
1319
|
+
&:first-of-type {
|
|
1320
|
+
margin-top: ${(p) => {
|
|
1321
|
+
var _a;
|
|
1322
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.medium;
|
|
1323
|
+
}};
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
&:last-of-type {
|
|
1327
|
+
padding-bottom: ${(p) => {
|
|
1328
|
+
var _a;
|
|
1329
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.medium;
|
|
1330
|
+
}};
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
* {
|
|
1334
|
+
font-size: ${(p) => {
|
|
1335
|
+
var _a;
|
|
1336
|
+
return (_a = p.theme.fonts) == null ? void 0 : _a.normal;
|
|
1337
|
+
}};
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
& span,
|
|
1341
|
+
p,
|
|
1342
|
+
a,
|
|
1343
|
+
div {
|
|
1344
|
+
font-weight: 300;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
& b,
|
|
1348
|
+
h1 {
|
|
1349
|
+
font-weight: normal;
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
${headingElement("h1", css`
|
|
1353
|
+
font-weight: normal;
|
|
1354
|
+
`)}
|
|
1355
|
+
`;
|
|
1356
|
+
export { Conversation as default };
|
|
1357
|
+
//# sourceMappingURL=conversation.js.map
|