@telia-ace/widget-conversation 1.0.15 → 1.0.18

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 (52) hide show
  1. package/LICENSE.txt +5 -5
  2. package/README.md +273 -256
  3. package/dist/agent.d.ts +17 -17
  4. package/dist/{ui → components}/conversation/conversation.d.ts +6 -6
  5. package/dist/{ui/conversation/conversation-component.d.ts → components/conversation/plugin.d.ts} +43 -37
  6. package/dist/components/conversation/ui/content.d.ts +2 -0
  7. package/dist/{ui/conversation/conversation-input.d.ts → components/conversation/ui/input.d.ts} +6 -6
  8. package/dist/{ui/conversation/conversation-loader.d.ts → components/conversation/ui/loader.d.ts} +8 -8
  9. package/dist/components/conversation/ui/message-list-items/button-list.d.ts +8 -0
  10. package/dist/{ui/conversation/message-types/custom-message-list-item.d.ts → components/conversation/ui/message-list-items/custom.d.ts} +9 -9
  11. package/dist/components/conversation/ui/message-list-items/html.d.ts +5 -0
  12. package/dist/components/conversation/ui/message-list-items/link-list.d.ts +8 -0
  13. package/dist/components/conversation/ui/message-list-items/separator.d.ts +2 -0
  14. package/dist/components/conversation/ui/message-list-items/text.d.ts +6 -0
  15. package/dist/{ui/conversation → components/conversation/ui}/message-types/agent.d.ts +11 -11
  16. package/dist/{ui/conversation → components/conversation/ui}/message-types/index.d.ts +4 -5
  17. package/dist/components/conversation/ui/message-types/message-list.d.ts +9 -0
  18. package/dist/{ui/conversation → components/conversation/ui}/message-types/system.d.ts +12 -12
  19. package/dist/{ui/conversation → components/conversation/ui}/message-types/timestamp.d.ts +8 -8
  20. package/dist/{ui/conversation → components/conversation/ui}/message-types/user.d.ts +8 -8
  21. package/dist/components/conversation/ui/message.d.ts +7 -0
  22. package/dist/components/conversation/ui/overlay-outlets.d.ts +13 -0
  23. package/dist/components/conversation/ui/styles.d.ts +27 -0
  24. package/dist/{ui/return-button/return-button-component.d.ts → components/return-button/plugin.d.ts} +18 -19
  25. package/dist/{ui → components}/return-button/return-button.d.ts +6 -6
  26. package/dist/conversation-controller.d.ts +88 -88
  27. package/dist/conversation-form-adapter.d.ts +7 -7
  28. package/dist/conversation-platform.d.ts +49 -50
  29. package/dist/conversation-provider.d.ts +22 -22
  30. package/dist/conversation.js +862 -118
  31. package/dist/conversation.js.map +1 -1
  32. package/dist/index.d.ts +10 -9
  33. package/dist/index.js +885 -9
  34. package/dist/index.js.map +1 -1
  35. package/dist/resolve-entity-value.d.ts +10 -10
  36. package/dist/return-button.js.map +1 -1
  37. package/dist/types.d.ts +96 -110
  38. package/dist/user.d.ts +7 -7
  39. package/dist/utils/custom-message.d.ts +3 -3
  40. package/dist/utils/index.d.ts +1 -1
  41. package/dist/utils/map-actions.d.ts +1 -0
  42. package/dist/utils/open-chat-widget.d.ts +4 -4
  43. package/package.json +8 -8
  44. package/dist/index2.js +0 -1678
  45. package/dist/index2.js.map +0 -1
  46. package/dist/ui/conversation/conversation-content.d.ts +0 -12
  47. package/dist/ui/conversation/conversation-message.d.ts +0 -7
  48. package/dist/ui/conversation/conversation-styles.d.ts +0 -11
  49. package/dist/ui/conversation/index.d.ts +0 -3
  50. package/dist/ui/conversation/message-types/custom.d.ts +0 -9
  51. package/dist/ui/index.d.ts +0 -2
  52. package/dist/ui/return-button/index.d.ts +0 -2
