@telia-ace/widget-conversation 1.0.23 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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;
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
- });
1
+ var U = Object.defineProperty, L = Object.defineProperties;
2
+ var _ = Object.getOwnPropertyDescriptors;
3
+ var C = Object.getOwnPropertySymbols;
4
+ var N = Object.prototype.hasOwnProperty, M = Object.prototype.propertyIsEnumerable;
5
+ var T = (r, t, e) => t in r ? U(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, p = (r, t) => {
6
+ for (var e in t || (t = {}))
7
+ N.call(t, e) && T(r, e, t[e]);
8
+ if (C)
9
+ for (var e of C(t))
10
+ M.call(t, e) && T(r, e, t[e]);
11
+ return r;
12
+ }, g = (r, t) => L(r, _(t));
13
+ var R = (r, t) => {
14
+ var e = {};
15
+ for (var s in r)
16
+ N.call(r, s) && t.indexOf(s) < 0 && (e[s] = r[s]);
17
+ if (r != null && C)
18
+ for (var s of C(r))
19
+ t.indexOf(s) < 0 && M.call(r, s) && (e[s] = r[s]);
20
+ return e;
51
21
  };
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;
22
+ var P = (r, t, e) => new Promise((s, n) => {
23
+ var i = (c) => {
24
+ try {
25
+ a(e.next(c));
26
+ } catch (h) {
27
+ n(h);
79
28
  }
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
+ n(h);
84
34
  }
35
+ }, a = (c) => c.done ? s(c.value) : Promise.resolve(c.value).then(i, o);
36
+ a((e = e.apply(r, t)).next());
37
+ });
38
+ import { ComponentPlatform as z } from "@telia-ace/widget-core";
39
+ import { createStorageWriter as H, StorageCategory as $, StorageMedium as m, StorageScope as F, readStorage as A } from "@telia-ace/widget-services";
40
+ import { uuid as j, lock as q } from "@telia-ace/widget-utilities";
41
+ import { FormBuilder as G } from "@telia-ace/widget-forms";
42
+ import { closeAllModals as D } from "@telia-ace/widget-plugins";
43
+ import { createReactComponent as Q } from "@telia-ace/widget-ui";
44
+ import { lazy as J } from "react";
45
+ class K {
46
+ constructor(t, e) {
47
+ this.provider = t, this.print = (s) => {
48
+ const n = { name: this.name, avatar: this.avatar }, i = x(s);
49
+ return this.provider.createEntry(i.key, i.content, E.Agent, n, i.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);
102
63
  }
103
- print(settings) {
104
- var _a;
105
- return (_a = this.controller) == null ? void 0 : _a.print(settings);
64
+ createAgent(t = {}) {
65
+ if (this.controller)
66
+ return new K(this, t);
106
67
  }
107
- setTypingState(sender, type) {
108
- var _a;
109
- return (_a = this.controller) == null ? void 0 : _a.setTypingState(sender, type);
68
+ print(t) {
69
+ var e;
70
+ return (e = this.controller) == null ? void 0 : e.print(t);
71
+ }
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, n, i) {
81
+ var o;
82
+ return (o = this.controller) == null ? void 0 : o.createEntry(t, e, s, n, i);
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 V {
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 Y {
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__ */ ((r) => (r.User = "user", r.Agent = "agent", r.System = "system", r))(E || {});
131
+ const x = (r) => {
132
+ let t, e = j(), s = Date.now();
133
+ if (Array.isArray(r) && r.length > -1)
134
+ typeof r[0] == "string" ? t = { items: [r] } : t = { items: r };
135
+ else if (typeof r == "string")
136
+ t = { body: r };
137
+ else if (r = r || {}, r.type)
138
+ t = p({}, r);
139
+ else {
140
+ if (t = {
141
+ body: r.body,
142
+ actions: r.actions,
143
+ title: r.title
144
+ }, r.key && (e = r.key), r.timestamp && (s = r.timestamp), r.form) {
145
+ const n = G.create(e);
146
+ r.form(n);
147
+ const i = n.get();
148
+ t.form = i;
222
149
  }
150
+ r.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 = (r, 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 = r.findIndex((n) => e === JSON.stringify(n));
157
+ if (s > -1)
158
+ return r.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 V(this), this.providers = [], this.active = !1, this.registeredProviders = [], this.loaders = 0, this.componentMounted = !1, this.messages = [], this.typingActors = [], this.print = (n) => {
163
+ const i = x(n);
164
+ return this.createEntry(i.key, i.content, "system", void 0, i.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((n, i) => (t.indexOf(i) === -1 && n.push(i), n), []).forEach((n) => {
172
+ const i = this.providers.indexOf(n);
173
+ i > -1 && (e.push(n), this.providers.splice(i, 1));
174
+ }), t.forEach((n) => {
175
+ this.providers.indexOf(n) === -1 && (s.push(n), this.providers.push(n));
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, n, i) {
214
+ const o = {
215
+ key: t,
216
+ content: e,
217
+ type: s,
218
+ sender: n || null,
219
+ timestamp: i || i === null ? i : 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, n);
222
+ const a = new Y((c) => {
223
+ if (c !== null) {
224
+ const h = c, { timestamp: u = void 0 } = h, f = R(h, ["timestamp"]);
225
+ o.content = f, u && (o.timestamp = u);
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 u = this.messages.indexOf(o);
228
+ o.content = null, u > -1 && this.messages.splice(u, 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,333 @@ 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 = (r, t) => {
268
+ const e = r.split("_contact");
269
+ return t.widgets.get(e[0]);
270
+ }, I = (r) => {
271
+ const t = r.get("$widget"), { name: e, implementation: s } = r.get("$widget"), n = e.indexOf("_contact") > -1 ? Z(e, s) : t, { data: i } = r.get("$settings"), { trigger: o } = n.container.get("$settings"), a = `${e.replace("_contact-method", "").replace("_contact", "")}_contact-method`, c = s.widgets.get(a);
272
+ return c && !o ? { chatWidget: c, mainWidget: n, data: i } : { mainWidget: n, data: i };
273
+ }, tt = (r) => {
274
+ const { chatWidget: t } = I(r);
275
+ return !!t;
276
+ }, B = (r, t, e) => {
277
+ const { mainWidget: s, data: n, chatWidget: i } = I(r);
278
+ return i ? i.state === "activated" ? i.invoke("open").then(() => {
279
+ i.container.getAsync("conversation").then((o) => {
280
+ o.navigateToConversationIfActive(t.id).then(() => D(r));
281
+ });
282
+ }) : i.activate().then(() => {
283
+ const { trigger: o } = i.container.get("$settings");
284
+ return o.action = "hide", i.invoke("setSettings", () => ({
285
+ data: n,
286
+ trigger: o,
287
+ activate: !0
288
+ })).then(() => i.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(() => i.invoke("attach", {
312
+ key: "contact-method",
313
+ triggerDOMElement: e,
314
+ withRenderState: "open"
315
+ })).then(() => (H(i.container, "activeStickyWidget", $.Necessary, {
316
+ medium: m.Local,
317
+ scope: F.Implementation
318
+ }).then((o) => o(i.name)), i.container.getAsync("conversation").then((o) => {
319
+ o.setConversationEndedBehavior(S.Deactivate);
320
+ }).then(() => D(r)).then(() => !1))) : (s.container.getAsync("conversation").then((o) => o.navigateToConversationIfActive(t.id).then(() => o.setConversationEndedBehavior(S.Navigate))), !i);
321
+ }, et = (r, t, e = "conversation") => {
322
+ const { mainWidget: s, chatWidget: n } = I(r);
323
+ return n ? n.container.getAsync("router").then((i) => {
324
+ i.navigate(e, { id: t.id });
325
+ }) : s.container.getAsync("conversation").then((i) => {
326
+ var o;
327
+ (o = i.setConversationEndedBehavior(S.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 S = /* @__PURE__ */ ((r) => (r.Deactivate = "deactivate", r.Navigate = "navigate", r.None = "none", r))(S || {});
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
+ H(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, n, i;
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 = (n = this.router) == null ? void 0 : n.getInitialRoute();
364
+ a && ((i = this.router) == null || i.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 q(t)(() => t.getAsync(e).then((s) => {
375
+ let n = s;
376
+ return n || z.getInstance(t).then((i) => (n = new b(t, i), n.initialize(), t.registerAsync(e, () => n), n));
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: n, params: i } = e.route;
384
+ (s = this.router) == null || s.navigate(n, i);
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((n) => n.conversation.providers.indexOf(t) > -1).forEach((n) => {
404
+ this.invokeHandler(s, n);
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((i) => i.conversation.id === t.id);
409
+ let n;
410
+ if (s < 0) {
411
+ n = { conversation: t, component: e }, this.controllers.push(n);
412
+ const i = (o) => {
413
+ o && this.providers.filter((a) => o.indexOf(a.name) > -1).forEach((a) => {
414
+ this.invokeHandler(a, n);
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((u) => {
423
+ this.disposeProviders[u].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
+ }), i(c);
427
+ })), this.subscriptions.push(t.onStarted((o, a) => {
428
+ var h, u;
429
+ const c = {
430
+ id: t.id,
431
+ route: (h = this.router) == null ? void 0 : h.getRouteData(),
432
+ conversationEndedBehavior: (u = this.sessionInfo) == null ? void 0 : u.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
+ })), i(t.providers), !0;
698
438
  }
439
+ return n = 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, n) {
466
+ return P(this, null, function* () {
467
+ if (tt(e)) {
468
+ t.preventDefault();
469
+ let i = document.getElementById("humany-dynamic-anchor");
470
+ i || (i = document.createElement("a"), i.setAttribute("href", "#"), i.id = "humany-dynamic-anchor", document.body.appendChild(i)), B(e, s, i);
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 P(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
+ const st = (r, t) => r.reduce((e, s, n) => {
482
+ var o, a;
483
+ const i = g(p({}, s), {
484
+ content: [g(p({}, s.content), { key: s.key })]
485
+ });
486
+ if (e.length > 0 && s.type !== E.System) {
487
+ const c = e[e.length - 1];
488
+ 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)
489
+ return c.timestamp = s.timestamp, c.content.push(g(p({}, s.content), { key: s.key })), e;
490
+ }
491
+ return e.push(i), e;
492
+ }, []), lt = (r) => Promise.all([
493
+ b.getInstance(r),
494
+ r.getAsync("router")
495
+ ]).then(([t, e]) => Q(r, "conversation", import("./conversation.edf14596.js"), (s) => {
496
+ const i = e.getRouteData().params.id || s.node.name || "component", o = t.createController(i), a = t.registerController(o, s), c = 3 * 60 * 1e3, h = (l) => {
497
+ const { providers: d = [] } = l;
498
+ if (d) {
499
+ const v = Array.isArray(d) ? d : [d];
500
+ return o.setProviders(v), v;
761
501
  }
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
- });
502
+ };
503
+ h(s.properties(h)), o.setComponentMountedState(!0);
504
+ const u = (l) => {
505
+ const { loading: d, typingActors: v, messages: w } = l;
506
+ s.writeProperties({
507
+ loading: d,
508
+ typingActors: v,
509
+ messages: st(w, c)
510
+ });
511
+ };
512
+ u(o.getMessageStream()), a && (s.actions.create("user-submit", (l, d) => {
513
+ if (d) {
514
+ const { preventDefault: v, validationPromise: w } = d;
515
+ if (v) {
516
+ w && w().then((W) => {
517
+ W && o.user.print(W);
840
518
  });
519
+ return;
841
520
  }
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 });
521
+ }
522
+ o.user.print(l.text);
523
+ }), s.actions.create("user-typing", (l, d) => {
524
+ }), s.actions.create("form", (l, d) => {
525
+ }), s.actions.create("action", (l, d) => {
526
+ }), s.actions.create("overlay-mounted", (l, d) => {
527
+ }), s.actions.create("show-overlay", (l, d) => {
528
+ s.writeProperties({
529
+ overlay: { conversation: !1, secondary: !1 }
530
+ });
531
+ }), s.actions.create("hide-overlay", (l, d) => {
532
+ s.writeProperties({
533
+ overlay: null
534
+ });
535
+ }), s.actions.create("show-overlay-conversation", (l, d) => {
536
+ s.writeProperties({
537
+ overlay: { conversation: !0, secondary: !1 }
538
+ });
539
+ }), s.actions.create("hide-overlay-conversation", (l, d) => {
540
+ s.writeProperties({
541
+ overlay: { conversation: !1, secondary: !1 }
542
+ });
543
+ }));
544
+ const f = o.events.subscribe("conversation:updated", (l, d) => {
545
+ u(d);
853
546
  });
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
- });
547
+ return () => {
548
+ o.setComponentMountedState(!1), f(), o.active || u({ messages: [], typingActors: [], loading: !1 });
549
+ };
550
+ }, { reuseController: !0 })), pt = (r) => Promise.all([
551
+ z.getInstance(r),
552
+ b.getInstance(r),
553
+ r.getAsync("router")
554
+ ]).then(([t, e, s]) => Q(r, "conversation-return-button", import("./return-button.facf6a45.js"), (n) => {
555
+ n.actions.create("toggle", (i = {}) => {
556
+ var o;
557
+ (o = e.getComponentRoute()) == null || o.then((a) => {
558
+ a && s.navigate(a.name, a.params);
868
559
  });
869
560
  });
561
+ }));
562
+ var rt = /* @__PURE__ */ ((r) => (r.LinkList = "link-list", r.Separator = "separator", r.ButtonList = "button-list", r.Text = "text", r.HTML = "html", r.VideoRequest = "video-request", r))(rt || {});
563
+ const vt = (r, t, e) => r.getAsync("componentResolver").then((s) => P(void 0, null, function* () {
564
+ (yield b.getInstance(r)).addSubscription(s.registerComponent(t, J(() => e)));
565
+ }));
566
+ export {
567
+ lt as ConversationComponent,
568
+ X as ConversationController,
569
+ S as ConversationEndedBehavior,
570
+ Y as ConversationEntry,
571
+ rt as ConversationMessageListItemType,
572
+ E as ConversationMessageType,
573
+ b as ConversationPlatform,
574
+ pt as ConversationReturnButtonComponent,
575
+ vt as registerCustomMessageComponent
870
576
  };
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
577
  //# sourceMappingURL=index.js.map