@telia-ace/widget-conversation 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/LICENSE.txt +6 -0
  2. package/README.md +256 -0
  3. package/lib/agent.d.ts +17 -0
  4. package/lib/agent.js +37 -0
  5. package/lib/conversation-controller.d.ts +87 -0
  6. package/lib/conversation-controller.js +298 -0
  7. package/lib/conversation-form-adapter.d.ts +7 -0
  8. package/lib/conversation-form-adapter.js +88 -0
  9. package/lib/conversation-platform.d.ts +49 -0
  10. package/lib/conversation-platform.js +295 -0
  11. package/lib/conversation-provider.d.ts +22 -0
  12. package/lib/conversation-provider.js +73 -0
  13. package/lib/index.d.ts +8 -0
  14. package/lib/index.js +15 -0
  15. package/lib/resolve-entity-value.d.ts +10 -0
  16. package/lib/resolve-entity-value.js +22 -0
  17. package/lib/types.d.ts +35 -0
  18. package/lib/types.js +2 -0
  19. package/lib/ui/conversation/conversation-component.d.ts +32 -0
  20. package/lib/ui/conversation/conversation-component.js +152 -0
  21. package/lib/ui/conversation/conversation-content.d.ts +11 -0
  22. package/lib/ui/conversation/conversation-content.js +100 -0
  23. package/lib/ui/conversation/conversation-input.d.ts +6 -0
  24. package/lib/ui/conversation/conversation-input.js +154 -0
  25. package/lib/ui/conversation/conversation-loader.d.ts +8 -0
  26. package/lib/ui/conversation/conversation-loader.js +18 -0
  27. package/lib/ui/conversation/conversation-message.d.ts +7 -0
  28. package/lib/ui/conversation/conversation-message.js +141 -0
  29. package/lib/ui/conversation/conversation-styles.d.ts +9 -0
  30. package/lib/ui/conversation/conversation-styles.js +63 -0
  31. package/lib/ui/conversation/conversation.d.ts +6 -0
  32. package/lib/ui/conversation/conversation.js +139 -0
  33. package/lib/ui/conversation/index.d.ts +2 -0
  34. package/lib/ui/conversation/index.js +7 -0
  35. package/lib/ui/conversation/message-types/agent.d.ts +11 -0
  36. package/lib/ui/conversation/message-types/agent.js +54 -0
  37. package/lib/ui/conversation/message-types/custom.d.ts +9 -0
  38. package/lib/ui/conversation/message-types/custom.js +26 -0
  39. package/lib/ui/conversation/message-types/index.d.ts +5 -0
  40. package/lib/ui/conversation/message-types/index.js +16 -0
  41. package/lib/ui/conversation/message-types/system.d.ts +12 -0
  42. package/lib/ui/conversation/message-types/system.js +26 -0
  43. package/lib/ui/conversation/message-types/timestamp.d.ts +8 -0
  44. package/lib/ui/conversation/message-types/timestamp.js +36 -0
  45. package/lib/ui/conversation/message-types/user.d.ts +8 -0
  46. package/lib/ui/conversation/message-types/user.js +24 -0
  47. package/lib/ui/index.d.ts +2 -0
  48. package/lib/ui/index.js +10 -0
  49. package/lib/ui/return-button/index.d.ts +2 -0
  50. package/lib/ui/return-button/index.js +7 -0
  51. package/lib/ui/return-button/return-button-component.d.ts +19 -0
  52. package/lib/ui/return-button/return-button-component.js +70 -0
  53. package/lib/ui/return-button/return-button.d.ts +6 -0
  54. package/lib/ui/return-button/return-button.js +82 -0
  55. package/lib/user.d.ts +7 -0
  56. package/lib/user.js +16 -0
  57. package/lib/utils/custom-message.d.ts +3 -0
  58. package/lib/utils/custom-message.js +56 -0
  59. package/lib/utils/index.d.ts +1 -0
  60. package/lib/utils/index.js +7 -0
  61. package/lib/utils/open-chat-widget.d.ts +4 -0
  62. package/lib/utils/open-chat-widget.js +148 -0
  63. package/lib-esm/agent.d.ts +17 -0
  64. package/lib-esm/agent.js +34 -0
  65. package/lib-esm/conversation-controller.d.ts +87 -0
  66. package/lib-esm/conversation-controller.js +294 -0
  67. package/lib-esm/conversation-form-adapter.d.ts +7 -0
  68. package/lib-esm/conversation-form-adapter.js +85 -0
  69. package/lib-esm/conversation-platform.d.ts +49 -0
  70. package/lib-esm/conversation-platform.js +292 -0
  71. package/lib-esm/conversation-provider.d.ts +22 -0
  72. package/lib-esm/conversation-provider.js +70 -0
  73. package/lib-esm/index.d.ts +8 -0
  74. package/lib-esm/index.js +5 -0
  75. package/lib-esm/resolve-entity-value.d.ts +10 -0
  76. package/lib-esm/resolve-entity-value.js +18 -0
  77. package/lib-esm/types.d.ts +35 -0
  78. package/lib-esm/types.js +1 -0
  79. package/lib-esm/ui/conversation/conversation-component.d.ts +32 -0
  80. package/lib-esm/ui/conversation/conversation-component.js +127 -0
  81. package/lib-esm/ui/conversation/conversation-content.d.ts +11 -0
  82. package/lib-esm/ui/conversation/conversation-content.js +72 -0
  83. package/lib-esm/ui/conversation/conversation-input.d.ts +6 -0
  84. package/lib-esm/ui/conversation/conversation-input.js +129 -0
  85. package/lib-esm/ui/conversation/conversation-loader.d.ts +8 -0
  86. package/lib-esm/ui/conversation/conversation-loader.js +13 -0
  87. package/lib-esm/ui/conversation/conversation-message.d.ts +7 -0
  88. package/lib-esm/ui/conversation/conversation-message.js +113 -0
  89. package/lib-esm/ui/conversation/conversation-styles.d.ts +9 -0
  90. package/lib-esm/ui/conversation/conversation-styles.js +37 -0
  91. package/lib-esm/ui/conversation/conversation.d.ts +6 -0
  92. package/lib-esm/ui/conversation/conversation.js +111 -0
  93. package/lib-esm/ui/conversation/index.d.ts +2 -0
  94. package/lib-esm/ui/conversation/index.js +2 -0
  95. package/lib-esm/ui/conversation/message-types/agent.d.ts +11 -0
  96. package/lib-esm/ui/conversation/message-types/agent.js +25 -0
  97. package/lib-esm/ui/conversation/message-types/custom.d.ts +9 -0
  98. package/lib-esm/ui/conversation/message-types/custom.js +21 -0
  99. package/lib-esm/ui/conversation/message-types/index.d.ts +5 -0
  100. package/lib-esm/ui/conversation/message-types/index.js +5 -0
  101. package/lib-esm/ui/conversation/message-types/system.d.ts +12 -0
  102. package/lib-esm/ui/conversation/message-types/system.js +20 -0
  103. package/lib-esm/ui/conversation/message-types/timestamp.d.ts +8 -0
  104. package/lib-esm/ui/conversation/message-types/timestamp.js +31 -0
  105. package/lib-esm/ui/conversation/message-types/user.d.ts +8 -0
  106. package/lib-esm/ui/conversation/message-types/user.js +19 -0
  107. package/lib-esm/ui/index.d.ts +2 -0
  108. package/lib-esm/ui/index.js +2 -0
  109. package/lib-esm/ui/return-button/index.d.ts +2 -0
  110. package/lib-esm/ui/return-button/index.js +2 -0
  111. package/lib-esm/ui/return-button/return-button-component.d.ts +19 -0
  112. package/lib-esm/ui/return-button/return-button-component.js +44 -0
  113. package/lib-esm/ui/return-button/return-button.d.ts +6 -0
  114. package/lib-esm/ui/return-button/return-button.js +54 -0
  115. package/lib-esm/user.d.ts +7 -0
  116. package/lib-esm/user.js +13 -0
  117. package/lib-esm/utils/custom-message.d.ts +3 -0
  118. package/lib-esm/utils/custom-message.js +52 -0
  119. package/lib-esm/utils/index.d.ts +1 -0
  120. package/lib-esm/utils/index.js +1 -0
  121. package/lib-esm/utils/open-chat-widget.d.ts +4 -0
  122. package/lib-esm/utils/open-chat-widget.js +142 -0
  123. package/package.json +43 -0
