@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.
- package/LICENSE.txt +6 -0
- package/README.md +256 -0
- package/lib/agent.d.ts +17 -0
- package/lib/agent.js +37 -0
- package/lib/conversation-controller.d.ts +87 -0
- package/lib/conversation-controller.js +298 -0
- package/lib/conversation-form-adapter.d.ts +7 -0
- package/lib/conversation-form-adapter.js +88 -0
- package/lib/conversation-platform.d.ts +49 -0
- package/lib/conversation-platform.js +295 -0
- package/lib/conversation-provider.d.ts +22 -0
- package/lib/conversation-provider.js +73 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +15 -0
- package/lib/resolve-entity-value.d.ts +10 -0
- package/lib/resolve-entity-value.js +22 -0
- package/lib/types.d.ts +35 -0
- package/lib/types.js +2 -0
- package/lib/ui/conversation/conversation-component.d.ts +32 -0
- package/lib/ui/conversation/conversation-component.js +152 -0
- package/lib/ui/conversation/conversation-content.d.ts +11 -0
- package/lib/ui/conversation/conversation-content.js +100 -0
- package/lib/ui/conversation/conversation-input.d.ts +6 -0
- package/lib/ui/conversation/conversation-input.js +154 -0
- package/lib/ui/conversation/conversation-loader.d.ts +8 -0
- package/lib/ui/conversation/conversation-loader.js +18 -0
- package/lib/ui/conversation/conversation-message.d.ts +7 -0
- package/lib/ui/conversation/conversation-message.js +141 -0
- package/lib/ui/conversation/conversation-styles.d.ts +9 -0
- package/lib/ui/conversation/conversation-styles.js +63 -0
- package/lib/ui/conversation/conversation.d.ts +6 -0
- package/lib/ui/conversation/conversation.js +139 -0
- package/lib/ui/conversation/index.d.ts +2 -0
- package/lib/ui/conversation/index.js +7 -0
- package/lib/ui/conversation/message-types/agent.d.ts +11 -0
- package/lib/ui/conversation/message-types/agent.js +54 -0
- package/lib/ui/conversation/message-types/custom.d.ts +9 -0
- package/lib/ui/conversation/message-types/custom.js +26 -0
- package/lib/ui/conversation/message-types/index.d.ts +5 -0
- package/lib/ui/conversation/message-types/index.js +16 -0
- package/lib/ui/conversation/message-types/system.d.ts +12 -0
- package/lib/ui/conversation/message-types/system.js +26 -0
- package/lib/ui/conversation/message-types/timestamp.d.ts +8 -0
- package/lib/ui/conversation/message-types/timestamp.js +36 -0
- package/lib/ui/conversation/message-types/user.d.ts +8 -0
- package/lib/ui/conversation/message-types/user.js +24 -0
- package/lib/ui/index.d.ts +2 -0
- package/lib/ui/index.js +10 -0
- package/lib/ui/return-button/index.d.ts +2 -0
- package/lib/ui/return-button/index.js +7 -0
- package/lib/ui/return-button/return-button-component.d.ts +19 -0
- package/lib/ui/return-button/return-button-component.js +70 -0
- package/lib/ui/return-button/return-button.d.ts +6 -0
- package/lib/ui/return-button/return-button.js +82 -0
- package/lib/user.d.ts +7 -0
- package/lib/user.js +16 -0
- package/lib/utils/custom-message.d.ts +3 -0
- package/lib/utils/custom-message.js +56 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +7 -0
- package/lib/utils/open-chat-widget.d.ts +4 -0
- package/lib/utils/open-chat-widget.js +148 -0
- package/lib-esm/agent.d.ts +17 -0
- package/lib-esm/agent.js +34 -0
- package/lib-esm/conversation-controller.d.ts +87 -0
- package/lib-esm/conversation-controller.js +294 -0
- package/lib-esm/conversation-form-adapter.d.ts +7 -0
- package/lib-esm/conversation-form-adapter.js +85 -0
- package/lib-esm/conversation-platform.d.ts +49 -0
- package/lib-esm/conversation-platform.js +292 -0
- package/lib-esm/conversation-provider.d.ts +22 -0
- package/lib-esm/conversation-provider.js +70 -0
- package/lib-esm/index.d.ts +8 -0
- package/lib-esm/index.js +5 -0
- package/lib-esm/resolve-entity-value.d.ts +10 -0
- package/lib-esm/resolve-entity-value.js +18 -0
- package/lib-esm/types.d.ts +35 -0
- package/lib-esm/types.js +1 -0
- package/lib-esm/ui/conversation/conversation-component.d.ts +32 -0
- package/lib-esm/ui/conversation/conversation-component.js +127 -0
- package/lib-esm/ui/conversation/conversation-content.d.ts +11 -0
- package/lib-esm/ui/conversation/conversation-content.js +72 -0
- package/lib-esm/ui/conversation/conversation-input.d.ts +6 -0
- package/lib-esm/ui/conversation/conversation-input.js +129 -0
- package/lib-esm/ui/conversation/conversation-loader.d.ts +8 -0
- package/lib-esm/ui/conversation/conversation-loader.js +13 -0
- package/lib-esm/ui/conversation/conversation-message.d.ts +7 -0
- package/lib-esm/ui/conversation/conversation-message.js +113 -0
- package/lib-esm/ui/conversation/conversation-styles.d.ts +9 -0
- package/lib-esm/ui/conversation/conversation-styles.js +37 -0
- package/lib-esm/ui/conversation/conversation.d.ts +6 -0
- package/lib-esm/ui/conversation/conversation.js +111 -0
- package/lib-esm/ui/conversation/index.d.ts +2 -0
- package/lib-esm/ui/conversation/index.js +2 -0
- package/lib-esm/ui/conversation/message-types/agent.d.ts +11 -0
- package/lib-esm/ui/conversation/message-types/agent.js +25 -0
- package/lib-esm/ui/conversation/message-types/custom.d.ts +9 -0
- package/lib-esm/ui/conversation/message-types/custom.js +21 -0
- package/lib-esm/ui/conversation/message-types/index.d.ts +5 -0
- package/lib-esm/ui/conversation/message-types/index.js +5 -0
- package/lib-esm/ui/conversation/message-types/system.d.ts +12 -0
- package/lib-esm/ui/conversation/message-types/system.js +20 -0
- package/lib-esm/ui/conversation/message-types/timestamp.d.ts +8 -0
- package/lib-esm/ui/conversation/message-types/timestamp.js +31 -0
- package/lib-esm/ui/conversation/message-types/user.d.ts +8 -0
- package/lib-esm/ui/conversation/message-types/user.js +19 -0
- package/lib-esm/ui/index.d.ts +2 -0
- package/lib-esm/ui/index.js +2 -0
- package/lib-esm/ui/return-button/index.d.ts +2 -0
- package/lib-esm/ui/return-button/index.js +2 -0
- package/lib-esm/ui/return-button/return-button-component.d.ts +19 -0
- package/lib-esm/ui/return-button/return-button-component.js +44 -0
- package/lib-esm/ui/return-button/return-button.d.ts +6 -0
- package/lib-esm/ui/return-button/return-button.js +54 -0
- package/lib-esm/user.d.ts +7 -0
- package/lib-esm/user.js +13 -0
- package/lib-esm/utils/custom-message.d.ts +3 -0
- package/lib-esm/utils/custom-message.js +52 -0
- package/lib-esm/utils/index.d.ts +1 -0
- package/lib-esm/utils/index.js +1 -0
- package/lib-esm/utils/open-chat-widget.d.ts +4 -0
- package/lib-esm/utils/open-chat-widget.js +142 -0
- package/package.json +43 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
37
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
38
|
+
if (!m) return o;
|
|
39
|
+
var i = m.call(o), r, ar = [], e;
|
|
40
|
+
try {
|
|
41
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
42
|
+
}
|
|
43
|
+
catch (error) { e = { error: error }; }
|
|
44
|
+
finally {
|
|
45
|
+
try {
|
|
46
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
47
|
+
}
|
|
48
|
+
finally { if (e) throw e.error; }
|
|
49
|
+
}
|
|
50
|
+
return ar;
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
var widget_ui_1 = require("@telia-ace/widget-ui");
|
|
54
|
+
var conversation_controller_1 = require("../../conversation-controller");
|
|
55
|
+
var conversation_platform_1 = require("../../conversation-platform");
|
|
56
|
+
/**
|
|
57
|
+
* Group items by sender, type and time. Current grouping threshold is 2000 ms.
|
|
58
|
+
* Put this as a property on either the component or on the provider?
|
|
59
|
+
* Could possibly be implemented directly in the createEntry method
|
|
60
|
+
* of the conversation controller to avoid iterating over the entire array on
|
|
61
|
+
* each update.
|
|
62
|
+
*/
|
|
63
|
+
var groupedMessages = function (messages, timeout) {
|
|
64
|
+
return messages.reduce(function (acc, current, index) {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
var newItem = __assign(__assign({}, current), { content: [__assign(__assign({}, current.content), { key: current.key })] });
|
|
67
|
+
if (acc.length > 0 && current.type !== conversation_controller_1.ConversationMessageType.System) {
|
|
68
|
+
var previous = acc[acc.length - 1];
|
|
69
|
+
if ((!timeout && timeout !== 0) ||
|
|
70
|
+
Math.abs(previous.timestamp - current.timestamp) < timeout) {
|
|
71
|
+
if (((_a = previous.sender) === null || _a === void 0 ? void 0 : _a.name) === ((_b = current.sender) === null || _b === void 0 ? void 0 : _b.name) &&
|
|
72
|
+
previous.type === current.type) {
|
|
73
|
+
previous.timestamp = current.timestamp;
|
|
74
|
+
previous.content.push(__assign(__assign({}, current.content), { key: current.key }));
|
|
75
|
+
return acc;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
acc.push(newItem);
|
|
80
|
+
return acc;
|
|
81
|
+
}, []);
|
|
82
|
+
};
|
|
83
|
+
var ConversationComponent = function (container) {
|
|
84
|
+
return Promise.all([
|
|
85
|
+
conversation_platform_1.ConversationPlatform.getInstance(container),
|
|
86
|
+
container.getAsync('router'),
|
|
87
|
+
]).then(function (_a) {
|
|
88
|
+
var _b = __read(_a, 2), platform = _b[0], router = _b[1];
|
|
89
|
+
return (0, widget_ui_1.createReactComponent)(container, 'conversation', Promise.resolve().then(function () { return __importStar(require('./conversation')); }), function (component) {
|
|
90
|
+
var routeData = router.getRouteData();
|
|
91
|
+
var name = routeData.params.id || component.node.name || 'component';
|
|
92
|
+
var conversation = platform.createController(name);
|
|
93
|
+
var isNewController = platform.registerController(conversation, component);
|
|
94
|
+
var messageGroupingTimeout = 3 * 60 * 1000;
|
|
95
|
+
var setProperties = function (properties) {
|
|
96
|
+
var _a = properties.providers, providers = _a === void 0 ? [] : _a;
|
|
97
|
+
if (providers) {
|
|
98
|
+
var providerKeys = Array.isArray(providers) ? providers : [providers];
|
|
99
|
+
conversation.setProviders(providerKeys);
|
|
100
|
+
return providerKeys;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
setProperties(component.properties(setProperties));
|
|
104
|
+
conversation.setComponentMountedState(true);
|
|
105
|
+
var writeMessages = function (messageStream) {
|
|
106
|
+
var loading = messageStream.loading, typingActors = messageStream.typingActors, messages = messageStream.messages;
|
|
107
|
+
component.writeProperties({
|
|
108
|
+
loading: loading,
|
|
109
|
+
typingActors: typingActors,
|
|
110
|
+
messages: groupedMessages(messages, messageGroupingTimeout),
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
writeMessages(conversation.getMessageStream());
|
|
114
|
+
if (isNewController) {
|
|
115
|
+
// todo: dont create actions here, there will be duplicates due to reuseController = true
|
|
116
|
+
component.actions.create('user-submit', function (data, options) {
|
|
117
|
+
if (options) {
|
|
118
|
+
var preventDefault = options.preventDefault, validationPromise = options.validationPromise;
|
|
119
|
+
if (preventDefault) {
|
|
120
|
+
if (validationPromise) {
|
|
121
|
+
validationPromise().then(function (text) {
|
|
122
|
+
if (text) {
|
|
123
|
+
conversation.user.print(text);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
conversation.user.print(data.text);
|
|
131
|
+
});
|
|
132
|
+
component.actions.create('user-typing', function (data, options) { });
|
|
133
|
+
component.actions.create('form', function (data, options) { });
|
|
134
|
+
component.actions.create('action', function (data, options) { });
|
|
135
|
+
}
|
|
136
|
+
var unsubscribe = conversation.events.subscribe('conversation:updated', function (e, conversationData) {
|
|
137
|
+
writeMessages(conversationData);
|
|
138
|
+
});
|
|
139
|
+
return function () {
|
|
140
|
+
conversation.setComponentMountedState(false);
|
|
141
|
+
unsubscribe();
|
|
142
|
+
if (!conversation.active) {
|
|
143
|
+
// unregisterController();
|
|
144
|
+
// todo: add possibility to dispose this through extendComponent()
|
|
145
|
+
// component.dispose();
|
|
146
|
+
writeMessages({ messages: [], typingActors: [], loading: false });
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}, { reuseController: true });
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
exports.default = ConversationComponent;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ConversationMessageContent } from '../../types';
|
|
3
|
+
declare type Props = {
|
|
4
|
+
className?: string;
|
|
5
|
+
content: ConversationMessageContent;
|
|
6
|
+
isUser: boolean;
|
|
7
|
+
stacked?: string;
|
|
8
|
+
CustomComponent?: any;
|
|
9
|
+
};
|
|
10
|
+
declare const ConversationContent: React.FC<Props>;
|
|
11
|
+
export default ConversationContent;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
+
return cooked;
|
|
5
|
+
};
|
|
6
|
+
var __assign = (this && this.__assign) || function () {
|
|
7
|
+
__assign = Object.assign || function(t) {
|
|
8
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
9
|
+
s = arguments[i];
|
|
10
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
11
|
+
t[p] = s[p];
|
|
12
|
+
}
|
|
13
|
+
return t;
|
|
14
|
+
};
|
|
15
|
+
return __assign.apply(this, arguments);
|
|
16
|
+
};
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
var widget_forms_1 = require("@telia-ace/widget-forms");
|
|
45
|
+
var widget_ui_1 = require("@telia-ace/widget-ui");
|
|
46
|
+
var react_1 = __importDefault(require("react"));
|
|
47
|
+
var styled_components_1 = __importStar(require("styled-components"));
|
|
48
|
+
var conversation_styles_1 = require("./conversation-styles");
|
|
49
|
+
var message_types_1 = require("./message-types");
|
|
50
|
+
var imageLightboxRenderer = function (attrs) { return react_1.default.createElement(widget_ui_1.Lightbox, { attrs: attrs }); };
|
|
51
|
+
var htmlParseInstructions = {
|
|
52
|
+
transform: {
|
|
53
|
+
img: imageLightboxRenderer,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
var ConversationContent = function (_a) {
|
|
57
|
+
var content = _a.content, isUser = _a.isUser, stacked = _a.stacked;
|
|
58
|
+
var dispatch = (0, widget_ui_1.useDispatch)();
|
|
59
|
+
var title = content.title, body = content.body, actions = content.actions, form = content.form, type = content.type;
|
|
60
|
+
if (type)
|
|
61
|
+
return react_1.default.createElement(message_types_1.CustomMessage, { type: type, content: content, isUser: isUser, stacked: stacked });
|
|
62
|
+
return (react_1.default.createElement(conversation_styles_1.MessageContent, { user: isUser, stacked: !!stacked && stacked, fullWidth: !!form || !!actions },
|
|
63
|
+
title && (react_1.default.createElement(conversation_styles_1.MessageContentPart, null,
|
|
64
|
+
react_1.default.createElement(conversation_styles_1.MessageTitle, { variant: "h2" }, title))),
|
|
65
|
+
body && (react_1.default.createElement(conversation_styles_1.MessageContentPart, null,
|
|
66
|
+
react_1.default.createElement(StyledHtml, { html: body, htmlParseInstruction: htmlParseInstructions }))),
|
|
67
|
+
form && (react_1.default.createElement(conversation_styles_1.MessageContentPart, null,
|
|
68
|
+
react_1.default.createElement(StyledForm, __assign({}, form, { onChange: function (key, data) {
|
|
69
|
+
dispatch('form', {
|
|
70
|
+
data: data,
|
|
71
|
+
formKey: form.schema.id,
|
|
72
|
+
actionKey: key,
|
|
73
|
+
});
|
|
74
|
+
} })))),
|
|
75
|
+
actions && (react_1.default.createElement(conversation_styles_1.MessageContentPart, null,
|
|
76
|
+
react_1.default.createElement(StyledActionList, { items: Object.keys(actions).map(function (i) {
|
|
77
|
+
return { label: actions[i], actionKey: i };
|
|
78
|
+
}), renderItem: function (item) {
|
|
79
|
+
return (react_1.default.createElement("li", { key: item.actionKey },
|
|
80
|
+
react_1.default.createElement(StyledActionButton, { onClick: function () {
|
|
81
|
+
dispatch('action', item.actionKey);
|
|
82
|
+
} }, item.label)));
|
|
83
|
+
} })))));
|
|
84
|
+
};
|
|
85
|
+
var StyledForm = (0, styled_components_1.default)(widget_forms_1.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) {
|
|
86
|
+
var _a, _b;
|
|
87
|
+
return (0, widget_ui_1.invertedHoverButton)({
|
|
88
|
+
active: false,
|
|
89
|
+
primaryColor: (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.primary,
|
|
90
|
+
secondaryColor: (_b = p.theme.colors) === null || _b === void 0 ? void 0 : _b.accent,
|
|
91
|
+
});
|
|
92
|
+
}, 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; });
|
|
93
|
+
var StyledHtml = (0, styled_components_1.default)(widget_ui_1.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) && widget_ui_1.borderTabStyle; });
|
|
94
|
+
var StyledActionList = (0, styled_components_1.default)(widget_ui_1.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; });
|
|
95
|
+
var StyledActionButton = styled_components_1.default.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"])), widget_ui_1.buttonCss, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.primary; }, function (p) {
|
|
96
|
+
var _a;
|
|
97
|
+
return ((_a = p.theme.accessibility) === null || _a === void 0 ? void 0 : _a.isTabbing) && (0, styled_components_1.css)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n ", "\n background-color: transparent;\n "], ["\n ", "\n background-color: transparent;\n "])), widget_ui_1.borderTabStyle);
|
|
98
|
+
});
|
|
99
|
+
exports.default = ConversationContent;
|
|
100
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
+
return cooked;
|
|
5
|
+
};
|
|
6
|
+
var __assign = (this && this.__assign) || function () {
|
|
7
|
+
__assign = Object.assign || function(t) {
|
|
8
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
9
|
+
s = arguments[i];
|
|
10
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
11
|
+
t[p] = s[p];
|
|
12
|
+
}
|
|
13
|
+
return t;
|
|
14
|
+
};
|
|
15
|
+
return __assign.apply(this, arguments);
|
|
16
|
+
};
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
41
|
+
var t = {};
|
|
42
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
43
|
+
t[p] = s[p];
|
|
44
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
45
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
46
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
47
|
+
t[p[i]] = s[p[i]];
|
|
48
|
+
}
|
|
49
|
+
return t;
|
|
50
|
+
};
|
|
51
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
52
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
53
|
+
if (!m) return o;
|
|
54
|
+
var i = m.call(o), r, ar = [], e;
|
|
55
|
+
try {
|
|
56
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
57
|
+
}
|
|
58
|
+
catch (error) { e = { error: error }; }
|
|
59
|
+
finally {
|
|
60
|
+
try {
|
|
61
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
62
|
+
}
|
|
63
|
+
finally { if (e) throw e.error; }
|
|
64
|
+
}
|
|
65
|
+
return ar;
|
|
66
|
+
};
|
|
67
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
68
|
+
var widget_ui_1 = require("@telia-ace/widget-ui");
|
|
69
|
+
var widget_utilities_1 = require("@telia-ace/widget-utilities");
|
|
70
|
+
var react_1 = __importStar(require("react"));
|
|
71
|
+
var styled_components_1 = __importStar(require("styled-components"));
|
|
72
|
+
var ConversationInput = function (_a) {
|
|
73
|
+
var className = _a.className;
|
|
74
|
+
var _b = __read((0, react_1.useState)(''), 2), inputText = _b[0], setInputText = _b[1];
|
|
75
|
+
var _c = __read((0, react_1.useState)(false), 2), inputFocus = _c[0], setInputFocus = _c[1];
|
|
76
|
+
var _d = __read((0, react_1.useState)(0), 2), calculatedLineHeight = _d[0], setCalculatedLineHeight = _d[1];
|
|
77
|
+
var _e = __read((0, react_1.useState)(0), 2), textareaMaxHeight = _e[0], setTextareaMaxHeight = _e[1];
|
|
78
|
+
var dispatch = (0, widget_ui_1.useDispatch)();
|
|
79
|
+
var _f = (0, widget_ui_1.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;
|
|
80
|
+
var _m = __read((0, widget_ui_1.useScroll)(true), 2), scrollableCss = _m[0], inputRef = _m[1];
|
|
81
|
+
(0, react_1.useEffect)(function () {
|
|
82
|
+
if (inputRef.current) {
|
|
83
|
+
var _a = getComputedStyle(inputRef.current), lineHeight = _a.lineHeight, maxHeight = _a.maxHeight;
|
|
84
|
+
if (lineHeight && lineHeight.indexOf('px') > -1) {
|
|
85
|
+
var lineHeightNumber = lineHeight.split('px');
|
|
86
|
+
var calcLH = parseInt(lineHeightNumber[0], 10);
|
|
87
|
+
setCalculatedLineHeight(calcLH);
|
|
88
|
+
var maxHeightNumber = maxHeight.split('px');
|
|
89
|
+
setTextareaMaxHeight(parseInt(maxHeightNumber[0], 10));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}, [inputRef.current]);
|
|
93
|
+
var submit = function (e) {
|
|
94
|
+
if (!e.shiftKey || !multiline) {
|
|
95
|
+
e.preventDefault();
|
|
96
|
+
if (inputText && inputText.length > 0) {
|
|
97
|
+
dispatch('user-submit', { text: inputText });
|
|
98
|
+
setInputText('');
|
|
99
|
+
onChange('');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (inputText.length < 1) {
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var calculateHeight = function (value) {
|
|
107
|
+
if (multiline && inputRef.current) {
|
|
108
|
+
var scrollHeight = inputRef.current.scrollHeight;
|
|
109
|
+
if (scrollHeight > calculatedLineHeight) {
|
|
110
|
+
inputRef.current.style.height = 'auto';
|
|
111
|
+
var areaHeight = scrollHeight;
|
|
112
|
+
if (value.length < 1) {
|
|
113
|
+
areaHeight = calculatedLineHeight;
|
|
114
|
+
}
|
|
115
|
+
inputRef.current.style.height = "".concat(areaHeight, "px");
|
|
116
|
+
if (areaHeight >= textareaMaxHeight) {
|
|
117
|
+
inputRef.current.style.overflowY = 'scroll';
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
inputRef.current.style.overflowY = 'hidden';
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var onChange = function (value) {
|
|
126
|
+
calculateHeight(value);
|
|
127
|
+
setInputText(value);
|
|
128
|
+
if (value && value.length > 0) {
|
|
129
|
+
dispatch('user-typing', { textLength: value.length });
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
if (inputHidden) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
return (react_1.default.createElement(Wrapper, { grow: multiline, className: (0, widget_utilities_1.appendClassNames)('humany-conversation-input', className), "data-has-focus": inputFocus, scrollableCss: scrollableCss },
|
|
136
|
+
multiline ? (react_1.default.createElement(StyledTextArea, { value: inputText, onChange: onChange, onEnter: submit, disabled: inputDisabled, "aria-label": inputPlaceholder, placeholder: inputPlaceholder, onFocusChange: setInputFocus, type: 'textarea', rows: 1, ref: inputRef })) : (react_1.default.createElement(StyledInput, { value: inputText, onChange: onChange, onEnter: submit, disabled: inputDisabled, "aria-label": inputPlaceholder, placeholder: inputPlaceholder, onFocusChange: setInputFocus })),
|
|
137
|
+
react_1.default.createElement(StyledButton, { disabled: inputDisabled, onClick: submit, title: sendButtonLabel, "aria-label": sendButtonLabel },
|
|
138
|
+
react_1.default.createElement(SendSymbol, { size: 22, symbol: { type: 'Svg', content: 'send' }, hasContent: inputText && inputText.length }))));
|
|
139
|
+
};
|
|
140
|
+
var StyledTextArea = (0, styled_components_1.default)(widget_ui_1.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; });
|
|
141
|
+
var StyledInput = (0, styled_components_1.default)(widget_ui_1.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; });
|
|
142
|
+
var StyledButton = (0, styled_components_1.default)(widget_ui_1.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) && widget_ui_1.borderTabStyle; });
|
|
143
|
+
var Wrapper = styled_components_1.default.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) {
|
|
144
|
+
return p.grow
|
|
145
|
+
? (0, styled_components_1.css)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n min-height: 50px;\n max-height: 150px;\n "], ["\n min-height: 50px;\n max-height: 150px;\n "]))) : (0, styled_components_1.css)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n height: 50px;\n "], ["\n height: 50px;\n "])));
|
|
146
|
+
}, 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) {
|
|
147
|
+
return p['data-has-focus'] && (0, styled_components_1.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) && widget_ui_1.borderTabStyle; });
|
|
148
|
+
}, StyledTextArea, function (p) { return !!p.scrollableCss && p.scrollableCss; });
|
|
149
|
+
var SendSymbol = (0, styled_components_1.default)(function (_a) {
|
|
150
|
+
var hasContent = _a.hasContent, other = __rest(_a, ["hasContent"]);
|
|
151
|
+
return react_1.default.createElement(widget_ui_1.SymbolBadge, __assign({}, other));
|
|
152
|
+
})(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'); });
|
|
153
|
+
exports.default = ConversationInput;
|
|
154
|
+
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,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var react_1 = __importDefault(require("react"));
|
|
7
|
+
var conversation_styles_1 = require("./conversation-styles");
|
|
8
|
+
var ConversationLoader = function (_a) {
|
|
9
|
+
var className = _a.className, agentData = _a.agentData;
|
|
10
|
+
return (react_1.default.createElement(conversation_styles_1.ContentBundle, null,
|
|
11
|
+
react_1.default.createElement(conversation_styles_1.MessageContainer, null,
|
|
12
|
+
react_1.default.createElement(conversation_styles_1.MessageContent, null,
|
|
13
|
+
react_1.default.createElement(conversation_styles_1.Loader, null,
|
|
14
|
+
react_1.default.createElement("div", null),
|
|
15
|
+
react_1.default.createElement("div", null),
|
|
16
|
+
react_1.default.createElement("div", null))))));
|
|
17
|
+
};
|
|
18
|
+
exports.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,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
+
return cooked;
|
|
5
|
+
};
|
|
6
|
+
var __assign = (this && this.__assign) || function () {
|
|
7
|
+
__assign = Object.assign || function(t) {
|
|
8
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
9
|
+
s = arguments[i];
|
|
10
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
11
|
+
t[p] = s[p];
|
|
12
|
+
}
|
|
13
|
+
return t;
|
|
14
|
+
};
|
|
15
|
+
return __assign.apply(this, arguments);
|
|
16
|
+
};
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
var widget_forms_1 = require("@telia-ace/widget-forms");
|
|
45
|
+
var widget_ui_1 = require("@telia-ace/widget-ui");
|
|
46
|
+
var react_1 = __importDefault(require("react"));
|
|
47
|
+
var styled_components_1 = __importStar(require("styled-components"));
|
|
48
|
+
var conversation_controller_1 = require("../../conversation-controller");
|
|
49
|
+
var conversation_content_1 = __importDefault(require("./conversation-content"));
|
|
50
|
+
var conversation_styles_1 = require("./conversation-styles");
|
|
51
|
+
var message_types_1 = require("./message-types");
|
|
52
|
+
var imageLightboxRenderer = function (attrs) { return react_1.default.createElement(widget_ui_1.Lightbox, { attrs: attrs }); };
|
|
53
|
+
var htmlParseInstructions = {
|
|
54
|
+
transform: {
|
|
55
|
+
img: imageLightboxRenderer,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
var ConversationMessageComponent = function (_a) {
|
|
59
|
+
var className = _a.className, timestamp = _a.timestamp, sender = _a.sender, type = _a.type, content = _a.content;
|
|
60
|
+
var dispatch = (0, widget_ui_1.useDispatch)();
|
|
61
|
+
var getMessageStackPosition = function (index) {
|
|
62
|
+
var messageOrder = undefined;
|
|
63
|
+
if (content.length > 1) {
|
|
64
|
+
messageOrder = index === 0 ? 'first' : index + 1 === content.length ? 'last' : 'middle';
|
|
65
|
+
}
|
|
66
|
+
return messageOrder;
|
|
67
|
+
};
|
|
68
|
+
var renderContent = function (content, isUser, stacked) {
|
|
69
|
+
if (isUser === void 0) { isUser = false; }
|
|
70
|
+
var title = content.title, body = content.body, actions = content.actions, form = content.form;
|
|
71
|
+
return (react_1.default.createElement(conversation_styles_1.MessageContent, { user: isUser, stacked: !!stacked && stacked, fullWidth: !!form || !!actions },
|
|
72
|
+
title && (react_1.default.createElement(conversation_styles_1.MessageContentPart, null,
|
|
73
|
+
react_1.default.createElement(conversation_styles_1.MessageTitle, { variant: "h2" }, title))),
|
|
74
|
+
body && (react_1.default.createElement(conversation_styles_1.MessageContentPart, null,
|
|
75
|
+
react_1.default.createElement(StyledHtml, { html: body, htmlParseInstruction: htmlParseInstructions }))),
|
|
76
|
+
form && (react_1.default.createElement(conversation_styles_1.MessageContentPart, null,
|
|
77
|
+
react_1.default.createElement(StyledForm, __assign({}, form, { onChange: function (key, data) {
|
|
78
|
+
dispatch('form', {
|
|
79
|
+
data: data,
|
|
80
|
+
formKey: form.schema.id,
|
|
81
|
+
actionKey: key,
|
|
82
|
+
});
|
|
83
|
+
} })))),
|
|
84
|
+
actions && (react_1.default.createElement(conversation_styles_1.MessageContentPart, null,
|
|
85
|
+
react_1.default.createElement(StyledActionList, { items: Object.keys(actions).map(function (i) {
|
|
86
|
+
return { label: actions[i], actionKey: i };
|
|
87
|
+
}), renderItem: function (item) {
|
|
88
|
+
return (react_1.default.createElement("li", { key: item.actionKey },
|
|
89
|
+
react_1.default.createElement(StyledActionButton, { onClick: function () {
|
|
90
|
+
dispatch('action', item.actionKey);
|
|
91
|
+
} }, item.label)));
|
|
92
|
+
} })))));
|
|
93
|
+
};
|
|
94
|
+
var createSystemMessage = function () {
|
|
95
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, content.map(function (item) {
|
|
96
|
+
var key = item.key, body = item.body, title = item.title, form = item.form, actions = item.actions;
|
|
97
|
+
var discrete = !!body && !title && !form && !actions;
|
|
98
|
+
return (react_1.default.createElement(message_types_1.SystemMessage, { className: className, key: key, discrete: discrete, timestamp: timestamp, fullWidth: !!form || !!actions }, discrete && body ? (react_1.default.createElement(widget_ui_1.Html, { html: body, htmlParseInstruction: htmlParseInstructions })) : (react_1.default.createElement(conversation_content_1.default, { content: item, isUser: false }))));
|
|
99
|
+
})));
|
|
100
|
+
};
|
|
101
|
+
var createAgentMessage = function () {
|
|
102
|
+
return (react_1.default.createElement(message_types_1.AgentMessage, { sender: sender, timestamp: timestamp, className: className },
|
|
103
|
+
react_1.default.createElement(conversation_styles_1.ContentBundle, null, content.map(function (item, index) {
|
|
104
|
+
return (react_1.default.createElement(conversation_styles_1.MessageContainer, { key: item.key },
|
|
105
|
+
react_1.default.createElement(conversation_content_1.default, { content: item, isUser: false, stacked: getMessageStackPosition(index) })));
|
|
106
|
+
}))));
|
|
107
|
+
};
|
|
108
|
+
var createUserMessage = function () {
|
|
109
|
+
return (react_1.default.createElement(message_types_1.UserMessage, { timestamp: timestamp, className: className },
|
|
110
|
+
react_1.default.createElement(conversation_styles_1.ContentBundle, null, content.map(function (item, index) {
|
|
111
|
+
return (react_1.default.createElement(conversation_styles_1.MessageContainer, { key: item.key },
|
|
112
|
+
react_1.default.createElement(conversation_content_1.default, { content: item, isUser: true, stacked: getMessageStackPosition(index) })));
|
|
113
|
+
}))));
|
|
114
|
+
};
|
|
115
|
+
switch (type) {
|
|
116
|
+
case conversation_controller_1.ConversationMessageType.System:
|
|
117
|
+
return createSystemMessage();
|
|
118
|
+
case conversation_controller_1.ConversationMessageType.Agent:
|
|
119
|
+
return createAgentMessage();
|
|
120
|
+
case conversation_controller_1.ConversationMessageType.User:
|
|
121
|
+
return createUserMessage();
|
|
122
|
+
default:
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
var StyledForm = (0, styled_components_1.default)(widget_forms_1.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) {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
return (0, widget_ui_1.invertedHoverButton)({
|
|
129
|
+
active: false,
|
|
130
|
+
primaryColor: (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.primary,
|
|
131
|
+
secondaryColor: (_b = p.theme.colors) === null || _b === void 0 ? void 0 : _b.accent,
|
|
132
|
+
});
|
|
133
|
+
}, 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; });
|
|
134
|
+
var StyledHtml = (0, styled_components_1.default)(widget_ui_1.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) && widget_ui_1.borderTabStyle; });
|
|
135
|
+
var StyledActionList = (0, styled_components_1.default)(widget_ui_1.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; });
|
|
136
|
+
var StyledActionButton = styled_components_1.default.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"])), widget_ui_1.buttonCss, function (p) { var _a; return (_a = p.theme.colors) === null || _a === void 0 ? void 0 : _a.primary; }, function (p) {
|
|
137
|
+
var _a;
|
|
138
|
+
return ((_a = p.theme.accessibility) === null || _a === void 0 ? void 0 : _a.isTabbing) && (0, styled_components_1.css)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n ", "\n background-color: transparent;\n "], ["\n ", "\n background-color: transparent;\n "])), widget_ui_1.borderTabStyle);
|
|
139
|
+
});
|
|
140
|
+
exports.default = ConversationMessageComponent;
|
|
141
|
+
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>;
|