@telia-ace/widget-conversation 1.0.23 → 1.0.26

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 (46) hide show
  1. package/README.md +110 -210
  2. package/dist/conversation.3981560b.js +1100 -0
  3. package/dist/conversation.3981560b.js.map +1 -0
  4. package/dist/index.d.ts +1 -2
  5. package/dist/index.js +432 -760
  6. package/dist/index.js.map +1 -1
  7. package/dist/return-button.8773c0de.js +159 -0
  8. package/dist/return-button.8773c0de.js.map +1 -0
  9. package/dist/types.d.ts +41 -34
  10. package/dist/{components/conversation/plugin.d.ts → ui/conversation/conversation-component.d.ts} +2 -13
  11. package/dist/ui/conversation/conversation-content.d.ts +11 -0
  12. package/dist/{components/conversation/ui/input.d.ts → ui/conversation/conversation-input.d.ts} +0 -0
  13. package/dist/ui/conversation/conversation-loader.d.ts +8 -0
  14. package/dist/ui/conversation/conversation-message.d.ts +7 -0
  15. package/dist/ui/conversation/conversation-styles.d.ts +11 -0
  16. package/dist/{components → ui}/conversation/conversation.d.ts +0 -0
  17. package/dist/ui/conversation/index.d.ts +2 -0
  18. package/dist/{components/conversation/ui → ui/conversation}/message-types/agent.d.ts +1 -1
  19. package/dist/ui/conversation/message-types/custom.d.ts +9 -0
  20. package/dist/{components/conversation/ui → ui/conversation}/message-types/index.d.ts +1 -0
  21. package/dist/{components/conversation/ui → ui/conversation}/message-types/system.d.ts +0 -0
  22. package/dist/{components/conversation/ui → ui/conversation}/message-types/timestamp.d.ts +0 -0
  23. package/dist/{components/conversation/ui → ui/conversation}/message-types/user.d.ts +0 -0
  24. package/dist/ui/index.d.ts +2 -0
  25. package/dist/ui/return-button/index.d.ts +2 -0
  26. package/dist/{components/return-button/plugin.d.ts → ui/return-button/return-button-component.d.ts} +2 -1
  27. package/dist/{components → ui}/return-button/return-button.d.ts +0 -0
  28. package/package.json +10 -10
  29. package/dist/components/conversation/ui/content.d.ts +0 -2
  30. package/dist/components/conversation/ui/loader.d.ts +0 -8
  31. package/dist/components/conversation/ui/message-list-items/button-list.d.ts +0 -8
  32. package/dist/components/conversation/ui/message-list-items/custom.d.ts +0 -9
  33. package/dist/components/conversation/ui/message-list-items/html.d.ts +0 -5
  34. package/dist/components/conversation/ui/message-list-items/link-list.d.ts +0 -8
  35. package/dist/components/conversation/ui/message-list-items/separator.d.ts +0 -2
  36. package/dist/components/conversation/ui/message-list-items/text.d.ts +0 -6
  37. package/dist/components/conversation/ui/message-list-items/video-request.d.ts +0 -8
  38. package/dist/components/conversation/ui/message-types/message-list.d.ts +0 -9
  39. package/dist/components/conversation/ui/message.d.ts +0 -7
  40. package/dist/components/conversation/ui/overlay-outlets.d.ts +0 -13
  41. package/dist/components/conversation/ui/styles.d.ts +0 -27
  42. package/dist/conversation.js +0 -1398
  43. package/dist/conversation.js.map +0 -1
  44. package/dist/return-button.js +0 -174
  45. package/dist/return-button.js.map +0 -1
  46. package/dist/utils/map-actions.d.ts +0 -1