package/dist/index2.js DELETED
@@ -1,1678 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
32
- var __async = (__this, __arguments, generator) => {
33
- return new Promise((resolve, reject) => {
34
- var fulfilled = (value) => {
35
- try {
36
- step(generator.next(value));
37
- } catch (e) {
38
- reject(e);
39
- }
40
- };
41
- var rejected = (value) => {
42
- try {
43
- step(generator.throw(value));
44
- } catch (e) {
45
- reject(e);
46
- }
47
- };
48
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
- step((generator = generator.apply(__this, __arguments)).next());
50
- });
51
- };
52
- import { ComponentPlatform } from "@telia-ace/widget-core";
53
- import { createStorageWriter, StorageCategory, StorageMedium, StorageScope, readStorage } from "@telia-ace/widget-services";
54
- import { uuid, lock, appendClassNames } from "@telia-ace/widget-utilities";
55
- import { FormBuilder, FormComponent } from "@telia-ace/widget-forms";
56
- import { closeAllModals } from "@telia-ace/widget-plugins";
57
- import { createReactComponent, Typography, useProperties, SymbolBadge, useComponent, invertedHoverButton, Html, borderTabStyle, List, buttonCss, useDispatch, Icon, Lightbox } from "@telia-ace/widget-ui";
58
- import React, { lazy, Suspense, Fragment } from "react";
59
- import styled, { keyframes, css } from "styled-components";
60
- class Agent {
61
- constructor(provider, settings) {
62
- this.provider = provider;
63
- this.print = (settings2) => {
64
- const sender = { name: this.name, avatar: this.avatar };
65
- const normalized = getNormalizedMessageSettings(settings2);
66
- return this.provider.createEntry(normalized.key, normalized.content, ConversationMessageType.Agent, sender, normalized.timestamp);
67
- };
68
- this.typing = () => {
69
- return this.provider.setTypingState({ name: this.name, avatar: this.avatar });
70
- };
71
- this.name = settings.name;
72
- this.avatar = settings.avatar;
73
- }
74
- update(settings) {
75
- const { name, avatar } = settings;
76
- if (avatar === null) {
77
- this.avatar = void 0;
78
- } else if (avatar) {
79
- this.avatar = avatar;
80
- }
81
- if (name === null) {
82
- this.name = void 0;
83
- } else if (name) {
84
- this.name = name;
85
- }
86
- }
87
- }
88
- class ConversationProvider {
89
- constructor(name, container, controller) {
90
- this.name = name;
91
- this.container = container;
92
- this.controller = controller;
93
- this.subscriptions = [];
94
- this.user = controller == null ? void 0 : controller.user;
95
- }
96
- static create(name, container, controller) {
97
- return new ConversationProvider(name, container, controller);
98
- }
99
- createAgent(settings = {}) {
100
- if (this.controller) {
101
- return new Agent(this, settings);
102
- }
103
- }
104
- print(settings) {
105
- var _a;
106
- return (_a = this.controller) == null ? void 0 : _a.print(settings);
107
- }
108
- setTypingState(sender, type) {
109
- var _a;
110
- return (_a = this.controller) == null ? void 0 : _a.setTypingState(sender, type);
111
- }
112
- loading() {
113
- if (!this.controller) {
114
- return () => () => {
115
- };
116
- }
117
- return this.controller.loader();
118
- }
119
- createEntry(key, content, type, sender, timestamp) {
120
- var _a;
121
- return (_a = this.controller) == null ? void 0 : _a.createEntry(key, content, type, sender, timestamp);
122
- }
123
- dispose() {
124
- var _a;
125
- (_a = this.controller) == null ? void 0 : _a.disposeProvider(this);
126
- this.controller = null;
127
- this.subscriptions.forEach((unsub) => unsub());
128
- }
129
- onUnreadMessage(fn) {
130
- var _a;
131
- if (this.controller) {
132
- const unsubscribe = (_a = this.controller) == null ? void 0 : _a.onUnreadMessage(fn);
133
- this.subscriptions.push(unsubscribe);
134
- return () => {
135
- unsubscribe();
136
- };
137
- }
138
- }
139
- onMounted(fn) {
140
- var _a;
141
- if (this.controller) {
142
- const unsubscribe = (_a = this.controller) == null ? void 0 : _a.events.subscribe("conversation:component-mount-changed", fn);
143
- this.subscriptions.push(unsubscribe);
144
- fn({}, this.controller.getComponentMountedState());
145
- return () => {
146
- unsubscribe();
147
- };
148
- }
149
- }
150
- }
151
- class User {
152
- constructor(controller) {
153
- this.controller = controller;
154
- this.print = (settings) => {
155
- const normalized = getNormalizedMessageSettings(settings);
156
- return this.controller.createEntry(normalized.key, normalized.content, ConversationMessageType.User, void 0, normalized.timestamp);
157
- };
158
- }
159
- }
160
- class ConversationEntry {
161
- constructor(writer) {
162
- this.writer = writer;
163
- }
164
- update(content) {
165
- const normalized = this.getNormalizedSettings(content);
166
- this.writer(normalized);
167
- }
168
- remove() {
169
- this.writer(null);
170
- }
171
- getNormalizedSettings(content) {
172
- if (typeof content === "string")
173
- return { body: content };
174
- else if (content.length > -1 && typeof content === "object")
175
- return { items: content };
176
- else
177
- return content;
178
- }
179
- }
180
- var ConversationMessageType = /* @__PURE__ */ ((ConversationMessageType2) => {
181
- ConversationMessageType2["User"] = "user";
182
- ConversationMessageType2["Agent"] = "agent";
183
- ConversationMessageType2["System"] = "system";
184
- return ConversationMessageType2;
185
- })(ConversationMessageType || {});
186
- const getNormalizedMessageSettings = (settings) => {
187
- let content;
188
- let key = uuid();
189
- let timestamp = Date.now();
190
- if (Array.isArray(settings) && settings.length > -1) {
191
- if (typeof settings[0] === "string") {
192
- content = { items: [settings] };
193
- } else {
194
- content = { items: settings };
195
- }
196
- } else if (typeof settings === "string") {
197
- content = { body: settings };
198
- } else {
199
- settings = settings || {};
200
- if (settings.type) {
201
- content = __spreadValues({}, settings);
202
- } else {
203
- content = {
204
- body: settings.body,
205
- actions: settings.actions,
206
- title: settings.title
207
- };
208
- if (settings.key) {
209
- key = settings.key;
210
- }
211
- if (settings.timestamp) {
212
- timestamp = settings.timestamp;
213
- }
214
- if (settings.form) {
215
- const builder = FormBuilder.create(key);
216
- settings.form(builder);
217
- const builtForm = builder.get();
218
- content.form = builtForm;
219
- }
220
- if (settings.timestamp === null) {
221
- timestamp = null;
222
- }
223
- }
224
- }
225
- return { content, key, timestamp };
226
- };
227
- const removeTypingState = (typingActors, sender) => {
228
- if (!sender) {
229
- return;
230
- }
231
- const senderString = JSON.stringify(sender);
232
- const indexToRemove = typingActors.findIndex((item) => {
233
- return senderString === JSON.stringify(item);
234
- });
235
- if (indexToRemove > -1) {
236
- return typingActors.splice(indexToRemove, 1);
237
- }
238
- };
239
- class ConversationController {
240
- constructor(container, id) {
241
- this.container = container;
242
- this.id = id;
243
- this.formHandlers = {};
244
- this.user = new User(this);
245
- this.providers = [];
246
- this.active = false;
247
- this.registeredProviders = [];
248
- this.loaders = 0;
249
- this.componentMounted = false;
250
- this.messages = [];
251
- this.typingActors = [];
252
- this.print = (settings) => {
253
- const normalized = getNormalizedMessageSettings(settings);
254
- return this.createEntry(normalized.key, normalized.content, "system", void 0, normalized.timestamp);
255
- };
256
- const widget = container.get("$widget");
257
- this.events = widget.events.createChild(this);
258
- }
259
- setProviders(providers) {
260
- const removed = [];
261
- const added = [];
262
- this.providers.reduce((acc, provider) => {
263
- if (providers.indexOf(provider) === -1) {
264
- acc.push(provider);
265
- }
266
- return acc;
267
- }, []).forEach((providerToRemove) => {
268
- const indexToRemove = this.providers.indexOf(providerToRemove);
269
- if (indexToRemove > -1) {
270
- removed.push(providerToRemove);
271
- this.providers.splice(indexToRemove, 1);
272
- }
273
- });
274
- providers.forEach((provider) => {
275
- if (this.providers.indexOf(provider) === -1) {
276
- added.push(provider);
277
- this.providers.push(provider);
278
- }
279
- });
280
- if (added.length || removed.length) {
281
- this.events.dispatch("conversation:providers-changed", { added, removed });
282
- }
283
- }
284
- createProvider(name) {
285
- const index = this.providerIndex(name);
286
- if (index > -1) {
287
- return this.registeredProviders[index];
288
- }
289
- const provider = ConversationProvider.create(name, this.container, this);
290
- this.registeredProviders.push(provider);
291
- return provider;
292
- }
293
- providerIndex(name) {
294
- return this.registeredProviders.findIndex((p) => p.name === name);
295
- }
296
- dispose() {
297
- this.registeredProviders.forEach((provider) => provider.dispose());
298
- this.messages = [];
299
- this.events.dispatch("conversation:controller-disposed", this);
300
- this.active = false;
301
- }
302
- onDispose(fn) {
303
- return this.events.subscribe("conversation:controller-disposed", fn);
304
- }
305
- onStarted(fn) {
306
- return this.events.subscribe("conversation:started", fn);
307
- }
308
- disposeProvider(target) {
309
- const index = this.providerIndex(target.name);
310
- index > -1 && this.registeredProviders.splice(index, 1);
311
- this.events.dispatch("conversation:providers-changed", { removed: [target.name] });
312
- if (!this.registeredProviders.length) {
313
- this.dispose();
314
- }
315
- }
316
- onProvidersChange(fn) {
317
- return this.events.subscribe("conversation:providers-changed", fn);
318
- }
319
- setComponentMountedState(mounted) {
320
- if (this.componentMounted === mounted) {
321
- return;
322
- }
323
- this.componentMounted = mounted;
324
- if (mounted) {
325
- this.events.dispatch("conversation:unread-message", false);
326
- this.events.dispatch("conversation:started", true);
327
- this.active = true;
328
- }
329
- this.events.dispatch("conversation:component-mount-changed", mounted);
330
- }
331
- getComponentMountedState() {
332
- return this.componentMounted;
333
- }
334
- onUnreadMessage(fn) {
335
- return this.events.subscribe("conversation:unread-message", fn);
336
- }
337
- createEntry(key, content, type, sender, timestamp) {
338
- const message = {
339
- key,
340
- content,
341
- type,
342
- sender: sender || null,
343
- timestamp: timestamp || timestamp === null ? timestamp : Date.now()
344
- };
345
- this.messages.push(message);
346
- message.type === "agent" && removeTypingState(this.typingActors, sender);
347
- const entry = new ConversationEntry((updated) => {
348
- if (updated !== null) {
349
- const _a = updated, { timestamp: updatedTimestamp = void 0 } = _a, content2 = __objRest(_a, ["timestamp"]);
350
- message.content = content2;
351
- if (updatedTimestamp) {
352
- message.timestamp = updatedTimestamp;
353
- }
354
- } else {
355
- const indexToRemove = this.messages.indexOf(message);
356
- message.content = null;
357
- if (indexToRemove > -1) {
358
- this.messages.splice(indexToRemove, 1);
359
- }
360
- }
361
- this.events.dispatch("conversation:message-updated", { message });
362
- this.update();
363
- });
364
- this.events.dispatch("conversation:message-created", { message });
365
- this.update();
366
- if (!this.componentMounted) {
367
- this.events.dispatch("conversation:unread-message", true);
368
- }
369
- return entry;
370
- }
371
- update() {
372
- this.events.dispatch("conversation:updated", {
373
- messages: this.messages,
374
- loading: this.loaders > 0,
375
- typingActors: this.typingActors
376
- });
377
- }
378
- getMessageStream() {
379
- return {
380
- messages: this.messages,
381
- loading: this.loaders > 0,
382
- typingActors: this.typingActors
383
- };
384
- }
385
- setTypingState(sender, type) {
386
- if (this.typingActors.indexOf(sender) === -1) {
387
- this.typingActors.push(sender);
388
- this.update();
389
- }
390
- return () => {
391
- removeTypingState(this.typingActors, sender);
392
- this.update();
393
- };
394
- }
395
- loader() {
396
- this.loaders = this.loaders + 1;
397
- let dismissed = false;
398
- if (this.loaders === 1) {
399
- this.update();
400
- }
401
- return () => {
402
- if (!dismissed) {
403
- dismissed = true;
404
- this.loaders = this.loaders - 1;
405
- if (this.loaders === 0) {
406
- this.update();
407
- }
408
- }
409
- };
410
- }
411
- submitForm(key, handler) {
412
- this.formHandlers[key] = __spreadProps(__spreadValues({}, this.formHandlers[key]), { submit: handler });
413
- }
414
- validateForm(key, handler) {
415
- this.formHandlers[key] = __spreadProps(__spreadValues({}, this.formHandlers[key]), { validate: handler });
416
- }
417
- }
418
- const getParentWidget = (widgetName, implementation) => {
419
- const mainWidgetName = widgetName.split("_contact");
420
- return implementation.widgets.get(mainWidgetName[0]);
421
- };
422
- const getSeparateWidget = (container) => {
423
- const originWidget = container.get("$widget");
424
- const { name, implementation } = container.get("$widget");
425
- const mainWidget = name.indexOf("_contact") > -1 ? getParentWidget(name, implementation) : originWidget;
426
- const { data } = container.get("$settings");
427
- const { trigger } = mainWidget.container.get("$settings");
428
- const chatWidgetName = `${name.replace("_contact-method", "").replace("_contact", "")}_contact-method`;
429
- const chatWidget = implementation.widgets.get(chatWidgetName);
430
- if (chatWidget && !trigger) {
431
- return { chatWidget, mainWidget, data };
432
- }
433
- return { mainWidget, data };
434
- };
435
- const shouldPreventDefault = (container) => {
436
- const { chatWidget } = getSeparateWidget(container);
437
- return !!chatWidget;
438
- };
439
- const openChatWidget = (container, contactMethod, triggerDOMTarget) => {
440
- const { mainWidget, data, chatWidget } = getSeparateWidget(container);
441
- if (chatWidget) {
442
- if (chatWidget.state === "activated") {
443
- return chatWidget.invoke("open").then(() => {
444
- chatWidget.container.getAsync("conversation").then((conversation) => {
445
- conversation.navigateToConversationIfActive(contactMethod.id).then(() => closeAllModals(container));
446
- });
447
- });
448
- }
449
- return chatWidget.activate().then(() => {
450
- const { trigger } = chatWidget.container.get("$settings");
451
- trigger.action = "hide";
452
- return chatWidget.invoke("setSettings", () => ({
453
- data,
454
- trigger,
455
- activate: true
456
- })).then(() => {
457
- return chatWidget.container.getAsync("components").then((components) => {
458
- const contactMethodsQuery = components.components().ofType("contact-method");
459
- components.write({
460
- key: "setContactMethodId",
461
- attributes: {
462
- properties: {
463
- id: contactMethod.id,
464
- guideId: contactMethod.guideId
465
- }
466
- },
467
- target: contactMethodsQuery,
468
- provider: "localStorage"
469
- });
470
- const conversationsQuery = components.components().ofType("conversation");
471
- components.write({
472
- key: "setConversationProvider",
473
- attributes: {
474
- properties: { providers: [contactMethod.clientName] }
475
- },
476
- target: conversationsQuery,
477
- provider: "localStorage"
478
- });
479
- });
480
- });
481
- }).then(() => {
482
- return chatWidget.invoke("attach", {
483
- key: "contact-method",
484
- triggerDOMElement: triggerDOMTarget,
485
- withRenderState: "open"
486
- });
487
- }).then(() => {
488
- createStorageWriter(chatWidget.container, "activeStickyWidget", StorageCategory.Necessary, {
489
- medium: StorageMedium.Local,
490
- scope: StorageScope.Implementation
491
- }).then((write) => write(chatWidget.name));
492
- return chatWidget.container.getAsync("conversation").then((platform) => {
493
- platform.setConversationEndedBehavior(ConversationEndedBehavior.Deactivate);
494
- }).then(() => closeAllModals(container)).then(() => false);
495
- });
496
- }
497
- mainWidget.container.getAsync("conversation").then((platform) => {
498
- return platform.navigateToConversationIfActive(contactMethod.id).then(() => platform.setConversationEndedBehavior(ConversationEndedBehavior.Navigate));
499
- });
500
- return chatWidget ? false : true;
501
- };
502
- const navigateToConversation = (container, contactMethod, routeName = "conversation") => {
503
- const { mainWidget, chatWidget } = getSeparateWidget(container);
504
- if (chatWidget) {
505
- return chatWidget.container.getAsync("router").then((router) => {
506
- router.navigate(routeName, { id: contactMethod.id });
507
- });
508
- }
509
- return mainWidget.container.getAsync("conversation").then((platform) => {
510
- var _a;
511
- (_a = platform.setConversationEndedBehavior(ConversationEndedBehavior.Navigate)) == null ? void 0 : _a.then(() => {
512
- mainWidget.container.getAsync("router").then((router) => {
513
- mainWidget.container.getAsync("components").then((components) => {
514
- const conversationQuery = components.components().ofType("conversation");
515
- components.write({
516
- key: "setConversationProvider",
517
- attributes: { properties: { providers: [contactMethod.clientName] } },
518
- target: conversationQuery,
519
- provider: "localStorage"
520
- });
521
- }).then(() => {
522
- router.navigate(routeName, { id: contactMethod.id });
523
- });
524
- });
525
- });
526
- });
527
- };
528
- const registerCustomMessageComponent = (container, type, component) => {
529
- return container.getAsync("componentResolver").then((o) => __async(this, null, function* () {
530
- const platform = yield ConversationPlatform.getInstance(container);
531
- platform.addSubscription(o.registerComponent(type, lazy(() => component)));
532
- }));
533
- };
534
- const STORAGE_KEY = "conversations";
535
- var ConversationEndedBehavior = /* @__PURE__ */ ((ConversationEndedBehavior2) => {
536
- ConversationEndedBehavior2["Deactivate"] = "deactivate";
537
- ConversationEndedBehavior2["Navigate"] = "navigate";
538
- ConversationEndedBehavior2["None"] = "none";
539
- return ConversationEndedBehavior2;
540
- })(ConversationEndedBehavior || {});
541
- class ConversationPlatform {
542
- constructor(container, components) {
543
- this.container = container;
544
- this.components = components;
545
- this.controllers = [];
546
- this.providers = [];
547
- this.disposeProviders = {};
548
- this.subscriptions = [];
549
- this.storageWriter = null;
550
- this.router = null;
551
- this.buttonQuery = null;
552
- this.sessionInfo = null;
553
- const widget = container.get("$widget");
554
- this.events = widget.events.createChild(this);
555
- }
556
- initialize() {
557
- createStorageWriter(this.container, STORAGE_KEY, StorageCategory.Necessary, {
558
- medium: StorageMedium.Local
559
- }).then((writer) => this.storageWriter = writer);
560
- readStorage(this.container, STORAGE_KEY, StorageMedium.Local).then((storedSession) => {
561
- this.buttonQuery = this.components.components().ofType("conversation-return-button");
562
- if (storedSession) {
563
- this.sessionInfo = storedSession;
564
- if (storedSession.id && storedSession.route) {
565
- this.writeToComponents({ active: true, alert: { show: false } });
566
- }
567
- }
568
- });
569
- this.container.getAsync("router").then((router) => this.router = router);
570
- this.events.subscribe("conversation:ended", (event, data) => {
571
- var _a, _b, _c;
572
- switch ((_a = this.sessionInfo) == null ? void 0 : _a.conversationEndedBehavior) {
573
- case "deactivate":
574
- const widget = this.container.get("$widget");
575
- widget.deactivate();
576
- break;
577
- case "navigate":
578
- const initialRoute = (_b = this.router) == null ? void 0 : _b.getInitialRoute();
579
- if (initialRoute) {
580
- (_c = this.router) == null ? void 0 : _c.navigate(initialRoute.name);
581
- }
582
- break;
583
- }
584
- this.writeToComponents({ active: false });
585
- this.sessionInfo = null;
586
- this.storageWriter && this.storageWriter();
587
- });
588
- }
589
- addSubscription(sub) {
590
- this.subscriptions.push(sub);
591
- }
592
- static getInstance(container, key = "conversation") {
593
- return lock(container)(() => {
594
- return container.getAsync(key).then((value) => {
595
- let conversation = value;
596
- if (!conversation) {
597
- return ComponentPlatform.getInstance(container).then((components) => {
598
- conversation = new ConversationPlatform(container, components);
599
- conversation.initialize();
600
- container.registerAsync(key, () => conversation);
601
- return conversation;
602
- });
603
- }
604
- return conversation;
605
- });
606
- });
607
- }
608
- navigateToConversationIfActive(id) {
609
- return readStorage(this.container, STORAGE_KEY, StorageMedium.Local).then((storedSession) => {
610
- var _a;
611
- if (storedSession && storedSession.id === id) {
612
- if (storedSession.route) {
613
- const { name, params } = storedSession.route;
614
- (_a = this.router) == null ? void 0 : _a.navigate(name, params);
615
- }
616
- }
617
- });
618
- }
619
- setConversationEndedBehavior(behavior) {
620
- return readStorage(this.container, STORAGE_KEY, StorageMedium.Local).then((stored) => {
621
- let storedSession = stored;
622
- if (storedSession) {
623
- storedSession.conversationEndedBehavior = behavior;
624
- } else {
625
- storedSession = { conversationEndedBehavior: behavior };
626
- }
627
- this.sessionInfo = storedSession;
628
- return this.storageWriter && this.storageWriter(this.sessionInfo) || Promise.resolve();
629
- });
630
- }
631
- createController(id) {
632
- const index = this.controllers.findIndex((c) => c.conversation.id === id);
633
- if (index > -1) {
634
- return this.controllers[index].conversation;
635
- }
636
- return new ConversationController(this.container, id);
637
- }
638
- registerConversationItem(name, component) {
639
- return registerCustomMessageComponent(this.container, name, component);
640
- }
641
- registerProvider(name, handler) {
642
- const provider = {
643
- name,
644
- handler
645
- };
646
- this.providers.push(provider);
647
- this.controllers.filter((controller) => controller.conversation.providers.indexOf(name) > -1).forEach((controller) => {
648
- this.invokeHandler(provider, controller);
649
- });
650
- }
651
- registerController(conversation, component) {
652
- const index = this.controllers.findIndex((c) => c.conversation.id === conversation.id);
653
- let controller;
654
- if (index < 0) {
655
- controller = { conversation, component };
656
- this.controllers.push(controller);
657
- const invokeHandlers = (providers) => {
658
- if (providers) {
659
- this.providers.filter((provider) => providers.indexOf(provider.name) > -1).forEach((provider) => {
660
- this.invokeHandler(provider, controller);
661
- });
662
- }
663
- };
664
- this.subscriptions.push(conversation.onDispose((event, data) => {
665
- const index2 = this.controllers.findIndex((c) => c.conversation === data);
666
- index2 > -1 && this.controllers.splice(index2, 1);
667
- this.components.components().ofType("conversation-return-button").select().writeProperties({ active: false });
668
- this.events.dispatch("conversation:ended", {}, { bubbles: true });
669
- }));
670
- this.subscriptions.push(conversation.onProvidersChange((event, data) => {
671
- const { added, removed } = data;
672
- removed.forEach((removedProvider) => {
673
- this.disposeProviders[removedProvider].forEach((dispose) => {
674
- dispose();
675
- });
676
- });
677
- invokeHandlers(added);
678
- }));
679
- this.subscriptions.push(conversation.onStarted((event, isActive) => {
680
- var _a, _b;
681
- const session = {
682
- id: conversation.id,
683
- route: (_a = this.router) == null ? void 0 : _a.getRouteData(),
684
- conversationEndedBehavior: (_b = this.sessionInfo) == null ? void 0 : _b.conversationEndedBehavior
685
- };
686
- this.sessionInfo = session;
687
- this.storageWriter && this.storageWriter(session);
688
- this.writeToComponents({ active: isActive });
689
- }));
690
- this.subscriptions.push(conversation.onUnreadMessage((event, data) => {
691
- this.events.dispatch("conversation:unread-message", data);
692
- this.writeToComponents({ alert: { show: data } });
693
- }));
694
- invokeHandlers(conversation.providers);
695
- return true;
696
- }
697
- controller = this.controllers[index];
698
- return false;
699
- }
700
- writeToComponents(properties, key = "conversationReturnButtonState") {
701
- if (this.buttonQuery) {
702
- this.components.write({
703
- key: "conversationReturnButtonState",
704
- attributes: { properties },
705
- target: this.buttonQuery,
706
- provider: "localStorage"
707
- });
708
- }
709
- }
710
- invokeHandler(provider, controller) {
711
- const dispose = provider.handler(controller.conversation.createProvider(provider.name), controller.component);
712
- if (dispose) {
713
- if (!this.disposeProviders[provider.name]) {
714
- this.disposeProviders[provider.name] = [];
715
- }
716
- this.disposeProviders[provider.name].push(dispose);
717
- }
718
- }
719
- getComponentRoute() {
720
- return readStorage(this.container, STORAGE_KEY, StorageMedium.Local).then((stored) => stored == null ? void 0 : stored.route);
721
- }
722
- dispose() {
723
- Object.keys(this.disposeProviders).forEach((key) => {
724
- this.disposeProviders[key].forEach((dispose) => {
725
- dispose();
726
- });
727
- });
728
- this.subscriptions.forEach((unsubscribe) => {
729
- unsubscribe();
730
- });
731
- this.controllers = [];
732
- this.providers = [];
733
- }
734
- static handleContactMethodClick(event, container, contactMethod, callback) {
735
- return __async(this, null, function* () {
736
- if (shouldPreventDefault(container)) {
737
- event.preventDefault();
738
- let triggerEl = document.getElementById("humany-dynamic-anchor");
739
- if (!triggerEl) {
740
- triggerEl = document.createElement("a");
741
- triggerEl.setAttribute("href", "#");
742
- triggerEl.id = "humany-dynamic-anchor";
743
- document.body.appendChild(triggerEl);
744
- }
745
- openChatWidget(container, contactMethod, triggerEl);
746
- }
747
- openChatWidget(container, contactMethod);
748
- });
749
- }
750
- static handleContactMethodSubmit(container, contactMethod) {
751
- return __async(this, null, function* () {
752
- return navigateToConversation(container, contactMethod);
753
- });
754
- }
755
- }
756
- var ConversationMessageListItemType = /* @__PURE__ */ ((ConversationMessageListItemType2) => {
757
- ConversationMessageListItemType2["Header"] = "header";
758
- ConversationMessageListItemType2["LinkList"] = "link-list";
759
- ConversationMessageListItemType2["Separator"] = "separator";
760
- ConversationMessageListItemType2["NoGoodAlternative"] = "no-good-alternative";
761
- ConversationMessageListItemType2["ButtonList"] = "button-list";
762
- ConversationMessageListItemType2["Text"] = "text";
763
- ConversationMessageListItemType2["HTML"] = "html";
764
- ConversationMessageListItemType2["FeedbackList"] = "feedback-list";
765
- return ConversationMessageListItemType2;
766
- })(ConversationMessageListItemType || {});
767
- const groupedMessages = (messages, timeout) => {
768
- return messages.reduce((acc, current, index) => {
769
- var _a, _b;
770
- const newItem = __spreadProps(__spreadValues({}, current), {
771
- content: [__spreadProps(__spreadValues({}, current.content), { key: current.key })]
772
- });
773
- if (acc.length > 0 && current.type !== ConversationMessageType.System) {
774
- const previous = acc[acc.length - 1];
775
- if (!timeout && timeout !== 0 || Math.abs(previous.timestamp - current.timestamp) < timeout) {
776
- if (((_a = previous.sender) == null ? void 0 : _a.name) === ((_b = current.sender) == null ? void 0 : _b.name) && previous.type === current.type) {
777
- previous.timestamp = current.timestamp;
778
- previous.content.push(__spreadProps(__spreadValues({}, current.content), { key: current.key }));
779
- return acc;
780
- }
781
- }
782
- }
783
- acc.push(newItem);
784
- return acc;
785
- }, []);
786
- };
787
- const ConversationComponent = (container) => {
788
- return Promise.all([
789
- ConversationPlatform.getInstance(container),
790
- container.getAsync("router")
791
- ]).then(([platform, router]) => {
792
- return createReactComponent(container, "conversation", import("./conversation.js"), (component) => {
793
- const routeData = router.getRouteData();
794
- const name = routeData.params.id || component.node.name || "component";
795
- const conversation = platform.createController(name);
796
- const isNewController = platform.registerController(conversation, component);
797
- const messageGroupingTimeout = 3 * 60 * 1e3;
798
- const setProperties = (properties) => {
799
- const { providers = [] } = properties;
800
- if (providers) {
801
- const providerKeys = Array.isArray(providers) ? providers : [providers];
802
- conversation.setProviders(providerKeys);
803
- return providerKeys;
804
- }
805
- };
806
- setProperties(component.properties(setProperties));
807
- conversation.setComponentMountedState(true);
808
- const writeMessages = (messageStream) => {
809
- const { loading, typingActors, messages } = messageStream;
810
- component.writeProperties({
811
- loading,
812
- typingActors,
813
- messages: groupedMessages(messages, messageGroupingTimeout)
814
- });
815
- };
816
- writeMessages(conversation.getMessageStream());
817
- if (isNewController) {
818
- component.actions.create("user-submit", (data, options) => {
819
- if (options) {
820
- const { preventDefault, validationPromise } = options;
821
- if (preventDefault) {
822
- if (validationPromise) {
823
- validationPromise().then((text) => {
824
- if (text) {
825
- conversation.user.print(text);
826
- }
827
- });
828
- }
829
- return;
830
- }
831
- }
832
- conversation.user.print(data.text);
833
- });
834
- component.actions.create("user-typing", (data, options) => {
835
- });
836
- component.actions.create("form", (data, options) => {
837
- });
838
- component.actions.create("action", (data, options) => {
839
- });
840
- }
841
- const unsubscribe = conversation.events.subscribe("conversation:updated", (e, conversationData) => {
842
- writeMessages(conversationData);
843
- });
844
- return () => {
845
- conversation.setComponentMountedState(false);
846
- unsubscribe();
847
- if (!conversation.active) {
848
- writeMessages({ messages: [], typingActors: [], loading: false });
849
- }
850
- };
851
- }, { reuseController: true });
852
- });
853
- };
854
- const Avatar = styled.div`
855
- width: ${(p) => p.avatarSize || "32px"};
856
- height: ${(p) => p.avatarSize || "32px"};
857
- border-radius: 50%;
858
- background-color: ${(p) => {
859
- var _a;
860
- return (_a = p.theme.colors) == null ? void 0 : _a.accent;
861
- }};
862
- border: ${(p) => p.theme.border};
863
- grid-area: avatar;
864
- align-self: flex-end;
865
- justify-self: center;
866
- overflow: hidden;
867
- margin-right: ${(p) => {
868
- var _a;
869
- return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
870
- }};
871
- display: flex;
872
- justify-content: center;
873
- align-items: center;
874
- color: ${(p) => {
875
- var _a;
876
- return (_a = p.theme.colors) == null ? void 0 : _a.text;
877
- }};
878
-
879
- > img {
880
- height: 100%;
881
- width: 100%;
882
- object-fit: cover;
883
- }
884
-
885
- > svg {
886
- width: 90%;
887
- height: 90%;
888
- padding: 10%;
889
- color: ${(p) => {
890
- var _a;
891
- return (_a = p.theme.colors) == null ? void 0 : _a.text;
892
- }};
893
-
894
- line,
895
- path,
896
- circle,
897
- fill {
898
- stroke: ${(p) => {
899
- var _a;
900
- return (_a = p.theme.colors) == null ? void 0 : _a.text;
901
- }};
902
- }
903
- }
904
- `;
905
- const LoaderAnimation = keyframes`
906
- 0% {
907
- opacity: 0;
908
- }
909
- 75% {
910
- opacity: 1;
911
- }
912
- 100% {
913
- opacity: 0;
914
- }
915
- `;
916
- const Loader = styled.div`
917
- display: flex;
918
- justify-content: center;
919
- > div {
920
- height: 10px;
921
- width: 10px;
922
- border-radius: 50%;
923
- margin: 5px;
924
- background-color: ${(p) => {
925
- var _a;
926
- return (_a = p.theme.colors) == null ? void 0 : _a.text;
927
- }};
928
- animation: ${LoaderAnimation} 1s infinite;
929
- }
930
- > div:nth-child(2) {
931
- animation-delay: 100ms;
932
- }
933
- > div:nth-child(3) {
934
- animation-delay: 200ms;
935
- }
936
- `;
937
- const ContentBundle = styled.div`
938
- grid-area: content;
939
- max-width: 100%;
940
- overflow: hidden;
941
- `;
942
- const MessageTitle = styled(Typography)`
943
- font-size: ${(p) => {
944
- var _a;
945
- return (_a = p.theme.fonts) == null ? void 0 : _a.normal;
946
- }};
947
- font-weight: normal;
948
- margin: 0;
949
- `;
950
- const MessageContainer = styled.div`
951
- display: flex;
952
- `;
953
- const MessageContent = styled.div`
954
- background-color: ${(p) => {
955
- var _a, _b;
956
- return p.user ? (_a = p.theme.colors) == null ? void 0 : _a.primary : (_b = p.theme.colors) == null ? void 0 : _b.accent;
957
- }};
958
- color: ${(p) => {
959
- var _a, _b;
960
- return p.user ? (_a = p.theme.colors) == null ? void 0 : _a.accent : (_b = p.theme.colors) == null ? void 0 : _b.text;
961
- }};
962
- border-radius: 5px; // TODO: prop?
963
- border: 1px solid rgb(231, 231, 231);
964
- padding-top: calc(${(p) => {
965
- var _a;
966
- return (_a = p.theme.sizes) == null ? void 0 : _a.medium;
967
- }} - ${(p) => {
968
- var _a;
969
- return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
970
- }});
971
- padding-bottom: calc(${(p) => {
972
- var _a;
973
- return (_a = p.theme.sizes) == null ? void 0 : _a.medium;
974
- }} - ${(p) => {
975
- var _a;
976
- return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
977
- }});
978
- margin-top: ${(p) => {
979
- var _a;
980
- return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
981
- }};
982
- display: inline-block;
983
- && > * {
984
- overflow-wrap: break-word;
985
- word-wrap: break-word;
986
- word-break: break-all;
987
- word-break: break-word;
988
- hyphens: auto;
989
- }
990
- max-width: 100%;
991
- ${(p) => p.fullWidth && "width: 100%;"}
992
-
993
- ${(p) => !p.user && css`
994
- border: ${p.theme.border};
995
- `}
996
- ${(p) => p.user && "margin-left: auto"};
997
-
998
- ${(p) => p.stacked === "first" && p.user && css`
999
- border-bottom-right-radius: 1px; // TODO: Prop?
1000
- `}
1001
- ${(p) => p.stacked === "middle" && p.user && css`
1002
- border-bottom-right-radius: 1px;
1003
- border-top-right-radius: 1px;
1004
- `}
1005
- ${(p) => p.stacked === "last" && p.user && css`
1006
- border-top-right-radius: 1px;
1007
- `}
1008
- ${(p) => p.stacked === "first" && !p.user && css`
1009
- border-bottom-left-radius: 1px;
1010
- `}
1011
- ${(p) => p.stacked === "middle" && !p.user && css`
1012
- border-bottom-left-radius: 1px;
1013
- border-top-left-radius: 1px;
1014
- `}
1015
- ${(p) => p.stacked === "last" && !p.user && css`
1016
- border-top-left-radius: 1px;
1017
- `};
1018
-
1019
- ${(p) => !p.stacked && css`
1020
- ${p.user ? "border-bottom-right-radius: 1px;" : "border-bottom-left-radius: 1px;"}
1021
- `};
1022
-
1023
- transition: border-radius 500ms linear;
1024
- `;
1025
- const MessageContentPart = styled.div`
1026
- padding: ${(p) => {
1027
- var _a;
1028
- return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
1029
- }} ${(p) => {
1030
- var _a;
1031
- return (_a = p.theme.sizes) == null ? void 0 : _a.medium;
1032
- }};
1033
-
1034
- ${(p) => p.noPadding && css`
1035
- padding: 0;
1036
- `}
1037
-
1038
- margin-bottom: ${(p) => {
1039
- var _a;
1040
- return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
1041
- }};
1042
- &:last-child {
1043
- margin-bottom: 0;
1044
- }
1045
- `;
1046
- const StyledTimestamp = styled.p`
1047
- && {
1048
- font-size: ${(p) => {
1049
- var _a;
1050
- return (_a = p.theme.fonts) == null ? void 0 : _a.small;
1051
- }};
1052
- font-weight: 300;
1053
- }
1054
- padding-top: ${(p) => {
1055
- var _a;
1056
- return (_a = p.theme.sizes) == null ? void 0 : _a.small;
1057
- }};
1058
- margin: 0;
1059
- line-height: 1.5em;
1060
- grid-area: info;
1061
- color: ${(p) => {
1062
- var _a;
1063
- return (_a = p.theme.colors) == null ? void 0 : _a.text;
1064
- }};
1065
- `;
1066
- const getTimestamp = (raw) => {
1067
- return new Date(raw).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
1068
- };
1069
- const Timestamp = ({ className, name, timestamp }) => {
1070
- if (!name && !timestamp) {
1071
- return null;
1072
- }
1073
- let output = "";
1074
- if (name) {
1075
- if (timestamp) {
1076
- output = `${name}: ${getTimestamp(timestamp)}`;
1077
- } else {
1078
- output = name;
1079
- }
1080
- } else if (timestamp) {
1081
- output = getTimestamp(timestamp);
1082
- }
1083
- return /* @__PURE__ */ React.createElement(StyledTimestamp, null, output);
1084
- };
1085
- const AgentMessage = ({ className, children, sender, timestamp }) => {
1086
- const { avatar, name } = sender;
1087
- const { avatarSize } = useProperties();
1088
- return /* @__PURE__ */ React.createElement(StyledAgentMessage, {
1089
- hasAvatar: !!avatar,
1090
- className: appendClassNames(className, "humany-conversation-agent-message")
1091
- }, avatar && /* @__PURE__ */ React.createElement(Avatar, {
1092
- avatarSize
1093
- }, typeof avatar === "string" ? /* @__PURE__ */ React.createElement("img", {
1094
- src: avatar
1095
- }) : /* @__PURE__ */ React.createElement(SymbolBadge, {
1096
- symbol: avatar
1097
- })), children, /* @__PURE__ */ React.createElement(Timestamp, {
1098
- name,
1099
- timestamp
1100
- }));
1101
- };
1102
- const StyledAgentMessage = styled.div`
1103
- display: grid;
1104
- margin-right: 10%;
1105
- width: 90%;
1106
- ${(p) => p.hasAvatar ? css`
1107
- grid-template-columns: auto 1fr;
1108
- grid-template-rows: 1fr auto;
1109
- grid-template-areas:
1110
- 'avatar content'
1111
- '. info';
1112
- ` : css`
1113
- grid-template-columns: 1fr;
1114
- grid-template-rows: 1fr auto;
1115
- grid-template-areas:
1116
- 'content'
1117
- 'info';
1118
- `};
1119
- `;
1120
- const CustomMessage = (props) => {
1121
- const CustomComponent = useComponent(props.type);
1122
- if (!CustomComponent) {
1123
- return null;
1124
- }
1125
- return /* @__PURE__ */ React.createElement(Suspense, {
1126
- fallback: null
1127
- }, /* @__PURE__ */ React.createElement(MessageContent, {
1128
- user: props.isUser,
1129
- stacked: !!props.stacked && props.stacked,
1130
- fullWidth: !!props.content.form || !!props.content.actions
1131
- }, /* @__PURE__ */ React.createElement(MessageContentPart, {
1132
- noPadding: !!props.content.noPadding && props.content.noPadding
1133
- }, /* @__PURE__ */ React.createElement(CustomComponent, __spreadValues({}, props.content)))));
1134
- };
1135
- const SystemMessage = ({
1136
- className,
1137
- children,
1138
- timestamp,
1139
- discrete,
1140
- fullWidth
1141
- }) => {
1142
- return /* @__PURE__ */ React.createElement(StyledSystemMessage, {
1143
- className: appendClassNames(className, "humany-conversation-system-message"),
1144
- fullWidth
1145
- }, discrete ? /* @__PURE__ */ React.createElement(Discrete, {
1146
- className: "humany-conversation-discrete-message"
1147
- }, children, /* @__PURE__ */ React.createElement(Timestamp, {
1148
- timestamp
1149
- })) : /* @__PURE__ */ React.createElement(React.Fragment, null, children, /* @__PURE__ */ React.createElement(Timestamp, {
1150
- timestamp
1151
- })));
1152
- };
1153
- const StyledSystemMessage = styled.div`
1154
- ${(p) => p.fullWidth && "width: 100%"};
1155
- padding: 0 ${(p) => {
1156
- var _a;
1157
- return (_a = p.theme.sizes) == null ? void 0 : _a.large;
1158
- }};
1159
- overflow: auto;
1160
- `;
1161
- const Discrete = styled.div`
1162
- text-align: center;
1163
- word-wrap: break-word;
1164
- font-size: ${(p) => {
1165
- var _a;
1166
- return (_a = p.theme.fonts) == null ? void 0 : _a.normal;
1167
- }};
1168
- color: ${(p) => {
1169
- var _a;
1170
- return (_a = p.theme.colors) == null ? void 0 : _a.text;
1171
- }};
1172
- > p {
1173
- margin: 0;
1174
- }
1175
- `;
1176
- const UserMessage = ({ className, children, timestamp }) => {
1177
- const { userLabel = "" } = useProperties();
1178
- return /* @__PURE__ */ React.createElement(StyledUserMessage, {
1179
- className: appendClassNames(className, "humany-conversation-user-message")
1180
- }, children, /* @__PURE__ */ React.createElement(Timestamp, {
1181
- name: userLabel,
1182
- timestamp
1183
- }));
1184
- };
1185
- const StyledUserMessage = styled.div`
1186
- margin-left: 10%;
1187
- width: 90%;
1188
- display: flex;
1189
- flex-direction: column;
1190
- align-items: flex-end;
1191
- `;
1192
- const CustomMessageListItem = ({ type, content = {} }) => {
1193
- const Component = useComponent(type);
1194
- if (!Component || !type) {
1195
- return null;
1196
- }
1197
- return /* @__PURE__ */ React.createElement(Component, __spreadValues({}, content));
1198
- };
1199
- const imageLightboxRenderer = (attrs) => /* @__PURE__ */ React.createElement(Lightbox, {
1200
- attrs
1201
- });
1202
- const htmlParseInstructions = {
1203
- transform: {
1204
- img: imageLightboxRenderer
1205
- }
1206
- };
1207
- const ConversationContent = ({ content, isUser, stacked }) => {
1208
- const dispatch = useDispatch();
1209
- const { title, body, actions, form, type, items } = content;
1210
- if (type)
1211
- return /* @__PURE__ */ React.createElement(CustomMessage, {
1212
- type,
1213
- content,
1214
- isUser,
1215
- stacked
1216
- });
1217
- return /* @__PURE__ */ React.createElement(MessageContent, {
1218
- noPadding: true,
1219
- user: isUser,
1220
- stacked: !!stacked && stacked,
1221
- fullWidth: !!form || !!actions
1222
- }, title && /* @__PURE__ */ React.createElement(MessageContentPart, null, /* @__PURE__ */ React.createElement(MessageTitle, {
1223
- variant: "h2"
1224
- }, title)), body && /* @__PURE__ */ React.createElement(MessageContentPart, null, /* @__PURE__ */ React.createElement(StyledHtml, {
1225
- html: body,
1226
- htmlParseInstruction: htmlParseInstructions
1227
- })), form && /* @__PURE__ */ React.createElement(MessageContentPart, null, /* @__PURE__ */ React.createElement(StyledForm, __spreadProps(__spreadValues({}, form), {
1228
- onChange: (key, data) => {
1229
- dispatch("form", {
1230
- data,
1231
- formKey: form.schema.id,
1232
- actionKey: key
1233
- });
1234
- }
1235
- }))), actions && /* @__PURE__ */ React.createElement(MessageContentPart, null, /* @__PURE__ */ React.createElement(StyledActionList, {
1236
- items: Object.keys(actions).map((i) => {
1237
- return { label: actions[i], actionKey: i };
1238
- }),
1239
- renderItem: (item) => {
1240
- return /* @__PURE__ */ React.createElement("li", {
1241
- key: item.actionKey
1242
- }, /* @__PURE__ */ React.createElement(StyledActionButton, {
1243
- onClick: () => {
1244
- dispatch("action", item.actionKey);
1245
- }
1246
- }, item.label));
1247
- }
1248
- })), items && /* @__PURE__ */ React.createElement(Fragment, null, /* @__PURE__ */ React.createElement(MessageContentPart, {
1249
- key: uuid(),
1250
- noPadding: true
1251
- }, /* @__PURE__ */ React.createElement(StyledActionList, {
1252
- items: items.map(([type2, content2]) => {
1253
- return { type: type2, content: content2 };
1254
- }),
1255
- renderItem: (item) => {
1256
- const itemKey = uuid();
1257
- switch (item.type) {
1258
- case ConversationMessageListItemType.Header: {
1259
- return /* @__PURE__ */ React.createElement(ConversationListItem, {
1260
- key: itemKey
1261
- }, /* @__PURE__ */ React.createElement(HeaderText, null, item.content));
1262
- }
1263
- case ConversationMessageListItemType.Text: {
1264
- return /* @__PURE__ */ React.createElement(ConversationListItem, {
1265
- key: itemKey
1266
- }, /* @__PURE__ */ React.createElement("span", null, item.content));
1267
- }
1268
- case ConversationMessageListItemType.HTML: {
1269
- return /* @__PURE__ */ React.createElement(ConversationListItem, {
1270
- key: itemKey
1271
- }, /* @__PURE__ */ React.createElement(StyledHtml, {
1272
- html: item.content.body,
1273
- htmlParseInstruction: htmlParseInstructions
1274
- }));
1275
- }
1276
- case ConversationMessageListItemType.Separator: {
1277
- return /* @__PURE__ */ React.createElement(ConversationListItem, {
1278
- key: itemKey,
1279
- noPadding: true
1280
- }, /* @__PURE__ */ React.createElement(SeparatorPadding, null, /* @__PURE__ */ React.createElement(Separator, null)));
1281
- }
1282
- case ConversationMessageListItemType.LinkList: {
1283
- return /* @__PURE__ */ React.createElement(ConversationListItem, {
1284
- key: itemKey
1285
- }, /* @__PURE__ */ React.createElement(StyledLinkList, {
1286
- items: Object.keys(item.content.actions).map((i) => {
1287
- return {
1288
- label: item.content.actions[i],
1289
- actionKey: i
1290
- };
1291
- }),
1292
- renderItem: (item2) => {
1293
- return /* @__PURE__ */ React.createElement("li", {
1294
- key: item2.actionKey
1295
- }, /* @__PURE__ */ React.createElement(StyledLinkButton, {
1296
- help: item2.actionKey === "help",
1297
- onClick: () => {
1298
- dispatch("action", item2.actionKey);
1299
- }
1300
- }, item2.label, item2.actionKey === "help" && /* @__PURE__ */ React.createElement(SymbolBadge, {
1301
- size: 14,
1302
- symbol: {
1303
- type: "Svg",
1304
- content: "caret-down"
1305
- }
1306
- })));
1307
- }
1308
- }));
1309
- }
1310
- case ConversationMessageListItemType.ButtonList: {
1311
- const items2 = Array.isArray(item.content.actions) ? item.content.actions : Object.keys(item.content.actions).map((i) => {
1312
- return {
1313
- label: item.content.actions[i],
1314
- actionKey: i
1315
- };
1316
- });
1317
- return /* @__PURE__ */ React.createElement(ConversationListItem, {
1318
- key: itemKey
1319
- }, /* @__PURE__ */ React.createElement(StyledButtonList, {
1320
- items: items2,
1321
- renderItem: (item2) => {
1322
- return /* @__PURE__ */ React.createElement("li", {
1323
- key: item2.actionKey
1324
- }, /* @__PURE__ */ React.createElement(StyledButtonListButton, {
1325
- onClick: () => {
1326
- dispatch("action", item2.actionKey);
1327
- }
1328
- }, /* @__PURE__ */ React.createElement(SymbolBadge, {
1329
- symbol: item2.symbol
1330
- }), item2.label));
1331
- }
1332
- }));
1333
- }
1334
- case ConversationMessageListItemType.NoGoodAlternative: {
1335
- return /* @__PURE__ */ React.createElement(ConversationListItem, {
1336
- key: itemKey
1337
- }, /* @__PURE__ */ React.createElement(NoGoodAlternativeWrapper, {
1338
- onClick: () => {
1339
- dispatch("action", "help");
1340
- }
1341
- }, /* @__PURE__ */ React.createElement(SymbolBadge, {
1342
- size: 14,
1343
- symbol: {
1344
- type: "FontAwesome",
1345
- content: "meh-o"
1346
- }
1347
- }), /* @__PURE__ */ React.createElement("span", null, item.content.body)));
1348
- }
1349
- case ConversationMessageListItemType.FeedbackList: {
1350
- return /* @__PURE__ */ React.createElement(ConversationListItem, {
1351
- key: itemKey
1352
- }, /* @__PURE__ */ React.createElement(StyledButtonList, {
1353
- items: Object.keys(item.content.actions).map((i) => {
1354
- return {
1355
- label: item.content.actions[i],
1356
- actionKey: i
1357
- };
1358
- }),
1359
- renderItem: (item2) => {
1360
- return /* @__PURE__ */ React.createElement(FeedbackItem, {
1361
- key: item2.actionKey
1362
- }, /* @__PURE__ */ React.createElement(FeedbackButton, {
1363
- className: "humany-feedback-button",
1364
- disabled: false,
1365
- "aria-pressed": true,
1366
- "data-selected": true,
1367
- "data-direction": "vertical",
1368
- onClick: () => {
1369
- dispatch("action", item2.actionKey);
1370
- }
1371
- }, /* @__PURE__ */ React.createElement(Icon, {
1372
- faIcon: item2.actionKey == "yes" ? "smile-o" : "frown-o"
1373
- }), /* @__PURE__ */ React.createElement("span", null, item2.label)));
1374
- }
1375
- }));
1376
- }
1377
- default: {
1378
- return /* @__PURE__ */ React.createElement(ConversationListItem, {
1379
- key: itemKey,
1380
- noPadding: true
1381
- }, /* @__PURE__ */ React.createElement(CustomMessageListItem, {
1382
- type: item.type,
1383
- content: item.content
1384
- }));
1385
- }
1386
- }
1387
- }
1388
- }))));
1389
- };
1390
- const StyledForm = styled(FormComponent)`
1391
- & button.humany-form-component-button {
1392
- ${(p) => {
1393
- var _a, _b;
1394
- return invertedHoverButton({
1395
- active: false,
1396
- primaryColor: (_a = p.theme.colors) == null ? void 0 : _a.primary,
1397
- secondaryColor: (_b = p.theme.colors) == null ? void 0 : _b.accent
1398
- });
1399
- }};
1400
- display: block;
1401
- width: 100%;
1402
- margin-bottom: ${(p) => {
1403
- var _a;
1404
- return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
1405
- }};
1406
- }
1407
- & button.humany-form-component-submit {
1408
- width: 100%;
1409
- margin: 0;
1410
- :not(:last-child) {
1411
- margin-bottom: ${(p) => {
1412
- var _a;
1413
- return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
1414
- }};
1415
- }
1416
- }
1417
- `;
1418
- const StyledHtml = styled(Html)`
1419
- white-space: pre-wrap;
1420
- a {
1421
- color: ${(p) => p.theme.colors.link};
1422
- &:focus {
1423
- ${(p) => {
1424
- var _a;
1425
- return ((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && borderTabStyle;
1426
- }};
1427
- }
1428
- }
1429
- `;
1430
- const StyledActionList = styled(List)`
1431
- padding: 0;
1432
- list-style: none;
1433
- margin: 0 -${(p) => {
1434
- var _a;
1435
- return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
1436
- }};
1437
- > li {
1438
- margin: ${(p) => {
1439
- var _a;
1440
- return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
1441
- }};
1442
- }
1443
- `;
1444
- const StyledButtonList = styled(List)`
1445
- padding: 0;
1446
- list-style: none;
1447
- > li {
1448
- margin: ${(p) => {
1449
- var _a;
1450
- return (_a = p.theme.sizes) == null ? void 0 : _a.small;
1451
- }} ${(p) => {
1452
- var _a;
1453
- return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
1454
- }};
1455
- margin-left: 0;
1456
- display: inline-block;
1457
- }
1458
- `;
1459
- const StyledButtonListButton = styled.button`
1460
- ${buttonCss};
1461
- display: block;
1462
- text-align: left;
1463
- background-color: ${(p) => {
1464
- var _a;
1465
- return (_a = p.theme.colors) == null ? void 0 : _a.primary;
1466
- }};
1467
- width: 100%;
1468
- color: #fff;
1469
- &:focus {
1470
- ${(p) => {
1471
- var _a;
1472
- return ((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && css`
1473
- ${borderTabStyle}
1474
- background-color: transparent;
1475
- `;
1476
- }}
1477
- }
1478
-
1479
- i,
1480
- svg {
1481
- margin-right: ${(p) => {
1482
- var _a;
1483
- return (_a = p.theme.sizes) == null ? void 0 : _a.small;
1484
- }};
1485
- }
1486
- `;
1487
- const StyledLinkList = styled(List)`
1488
- padding: 0;
1489
- list-style: none;
1490
- > li {
1491
- margin-bottom: ${(p) => {
1492
- var _a;
1493
- return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
1494
- }};
1495
-
1496
- &:last-child {
1497
- margin-bottom: 0;
1498
- }
1499
- }
1500
- `;
1501
- const HeaderText = styled.strong`
1502
- font-size: ${(p) => {
1503
- var _a;
1504
- return (_a = p.theme.fonts) == null ? void 0 : _a.huge;
1505
- }};
1506
- `;
1507
- const StyledLinkButton = styled.button`
1508
- display: block;
1509
- background-color: transparent;
1510
- text-align: left;
1511
- border: none;
1512
- padding: 0;
1513
- font-weight: 300;
1514
- font-family: inherit;
1515
- cursor: pointer;
1516
- color: ${(p) => {
1517
- var _a;
1518
- return (_a = p.theme.colors) == null ? void 0 : _a.primary;
1519
- }};
1520
-
1521
- ${(p) => {
1522
- var _a, _b;
1523
- return p.help && css`
1524
- color: ${(_a = p.theme.colors) == null ? void 0 : _a.text};
1525
- text-decoration: underline;
1526
-
1527
- i,
1528
- svg {
1529
- margin-left: ${(_b = p.theme.sizes) == null ? void 0 : _b.small};
1530
- }
1531
- `;
1532
- }}
1533
- `;
1534
- const StyledActionButton = styled.button`
1535
- ${buttonCss};
1536
- display: block;
1537
- background-color: ${(p) => {
1538
- var _a;
1539
- return (_a = p.theme.colors) == null ? void 0 : _a.primary;
1540
- }};
1541
- width: 100%;
1542
- color: #fff;
1543
- font-family: Lato;
1544
- font-size: ${(p) => {
1545
- var _a;
1546
- return (_a = p.theme.fonts) == null ? void 0 : _a.huge;
1547
- }};
1548
- font-weight: 300;
1549
- &:focus {
1550
- ${(p) => {
1551
- var _a;
1552
- return ((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && css`
1553
- ${borderTabStyle}
1554
- background-color: transparent;
1555
- `;
1556
- }}
1557
- }
1558
- `;
1559
- const SeparatorPadding = styled.div`
1560
- padding-top: calc(${(p) => {
1561
- var _a;
1562
- return (_a = p.theme.sizes) == null ? void 0 : _a.medium;
1563
- }} - ${(p) => {
1564
- var _a;
1565
- return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
1566
- }});
1567
- padding-bottom: calc(${(p) => {
1568
- var _a;
1569
- return (_a = p.theme.sizes) == null ? void 0 : _a.medium;
1570
- }} - ${(p) => {
1571
- var _a;
1572
- return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
1573
- }});
1574
- `;
1575
- const Separator = styled.div`
1576
- background-color: #efefef;
1577
- height: 1px;
1578
- width: 100%;
1579
- `;
1580
- const NoGoodAlternativeWrapper = styled.div`
1581
- display: flex;
1582
- align-items: center;
1583
- justify-content: center;
1584
- cursor: pointer;
1585
-
1586
- > i,
1587
- svg {
1588
- margin-right: ${(p) => {
1589
- var _a;
1590
- return (_a = p.theme.sizes) == null ? void 0 : _a.small;
1591
- }};
1592
- }
1593
- `;
1594
- const ConversationListItem = styled.li`
1595
- padding-left: ${(p) => {
1596
- var _a;
1597
- return p.noPadding ? 0 : (_a = p.theme.sizes) == null ? void 0 : _a.medium;
1598
- }};
1599
- padding-right: ${(p) => {
1600
- var _a;
1601
- return p.noPadding ? 0 : (_a = p.theme.sizes) == null ? void 0 : _a.medium;
1602
- }};
1603
- `;
1604
- const FeedbackItem = styled.li`
1605
- @media (min-width: 768px) {
1606
- display: list-item !important;
1607
- margin-right: 0 !important;
1608
- margin-top: ${(p) => {
1609
- var _a;
1610
- return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
1611
- }} !important;
1612
- }
1613
- `;
1614
- const FeedbackButton = styled.button`
1615
- @media (min-width: 768px) {
1616
- min-width: 100%;
1617
- margin-right: 0;
1618
- }
1619
- display: inline-block;
1620
- font-size: ${(p) => {
1621
- var _a;
1622
- return (_a = p.theme.fonts) == null ? void 0 : _a.normal;
1623
- }};
1624
- border-color: ${(p) => {
1625
- var _a;
1626
- return (_a = p.theme.colors) == null ? void 0 : _a.primary;
1627
- }} !important;
1628
- font-weight: 300;
1629
- && {
1630
- margin-right: ${(p) => {
1631
- var _a;
1632
- return (_a = p.theme.sizes) == null ? void 0 : _a.small;
1633
- }};
1634
- }
1635
- ${(p) => {
1636
- var _a, _b;
1637
- return p["data-direction"] === "horizontal" && css`
1638
- width: 225px;
1639
- max-width: calc(50% - ${(_a = p.theme.sizes) == null ? void 0 : _a.large} - ${(_b = p.theme.sizes) == null ? void 0 : _b.small});
1640
- `;
1641
- }}
1642
- ${(p) => p["data-direction"] === "vertical" && css`
1643
- min-width: 150px;
1644
- `}
1645
- ${(p) => {
1646
- var _a;
1647
- return invertedHoverButton({
1648
- primaryColor: `${(_a = p.theme.colors) == null ? void 0 : _a.primary}`,
1649
- secondaryColor: "#FFFFFF"
1650
- });
1651
- }}
1652
- i {
1653
- margin: 0 ${(p) => {
1654
- var _a;
1655
- return (_a = p.theme.sizes) == null ? void 0 : _a.small;
1656
- }} 0 0;
1657
- }
1658
- span {
1659
- }
1660
- `;
1661
- const ConversationReturnButtonComponent = (container) => {
1662
- return Promise.all([
1663
- ComponentPlatform.getInstance(container),
1664
- ConversationPlatform.getInstance(container),
1665
- container.getAsync("router")
1666
- ]).then(([components, platform, router]) => {
1667
- return createReactComponent(container, "conversation-return-button", import("./return-button.js"), (component) => {
1668
- component.actions.create("toggle", (options = {}) => {
1669
- var _a;
1670
- (_a = platform.getComponentRoute()) == null ? void 0 : _a.then((route) => {
1671
- route && router.navigate(route.name, route.params);
1672
- });
1673
- });
1674
- });
1675
- });
1676
- };
1677
- export { AgentMessage as A, ContentBundle as C, Loader as L, MessageContainer as M, SystemMessage as S, UserMessage as U, MessageContent as a, ConversationMessageType as b, ConversationContent as c, ConversationPlatform as d, ConversationEndedBehavior as e, ConversationController as f, ConversationEntry as g, ConversationMessageListItemType as h, ConversationComponent as i, ConversationReturnButtonComponent as j, StyledButtonList as k, registerCustomMessageComponent as r };
1678
- //# sourceMappingURL=index2.js.map