@@ -0,0 +1,72 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ var __assign = (this && this.__assign) || function () {
6
+ __assign = Object.assign || function(t) {
7
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8
+ s = arguments[i];
9
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
10
+ t[p] = s[p];
11
+ }
12
+ return t;
13
+ };
14
+ return __assign.apply(this, arguments);
15
+ };
16
+ import { FormComponent } from '@telia-ace/widget-forms';
17
+ import { borderTabStyle, buttonCss, Html, invertedHoverButton, Lightbox, List, useDispatch, } from '@telia-ace/widget-ui';
18
+ import React from 'react';
19
+ import styled, { css } from 'styled-components';
20
+ import { MessageContent, MessageContentPart as Part, MessageTitle } from './conversation-styles';
21
+ import { CustomMessage } from './message-types';
22
+ var imageLightboxRenderer = function (attrs) { return React.createElement(Lightbox, { attrs: attrs }); };
23
+ var htmlParseInstructions = {
24
+ transform: {
25
+ img: imageLightboxRenderer,
26
+ },
27
+ };
28
+ var ConversationContent = function (_a) {
29
+ var content = _a.content, isUser = _a.isUser, stacked = _a.stacked;
30
+ var dispatch = useDispatch();
31
+ var title = content.title, body = content.body, actions = content.actions, form = content.form, type = content.type;
32
+ if (type)
33
+ return React.createElement(CustomMessage, { type: type, content: content, isUser: isUser, stacked: stacked });
34
+ return (React.createElement(MessageContent, { user: isUser, stacked: !!stacked && stacked, fullWidth: !!form || !!actions },
35
+ title && (React.createElement(Part, null,
36
+ React.createElement(MessageTitle, { variant: "h2" }, title))),
37
+ body && (React.createElement(Part, null,
38
+ React.createElement(StyledHtml, { html: body, htmlParseInstruction: htmlParseInstructions }))),
39
+ form && (React.createElement(Part, null,
40
+ React.createElement(StyledForm, __assign({}, form, { onChange: function (key, data) {
41
+ dispatch('form', {
42
+ data: data,
43
+ formKey: form.schema.id,
44
+ actionKey: key,
45
+ });
46
+ } })))),
47
+ actions && (React.createElement(Part, null,
48
+ React.createElement(StyledActionList, { items: Object.keys(actions).map(function (i) {
49
+ return { label: actions[i], actionKey: i };
50
+ }), renderItem: function (item) {
51
+ return (React.createElement("li", { key: item.actionKey },
52
+ React.createElement(StyledActionButton, { onClick: function () {
53
+ dispatch('action', item.actionKey);
54
+ } }, item.label)));
55
+ } })))));
56
+ };
57
+ var StyledForm = styled(FormComponent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n & button.humany-form-component-button {\n ", ";\n display: block;\n width: 100%;\n margin-bottom: ", ";\n }\n & button.humany-form-component-submit {\n width: 100%;\n margin: 0;\n :not(:last-child) {\n margin-bottom: ", ";\n }\n }\n"], ["\n & button.humany-form-component-button {\n ", ";\n display: block;\n width: 100%;\n margin-bottom: ", ";\n }\n & button.humany-form-component-submit {\n width: 100%;\n margin: 0;\n :not(:last-child) {\n margin-bottom: ", ";\n }\n }\n"])), function (p) {
58
+ var _a, _b;
59
+ return invertedHoverButton({
60
+ active: false,
61
+ primaryColor: (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.primary,
62
+ secondaryColor: (_b = p.theme.colors) === null || _b === void 0 ? void 0 : _b.accent,
63
+ });
64
+ }, function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.normal; }, function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.normal; });
65
+ var StyledHtml = styled(Html)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n white-space: pre-wrap;\n a {\n color: ", ";\n &:focus {\n ", ";\n }\n }\n"], ["\n white-space: pre-wrap;\n a {\n color: ", ";\n &:focus {\n ", ";\n }\n }\n"])), function (p) { return p.theme.colors.link; }, function (p) { var _a; return ((_a = p.theme.accessibility) === null || _a === void 0 ? void 0 : _a.isTabbing) && borderTabStyle; });
66
+ var StyledActionList = styled(List)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n padding: 0;\n list-style: none;\n margin: 0 -", ";\n > li {\n margin: ", ";\n }\n"], ["\n padding: 0;\n list-style: none;\n margin: 0 -", ";\n > li {\n margin: ", ";\n }\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.normal; }, function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.normal; });
67
+ var StyledActionButton = styled.button(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n ", ";\n display: block;\n background-color: ", ";\n width: 100%;\n color: #fff;\n &:focus {\n ", "\n }\n"], ["\n ", ";\n display: block;\n background-color: ", ";\n width: 100%;\n color: #fff;\n &:focus {\n ", "\n }\n"])), buttonCss, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.primary; }, function (p) {
68
+ var _a;
69
+ return ((_a = p.theme.accessibility) === null || _a === void 0 ? void 0 : _a.isTabbing) && css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n ", "\n background-color: transparent;\n "], ["\n ", "\n background-color: transparent;\n "])), borderTabStyle);
70
+ });
71
+ export default ConversationContent;
72
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ declare type Props = {
3
+ className?: string;
4
+ };
5
+ declare const ConversationInput: React.FC<Props>;
6
+ export default ConversationInput;
@@ -0,0 +1,129 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ var __assign = (this && this.__assign) || function () {
6
+ __assign = Object.assign || function(t) {
7
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8
+ s = arguments[i];
9
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
10
+ t[p] = s[p];
11
+ }
12
+ return t;
13
+ };
14
+ return __assign.apply(this, arguments);
15
+ };
16
+ var __rest = (this && this.__rest) || function (s, e) {
17
+ var t = {};
18
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
19
+ t[p] = s[p];
20
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
21
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
22
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
23
+ t[p[i]] = s[p[i]];
24
+ }
25
+ return t;
26
+ };
27
+ var __read = (this && this.__read) || function (o, n) {
28
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
29
+ if (!m) return o;
30
+ var i = m.call(o), r, ar = [], e;
31
+ try {
32
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
33
+ }
34
+ catch (error) { e = { error: error }; }
35
+ finally {
36
+ try {
37
+ if (r && !r.done && (m = i["return"])) m.call(i);
38
+ }
39
+ finally { if (e) throw e.error; }
40
+ }
41
+ return ar;
42
+ };
43
+ import { borderTabStyle, Button, Input, SymbolBadge, useDispatch, useProperties, useScroll, } from '@telia-ace/widget-ui';
44
+ import { appendClassNames } from '@telia-ace/widget-utilities';
45
+ import React, { useEffect, useState } from 'react';
46
+ import styled, { css } from 'styled-components';
47
+ var ConversationInput = function (_a) {
48
+ var className = _a.className;
49
+ var _b = __read(useState(''), 2), inputText = _b[0], setInputText = _b[1];
50
+ var _c = __read(useState(false), 2), inputFocus = _c[0], setInputFocus = _c[1];
51
+ var _d = __read(useState(0), 2), calculatedLineHeight = _d[0], setCalculatedLineHeight = _d[1];
52
+ var _e = __read(useState(0), 2), textareaMaxHeight = _e[0], setTextareaMaxHeight = _e[1];
53
+ var dispatch = useDispatch();
54
+ var _f = useProperties(), _g = _f.inputPlaceholder, inputPlaceholder = _g === void 0 ? 'Type your message' : _g, _h = _f.inputHidden, inputHidden = _h === void 0 ? false : _h, _j = _f.inputDisabled, inputDisabled = _j === void 0 ? false : _j, _k = _f.sendButtonLabel, sendButtonLabel = _k === void 0 ? 'Send message' : _k, _l = _f.inputMultiline, multiline = _l === void 0 ? true : _l;
55
+ var _m = __read(useScroll(true), 2), scrollableCss = _m[0], inputRef = _m[1];
56
+ useEffect(function () {
57
+ if (inputRef.current) {
58
+ var _a = getComputedStyle(inputRef.current), lineHeight = _a.lineHeight, maxHeight = _a.maxHeight;
59
+ if (lineHeight && lineHeight.indexOf('px') > -1) {
60
+ var lineHeightNumber = lineHeight.split('px');
61
+ var calcLH = parseInt(lineHeightNumber[0], 10);
62
+ setCalculatedLineHeight(calcLH);
63
+ var maxHeightNumber = maxHeight.split('px');
64
+ setTextareaMaxHeight(parseInt(maxHeightNumber[0], 10));
65
+ }
66
+ }
67
+ }, [inputRef.current]);
68
+ var submit = function (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
+ }
77
+ else if (inputText.length < 1) {
78
+ e.preventDefault();
79
+ }
80
+ };
81
+ var calculateHeight = function (value) {
82
+ if (multiline && inputRef.current) {
83
+ var scrollHeight = inputRef.current.scrollHeight;
84
+ if (scrollHeight > calculatedLineHeight) {
85
+ inputRef.current.style.height = 'auto';
86
+ var areaHeight = scrollHeight;
87
+ if (value.length < 1) {
88
+ areaHeight = calculatedLineHeight;
89
+ }
90
+ inputRef.current.style.height = "".concat(areaHeight, "px");
91
+ if (areaHeight >= textareaMaxHeight) {
92
+ inputRef.current.style.overflowY = 'scroll';
93
+ }
94
+ else {
95
+ inputRef.current.style.overflowY = 'hidden';
96
+ }
97
+ }
98
+ }
99
+ };
100
+ var onChange = function (value) {
101
+ calculateHeight(value);
102
+ setInputText(value);
103
+ if (value && value.length > 0) {
104
+ dispatch('user-typing', { textLength: value.length });
105
+ }
106
+ };
107
+ if (inputHidden) {
108
+ return null;
109
+ }
110
+ return (React.createElement(Wrapper, { grow: multiline, className: appendClassNames('humany-conversation-input', className), "data-has-focus": inputFocus, scrollableCss: scrollableCss },
111
+ multiline ? (React.createElement(StyledTextArea, { value: inputText, onChange: onChange, onEnter: submit, disabled: inputDisabled, "aria-label": inputPlaceholder, placeholder: inputPlaceholder, onFocusChange: setInputFocus, type: 'textarea', rows: 1, ref: inputRef })) : (React.createElement(StyledInput, { value: inputText, onChange: onChange, onEnter: submit, disabled: inputDisabled, "aria-label": inputPlaceholder, placeholder: inputPlaceholder, onFocusChange: setInputFocus })),
112
+ React.createElement(StyledButton, { disabled: inputDisabled, onClick: submit, title: sendButtonLabel, "aria-label": sendButtonLabel },
113
+ React.createElement(SendSymbol, { size: 22, symbol: { type: 'Svg', content: 'send' }, hasContent: inputText && inputText.length }))));
114
+ };
115
+ var StyledTextArea = styled(Input)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n resize: none;\n flex: 1;\n flex-shrink: 1;\n min-height: 1.2em;\n max-height: 148px;\n line-height: 1.2em;\n height: 1.2em;\n padding: 0;\n margin: ", " ", ";\n font-size: ", ";\n border: none;\n transition: height 200ms linear;\n outline: none;\n"], ["\n resize: none;\n flex: 1;\n flex-shrink: 1;\n min-height: 1.2em;\n max-height: 148px;\n line-height: 1.2em;\n height: 1.2em;\n padding: 0;\n margin: ", " ", ";\n font-size: ", ";\n border: none;\n transition: height 200ms linear;\n outline: none;\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.small; }, function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium; }, function (p) { var _a; return (_a = p.theme.fonts) === null || _a === void 0 ? void 0 : _a.normal; });
116
+ var StyledInput = styled(Input)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n flex: 1;\n border: none;\n background-color: transparent;\n font-weight: 300;\n font-size: ", ";\n line-height: 1.2em;\n outline: none;\n padding-left: ", ";\n color: ", ";\n &::placeholder {\n color: ", ";\n font-style: italic;\n }\n"], ["\n flex: 1;\n border: none;\n background-color: transparent;\n font-weight: 300;\n font-size: ", ";\n line-height: 1.2em;\n outline: none;\n padding-left: ", ";\n color: ", ";\n &::placeholder {\n color: ", ";\n font-style: italic;\n }\n"])), function (p) { var _a; return (_a = p.theme.fonts) === null || _a === void 0 ? void 0 : _a.normal; }, function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.large; }, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.text; }, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.textLight; });
117
+ var StyledButton = styled(Button)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n flex: 0 0 50px;\n align-self: stretch;\n background-color: transparent;\n border: none;\n &:focus {\n ", ";\n }\n"], ["\n flex: 0 0 50px;\n align-self: stretch;\n background-color: transparent;\n border: none;\n &:focus {\n ", ";\n }\n"])), function (p) { var _a; return ((_a = p.theme.accessibility) === null || _a === void 0 ? void 0 : _a.isTabbing) && borderTabStyle; });
118
+ var Wrapper = styled.div(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n ", "\n flex: 0 0 auto;\n display: flex;\n align-items: center;\n background-color: ", ";\n border-top: ", ";\n ", "\n ", " {\n ", "\n }\n"], ["\n ", "\n flex: 0 0 auto;\n display: flex;\n align-items: center;\n background-color: ", ";\n border-top: ", ";\n ", "\n ", " {\n ", "\n }\n"])), function (p) {
119
+ return p.grow
120
+ ? css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n min-height: 50px;\n max-height: 150px;\n "], ["\n min-height: 50px;\n max-height: 150px;\n "]))) : css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n height: 50px;\n "], ["\n height: 50px;\n "])));
121
+ }, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.accent; }, function (p) { return p.theme.inputBorder; }, function (p) {
122
+ return p['data-has-focus'] && css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n ", ";\n "], ["\n ", ";\n "])), function (p) { var _a; return ((_a = p.theme.accessibility) === null || _a === void 0 ? void 0 : _a.isTabbing) && borderTabStyle; });
123
+ }, StyledTextArea, function (p) { return !!p.scrollableCss && p.scrollableCss; });
124
+ var SendSymbol = styled(function (_a) {
125
+ var hasContent = _a.hasContent, other = __rest(_a, ["hasContent"]);
126
+ return React.createElement(SymbolBadge, __assign({}, other));
127
+ })(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n line,\n path {\n stroke: ", ";\n fill: ", ";\n }\n"], ["\n line,\n path {\n stroke: ", ";\n fill: ", ";\n }\n"])), function (p) { var _a; return (p.hasContent ? (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.primary : '#a6a6a6'); }, function (p) { var _a; return (p.hasContent ? (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.primary : '#a6a6a6'); });
128
+ export default ConversationInput;
129
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { ConversationMessageSender } from '../../types';
3
+ declare type Props = {
4
+ className?: string;
5
+ agentData?: ConversationMessageSender;
6
+ };
7
+ declare const ConversationLoader: React.FC<Props>;
8
+ export default ConversationLoader;
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { ContentBundle, Loader, MessageContainer, MessageContent } from './conversation-styles';
3
+ var ConversationLoader = function (_a) {
4
+ var className = _a.className, agentData = _a.agentData;
5
+ return (React.createElement(ContentBundle, null,
6
+ React.createElement(MessageContainer, null,
7
+ React.createElement(MessageContent, null,
8
+ React.createElement(Loader, null,
9
+ React.createElement("div", null),
10
+ React.createElement("div", null),
11
+ React.createElement("div", null))))));
12
+ };
13
+ export default ConversationLoader;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { BundledConversationMessage } from './conversation-component';
3
+ declare type Props = {
4
+ className?: string;
5
+ } & BundledConversationMessage;
6
+ declare const ConversationMessageComponent: React.FC<Props>;
7
+ export default ConversationMessageComponent;
@@ -0,0 +1,113 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ var __assign = (this && this.__assign) || function () {
6
+ __assign = Object.assign || function(t) {
7
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8
+ s = arguments[i];
9
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
10
+ t[p] = s[p];
11
+ }
12
+ return t;
13
+ };
14
+ return __assign.apply(this, arguments);
15
+ };
16
+ import { FormComponent } from '@telia-ace/widget-forms';
17
+ import { borderTabStyle, buttonCss, Html, invertedHoverButton, Lightbox, List, useDispatch, } from '@telia-ace/widget-ui';
18
+ import React from 'react';
19
+ import styled, { css } from 'styled-components';
20
+ import { ConversationMessageType } from '../../conversation-controller';
21
+ import ConversationContent from './conversation-content';
22
+ import { ContentBundle, MessageContainer, MessageContent, MessageContentPart as Part, MessageTitle, } from './conversation-styles';
23
+ import { AgentMessage, SystemMessage, UserMessage } from './message-types';
24
+ var imageLightboxRenderer = function (attrs) { return React.createElement(Lightbox, { attrs: attrs }); };
25
+ var htmlParseInstructions = {
26
+ transform: {
27
+ img: imageLightboxRenderer,
28
+ },
29
+ };
30
+ var ConversationMessageComponent = function (_a) {
31
+ var className = _a.className, timestamp = _a.timestamp, sender = _a.sender, type = _a.type, content = _a.content;
32
+ var dispatch = useDispatch();
33
+ var getMessageStackPosition = function (index) {
34
+ var messageOrder = undefined;
35
+ if (content.length > 1) {
36
+ messageOrder = index === 0 ? 'first' : index + 1 === content.length ? 'last' : 'middle';
37
+ }
38
+ return messageOrder;
39
+ };
40
+ var renderContent = function (content, isUser, stacked) {
41
+ if (isUser === void 0) { isUser = false; }
42
+ var title = content.title, body = content.body, actions = content.actions, form = content.form;
43
+ return (React.createElement(MessageContent, { user: isUser, stacked: !!stacked && stacked, fullWidth: !!form || !!actions },
44
+ title && (React.createElement(Part, null,
45
+ React.createElement(MessageTitle, { variant: "h2" }, title))),
46
+ body && (React.createElement(Part, null,
47
+ React.createElement(StyledHtml, { html: body, htmlParseInstruction: htmlParseInstructions }))),
48
+ form && (React.createElement(Part, null,
49
+ React.createElement(StyledForm, __assign({}, form, { onChange: function (key, data) {
50
+ dispatch('form', {
51
+ data: data,
52
+ formKey: form.schema.id,
53
+ actionKey: key,
54
+ });
55
+ } })))),
56
+ actions && (React.createElement(Part, null,
57
+ React.createElement(StyledActionList, { items: Object.keys(actions).map(function (i) {
58
+ return { label: actions[i], actionKey: i };
59
+ }), renderItem: function (item) {
60
+ return (React.createElement("li", { key: item.actionKey },
61
+ React.createElement(StyledActionButton, { onClick: function () {
62
+ dispatch('action', item.actionKey);
63
+ } }, item.label)));
64
+ } })))));
65
+ };
66
+ var createSystemMessage = function () {
67
+ return (React.createElement(React.Fragment, null, content.map(function (item) {
68
+ var key = item.key, body = item.body, title = item.title, form = item.form, actions = item.actions;
69
+ var discrete = !!body && !title && !form && !actions;
70
+ return (React.createElement(SystemMessage, { className: className, key: key, discrete: discrete, timestamp: timestamp, fullWidth: !!form || !!actions }, discrete && body ? (React.createElement(Html, { html: body, htmlParseInstruction: htmlParseInstructions })) : (React.createElement(ConversationContent, { content: item, isUser: false }))));
71
+ })));
72
+ };
73
+ var createAgentMessage = function () {
74
+ return (React.createElement(AgentMessage, { sender: sender, timestamp: timestamp, className: className },
75
+ React.createElement(ContentBundle, null, content.map(function (item, index) {
76
+ return (React.createElement(MessageContainer, { key: item.key },
77
+ React.createElement(ConversationContent, { content: item, isUser: false, stacked: getMessageStackPosition(index) })));
78
+ }))));
79
+ };
80
+ var createUserMessage = function () {
81
+ return (React.createElement(UserMessage, { timestamp: timestamp, className: className },
82
+ React.createElement(ContentBundle, null, content.map(function (item, index) {
83
+ return (React.createElement(MessageContainer, { key: item.key },
84
+ React.createElement(ConversationContent, { content: item, isUser: true, stacked: getMessageStackPosition(index) })));
85
+ }))));
86
+ };
87
+ switch (type) {
88
+ case ConversationMessageType.System:
89
+ return createSystemMessage();
90
+ case ConversationMessageType.Agent:
91
+ return createAgentMessage();
92
+ case ConversationMessageType.User:
93
+ return createUserMessage();
94
+ default:
95
+ return null;
96
+ }
97
+ };
98
+ var StyledForm = styled(FormComponent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n & button.humany-form-component-button {\n ", ";\n display: block;\n width: 100%;\n margin-bottom: ", ";\n }\n\n & button.humany-form-component-submit {\n width: 100%;\n margin: 0;\n :not(:last-child) {\n margin-bottom: ", ";\n }\n }\n"], ["\n & button.humany-form-component-button {\n ", ";\n display: block;\n width: 100%;\n margin-bottom: ", ";\n }\n\n & button.humany-form-component-submit {\n width: 100%;\n margin: 0;\n :not(:last-child) {\n margin-bottom: ", ";\n }\n }\n"])), function (p) {
99
+ var _a, _b;
100
+ return invertedHoverButton({
101
+ active: false,
102
+ primaryColor: (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.primary,
103
+ secondaryColor: (_b = p.theme.colors) === null || _b === void 0 ? void 0 : _b.accent,
104
+ });
105
+ }, function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.normal; }, function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.normal; });
106
+ var StyledHtml = styled(Html)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n white-space: pre-wrap;\n\n a {\n color: ", ";\n &:focus {\n ", ";\n }\n }\n"], ["\n white-space: pre-wrap;\n\n a {\n color: ", ";\n &:focus {\n ", ";\n }\n }\n"])), function (p) { return p.theme.colors.link; }, function (p) { var _a; return ((_a = p.theme.accessibility) === null || _a === void 0 ? void 0 : _a.isTabbing) && borderTabStyle; });
107
+ var StyledActionList = styled(List)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n padding: 0;\n list-style: none;\n margin: 0 -", ";\n > li {\n margin: ", ";\n }\n"], ["\n padding: 0;\n list-style: none;\n margin: 0 -", ";\n > li {\n margin: ", ";\n }\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.normal; }, function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.normal; });
108
+ var StyledActionButton = styled.button(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n ", ";\n display: block;\n background-color: ", ";\n width: 100%;\n color: #fff;\n &:focus {\n ", "\n }\n"], ["\n ", ";\n display: block;\n background-color: ", ";\n width: 100%;\n color: #fff;\n &:focus {\n ", "\n }\n"])), buttonCss, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.primary; }, function (p) {
109
+ var _a;
110
+ return ((_a = p.theme.accessibility) === null || _a === void 0 ? void 0 : _a.isTabbing) && css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n ", "\n background-color: transparent;\n "], ["\n ", "\n background-color: transparent;\n "])), borderTabStyle);
111
+ });
112
+ export default ConversationMessageComponent;
113
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ export declare const Avatar: import("styled-components").StyledComponent<"div", any, any, never>;
3
+ export declare const LoaderAnimation: import("styled-components").Keyframes;
4
+ export declare const Loader: import("styled-components").StyledComponent<"div", any, {}, never>;
5
+ export declare const ContentBundle: import("styled-components").StyledComponent<"div", any, {}, never>;
6
+ export declare const MessageTitle: import("styled-components").StyledComponent<import("react").FC<import("@telia-ace/widget-ui").TypographyProps>, any, {}, never>;
7
+ export declare const MessageContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
8
+ export declare const MessageContent: import("styled-components").StyledComponent<"div", any, any, never>;
9
+ export declare const MessageContentPart: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -0,0 +1,37 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ import { Typography } from '@telia-ace/widget-ui';
6
+ import styled, { css, keyframes } from 'styled-components';
7
+ export var Avatar = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: ", ";\n height: ", ";\n border-radius: 50%;\n background-color: ", ";\n border: ", ";\n grid-area: avatar;\n align-self: flex-end;\n justify-self: center;\n overflow: hidden;\n margin-right: 10px;\n display: flex;\n justify-content: center;\n align-items: center;\n color: ", ";\n\n > img {\n height: 100%;\n width: 100%;\n object-fit: cover;\n }\n\n > svg {\n width: 90%;\n height: 90%;\n padding: 10%;\n color: ", ";\n\n line,\n path,\n circle,\n fill {\n stroke: ", ";\n }\n }\n"], ["\n width: ", ";\n height: ", ";\n border-radius: 50%;\n background-color: ", ";\n border: ", ";\n grid-area: avatar;\n align-self: flex-end;\n justify-self: center;\n overflow: hidden;\n margin-right: 10px;\n display: flex;\n justify-content: center;\n align-items: center;\n color: ", ";\n\n > img {\n height: 100%;\n width: 100%;\n object-fit: cover;\n }\n\n > svg {\n width: 90%;\n height: 90%;\n padding: 10%;\n color: ", ";\n\n line,\n path,\n circle,\n fill {\n stroke: ", ";\n }\n }\n"])), function (p) { return p.avatarSize || '32px'; }, function (p) { return p.avatarSize || '32px'; }, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.accent; }, function (p) { return p.theme.border; }, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.text; }, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.text; }, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.text; });
8
+ export var LoaderAnimation = keyframes(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n 0% {\n opacity: 0;\n }\n 75% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n"], ["\n 0% {\n opacity: 0;\n }\n 75% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n"])));
9
+ export var Loader = styled.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n display: flex;\n justify-content: center;\n > div {\n height: 10px;\n width: 10px;\n border-radius: 50%;\n margin: 5px;\n background-color: ", ";\n animation: ", " 1s infinite;\n }\n > div:nth-child(2) {\n animation-delay: 100ms;\n }\n > div:nth-child(3) {\n animation-delay: 200ms;\n }\n"], ["\n display: flex;\n justify-content: center;\n > div {\n height: 10px;\n width: 10px;\n border-radius: 50%;\n margin: 5px;\n background-color: ", ";\n animation: ", " 1s infinite;\n }\n > div:nth-child(2) {\n animation-delay: 100ms;\n }\n > div:nth-child(3) {\n animation-delay: 200ms;\n }\n"])), function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.text; }, LoaderAnimation);
10
+ export var ContentBundle = styled.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n grid-area: content;\n max-width: 100%;\n overflow: auto;\n"], ["\n grid-area: content;\n max-width: 100%;\n overflow: auto;\n"])));
11
+ export var MessageTitle = styled(Typography)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n font-size: ", ";\n font-weight: normal;\n margin: 0;\n"], ["\n font-size: ", ";\n font-weight: normal;\n margin: 0;\n"])), function (p) { var _a; return (_a = p.theme.fonts) === null || _a === void 0 ? void 0 : _a.normal; });
12
+ export var MessageContainer = styled.div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n display: flex;\n"], ["\n display: flex;\n"])));
13
+ export var MessageContent = styled.div(templateObject_15 || (templateObject_15 = __makeTemplateObject(["\n padding: ", ";\n background-color: ", ";\n color: ", ";\n border-radius: 5px; // TODO: prop?\n margin-top: ", ";\n display: inline-block;\n && > * {\n overflow-wrap: break-word;\n word-wrap: break-word;\n word-break: break-all;\n word-break: break-word;\n hyphens: auto;\n }\n max-width: 100%;\n ", "\n\n ", "\n ", ";\n\n ", "\n ", "\n ", "\n ", "\n ", "\n ", ";\n\n ", ";\n\n transition: border-radius 500ms linear;\n"], ["\n padding: ", ";\n background-color: ", ";\n color: ", ";\n border-radius: 5px; // TODO: prop?\n margin-top: ", ";\n display: inline-block;\n && > * {\n overflow-wrap: break-word;\n word-wrap: break-word;\n word-break: break-all;\n word-break: break-word;\n hyphens: auto;\n }\n max-width: 100%;\n ", "\n\n ", "\n ", ";\n\n ", "\n ", "\n ", "\n ", "\n ", "\n ", ";\n\n ", ";\n\n transition: border-radius 500ms linear;\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium; }, function (p) { var _a, _b; return (p.user ? (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.primary : (_b = p.theme.colors) === null || _b === void 0 ? void 0 : _b.accent); }, function (p) { var _a, _b; return (p.user ? (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.accent : (_b = p.theme.colors) === null || _b === void 0 ? void 0 : _b.text); }, function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.normal; }, function (p) { return p.fullWidth && 'width: 100%;'; }, function (p) {
14
+ return !p.user && css(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n border: ", ";\n "], ["\n border: ", ";\n "])), p.theme.border);
15
+ }, function (p) { return p.user && 'margin-left: auto'; }, function (p) {
16
+ return p.stacked === 'first' &&
17
+ p.user && css(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n border-bottom-right-radius: 1px; // TODO: Prop?\n "], ["\n border-bottom-right-radius: 1px; // TODO: Prop?\n "])));
18
+ }, function (p) {
19
+ return p.stacked === 'middle' &&
20
+ p.user && css(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n border-bottom-right-radius: 1px;\n border-top-right-radius: 1px;\n "], ["\n border-bottom-right-radius: 1px;\n border-top-right-radius: 1px;\n "])));
21
+ }, function (p) {
22
+ return p.stacked === 'last' &&
23
+ p.user && css(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n border-top-right-radius: 1px;\n "], ["\n border-top-right-radius: 1px;\n "])));
24
+ }, function (p) {
25
+ return p.stacked === 'first' &&
26
+ !p.user && css(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n border-bottom-left-radius: 1px;\n "], ["\n border-bottom-left-radius: 1px;\n "])));
27
+ }, function (p) {
28
+ return p.stacked === 'middle' &&
29
+ !p.user && css(templateObject_12 || (templateObject_12 = __makeTemplateObject(["\n border-bottom-left-radius: 1px;\n border-top-left-radius: 1px;\n "], ["\n border-bottom-left-radius: 1px;\n border-top-left-radius: 1px;\n "])));
30
+ }, function (p) {
31
+ return p.stacked === 'last' &&
32
+ !p.user && css(templateObject_13 || (templateObject_13 = __makeTemplateObject(["\n border-top-left-radius: 1px;\n "], ["\n border-top-left-radius: 1px;\n "])));
33
+ }, function (p) {
34
+ return !p.stacked && css(templateObject_14 || (templateObject_14 = __makeTemplateObject(["\n ", "\n "], ["\n ", "\n "])), p.user ? 'border-bottom-right-radius: 1px;' : 'border-bottom-left-radius: 1px;');
35
+ });
36
+ export var MessageContentPart = styled.div(templateObject_16 || (templateObject_16 = __makeTemplateObject(["\n margin-bottom: ", ";\n &:last-child {\n margin-bottom: 0;\n }\n"], ["\n margin-bottom: ", ";\n &:last-child {\n margin-bottom: 0;\n }\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.normal; });
37
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15, templateObject_16;
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ declare type Props = {
3
+ className: string;
4
+ };
5
+ declare const Conversation: React.FC<Props>;
6
+ export default Conversation;
@@ -0,0 +1,111 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ var __assign = (this && this.__assign) || function () {
6
+ __assign = Object.assign || function(t) {
7
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8
+ s = arguments[i];
9
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
10
+ t[p] = s[p];
11
+ }
12
+ return t;
13
+ };
14
+ return __assign.apply(this, arguments);
15
+ };
16
+ var __read = (this && this.__read) || function (o, n) {
17
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
18
+ if (!m) return o;
19
+ var i = m.call(o), r, ar = [], e;
20
+ try {
21
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
22
+ }
23
+ catch (error) { e = { error: error }; }
24
+ finally {
25
+ try {
26
+ if (r && !r.done && (m = i["return"])) m.call(i);
27
+ }
28
+ finally { if (e) throw e.error; }
29
+ }
30
+ return ar;
31
+ };
32
+ import { borderTabStyle, headingElement, useProperties, useScroll, useTransitionEnd, } from '@telia-ace/widget-ui';
33
+ import { appendClassNames } from '@telia-ace/widget-utilities';
34
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
35
+ import styled, { css } from 'styled-components';
36
+ import ConversationInput from './conversation-input';
37
+ import ConversationLoader from './conversation-loader';
38
+ import ConversationMessageComponent from './conversation-message';
39
+ import { AgentMessage } from './message-types';
40
+ var Conversation = function (_a) {
41
+ var className = _a.className;
42
+ var lastEntry = useRef(document.createElement('div'));
43
+ var _b = __read(useScroll(true), 2), scrollableCss = _b[0], viewElem = _b[1];
44
+ var _c = useProperties(), messages = _c.messages, loading = _c.loading, typingActors = _c.typingActors;
45
+ var _d = __read(useState(false), 2), canSmooth = _d[0], setCanSmooth = _d[1];
46
+ var scrollView = useCallback(function (lastEntry, smooth) {
47
+ if (smooth === void 0) { smooth = true; }
48
+ if (lastEntry !== null && lastEntry.current !== null) {
49
+ if (messages && messages.length === 1) {
50
+ lastEntry.current.focus();
51
+ }
52
+ /**
53
+ * Don't scroll on typing state if the user has scrolled up a bit.
54
+ */
55
+ if (lastEntry.current.id.indexOf('typing_') !== -1 &&
56
+ viewElem.current.scrollTopMax - viewElem.current.scrollTop >
57
+ lastEntry.current.clientHeight + 100) {
58
+ return;
59
+ }
60
+ setTimeout(function () {
61
+ if (lastEntry.current) {
62
+ lastEntry.current.scrollIntoView({
63
+ block: 'end',
64
+ behavior: smooth ? 'smooth' : 'auto',
65
+ });
66
+ }
67
+ }, 0);
68
+ }
69
+ }, [lastEntry]);
70
+ useEffect(function () {
71
+ if (canSmooth) {
72
+ scrollView(lastEntry);
73
+ }
74
+ }, [messages, typingActors]);
75
+ useTransitionEnd(function () {
76
+ setCanSmooth(true);
77
+ scrollView(lastEntry, false);
78
+ });
79
+ var renderTypingActors = function () {
80
+ if (typingActors && typingActors.length) {
81
+ return typingActors.map(function (actor, index) {
82
+ return (React.createElement(MessageEntry, { id: "typing_".concat(actor.name), ref: typingActors.length ? lastEntry : null, key: "typing_".concat(actor.name) },
83
+ React.createElement(AgentMessage, { timestamp: Date.now(), sender: actor },
84
+ React.createElement(ConversationLoader, null))));
85
+ });
86
+ }
87
+ return null;
88
+ };
89
+ return (React.createElement(Wrapper, { className: appendClassNames(className, 'humany-conversation-component') },
90
+ React.createElement(Scrollable, { tabIndex: 0, scrollableCss: scrollableCss, ref: viewElem },
91
+ messages && messages.length
92
+ ? messages.map(function (message, index) {
93
+ var type = message.type, timestamp = message.timestamp, sender = message.sender, content = message.content;
94
+ return (React.createElement(MessageEntry, { className: 'humany-conversation-entry', tabIndex: -1, key: "".concat(type, "_").concat(sender === null || sender === void 0 ? void 0 : sender.name, "_").concat(timestamp, "_").concat(content[0].key), ref: index + 1 < messages.length
95
+ ? null
96
+ : typingActors.length
97
+ ? null
98
+ : lastEntry },
99
+ React.createElement(ConversationMessageComponent, __assign({}, message))));
100
+ })
101
+ : null,
102
+ renderTypingActors(),
103
+ loading && (React.createElement(MessageEntry, null,
104
+ React.createElement(ConversationLoader, null)))),
105
+ React.createElement(ConversationInput, null)));
106
+ };
107
+ var Wrapper = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: absolute;\n right: 0;\n left: 0;\n bottom: 0;\n top: 0;\n overflow: hidden;\n display: flex;\n flex-direction: column;\n"], ["\n position: absolute;\n right: 0;\n left: 0;\n bottom: 0;\n top: 0;\n overflow: hidden;\n display: flex;\n flex-direction: column;\n"])));
108
+ var Scrollable = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: flex;\n flex-direction: column;\n align-items: stretch;\n flex: 0 1 100%;\n padding: 0 ", ";\n ", ";\n &:focus {\n ", ";\n }\n"], ["\n display: flex;\n flex-direction: column;\n align-items: stretch;\n flex: 0 1 100%;\n padding: 0 ", ";\n ", ";\n &:focus {\n ", ";\n }\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium; }, function (p) { return !!p.scrollableCss && p.scrollableCss; }, function (p) { var _a; return ((_a = p.theme.accessibility) === null || _a === void 0 ? void 0 : _a.isTabbing) && borderTabStyle; });
109
+ var MessageEntry = styled.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n margin: 0;\n margin-bottom: ", ";\n\n &:first-of-type {\n margin-top: ", ";\n }\n\n &:last-of-type {\n padding-bottom: ", ";\n }\n\n * {\n font-size: ", ";\n }\n\n & span,\n p,\n a,\n div {\n font-weight: 300;\n }\n\n & b,\n h1 {\n font-weight: normal;\n }\n\n ", "\n"], ["\n margin: 0;\n margin-bottom: ", ";\n\n &:first-of-type {\n margin-top: ", ";\n }\n\n &:last-of-type {\n padding-bottom: ", ";\n }\n\n * {\n font-size: ", ";\n }\n\n & span,\n p,\n a,\n div {\n font-weight: 300;\n }\n\n & b,\n h1 {\n font-weight: normal;\n }\n\n ", "\n"])), function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium; }, function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium; }, function (p) { var _a; return (_a = p.theme.sizes) === null || _a === void 0 ? void 0 : _a.medium; }, function (p) { var _a; return (_a = p.theme.fonts) === null || _a === void 0 ? void 0 : _a.normal; }, headingElement('h1', css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n font-weight: normal;\n "], ["\n font-weight: normal;\n "])))));
110
+ export default Conversation;
111
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
@@ -0,0 +1,2 @@
1
+ import ConversationComponent from './conversation-component';
2
+ export default ConversationComponent;
@@ -0,0 +1,2 @@
1
+ import ConversationComponent from './conversation-component';
2
+ export default ConversationComponent;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { ConversationMessageSender } from '../../../types';
3
+ declare type Props = {
4
+ className?: string;
5
+ children: any;
6
+ sender: ConversationMessageSender;
7
+ timestamp: number | null;
8
+ };
9
+ declare const AgentMessage: React.FC<Props>;
10
+ export declare const StyledAgentMessage: import("styled-components").StyledComponent<"div", any, any, never>;
11
+ export default AgentMessage;
@@ -0,0 +1,25 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ import { SymbolBadge, useProperties } from '@telia-ace/widget-ui';
6
+ import { appendClassNames } from '@telia-ace/widget-utilities';
7
+ import React from 'react';
8
+ import styled, { css } from 'styled-components';
9
+ import { Avatar } from '../conversation-styles';
10
+ import Timestamp from './timestamp';
11
+ var AgentMessage = function (_a) {
12
+ var className = _a.className, children = _a.children, sender = _a.sender, timestamp = _a.timestamp;
13
+ var avatar = sender.avatar, name = sender.name;
14
+ var avatarSize = useProperties().avatarSize;
15
+ return (React.createElement(StyledAgentMessage, { hasAvatar: !!avatar, className: appendClassNames(className, 'humany-conversation-agent-message') },
16
+ avatar && (React.createElement(Avatar, { avatarSize: avatarSize }, typeof avatar === 'string' ? (React.createElement("img", { src: avatar })) : (React.createElement(SymbolBadge, { symbol: avatar })))),
17
+ children,
18
+ React.createElement(Timestamp, { name: name, timestamp: timestamp })));
19
+ };
20
+ export var StyledAgentMessage = styled.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n display: grid;\n margin-right: 0;\n width: 100%;\n ", ";\n"], ["\n display: grid;\n margin-right: 0;\n width: 100%;\n ", ";\n"])), function (p) {
21
+ return p.hasAvatar
22
+ ? css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n grid-template-columns: auto 1fr;\n grid-template-rows: 1fr auto;\n grid-template-areas:\n 'avatar content'\n '. info';\n "], ["\n grid-template-columns: auto 1fr;\n grid-template-rows: 1fr auto;\n grid-template-areas:\n 'avatar content'\n '. info';\n "]))) : css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n grid-template-columns: 1fr;\n grid-template-rows: 1fr auto;\n grid-template-areas:\n 'content'\n 'info';\n "], ["\n grid-template-columns: 1fr;\n grid-template-rows: 1fr auto;\n grid-template-areas:\n 'content'\n 'info';\n "])));
23
+ });
24
+ export default AgentMessage;
25
+ var templateObject_1, templateObject_2, templateObject_3;
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ export declare type Props = {
3
+ type: any;
4
+ content: any;
5
+ isUser: any;
6
+ stacked: any;
7
+ };
8
+ declare const CustomMessage: React.FC<Props>;
9
+ export default CustomMessage;