package/dist/index.js CHANGED
@@ -1,371 +1,235 @@
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;
1
+ var U = Object.defineProperty, F = Object.defineProperties;
2
+ var _ = Object.getOwnPropertyDescriptors;
3
+ var C = Object.getOwnPropertySymbols;
4
+ var T = Object.prototype.hasOwnProperty, D = Object.prototype.propertyIsEnumerable;
5
+ var N = (i, t, e) => t in i ? U(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e, p = (i, t) => {
6
+ for (var e in t || (t = {}))
7
+ T.call(t, e) && N(i, e, t[e]);
8
+ if (C)
9
+ for (var e of C(t))
10
+ D.call(t, e) && N(i, e, t[e]);
11
+ return i;
12
+ }, g = (i, t) => F(i, _(t));
13
+ var R = (i, t) => {
14
+ var e = {};
15
+ for (var s in i)
16
+ T.call(i, s) && t.indexOf(s) < 0 && (e[s] = i[s]);
17
+ if (i != null && C)
18
+ for (var s of C(i))
19
+ t.indexOf(s) < 0 && D.call(i, s) && (e[s] = i[s]);
20
+ return e;
18
21
  };
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];
22
+ var S = (i, t, e) => new Promise((s, r) => {
23
+ var n = (c) => {
24
+ try {
25
+ a(e.next(c));
26
+ } catch (h) {
27
+ r(h);
29
28
  }
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 } from "@telia-ace/widget-utilities";
55
- import { FormBuilder } from "@telia-ace/widget-forms";
56
- import { closeAllModals } from "@telia-ace/widget-plugins";
57
- import { createReactComponent } from "@telia-ace/widget-ui";
58
- import { lazy } from "react";
59
- class Agent {
60
- constructor(provider, settings) {
61
- this.provider = provider;
62
- this.print = (settings2) => {
63
- const sender = { name: this.name, avatar: this.avatar };
64
- const normalized = getNormalizedMessageSettings(settings2);
65
- return this.provider.createEntry(normalized.key, normalized.content, ConversationMessageType.Agent, sender, normalized.timestamp);
66
- };
67
- this.typing = () => {
68
- return this.provider.setTypingState({ name: this.name, avatar: this.avatar });
69
- };
70
- this.name = settings.name;
71
- this.avatar = settings.avatar;
72
- }
73
- update(settings) {
74
- const { name, avatar } = settings;
75
- if (avatar === null) {
76
- this.avatar = void 0;
77
- } else if (avatar) {
78
- this.avatar = avatar;
79
- }
80
- if (name === null) {
81
- this.name = void 0;
82
- } else if (name) {
83
- this.name = name;
29
+ }, o = (c) => {
30
+ try {
31
+ a(e.throw(c));
32
+ } catch (h) {
33
+ r(h);
84
34
  }
35
+ }, a = (c) => c.done ? s(c.value) : Promise.resolve(c.value).then(n, o);
36
+ a((e = e.apply(i, t)).next());
37
+ });
38
+ import { ComponentPlatform as H } from "@telia-ace/widget-core";
39
+ import { createStorageWriter as z, StorageCategory as $, StorageMedium as m, StorageScope as L, readStorage as A } from "@telia-ace/widget-services";
40
+ import { uuid as j, lock as G } from "@telia-ace/widget-utilities";
41
+ import { FormBuilder as J } from "@telia-ace/widget-forms";
42
+ import { closeAllModals as M } from "@telia-ace/widget-plugins";
43
+ import { createReactComponent as Q } from "@telia-ace/widget-ui";
44
+ import { lazy as K } from "react";
45
+ class V {
46
+ constructor(t, e) {
47
+ this.provider = t, this.print = (s) => {
48
+ const r = { name: this.name, avatar: this.avatar }, n = x(s);
49
+ return this.provider.createEntry(n.key, n.content, E.Agent, r, n.timestamp);
50
+ }, this.typing = () => this.provider.setTypingState({ name: this.name, avatar: this.avatar }), this.name = e.name, this.avatar = e.avatar;
51
+ }
52
+ update(t) {
53
+ const { name: e, avatar: s } = t;
54
+ s === null ? this.avatar = void 0 : s && (this.avatar = s), e === null ? this.name = void 0 : e && (this.name = e);
85
55
  }
86
56
  }
87
- class ConversationProvider {
88
- constructor(name, container, controller) {
89
- this.name = name;
90
- this.container = container;
91
- this.controller = controller;
92
- this.subscriptions = [];
93
- this.user = controller == null ? void 0 : controller.user;
94
- }
95
- static create(name, container, controller) {
96
- return new ConversationProvider(name, container, controller);
97
- }
98
- createAgent(settings = {}) {
99
- if (this.controller) {
100
- return new Agent(this, settings);
101
- }
57
+ class k {
58
+ constructor(t, e, s) {
59
+ this.name = t, this.container = e, this.controller = s, this.subscriptions = [], this.user = s == null ? void 0 : s.user;
60
+ }
61
+ static create(t, e, s) {
62
+ return new k(t, e, s);
63
+ }
64
+ createAgent(t = {}) {
65
+ if (this.controller)
66
+ return new V(this, t);
102
67
  }
103
- print(settings) {
104
- var _a;
105
- return (_a = this.controller) == null ? void 0 : _a.print(settings);
68
+ print(t) {
69
+ var e;
70
+ return (e = this.controller) == null ? void 0 : e.print(t);
106
71
  }
107
- setTypingState(sender, type) {
108
- var _a;
109
- return (_a = this.controller) == null ? void 0 : _a.setTypingState(sender, type);
72
+ setTypingState(t, e) {
73
+ var s;
74
+ return (s = this.controller) == null ? void 0 : s.setTypingState(t, e);
110
75
  }
111
76
  loading() {
112
- if (!this.controller) {
113
- return () => () => {
114
- };
115
- }
116
- return this.controller.loader();
77
+ return this.controller ? this.controller.loader() : () => () => {
78
+ };
117
79
  }
118
- createEntry(key, content, type, sender, timestamp) {
119
- var _a;
120
- return (_a = this.controller) == null ? void 0 : _a.createEntry(key, content, type, sender, timestamp);
80
+ createEntry(t, e, s, r, n) {
81
+ var o;
82
+ return (o = this.controller) == null ? void 0 : o.createEntry(t, e, s, r, n);
121
83
  }
122
84
  dispose() {
123
- var _a;
124
- (_a = this.controller) == null ? void 0 : _a.disposeProvider(this);
125
- this.controller = null;
126
- this.subscriptions.forEach((unsub) => unsub());
85
+ var t;
86
+ process.env.NODE_ENV !== "production" && console.log(`conversation-provider: dispose (${this.name})`), (t = this.controller) == null || t.disposeProvider(this), this.controller = null, this.subscriptions.forEach((e) => e());
127
87
  }
128
- onUnreadMessage(fn) {
129
- var _a;
88
+ onUnreadMessage(t) {
89
+ var e;
130
90
  if (this.controller) {
131
- const unsubscribe = (_a = this.controller) == null ? void 0 : _a.onUnreadMessage(fn);
132
- this.subscriptions.push(unsubscribe);
133
- return () => {
134
- unsubscribe();
91
+ const s = (e = this.controller) == null ? void 0 : e.onUnreadMessage(t);
92
+ return this.subscriptions.push(s), () => {
93
+ s();
135
94
  };
136
95
  }
137
96
  }
138
- onMounted(fn) {
139
- var _a;
97
+ onMounted(t) {
98
+ var e;
140
99
  if (this.controller) {
141
- const unsubscribe = (_a = this.controller) == null ? void 0 : _a.events.subscribe("conversation:component-mount-changed", fn);
142
- this.subscriptions.push(unsubscribe);
143
- fn({}, this.controller.getComponentMountedState());
144
- return () => {
145
- unsubscribe();
100
+ const s = (e = this.controller) == null ? void 0 : e.events.subscribe("conversation:component-mount-changed", t);
101
+ return this.subscriptions.push(s), t({}, this.controller.getComponentMountedState()), () => {
102
+ s();
146
103
  };
147
104
  }
148
105
  }
149
106
  }
150
- class User {
151
- constructor(controller) {
152
- this.controller = controller;
153
- this.print = (settings) => {
154
- const normalized = getNormalizedMessageSettings(settings);
155
- return this.controller.createEntry(normalized.key, normalized.content, ConversationMessageType.User, void 0, normalized.timestamp);
107
+ class Y {
108
+ constructor(t) {
109
+ this.controller = t, this.print = (e) => {
110
+ const s = x(e);
111
+ return this.controller.createEntry(s.key, s.content, E.User, void 0, s.timestamp);
156
112
  };
157
113
  }
158
114
  }
159
- class ConversationEntry {
160
- constructor(writer) {
161
- this.writer = writer;
115
+ class q {
116
+ constructor(t) {
117
+ this.writer = t;
162
118
  }
163
- update(content) {
164
- const normalized = this.getNormalizedSettings(content);
165
- this.writer(normalized);
119
+ update(t) {
120
+ const e = this.getNormalizedSettings(t);
121
+ this.writer(e);
166
122
  }
167
123
  remove() {
168
124
  this.writer(null);
169
125
  }
170
- getNormalizedSettings(content) {
171
- if (typeof content === "string")
172
- return { body: content };
173
- else if (content.length > -1 && typeof content === "object")
174
- return { items: content };
175
- else
176
- return content;
126
+ getNormalizedSettings(t) {
127
+ return typeof t == "string" ? { body: t } : t.length > -1 && typeof t == "object" ? { items: t } : t;
177
128
  }
178
129
  }
179
- var ConversationMessageType = /* @__PURE__ */ ((ConversationMessageType2) => {
180
- ConversationMessageType2["User"] = "user";
181
- ConversationMessageType2["Agent"] = "agent";
182
- ConversationMessageType2["System"] = "system";
183
- return ConversationMessageType2;
184
- })(ConversationMessageType || {});
185
- const getNormalizedMessageSettings = (settings) => {
186
- let content;
187
- let key = uuid();
188
- let timestamp = Date.now();
189
- if (Array.isArray(settings) && settings.length > -1) {
190
- if (typeof settings[0] === "string") {
191
- content = { items: [settings] };
192
- } else {
193
- content = { items: settings };
194
- }
195
- } else if (typeof settings === "string") {
196
- content = { body: settings };
197
- } else {
198
- settings = settings || {};
199
- if (settings.type) {
200
- content = __spreadValues({}, settings);
201
- } else {
202
- content = {
203
- body: settings.body,
204
- actions: settings.actions,
205
- title: settings.title
206
- };
207
- if (settings.key) {
208
- key = settings.key;
209
- }
210
- if (settings.timestamp) {
211
- timestamp = settings.timestamp;
212
- }
213
- if (settings.form) {
214
- const builder = FormBuilder.create(key);
215
- settings.form(builder);
216
- const builtForm = builder.get();
217
- content.form = builtForm;
218
- }
219
- if (settings.timestamp === null) {
220
- timestamp = null;
221
- }
130
+ var E = /* @__PURE__ */ ((i) => (i.User = "user", i.Agent = "agent", i.System = "system", i))(E || {});
131
+ const x = (i) => {
132
+ let t, e = j(), s = Date.now();
133
+ if (i.length > -1 && typeof i == "object")
134
+ typeof i[0] == "string" ? t = { items: [i] } : t = { items: i };
135
+ else if (typeof i == "string")
136
+ t = { body: i };
137
+ else if (i = i, i.type)
138
+ t = p({}, i);
139
+ else {
140
+ if (t = {
141
+ body: i.body,
142
+ actions: i.actions,
143
+ title: i.title
144
+ }, i.key && (e = i.key), i.timestamp && (s = i.timestamp), i.form) {
145
+ const r = J.create(e);
146
+ i.form(r);
147
+ const n = r.get();
148
+ t.form = n;
222
149
  }
150
+ i.timestamp === null && (s = null);
223
151
  }
224
- return { content, key, timestamp };
225
- };
226
- const removeTypingState = (typingActors, sender) => {
227
- if (!sender) {
152
+ return { content: t, key: e, timestamp: s };
153
+ }, O = (i, t) => {
154
+ if (!t)
228
155
  return;
229
- }
230
- const senderString = JSON.stringify(sender);
231
- const indexToRemove = typingActors.findIndex((item) => {
232
- return senderString === JSON.stringify(item);
233
- });
234
- if (indexToRemove > -1) {
235
- return typingActors.splice(indexToRemove, 1);
236
- }
156
+ const e = JSON.stringify(t), s = i.findIndex((r) => e === JSON.stringify(r));
157
+ if (s > -1)
158
+ return i.splice(s, 1);
237
159
  };
238
- class ConversationController {
239
- constructor(container, id) {
240
- this.container = container;
241
- this.id = id;
242
- this.formHandlers = {};
243
- this.user = new User(this);
244
- this.providers = [];
245
- this.active = false;
246
- this.registeredProviders = [];
247
- this.loaders = 0;
248
- this.componentMounted = false;
249
- this.messages = [];
250
- this.typingActors = [];
251
- this.print = (settings) => {
252
- const normalized = getNormalizedMessageSettings(settings);
253
- return this.createEntry(normalized.key, normalized.content, "system", void 0, normalized.timestamp);
160
+ class X {
161
+ constructor(t, e) {
162
+ this.container = t, this.id = e, this.formHandlers = {}, this.user = new Y(this), this.providers = [], this.active = !1, this.registeredProviders = [], this.loaders = 0, this.componentMounted = !1, this.messages = [], this.typingActors = [], this.print = (r) => {
163
+ const n = x(r);
164
+ return this.createEntry(n.key, n.content, "system", void 0, n.timestamp);
254
165
  };
255
- const widget = container.get("$widget");
256
- this.events = widget.events.createChild(this);
257
- }
258
- setProviders(providers) {
259
- const removed = [];
260
- const added = [];
261
- this.providers.reduce((acc, provider) => {
262
- if (providers.indexOf(provider) === -1) {
263
- acc.push(provider);
264
- }
265
- return acc;
266
- }, []).forEach((providerToRemove) => {
267
- const indexToRemove = this.providers.indexOf(providerToRemove);
268
- if (indexToRemove > -1) {
269
- removed.push(providerToRemove);
270
- this.providers.splice(indexToRemove, 1);
271
- }
272
- });
273
- providers.forEach((provider) => {
274
- if (this.providers.indexOf(provider) === -1) {
275
- added.push(provider);
276
- this.providers.push(provider);
277
- }
278
- });
279
- if (added.length || removed.length) {
280
- this.events.dispatch("conversation:providers-changed", { added, removed });
281
- }
166
+ const s = t.get("$widget");
167
+ this.events = s.events.createChild(this);
168
+ }
169
+ setProviders(t) {
170
+ const e = [], s = [];
171
+ this.providers.reduce((r, n) => (t.indexOf(n) === -1 && r.push(n), r), []).forEach((r) => {
172
+ const n = this.providers.indexOf(r);
173
+ n > -1 && (e.push(r), this.providers.splice(n, 1));
174
+ }), t.forEach((r) => {
175
+ this.providers.indexOf(r) === -1 && (s.push(r), this.providers.push(r));
176
+ }), (s.length || e.length) && this.events.dispatch("conversation:providers-changed", { added: s, removed: e });
177
+ }
178
+ createProvider(t) {
179
+ const e = this.providerIndex(t);
180
+ if (e > -1)
181
+ return this.registeredProviders[e];
182
+ const s = k.create(t, this.container, this);
183
+ return this.registeredProviders.push(s), s;
184
+ }
185
+ providerIndex(t) {
186
+ return this.registeredProviders.findIndex((e) => e.name === t);
282
187
  }
283
- createProvider(name) {
284
- const index = this.providerIndex(name);
285
- if (index > -1) {
286
- return this.registeredProviders[index];
287
- }
288
- const provider = ConversationProvider.create(name, this.container, this);
289
- this.registeredProviders.push(provider);
290
- return provider;
188
+ dispose() {
189
+ this.registeredProviders.forEach((t) => t.dispose()), this.messages = [], this.events.dispatch("conversation:controller-disposed", this), this.active = !1;
291
190
  }
292
- providerIndex(name) {
293
- return this.registeredProviders.findIndex((p) => p.name === name);
191
+ onDispose(t) {
192
+ return this.events.subscribe("conversation:controller-disposed", t);
294
193
  }
295
- dispose() {
296
- this.registeredProviders.forEach((provider) => provider.dispose());
297
- this.messages = [];
298
- this.events.dispatch("conversation:controller-disposed", this);
299
- this.active = false;
300
- }
301
- onDispose(fn) {
302
- return this.events.subscribe("conversation:controller-disposed", fn);
303
- }
304
- onStarted(fn) {
305
- return this.events.subscribe("conversation:started", fn);
306
- }
307
- disposeProvider(target) {
308
- const index = this.providerIndex(target.name);
309
- index > -1 && this.registeredProviders.splice(index, 1);
310
- this.events.dispatch("conversation:providers-changed", { removed: [target.name] });
311
- if (!this.registeredProviders.length) {
312
- this.dispose();
313
- }
194
+ onStarted(t) {
195
+ return this.events.subscribe("conversation:started", t);
314
196
  }
315
- onProvidersChange(fn) {
316
- return this.events.subscribe("conversation:providers-changed", fn);
197
+ disposeProvider(t) {
198
+ const e = this.providerIndex(t.name);
199
+ e > -1 && this.registeredProviders.splice(e, 1), this.events.dispatch("conversation:providers-changed", { removed: [t.name] }), this.registeredProviders.length || this.dispose();
317
200
  }
318
- setComponentMountedState(mounted) {
319
- if (this.componentMounted === mounted) {
320
- return;
321
- }
322
- this.componentMounted = mounted;
323
- if (mounted) {
324
- this.events.dispatch("conversation:unread-message", false);
325
- this.events.dispatch("conversation:started", true);
326
- this.active = true;
327
- }
328
- this.events.dispatch("conversation:component-mount-changed", mounted);
201
+ onProvidersChange(t) {
202
+ return this.events.subscribe("conversation:providers-changed", t);
203
+ }
204
+ setComponentMountedState(t) {
205
+ this.componentMounted !== t && (this.componentMounted = t, t && (this.events.dispatch("conversation:unread-message", !1), this.events.dispatch("conversation:started", !0), this.active = !0), this.events.dispatch("conversation:component-mount-changed", t));
329
206
  }
330
207
  getComponentMountedState() {
331
208
  return this.componentMounted;
332
209
  }
333
- onUnreadMessage(fn) {
334
- return this.events.subscribe("conversation:unread-message", fn);
210
+ onUnreadMessage(t) {
211
+ return this.events.subscribe("conversation:unread-message", t);
335
212
  }
336
- createEntry(key, content, type, sender, timestamp) {
337
- const message = {
338
- key,
339
- content,
340
- type,
341
- sender: sender || null,
342
- timestamp: timestamp || timestamp === null ? timestamp : Date.now()
213
+ createEntry(t, e, s, r, n) {
214
+ const o = {
215
+ key: t,
216
+ content: e,
217
+ type: s,
218
+ sender: r || null,
219
+ timestamp: n || n === null ? n : Date.now()
343
220
  };
344
- this.messages.push(message);
345
- message.type === "agent" && removeTypingState(this.typingActors, sender);
346
- const entry = new ConversationEntry((updated) => {
347
- if (updated !== null) {
348
- const _a = updated, { timestamp: updatedTimestamp = void 0 } = _a, content2 = __objRest(_a, ["timestamp"]);
349
- message.content = content2;
350
- if (updatedTimestamp) {
351
- message.timestamp = updatedTimestamp;
352
- }
221
+ this.messages.push(o), o.type === "agent" && O(this.typingActors, r);
222
+ const a = new q((c) => {
223
+ if (c !== null) {
224
+ const h = c, { timestamp: d = void 0 } = h, f = R(h, ["timestamp"]);
225
+ o.content = f, d && (o.timestamp = d);
353
226
  } else {
354
- const indexToRemove = this.messages.indexOf(message);
355
- message.content = null;
356
- if (indexToRemove > -1) {
357
- this.messages.splice(indexToRemove, 1);
358
- }
227
+ const d = this.messages.indexOf(o);
228
+ o.content = null, d > -1 && this.messages.splice(d, 1);
359
229
  }
360
- this.events.dispatch("conversation:message-updated", { message });
361
- this.update();
230
+ this.events.dispatch("conversation:message-updated", { message: o }), this.update();
362
231
  });
363
- this.events.dispatch("conversation:message-created", { message });
364
- this.update();
365
- if (!this.componentMounted) {
366
- this.events.dispatch("conversation:unread-message", true);
367
- }
368
- return entry;
232
+ return this.events.dispatch("conversation:message-created", { message: o }), this.update(), this.componentMounted || this.events.dispatch("conversation:unread-message", !0), a;
369
233
  }
370
234
  update() {
371
235
  this.events.dispatch("conversation:updated", {
@@ -381,507 +245,315 @@ class ConversationController {
381
245
  typingActors: this.typingActors
382
246
  };
383
247
  }
384
- setTypingState(sender, type) {
385
- if (this.typingActors.indexOf(sender) === -1) {
386
- this.typingActors.push(sender);
387
- this.update();
388
- }
389
- return () => {
390
- removeTypingState(this.typingActors, sender);
391
- this.update();
248
+ setTypingState(t, e) {
249
+ return this.typingActors.indexOf(t) === -1 && (this.typingActors.push(t), this.update()), () => {
250
+ O(this.typingActors, t), this.update();
392
251
  };
393
252
  }
394
253
  loader() {
395
254
  this.loaders = this.loaders + 1;
396
- let dismissed = false;
397
- if (this.loaders === 1) {
398
- this.update();
399
- }
400
- return () => {
401
- if (!dismissed) {
402
- dismissed = true;
403
- this.loaders = this.loaders - 1;
404
- if (this.loaders === 0) {
405
- this.update();
406
- }
407
- }
255
+ let t = !1;
256
+ return this.loaders === 1 && this.update(), () => {
257
+ t || (t = !0, this.loaders = this.loaders - 1, this.loaders === 0 && this.update());
408
258
  };
409
259
  }
410
- submitForm(key, handler) {
411
- this.formHandlers[key] = __spreadProps(__spreadValues({}, this.formHandlers[key]), { submit: handler });
260
+ submitForm(t, e) {
261
+ this.formHandlers[t] = g(p({}, this.formHandlers[t]), { submit: e });
412
262
  }
413
- validateForm(key, handler) {
414
- this.formHandlers[key] = __spreadProps(__spreadValues({}, this.formHandlers[key]), { validate: handler });
263
+ validateForm(t, e) {
264
+ this.formHandlers[t] = g(p({}, this.formHandlers[t]), { validate: e });
415
265
  }
416
266
  }
417
- const getParentWidget = (widgetName, implementation) => {
418
- const mainWidgetName = widgetName.split("_contact");
419
- return implementation.widgets.get(mainWidgetName[0]);
420
- };
421
- const getSeparateWidget = (container) => {
422
- const originWidget = container.get("$widget");
423
- const { name, implementation } = container.get("$widget");
424
- const mainWidget = name.indexOf("_contact") > -1 ? getParentWidget(name, implementation) : originWidget;
425
- const { data } = container.get("$settings");
426
- const { trigger } = mainWidget.container.get("$settings");
427
- const chatWidgetName = `${name.replace("_contact-method", "").replace("_contact", "")}_contact-method`;
428
- const chatWidget = implementation.widgets.get(chatWidgetName);
429
- if (chatWidget && !trigger) {
430
- return { chatWidget, mainWidget, data };
431
- }
432
- return { mainWidget, data };
433
- };
434
- const shouldPreventDefault = (container) => {
435
- const { chatWidget } = getSeparateWidget(container);
436
- return !!chatWidget;
437
- };
438
- const openChatWidget = (container, contactMethod, triggerDOMTarget) => {
439
- const { mainWidget, data, chatWidget } = getSeparateWidget(container);
440
- if (chatWidget) {
441
- if (chatWidget.state === "activated") {
442
- return chatWidget.invoke("open").then(() => {
443
- chatWidget.container.getAsync("conversation").then((conversation) => {
444
- conversation.navigateToConversationIfActive(contactMethod.id).then(() => closeAllModals(container));
445
- });
446
- });
447
- }
448
- return chatWidget.activate().then(() => {
449
- const { trigger } = chatWidget.container.get("$settings");
450
- trigger.action = "hide";
451
- return chatWidget.invoke("setSettings", () => ({
452
- data,
453
- trigger,
454
- activate: true
455
- })).then(() => {
456
- return chatWidget.container.getAsync("components").then((components) => {
457
- const contactMethodsQuery = components.components().ofType("contact-method");
458
- components.write({
459
- key: "setContactMethodId",
460
- attributes: {
461
- properties: {
462
- id: contactMethod.id,
463
- guideId: contactMethod.guideId
464
- }
465
- },
466
- target: contactMethodsQuery,
467
- provider: "localStorage"
468
- });
469
- const conversationsQuery = components.components().ofType("conversation");
470
- components.write({
471
- key: "setConversationProvider",
472
- attributes: {
473
- properties: { providers: [contactMethod.clientName] }
474
- },
475
- target: conversationsQuery,
476
- provider: "localStorage"
477
- });
478
- });
267
+ const Z = (i, t) => {
268
+ const e = i.split("_contact");
269
+ return t.widgets.get(e[0]);
270
+ }, I = (i) => {
271
+ const t = i.get("$widget"), { name: e, implementation: s } = i.get("$widget"), r = e.indexOf("_contact") > -1 ? Z(e, s) : t, { data: n } = i.get("$settings"), { trigger: o } = r.container.get("$settings"), a = `${e.replace("_contact-method", "").replace("_contact", "")}_contact-method`, c = s.widgets.get(a);
272
+ return c && !o ? { chatWidget: c, mainWidget: r, data: n } : { mainWidget: r, data: n };
273
+ }, tt = (i) => {
274
+ const { chatWidget: t } = I(i);
275
+ return !!t;
276
+ }, B = (i, t, e) => {
277
+ const { mainWidget: s, data: r, chatWidget: n } = I(i);
278
+ return n ? n.state === "activated" ? n.invoke("open").then(() => {
279
+ n.container.getAsync("conversation").then((o) => {
280
+ o.navigateToConversationIfActive(t.id).then(() => M(i));
281
+ });
282
+ }) : n.activate().then(() => {
283
+ const { trigger: o } = n.container.get("$settings");
284
+ return o.action = "hide", n.invoke("setSettings", () => ({
285
+ data: r,
286
+ trigger: o,
287
+ activate: !0
288
+ })).then(() => n.container.getAsync("components").then((a) => {
289
+ const c = a.components().ofType("contact-method");
290
+ a.write({
291
+ key: "setContactMethodId",
292
+ attributes: {
293
+ properties: {
294
+ id: t.id,
295
+ guideId: t.guideId
296
+ }
297
+ },
298
+ target: c,
299
+ provider: "localStorage"
479
300
  });
480
- }).then(() => {
481
- return chatWidget.invoke("attach", {
482
- key: "contact-method",
483
- triggerDOMElement: triggerDOMTarget,
484
- withRenderState: "open"
301
+ const h = a.components().ofType("conversation");
302
+ a.write({
303
+ key: "setConversationProvider",
304
+ attributes: {
305
+ properties: { providers: [t.clientName] }
306
+ },
307
+ target: h,
308
+ provider: "localStorage"
485
309
  });
486
- }).then(() => {
487
- createStorageWriter(chatWidget.container, "activeStickyWidget", StorageCategory.Necessary, {
488
- medium: StorageMedium.Local,
489
- scope: StorageScope.Implementation
490
- }).then((write) => write(chatWidget.name));
491
- return chatWidget.container.getAsync("conversation").then((platform) => {
492
- platform.setConversationEndedBehavior(ConversationEndedBehavior.Deactivate);
493
- }).then(() => closeAllModals(container)).then(() => false);
494
- });
495
- }
496
- mainWidget.container.getAsync("conversation").then((platform) => {
497
- return platform.navigateToConversationIfActive(contactMethod.id).then(() => platform.setConversationEndedBehavior(ConversationEndedBehavior.Navigate));
498
- });
499
- return chatWidget ? false : true;
500
- };
501
- const navigateToConversation = (container, contactMethod, routeName = "conversation") => {
502
- const { mainWidget, chatWidget } = getSeparateWidget(container);
503
- if (chatWidget) {
504
- return chatWidget.container.getAsync("router").then((router) => {
505
- router.navigate(routeName, { id: contactMethod.id });
506
- });
507
- }
508
- return mainWidget.container.getAsync("conversation").then((platform) => {
509
- var _a;
510
- (_a = platform.setConversationEndedBehavior(ConversationEndedBehavior.Navigate)) == null ? void 0 : _a.then(() => {
511
- mainWidget.container.getAsync("router").then((router) => {
512
- mainWidget.container.getAsync("components").then((components) => {
513
- const conversationQuery = components.components().ofType("conversation");
514
- components.write({
310
+ }));
311
+ }).then(() => n.invoke("attach", {
312
+ key: "contact-method",
313
+ triggerDOMElement: e,
314
+ withRenderState: "open"
315
+ })).then(() => (z(n.container, "activeStickyWidget", $.Necessary, {
316
+ medium: m.Local,
317
+ scope: L.Implementation
318
+ }).then((o) => o(n.name)), n.container.getAsync("conversation").then((o) => {
319
+ o.setConversationEndedBehavior(P.Deactivate);
320
+ }).then(() => M(i)).then(() => !1))) : (s.container.getAsync("conversation").then((o) => o.navigateToConversationIfActive(t.id).then(() => o.setConversationEndedBehavior(P.Navigate))), !n);
321
+ }, et = (i, t, e = "conversation") => {
322
+ const { mainWidget: s, chatWidget: r } = I(i);
323
+ return r ? r.container.getAsync("router").then((n) => {
324
+ n.navigate(e, { id: t.id });
325
+ }) : s.container.getAsync("conversation").then((n) => {
326
+ var o;
327
+ (o = n.setConversationEndedBehavior(P.Navigate)) == null || o.then(() => {
328
+ s.container.getAsync("router").then((a) => {
329
+ s.container.getAsync("components").then((c) => {
330
+ const h = c.components().ofType("conversation");
331
+ c.write({
515
332
  key: "setConversationProvider",
516
- attributes: { properties: { providers: [contactMethod.clientName] } },
517
- target: conversationQuery,
333
+ attributes: { properties: { providers: [t.clientName] } },
334
+ target: h,
518
335
  provider: "localStorage"
519
336
  });
520
337
  }).then(() => {
521
- router.navigate(routeName, { id: contactMethod.id });
338
+ a.navigate(e, { id: t.id });
522
339
  });
523
340
  });
524
341
  });
525
342
  });
526
- };
527
- const STORAGE_KEY = "conversations";
528
- var ConversationEndedBehavior = /* @__PURE__ */ ((ConversationEndedBehavior2) => {
529
- ConversationEndedBehavior2["Deactivate"] = "deactivate";
530
- ConversationEndedBehavior2["Navigate"] = "navigate";
531
- ConversationEndedBehavior2["None"] = "none";
532
- return ConversationEndedBehavior2;
533
- })(ConversationEndedBehavior || {});
534
- class ConversationPlatform {
535
- constructor(container, components) {
536
- this.container = container;
537
- this.components = components;
538
- this.controllers = [];
539
- this.providers = [];
540
- this.disposeProviders = {};
541
- this.subscriptions = [];
542
- this.storageWriter = null;
543
- this.router = null;
544
- this.buttonQuery = null;
545
- this.sessionInfo = null;
546
- const widget = container.get("$widget");
547
- this.events = widget.events.createChild(this);
343
+ }, y = "conversations";
344
+ var P = /* @__PURE__ */ ((i) => (i.Deactivate = "deactivate", i.Navigate = "navigate", i.None = "none", i))(P || {});
345
+ class b {
346
+ constructor(t, e) {
347
+ this.container = t, this.components = e, this.controllers = [], this.providers = [], this.disposeProviders = {}, this.subscriptions = [], this.storageWriter = null, this.router = null, this.buttonQuery = null, this.sessionInfo = null;
348
+ const s = t.get("$widget");
349
+ this.events = s.events.createChild(this);
548
350
  }
549
351
  initialize() {
550
- createStorageWriter(this.container, STORAGE_KEY, StorageCategory.Necessary, {
551
- medium: StorageMedium.Local
552
- }).then((writer) => this.storageWriter = writer);
553
- readStorage(this.container, STORAGE_KEY, StorageMedium.Local).then((storedSession) => {
554
- this.buttonQuery = this.components.components().ofType("conversation-return-button");
555
- if (storedSession) {
556
- this.sessionInfo = storedSession;
557
- if (storedSession.id && storedSession.route) {
558
- this.writeToComponents({ active: true, alert: { show: false } });
559
- }
560
- }
561
- });
562
- this.container.getAsync("router").then((router) => this.router = router);
563
- this.events.subscribe("conversation:ended", (event, data) => {
564
- var _a, _b, _c;
565
- switch ((_a = this.sessionInfo) == null ? void 0 : _a.conversationEndedBehavior) {
352
+ z(this.container, y, $.Necessary, {
353
+ medium: m.Local
354
+ }).then((t) => this.storageWriter = t), A(this.container, y, m.Local).then((t) => {
355
+ this.buttonQuery = this.components.components().ofType("conversation-return-button"), t && (this.sessionInfo = t, t.id && t.route && this.writeToComponents({ active: !0, alert: { show: !1 } }));
356
+ }), this.container.getAsync("router").then((t) => this.router = t), this.events.subscribe("conversation:ended", (t, e) => {
357
+ var s, r, n;
358
+ switch ((s = this.sessionInfo) == null ? void 0 : s.conversationEndedBehavior) {
566
359
  case "deactivate":
567
- const widget = this.container.get("$widget");
568
- widget.deactivate();
360
+ this.container.get("$widget").deactivate();
569
361
  break;
570
362
  case "navigate":
571
- const initialRoute = (_b = this.router) == null ? void 0 : _b.getInitialRoute();
572
- if (initialRoute) {
573
- (_c = this.router) == null ? void 0 : _c.navigate(initialRoute.name);
574
- }
363
+ const a = (r = this.router) == null ? void 0 : r.getInitialRoute();
364
+ a && ((n = this.router) == null || n.navigate(a.name));
575
365
  break;
576
366
  }
577
- this.writeToComponents({ active: false });
578
- this.sessionInfo = null;
579
- this.storageWriter && this.storageWriter();
580
- });
581
- }
582
- addSubscription(sub) {
583
- this.subscriptions.push(sub);
584
- }
585
- static getInstance(container, key = "conversation") {
586
- return lock(container)(() => {
587
- return container.getAsync(key).then((value) => {
588
- let conversation = value;
589
- if (!conversation) {
590
- return ComponentPlatform.getInstance(container).then((components) => {
591
- conversation = new ConversationPlatform(container, components);
592
- conversation.initialize();
593
- container.registerAsync(key, () => conversation);
594
- return conversation;
595
- });
596
- }
597
- return conversation;
598
- });
367
+ this.writeToComponents({ active: !1 }), this.sessionInfo = null, this.storageWriter && this.storageWriter();
599
368
  });
600
369
  }
601
- navigateToConversationIfActive(id) {
602
- return readStorage(this.container, STORAGE_KEY, StorageMedium.Local).then((storedSession) => {
603
- var _a;
604
- if (storedSession && storedSession.id === id) {
605
- if (storedSession.route) {
606
- const { name, params } = storedSession.route;
607
- (_a = this.router) == null ? void 0 : _a.navigate(name, params);
608
- }
370
+ addSubscription(t) {
371
+ this.subscriptions.push(t);
372
+ }
373
+ static getInstance(t, e = "conversation") {
374
+ return G(t)(() => t.getAsync(e).then((s) => {
375
+ let r = s;
376
+ return r || H.getInstance(t).then((n) => (r = new b(t, n), r.initialize(), t.registerAsync(e, () => r), r));
377
+ }));
378
+ }
379
+ navigateToConversationIfActive(t) {
380
+ return A(this.container, y, m.Local).then((e) => {
381
+ var s;
382
+ if (e && e.id === t && e.route) {
383
+ const { name: r, params: n } = e.route;
384
+ (s = this.router) == null || s.navigate(r, n);
609
385
  }
610
386
  });
611
387
  }
612
- setConversationEndedBehavior(behavior) {
613
- return readStorage(this.container, STORAGE_KEY, StorageMedium.Local).then((stored) => {
614
- let storedSession = stored;
615
- if (storedSession) {
616
- storedSession.conversationEndedBehavior = behavior;
617
- } else {
618
- storedSession = { conversationEndedBehavior: behavior };
619
- }
620
- this.sessionInfo = storedSession;
621
- return this.storageWriter && this.storageWriter(this.sessionInfo) || Promise.resolve();
388
+ setConversationEndedBehavior(t) {
389
+ return A(this.container, y, m.Local).then((e) => {
390
+ let s = e;
391
+ return s ? s.conversationEndedBehavior = t : s = { conversationEndedBehavior: t }, this.sessionInfo = s, this.storageWriter && this.storageWriter(this.sessionInfo) || Promise.resolve();
622
392
  });
623
393
  }
624
- createController(id) {
625
- const index = this.controllers.findIndex((c) => c.conversation.id === id);
626
- if (index > -1) {
627
- return this.controllers[index].conversation;
628
- }
629
- return new ConversationController(this.container, id);
394
+ createController(t) {
395
+ const e = this.controllers.findIndex((s) => s.conversation.id === t);
396
+ return e > -1 ? this.controllers[e].conversation : new X(this.container, t);
630
397
  }
631
- registerProvider(name, handler) {
632
- const provider = {
633
- name,
634
- handler
398
+ registerProvider(t, e) {
399
+ const s = {
400
+ name: t,
401
+ handler: e
635
402
  };
636
- this.providers.push(provider);
637
- this.controllers.filter((controller) => controller.conversation.providers.indexOf(name) > -1).forEach((controller) => {
638
- this.invokeHandler(provider, controller);
403
+ this.providers.push(s), this.controllers.filter((r) => r.conversation.providers.indexOf(t) > -1).forEach((r) => {
404
+ this.invokeHandler(s, r);
639
405
  });
640
406
  }
641
- registerController(conversation, component) {
642
- const index = this.controllers.findIndex((c) => c.conversation.id === conversation.id);
643
- let controller;
644
- if (index < 0) {
645
- controller = { conversation, component };
646
- this.controllers.push(controller);
647
- const invokeHandlers = (providers) => {
648
- if (providers) {
649
- this.providers.filter((provider) => providers.indexOf(provider.name) > -1).forEach((provider) => {
650
- this.invokeHandler(provider, controller);
651
- });
652
- }
407
+ registerController(t, e) {
408
+ const s = this.controllers.findIndex((n) => n.conversation.id === t.id);
409
+ let r;
410
+ if (s < 0) {
411
+ r = { conversation: t, component: e }, this.controllers.push(r);
412
+ const n = (o) => {
413
+ o && this.providers.filter((a) => o.indexOf(a.name) > -1).forEach((a) => {
414
+ this.invokeHandler(a, r);
415
+ });
653
416
  };
654
- this.subscriptions.push(conversation.onDispose((event, data) => {
655
- const index2 = this.controllers.findIndex((c) => c.conversation === data);
656
- index2 > -1 && this.controllers.splice(index2, 1);
657
- this.components.components().ofType("conversation-return-button").select().writeProperties({ active: false });
658
- this.events.dispatch("conversation:ended", {}, { bubbles: true });
659
- }));
660
- this.subscriptions.push(conversation.onProvidersChange((event, data) => {
661
- const { added, removed } = data;
662
- removed.forEach((removedProvider) => {
663
- this.disposeProviders[removedProvider].forEach((dispose) => {
664
- dispose();
417
+ return this.subscriptions.push(t.onDispose((o, a) => {
418
+ const c = this.controllers.findIndex((h) => h.conversation === a);
419
+ c > -1 && this.controllers.splice(c, 1), this.components.components().ofType("conversation-return-button").select().writeProperties({ active: !1 }), this.events.dispatch("conversation:ended", {}, { bubbles: !0 });
420
+ })), this.subscriptions.push(t.onProvidersChange((o, a) => {
421
+ const { added: c, removed: h } = a;
422
+ h.forEach((d) => {
423
+ this.disposeProviders[d].forEach((f) => {
424
+ f();
665
425
  });
666
- });
667
- invokeHandlers(added);
668
- }));
669
- this.subscriptions.push(conversation.onStarted((event, isActive) => {
670
- var _a, _b;
671
- const session = {
672
- id: conversation.id,
673
- route: (_a = this.router) == null ? void 0 : _a.getRouteData(),
674
- conversationEndedBehavior: (_b = this.sessionInfo) == null ? void 0 : _b.conversationEndedBehavior
426
+ }), n(c);
427
+ })), this.subscriptions.push(t.onStarted((o, a) => {
428
+ var h, d;
429
+ const c = {
430
+ id: t.id,
431
+ route: (h = this.router) == null ? void 0 : h.getRouteData(),
432
+ conversationEndedBehavior: (d = this.sessionInfo) == null ? void 0 : d.conversationEndedBehavior
675
433
  };
676
- this.sessionInfo = session;
677
- this.storageWriter && this.storageWriter(session);
678
- this.writeToComponents({ active: isActive });
679
- }));
680
- this.subscriptions.push(conversation.onUnreadMessage((event, data) => {
681
- this.events.dispatch("conversation:unread-message", data);
682
- this.writeToComponents({ alert: { show: data } });
683
- }));
684
- invokeHandlers(conversation.providers);
685
- return true;
686
- }
687
- controller = this.controllers[index];
688
- return false;
689
- }
690
- writeToComponents(properties, key = "conversationReturnButtonState") {
691
- if (this.buttonQuery) {
692
- this.components.write({
693
- key: "conversationReturnButtonState",
694
- attributes: { properties },
695
- target: this.buttonQuery,
696
- provider: "localStorage"
697
- });
434
+ this.sessionInfo = c, this.storageWriter && this.storageWriter(c), this.writeToComponents({ active: a });
435
+ })), this.subscriptions.push(t.onUnreadMessage((o, a) => {
436
+ this.events.dispatch("conversation:unread-message", a), this.writeToComponents({ alert: { show: a } });
437
+ })), n(t.providers), !0;
698
438
  }
439
+ return r = this.controllers[s], !1;
440
+ }
441
+ writeToComponents(t, e = "conversationReturnButtonState") {
442
+ this.buttonQuery && this.components.write({
443
+ key: "conversationReturnButtonState",
444
+ attributes: { properties: t },
445
+ target: this.buttonQuery,
446
+ provider: "localStorage"
447
+ });
699
448
  }
700
- invokeHandler(provider, controller) {
701
- const dispose = provider.handler(controller.conversation.createProvider(provider.name), controller.component);
702
- if (dispose) {
703
- if (!this.disposeProviders[provider.name]) {
704
- this.disposeProviders[provider.name] = [];
705
- }
706
- this.disposeProviders[provider.name].push(dispose);
707
- }
449
+ invokeHandler(t, e) {
450
+ const s = t.handler(e.conversation.createProvider(t.name), e.component);
451
+ s && (this.disposeProviders[t.name] || (this.disposeProviders[t.name] = []), this.disposeProviders[t.name].push(s));
708
452
  }
709
453
  getComponentRoute() {
710
- return readStorage(this.container, STORAGE_KEY, StorageMedium.Local).then((stored) => stored == null ? void 0 : stored.route);
454
+ return A(this.container, y, m.Local).then((t) => t == null ? void 0 : t.route);
711
455
  }
712
456
  dispose() {
713
- Object.keys(this.disposeProviders).forEach((key) => {
714
- this.disposeProviders[key].forEach((dispose) => {
715
- dispose();
457
+ Object.keys(this.disposeProviders).forEach((t) => {
458
+ this.disposeProviders[t].forEach((e) => {
459
+ e();
716
460
  });
717
- });
718
- this.subscriptions.forEach((unsubscribe) => {
719
- unsubscribe();
720
- });
721
- this.controllers = [];
722
- this.providers = [];
723
- }
724
- static handleContactMethodClick(event, container, contactMethod, callback) {
725
- return __async(this, null, function* () {
726
- if (shouldPreventDefault(container)) {
727
- event.preventDefault();
728
- let triggerEl = document.getElementById("humany-dynamic-anchor");
729
- if (!triggerEl) {
730
- triggerEl = document.createElement("a");
731
- triggerEl.setAttribute("href", "#");
732
- triggerEl.id = "humany-dynamic-anchor";
733
- document.body.appendChild(triggerEl);
734
- }
735
- openChatWidget(container, contactMethod, triggerEl);
461
+ }), this.subscriptions.forEach((t) => {
462
+ t();
463
+ }), this.controllers = [], this.providers = [];
464
+ }
465
+ static handleContactMethodClick(t, e, s, r) {
466
+ return S(this, null, function* () {
467
+ if (tt(e)) {
468
+ t.preventDefault();
469
+ let n = document.getElementById("humany-dynamic-anchor");
470
+ n || (n = document.createElement("a"), n.setAttribute("href", "#"), n.id = "humany-dynamic-anchor", document.body.appendChild(n)), B(e, s, n);
736
471
  }
737
- openChatWidget(container, contactMethod);
472
+ B(e, s);
738
473
  });
739
474
  }
740
- static handleContactMethodSubmit(container, contactMethod) {
741
- return __async(this, null, function* () {
742
- return navigateToConversation(container, contactMethod);
475
+ static handleContactMethodSubmit(t, e) {
476
+ return S(this, null, function* () {
477
+ return et(t, e);
743
478
  });
744
479
  }
745
480
  }
746
- const groupedMessages = (messages, timeout) => {
747
- return messages.reduce((acc, current, index) => {
748
- var _a, _b;
749
- const newItem = __spreadProps(__spreadValues({}, current), {
750
- content: [__spreadProps(__spreadValues({}, current.content), { key: current.key })]
751
- });
752
- if (acc.length > 0 && current.type !== ConversationMessageType.System) {
753
- const previous = acc[acc.length - 1];
754
- if (!timeout && timeout !== 0 || Math.abs(previous.timestamp - current.timestamp) < timeout) {
755
- if (((_a = previous.sender) == null ? void 0 : _a.name) === ((_b = current.sender) == null ? void 0 : _b.name) && previous.type === current.type) {
756
- previous.timestamp = current.timestamp;
757
- previous.content.push(__spreadProps(__spreadValues({}, current.content), { key: current.key }));
758
- return acc;
759
- }
760
- }
481
+ var st = /* @__PURE__ */ ((i) => (i.Header = "header", i.LinkList = "link-list", i.Separator = "separator", i.NoGoodAlternative = "no-good-alternative", i.ButtonList = "button-list", i.Text = "text", i.HTML = "html", i.FeedbackList = "feedback-list", i))(st || {});
482
+ const it = (i, t) => i.reduce((e, s, r) => {
483
+ var o, a;
484
+ const n = g(p({}, s), {
485
+ content: [g(p({}, s.content), { key: s.key })]
486
+ });
487
+ if (e.length > 0 && s.type !== E.System) {
488
+ const c = e[e.length - 1];
489
+ if ((!t && t !== 0 || Math.abs(c.timestamp - s.timestamp) < t) && ((o = c.sender) == null ? void 0 : o.name) === ((a = s.sender) == null ? void 0 : a.name) && c.type === s.type)
490
+ return c.timestamp = s.timestamp, c.content.push(g(p({}, s.content), { key: s.key })), e;
491
+ }
492
+ return e.push(n), e;
493
+ }, []), lt = (i) => Promise.all([
494
+ b.getInstance(i),
495
+ i.getAsync("router")
496
+ ]).then(([t, e]) => Q(i, "conversation", import("./conversation.3981560b.js"), (s) => {
497
+ const n = e.getRouteData().params.id || s.node.name || "component", o = t.createController(n), a = t.registerController(o, s), c = 3 * 60 * 1e3, h = (l) => {
498
+ const { providers: u = [] } = l;
499
+ if (u) {
500
+ const v = Array.isArray(u) ? u : [u];
501
+ return o.setProviders(v), v;
761
502
  }
762
- acc.push(newItem);
763
- return acc;
764
- }, []);
765
- };
766
- const ConversationComponent = (container) => {
767
- return Promise.all([
768
- ConversationPlatform.getInstance(container),
769
- container.getAsync("router")
770
- ]).then(([platform, router]) => {
771
- return createReactComponent(container, "conversation", import("./conversation.js"), (component) => {
772
- const routeData = router.getRouteData();
773
- const name = routeData.params.id || component.node.name || "component";
774
- const conversation = platform.createController(name);
775
- const isNewController = platform.registerController(conversation, component);
776
- const messageGroupingTimeout = 3 * 60 * 1e3;
777
- const setProperties = (properties) => {
778
- const { providers = [] } = properties;
779
- if (providers) {
780
- const providerKeys = Array.isArray(providers) ? providers : [providers];
781
- conversation.setProviders(providerKeys);
782
- return providerKeys;
783
- }
784
- };
785
- setProperties(component.properties(setProperties));
786
- conversation.setComponentMountedState(true);
787
- const writeMessages = (messageStream) => {
788
- const { loading, typingActors, messages } = messageStream;
789
- component.writeProperties({
790
- loading,
791
- typingActors,
792
- messages: groupedMessages(messages, messageGroupingTimeout)
793
- });
794
- };
795
- writeMessages(conversation.getMessageStream());
796
- if (isNewController) {
797
- component.actions.create("user-submit", (data, options) => {
798
- if (options) {
799
- const { preventDefault, validationPromise } = options;
800
- if (preventDefault) {
801
- if (validationPromise) {
802
- validationPromise().then((text) => {
803
- if (text) {
804
- conversation.user.print(text);
805
- }
806
- });
807
- }
808
- return;
809
- }
810
- }
811
- conversation.user.print(data.text);
812
- });
813
- component.actions.create("user-typing", (data, options) => {
814
- });
815
- component.actions.create("form", (data, options) => {
816
- });
817
- component.actions.create("action", (data, options) => {
818
- });
819
- component.actions.create("overlay-mounted", (data, options) => {
820
- });
821
- component.actions.create("show-overlay", (data, options) => {
822
- component.writeProperties({
823
- overlay: { conversation: false, secondary: false }
824
- });
825
- });
826
- component.actions.create("hide-overlay", (data, options) => {
827
- component.writeProperties({
828
- overlay: null
829
- });
830
- });
831
- component.actions.create("show-overlay-conversation", (data, options) => {
832
- component.writeProperties({
833
- overlay: { conversation: true, secondary: false }
834
- });
835
- });
836
- component.actions.create("hide-overlay-conversation", (data, options) => {
837
- component.writeProperties({
838
- overlay: { conversation: false, secondary: false }
839
- });
503
+ };
504
+ h(s.properties(h)), o.setComponentMountedState(!0);
505
+ const d = (l) => {
506
+ const { loading: u, typingActors: v, messages: w } = l;
507
+ s.writeProperties({
508
+ loading: u,
509
+ typingActors: v,
510
+ messages: it(w, c)
511
+ });
512
+ };
513
+ d(o.getMessageStream()), a && (s.actions.create("user-submit", (l, u) => {
514
+ if (u) {
515
+ const { preventDefault: v, validationPromise: w } = u;
516
+ if (v) {
517
+ w && w().then((W) => {
518
+ W && o.user.print(W);
840
519
  });
520
+ return;
841
521
  }
842
- const unsubscribe = conversation.events.subscribe("conversation:updated", (e, conversationData) => {
843
- writeMessages(conversationData);
844
- });
845
- return () => {
846
- conversation.setComponentMountedState(false);
847
- unsubscribe();
848
- if (!conversation.active) {
849
- writeMessages({ messages: [], typingActors: [], loading: false });
850
- }
851
- };
852
- }, { reuseController: true });
522
+ }
523
+ o.user.print(l.text);
524
+ }), s.actions.create("user-typing", (l, u) => {
525
+ }), s.actions.create("form", (l, u) => {
526
+ }), s.actions.create("action", (l, u) => {
527
+ }));
528
+ const f = o.events.subscribe("conversation:updated", (l, u) => {
529
+ d(u);
853
530
  });
854
- };
855
- const ConversationReturnButtonComponent = (container) => {
856
- return Promise.all([
857
- ComponentPlatform.getInstance(container),
858
- ConversationPlatform.getInstance(container),
859
- container.getAsync("router")
860
- ]).then(([components, platform, router]) => {
861
- return createReactComponent(container, "conversation-return-button", import("./return-button.js"), (component) => {
862
- component.actions.create("toggle", (options = {}) => {
863
- var _a;
864
- (_a = platform.getComponentRoute()) == null ? void 0 : _a.then((route) => {
865
- route && router.navigate(route.name, route.params);
866
- });
867
- });
531
+ return () => {
532
+ o.setComponentMountedState(!1), f(), o.active || d({ messages: [], typingActors: [], loading: !1 });
533
+ };
534
+ }, { reuseController: !0 })), pt = (i) => Promise.all([
535
+ H.getInstance(i),
536
+ b.getInstance(i),
537
+ i.getAsync("router")
538
+ ]).then(([t, e, s]) => Q(i, "conversation-return-button", import("./return-button.8773c0de.js"), (r) => {
539
+ r.actions.create("toggle", (n = {}) => {
540
+ var o;
541
+ (o = e.getComponentRoute()) == null || o.then((a) => {
542
+ a && s.navigate(a.name, a.params);
868
543
  });
869
544
  });
545
+ })), vt = (i, t, e) => i.getAsync("componentResolver").then((s) => S(void 0, null, function* () {
546
+ (yield b.getInstance(i)).addSubscription(s.registerComponent(t, K(() => e)));
547
+ }));
548
+ export {
549
+ lt as ConversationComponent,
550
+ X as ConversationController,
551
+ P as ConversationEndedBehavior,
552
+ q as ConversationEntry,
553
+ st as ConversationMessageListItemType,
554
+ E as ConversationMessageType,
555
+ b as ConversationPlatform,
556
+ pt as ConversationReturnButtonComponent,
557
+ vt as registerCustomMessageComponent
870
558
  };
871
- var ConversationMessageListItemType = /* @__PURE__ */ ((ConversationMessageListItemType2) => {
872
- ConversationMessageListItemType2["LinkList"] = "link-list";
873
- ConversationMessageListItemType2["Separator"] = "separator";
874
- ConversationMessageListItemType2["ButtonList"] = "button-list";
875
- ConversationMessageListItemType2["Text"] = "text";
876
- ConversationMessageListItemType2["HTML"] = "html";
877
- ConversationMessageListItemType2["VideoRequest"] = "video-request";
878
- return ConversationMessageListItemType2;
879
- })(ConversationMessageListItemType || {});
880
- const registerCustomMessageComponent = (container, type, component) => {
881
- return container.getAsync("componentResolver").then((o) => __async(this, null, function* () {
882
- const platform = yield ConversationPlatform.getInstance(container);
883
- platform.addSubscription(o.registerComponent(type, lazy(() => component)));
884
- }));
885
- };
886
- export { ConversationComponent, ConversationController, ConversationEndedBehavior, ConversationEntry, ConversationMessageListItemType, ConversationMessageType, ConversationPlatform, ConversationReturnButtonComponent, registerCustomMessageComponent };
887
559
  //# sourceMappingURL=index.js.map