@telia-ace/widget-conversation 1.3.0-rc.9 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,6 +35,7 @@ export type ConversationComponentProperties = {
35
35
  typingActors: any[];
36
36
  conversationControllerId?: string;
37
37
  sendButtonLabel: string;
38
+ avatarLabel?: string;
38
39
  secondaryAction?: {
39
40
  icon?: string;
40
41
  action: string;
@@ -1,36 +1,36 @@
1
1
  import { jsx as n, jsxs as h, Fragment as N } from "react/jsx-runtime";
2
2
  import i from "@emotion/styled";
3
- import { Input as se, borderTabStyle as b, Button as I, SymbolBadge as k, useIsTabbing as ae, useDispatch as G, useProperties as S, useScroll as ie, useContainer as A, Typography as J, invertedHoverButton as xe, Html as Q, List as le, buttonCss as B, ItemList as K, itemList as D, Link as ke, useComponent as we, genericHtml as Se, headingElement as Z, usePrevious as Ce, list as ze, WidgetOverlayOutlet as ce, ConversationContext as Le } from "@telia-ace/widget-ui";
3
+ import { Input as se, borderTabStyle as b, Button as A, SymbolBadge as k, useIsTabbing as ae, useDispatch as G, useProperties as S, useScroll as ie, useContainer as I, Typography as J, invertedHoverButton as xe, Html as Q, List as le, buttonCss as B, ItemList as K, itemList as D, Link as ke, useComponent as we, genericHtml as Se, headingElement as Z, usePrevious as Ce, list as Le, WidgetOverlayOutlet as ce, ConversationContext as ze } from "@telia-ace/widget-ui";
4
4
  import { appendClassNames as H, htmlParentContains as Ne } from "@telia-ace/widget-utilities";
5
5
  import { css as x, keyframes as Me } from "@emotion/react";
6
- import de, { useState as q, useEffect as j, forwardRef as ee, useContext as Ie, Suspense as Ae, useRef as me, useMemo as He, useCallback as ue } from "react";
6
+ import de, { useState as q, useEffect as j, forwardRef as ee, useContext as Ae, Suspense as Ie, useRef as me, useMemo as He, useCallback as ue } from "react";
7
7
  import { FormComponent as Te } from "@telia-ace/widget-forms";
8
8
  import { ConversationMessageListItemType as w, ConversationMessageType as U } from "./index.mjs";
9
9
  import "@telia-ace/widget-core";
10
10
  import "@telia-ace/widget-services";
11
11
  import "@telia-ace/widget-plugins";
12
12
  const Oe = ({ className: t }) => {
13
- const [e, r] = q(""), [s, a] = q(0), [o, d] = q(0), u = ae(), l = G(), {
13
+ const [e, o] = q(""), [s, a] = q(0), [r, d] = q(0), u = ae(), l = G(), {
14
14
  inputPlaceholder: m = "Type your message",
15
15
  inputHidden: y = !1,
16
16
  inputDisabled: c = !1,
17
17
  sendButtonLabel: g = "Send message",
18
18
  inputMultiline: p = !0,
19
19
  secondaryAction: $
20
- } = S(), [z, v] = ie(!0), O = A();
20
+ } = S(), [L, v] = ie(!0), O = I();
21
21
  j(() => {
22
22
  if (v.current) {
23
- const { lineHeight: f, maxHeight: L } = getComputedStyle(v.current);
23
+ const { lineHeight: f, maxHeight: z } = getComputedStyle(v.current);
24
24
  if (f && f.indexOf("px") > -1) {
25
25
  const T = f.split("px"), $e = parseInt(T[0], 10);
26
26
  a($e);
27
- const ve = L.split("px");
27
+ const ve = z.split("px");
28
28
  d(parseInt(ve[0], 10));
29
29
  }
30
30
  }
31
31
  }, [v.current]);
32
32
  const P = (f) => {
33
- !f.shiftKey || !p ? (f.preventDefault(), e && e.length > 0 && (l("user-submit", { text: e }), r(""), W(""))) : e.length < 1 && f.preventDefault();
33
+ !f.shiftKey || !p ? (f.preventDefault(), e && e.length > 0 && (l("user-submit", { text: e }), o(""), W(""))) : e.length < 1 && f.preventDefault();
34
34
  }, pe = (f) => {
35
35
  if (!$)
36
36
  return;
@@ -38,26 +38,26 @@ const Oe = ({ className: t }) => {
38
38
  actionKey: $.action,
39
39
  ...$
40
40
  });
41
- const { events: L } = O.get("$widget");
42
- L.dispatch("tracking:secondary-clicked", {});
41
+ const { events: z } = O.get("$widget");
42
+ z.dispatch("tracking:secondary-clicked", {});
43
43
  }, be = (f) => {
44
44
  if (p && v.current) {
45
- const L = v.current.scrollHeight;
46
- if (L > s) {
45
+ const z = v.current.scrollHeight;
46
+ if (z > s) {
47
47
  v.current.style.height = "auto";
48
- let T = L;
49
- f.length < 1 && (T = s), v.current.style.height = `${T}px`, T >= o ? v.current.style.overflowY = "scroll" : v.current.style.overflowY = "hidden";
48
+ let T = z;
49
+ f.length < 1 && (T = s), v.current.style.height = `${T}px`, T >= r ? v.current.style.overflowY = "scroll" : v.current.style.overflowY = "hidden";
50
50
  }
51
51
  }
52
52
  }, W = (f) => {
53
- be(f), r(f), f && f.length > 0 && l("user-typing", { textLength: f.length });
53
+ be(f), o(f), f && f.length > 0 && l("user-typing", { textLength: f.length });
54
54
  };
55
55
  return y ? null : /* @__PURE__ */ h(
56
56
  Ke,
57
57
  {
58
58
  grow: p,
59
59
  className: H("humany-conversation-input", t),
60
- scrollableCss: z,
60
+ scrollableCss: L,
61
61
  isTabbing: u,
62
62
  children: [
63
63
  $ && /* @__PURE__ */ n(
@@ -172,7 +172,7 @@ const Oe = ({ className: t }) => {
172
172
  }};
173
173
  font-style: italic;
174
174
  }
175
- `, he = i(I)`
175
+ `, he = i(A)`
176
176
  flex: 0 0 50px;
177
177
  align-self: stretch;
178
178
  background-color: transparent;
@@ -343,13 +343,13 @@ const Oe = ({ className: t }) => {
343
343
  ${(t) => t.fullWidth && "width: 100%;"}
344
344
  `, Ue = (t, e) => {
345
345
  var s, a;
346
- const r = x`
346
+ const o = x`
347
347
  background-color: ${(s = e.colors) == null ? void 0 : s.accent};
348
348
  color: ${(a = e.colors) == null ? void 0 : a.text};
349
349
  ${e.border && `border: ${e.border};`};
350
350
  `;
351
351
  return e.borderRadius ? x`
352
- ${r}
352
+ ${o}
353
353
 
354
354
  border-top-right-radius: ${e.borderRadius};
355
355
  border-bottom-right-radius: ${e.borderRadius};
@@ -361,15 +361,15 @@ const Oe = ({ className: t }) => {
361
361
  ${t === "last" && `
362
362
  border-bottom-left-radius: ${e.borderRadius};
363
363
  `}
364
- ` : r;
364
+ ` : o;
365
365
  }, Ve = (t, e) => {
366
366
  var s, a;
367
- const r = x`
367
+ const o = x`
368
368
  background-color: ${(s = e.colors) == null ? void 0 : s.primary};
369
369
  color: ${(a = e.colors) == null ? void 0 : a.accent};
370
370
  `;
371
371
  return e.borderRadius ? x`
372
- ${r}
372
+ ${o}
373
373
 
374
374
  border-top-left-radius: ${e.borderRadius};
375
375
  border-bottom-left-radius: ${e.borderRadius};
@@ -381,7 +381,7 @@ const Oe = ({ className: t }) => {
381
381
  ${t === "last" && `
382
382
  border-bottom-right-radius: ${e.borderRadius};
383
383
  `}
384
- ` : r;
384
+ ` : o;
385
385
  }, E = i.div`
386
386
  margin-bottom: ${(t) => {
387
387
  var e;
@@ -391,16 +391,16 @@ const Oe = ({ className: t }) => {
391
391
  margin-bottom: 0;
392
392
  }
393
393
  `, C = (t) => {
394
- var e, r;
394
+ var e, o;
395
395
  return x`
396
396
  margin: ${(e = t.theme.sizes) == null ? void 0 : e.medium} 0;
397
- padding: 0 ${(r = t.theme.sizes) == null ? void 0 : r.medium};
397
+ padding: 0 ${(o = t.theme.sizes) == null ? void 0 : o.medium};
398
398
  `;
399
399
  }, _e = i(Te)`
400
400
  & button.humany-form-component-button {
401
401
  ${(t) => {
402
- var e, r, s, a;
403
- return ((e = t.theme.colors) == null ? void 0 : e.primary) && ((r = t.theme.colors) == null ? void 0 : r.accent) && xe({
402
+ var e, o, s, a;
403
+ return ((e = t.theme.colors) == null ? void 0 : e.primary) && ((o = t.theme.colors) == null ? void 0 : o.accent) && xe({
404
404
  active: !1,
405
405
  primaryColor: (s = t.theme.colors) == null ? void 0 : s.primary,
406
406
  secondaryColor: (a = t.theme.colors) == null ? void 0 : a.accent,
@@ -462,7 +462,7 @@ const Oe = ({ className: t }) => {
462
462
  background-color: transparent;
463
463
  }
464
464
  `, ne = ee(
465
- ({ boxed: t, className: e, agentData: r }, s) => /* @__PURE__ */ n(F, { ref: s, children: /* @__PURE__ */ n(Y, { left: t, center: !t, children: /* @__PURE__ */ n(
465
+ ({ boxed: t, className: e, agentData: o }, s) => /* @__PURE__ */ n(F, { ref: s, children: /* @__PURE__ */ n(Y, { left: t, center: !t, children: /* @__PURE__ */ n(
466
466
  X,
467
467
  {
468
468
  padded: !!t,
@@ -489,27 +489,27 @@ const Oe = ({ className: t }) => {
489
489
  var e;
490
490
  return (e = t.theme.colors) == null ? void 0 : e.text;
491
491
  }};
492
- `, oe = (t, e) => new Date(t).toLocaleTimeString(e || [], {
492
+ `, re = (t, e) => new Date(t).toLocaleTimeString(e || [], {
493
493
  hour: "numeric",
494
494
  minute: "2-digit"
495
495
  }), M = ({
496
496
  className: t,
497
497
  name: e,
498
- timestamp: r,
498
+ timestamp: o,
499
499
  ariaHidden: s = !1
500
500
  }) => {
501
- const a = Ie(ge);
502
- if (!e && !r)
501
+ const a = Ae(ge);
502
+ if (!e && !o)
503
503
  return null;
504
- let o = "";
505
- return e ? r ? o = `${e}: ${oe(r, a)}` : o = e : r && (o = oe(r, a)), /* @__PURE__ */ n(Ge, { "aria-hidden": s, children: o });
504
+ let r = "";
505
+ return e ? o ? r = `${e}: ${re(o, a)}` : r = e : o && (r = re(o, a)), /* @__PURE__ */ n(Ge, { "aria-hidden": s, children: r });
506
506
  }, fe = ({
507
507
  className: t,
508
508
  children: e,
509
- sender: r,
509
+ sender: o,
510
510
  timestamp: s
511
511
  }) => {
512
- const { avatar: a, name: o } = r, { avatarSize: d } = S();
512
+ const { avatar: a, name: r } = o, { avatarSize: d, avatarLabel: u = "Avatar" } = S();
513
513
  return /* @__PURE__ */ h(
514
514
  Je,
515
515
  {
@@ -521,13 +521,13 @@ const Oe = ({ className: t }) => {
521
521
  children: [
522
522
  a && /* @__PURE__ */ n(je, { className: "humany-agent-avatar", avatarSize: d, children: typeof a == "string" ? (
523
523
  // eslint-disable-next-line jsx-a11y/alt-text
524
- /* @__PURE__ */ n("img", { src: a })
524
+ /* @__PURE__ */ n("img", { src: a, alt: u })
525
525
  ) : /* @__PURE__ */ n(k, { symbol: a }) }),
526
526
  e,
527
527
  /* @__PURE__ */ n(
528
528
  M,
529
529
  {
530
- name: o,
530
+ name: r,
531
531
  timestamp: s,
532
532
  ariaHidden: !0
533
533
  }
@@ -553,10 +553,10 @@ const Oe = ({ className: t }) => {
553
553
  'info';
554
554
  `};
555
555
  `, Qe = ee(
556
- ({ className: t, children: e, timestamp: r, discrete: s, fullWidth: a }, o) => /* @__PURE__ */ n(
556
+ ({ className: t, children: e, timestamp: o, discrete: s, fullWidth: a }, r) => /* @__PURE__ */ n(
557
557
  Ze,
558
558
  {
559
- ref: o,
559
+ ref: r,
560
560
  className: H(
561
561
  t,
562
562
  "humany-conversation-system-message"
@@ -564,10 +564,10 @@ const Oe = ({ className: t }) => {
564
564
  fullWidth: a,
565
565
  children: s ? /* @__PURE__ */ h(et, { className: "humany-conversation-discrete-message", children: [
566
566
  e,
567
- /* @__PURE__ */ n(M, { timestamp: r })
567
+ /* @__PURE__ */ n(M, { timestamp: o })
568
568
  ] }) : /* @__PURE__ */ h(N, { children: [
569
569
  e,
570
- /* @__PURE__ */ n(M, { timestamp: r })
570
+ /* @__PURE__ */ n(M, { timestamp: o })
571
571
  ] })
572
572
  }
573
573
  )
@@ -592,7 +592,7 @@ const Oe = ({ className: t }) => {
592
592
  > p {
593
593
  margin: 0;
594
594
  }
595
- `, tt = ({ className: t, children: e, timestamp: r }) => {
595
+ `, tt = ({ className: t, children: e, timestamp: o }) => {
596
596
  const { userLabel: s = "" } = S();
597
597
  return /* @__PURE__ */ h(
598
598
  nt,
@@ -607,7 +607,7 @@ const Oe = ({ className: t }) => {
607
607
  M,
608
608
  {
609
609
  name: s,
610
- timestamp: r,
610
+ timestamp: o,
611
611
  ariaHidden: !0
612
612
  }
613
613
  )
@@ -623,47 +623,47 @@ const Oe = ({ className: t }) => {
623
623
  `, te = (t) => Array.isArray(t) ? t : Object.keys(t).map((e) => ({
624
624
  label: t[e],
625
625
  actionKey: e
626
- })), ot = ({ header: t, actions: e, dispatch: r }) => {
627
- const s = A(), { events: a } = s.get("$widget");
626
+ })), rt = ({ header: t, actions: e, dispatch: o }) => {
627
+ const s = I(), { events: a } = s.get("$widget");
628
628
  return /* @__PURE__ */ n(
629
- rt,
629
+ ot,
630
630
  {
631
631
  className: "humany-conversation-button-list",
632
632
  header: t,
633
633
  items: te(e),
634
- renderItem: (o) => {
634
+ renderItem: (r) => {
635
635
  var u;
636
- const d = !!((u = o == null ? void 0 : o.data) != null && u.href);
636
+ const d = !!((u = r == null ? void 0 : r.data) != null && u.href);
637
637
  return /* @__PURE__ */ n("li", { children: d ? /* @__PURE__ */ h(
638
638
  st,
639
639
  {
640
- href: o.data.href,
641
- target: o.data.target,
642
- "aria-label": o.label,
643
- title: o.label,
640
+ href: r.data.href,
641
+ target: r.data.target,
642
+ "aria-label": r.label,
643
+ title: r.label,
644
644
  children: [
645
- /* @__PURE__ */ n(k, { symbol: o.symbol }),
646
- o.label
645
+ /* @__PURE__ */ n(k, { symbol: r.symbol }),
646
+ r.label
647
647
  ]
648
648
  }
649
649
  ) : /* @__PURE__ */ h(
650
650
  at,
651
651
  {
652
652
  onClick: () => {
653
- r("action", o), a.dispatch("tracking:button-list-item-clicked", o);
653
+ o("action", r), a.dispatch("tracking:button-list-item-clicked", r);
654
654
  },
655
- "aria-label": o.label,
656
- title: o.label,
655
+ "aria-label": r.label,
656
+ title: r.label,
657
657
  children: [
658
- /* @__PURE__ */ n(k, { symbol: o.symbol }),
659
- o.label
658
+ /* @__PURE__ */ n(k, { symbol: r.symbol }),
659
+ r.label
660
660
  ]
661
661
  }
662
- ) }, o.actionKey);
662
+ ) }, r.actionKey);
663
663
  }
664
664
  }
665
665
  );
666
- }, rt = i(K)`
666
+ }, ot = i(K)`
667
667
  ${D}
668
668
  > ul {
669
669
  display: flex;
@@ -705,7 +705,7 @@ const Oe = ({ className: t }) => {
705
705
  return (e = t.theme.sizes) == null ? void 0 : e.small;
706
706
  }};
707
707
  }
708
- `, at = i(I)`
708
+ `, at = i(A)`
709
709
  ${B};
710
710
 
711
711
  display: block;
@@ -734,8 +734,8 @@ const Oe = ({ className: t }) => {
734
734
  }};
735
735
  }
736
736
  `, it = ({ type: t, content: e = {} }) => {
737
- const r = we(t);
738
- return !r || !t ? null : /* @__PURE__ */ n(Ae, { fallback: null, children: /* @__PURE__ */ n(r, { ...e }) });
737
+ const o = we(t);
738
+ return !o || !t ? null : /* @__PURE__ */ n(Ie, { fallback: null, children: /* @__PURE__ */ n(o, { ...e }) });
739
739
  }, lt = ({ body: t }) => /* @__PURE__ */ n(ct, { className: "humany-html", html: t }), ct = i(Q)`
740
740
  ${Se}
741
741
  color: inherit;
@@ -750,7 +750,7 @@ const Oe = ({ className: t }) => {
750
750
  p {
751
751
  word-break: auto-phrase;
752
752
  }
753
- `, dt = ({ header: t, actions: e, dispatch: r }) => /* @__PURE__ */ n(
753
+ `, dt = ({ header: t, actions: e, dispatch: o }) => /* @__PURE__ */ n(
754
754
  mt,
755
755
  {
756
756
  className: "humany-conversation-item-list",
@@ -771,10 +771,10 @@ const Oe = ({ className: t }) => {
771
771
  ) }),
772
772
  /* @__PURE__ */ h("div", { className: "item-body", children: [
773
773
  /* @__PURE__ */ n(
774
- I,
774
+ A,
775
775
  {
776
776
  onClick: () => {
777
- r("action", s);
777
+ o("action", s);
778
778
  },
779
779
  "aria-label": s.label,
780
780
  title: s.label,
@@ -873,8 +873,8 @@ const Oe = ({ className: t }) => {
873
873
  }
874
874
  }
875
875
  }
876
- `, ht = ({ header: t, actions: e, dispatch: r }) => {
877
- const s = Ce(e), a = me(), o = ae(), d = A(), { events: u } = d.get("$widget");
876
+ `, ht = ({ header: t, actions: e, dispatch: o }) => {
877
+ const s = Ce(e), a = me(), r = ae(), d = I(), { events: u } = d.get("$widget");
878
878
  return j(() => {
879
879
  if (s && Array.isArray(e) && Array.isArray(s) && s.length < e.length && a.current) {
880
880
  const l = a.current.querySelectorAll(
@@ -894,8 +894,8 @@ const Oe = ({ className: t }) => {
894
894
  if (p.addedNodes) {
895
895
  const $ = Array.from(
896
896
  p.addedNodes
897
- ).find((z) => z.tagName === "BUTTON");
898
- $ && Ne(a.current, document.activeElement) && (o && $.focus(), g.disconnect());
897
+ ).find((L) => L.tagName === "BUTTON");
898
+ $ && Ne(a.current, document.activeElement) && (r && $.focus(), g.disconnect());
899
899
  }
900
900
  });
901
901
  }).observe(m, {
@@ -919,7 +919,7 @@ const Oe = ({ className: t }) => {
919
919
  {
920
920
  help: l.actionKey === "help",
921
921
  onClick: () => {
922
- r("action", l), u.dispatch("tracking:link-list-item-clicked", l);
922
+ o("action", l), u.dispatch("tracking:link-list-item-clicked", l);
923
923
  },
924
924
  "aria-label": l.label,
925
925
  title: l.label,
@@ -962,7 +962,7 @@ const Oe = ({ className: t }) => {
962
962
  margin: 0;
963
963
  }
964
964
  }
965
- `, ft = i(I)`
965
+ `, ft = i(A)`
966
966
  display: block;
967
967
  text-align: left;
968
968
  font-weight: 300;
@@ -975,14 +975,14 @@ const Oe = ({ className: t }) => {
975
975
  overflow: hidden;
976
976
 
977
977
  ${(t) => {
978
- var e, r;
978
+ var e, o;
979
979
  return t.help && x`
980
980
  color: ${(e = t.theme.colors) == null ? void 0 : e.text};
981
981
  text-decoration: underline;
982
982
 
983
983
  i,
984
984
  svg {
985
- margin-left: ${(r = t.theme.sizes) == null ? void 0 : r.small};
985
+ margin-left: ${(o = t.theme.sizes) == null ? void 0 : o.small};
986
986
  }
987
987
  `;
988
988
  }}
@@ -1005,7 +1005,7 @@ const Oe = ({ className: t }) => {
1005
1005
  `, vt = ({
1006
1006
  header: t = "Video call",
1007
1007
  acceptLabel: e = "Accept",
1008
- declineLabel: r = "Decline",
1008
+ declineLabel: o = "Decline",
1009
1009
  dispatch: s
1010
1010
  }) => {
1011
1011
  const a = He(() => [
@@ -1018,34 +1018,34 @@ const Oe = ({ className: t }) => {
1018
1018
  }
1019
1019
  },
1020
1020
  {
1021
- label: r,
1021
+ label: o,
1022
1022
  actionKey: "decline-video-call",
1023
1023
  symbol: {
1024
1024
  type: "Svg",
1025
1025
  content: "close"
1026
1026
  }
1027
1027
  }
1028
- ], [e, r]);
1028
+ ], [e, o]);
1029
1029
  return /* @__PURE__ */ n(
1030
1030
  xt,
1031
1031
  {
1032
1032
  className: "humany-conversation-video-request",
1033
1033
  header: t,
1034
1034
  items: a,
1035
- renderItem: (o) => {
1036
- const d = o.actionKey === "accept-video-call" ? "#70c48e" : "#da5c85";
1035
+ renderItem: (r) => {
1036
+ const d = r.actionKey === "accept-video-call" ? "#70c48e" : "#da5c85";
1037
1037
  return /* @__PURE__ */ n("li", { children: /* @__PURE__ */ n(
1038
1038
  kt,
1039
1039
  {
1040
1040
  onClick: () => {
1041
- s("action", o);
1041
+ s("action", r);
1042
1042
  },
1043
- "aria-label": o.label,
1044
- title: o.label,
1043
+ "aria-label": r.label,
1044
+ title: r.label,
1045
1045
  bgColor: d,
1046
- children: /* @__PURE__ */ n(k, { symbol: o.symbol, size: 25 })
1046
+ children: /* @__PURE__ */ n(k, { symbol: r.symbol, size: 25 })
1047
1047
  }
1048
- ) }, o.actionKey);
1048
+ ) }, r.actionKey);
1049
1049
  }
1050
1050
  }
1051
1051
  );
@@ -1063,7 +1063,7 @@ const Oe = ({ className: t }) => {
1063
1063
  }
1064
1064
  }
1065
1065
  ${(t) => C(t)}
1066
- `, kt = i(I)`
1066
+ `, kt = i(A)`
1067
1067
  ${B};
1068
1068
 
1069
1069
  background-color: ${(t) => t.bgColor};
@@ -1104,54 +1104,54 @@ const Oe = ({ className: t }) => {
1104
1104
  }
1105
1105
  }
1106
1106
  `, R = ([t, e]) => ({ type: t, content: e }), wt = ({ items: t, dispatch: e }) => {
1107
- const r = t.map(R).filter((o) => o.type.includes("ace-knowledge")).map((o) => "humany-" + o.type.toString());
1108
- return !!t.map(R).filter((o) => {
1109
- const d = o == null ? void 0 : o.content, u = d == null ? void 0 : d.actions;
1107
+ const o = t.map(R).filter((r) => r.type.includes("ace-knowledge")).map((r) => "humany-" + r.type.toString());
1108
+ return !!t.map(R).filter((r) => {
1109
+ const d = r == null ? void 0 : r.content, u = d == null ? void 0 : d.actions;
1110
1110
  return !!(u != null && u.filter((l) => l.actionKey === "contact").length);
1111
- }).length && r.push("humany-secondary-action-list"), !!t.map(R).filter((o) => {
1111
+ }).length && o.push("humany-secondary-action-list"), !!t.map(R).filter((r) => {
1112
1112
  var u;
1113
- const d = o == null ? void 0 : o.content;
1113
+ const d = r == null ? void 0 : r.content;
1114
1114
  return !!((u = d == null ? void 0 : d.tags) != null && u.includes("category"));
1115
- }).length && r.push("humany-category-list"), /* @__PURE__ */ n(
1115
+ }).length && o.push("humany-category-list"), /* @__PURE__ */ n(
1116
1116
  St,
1117
1117
  {
1118
1118
  role: "none",
1119
1119
  className: H(
1120
1120
  "humany-message-list",
1121
- r.join(" ")
1121
+ o.join(" ")
1122
1122
  ),
1123
1123
  items: t.map(R),
1124
1124
  renderLi: !0,
1125
- renderItem: (o) => {
1126
- switch (o.type) {
1125
+ renderItem: (r) => {
1126
+ switch (r.type) {
1127
1127
  case w.Text:
1128
- return /* @__PURE__ */ n(bt, { text: o.content });
1128
+ return /* @__PURE__ */ n(bt, { text: r.content });
1129
1129
  case w.HTML:
1130
- return /* @__PURE__ */ n(lt, { ...o.content });
1130
+ return /* @__PURE__ */ n(lt, { ...r.content });
1131
1131
  case w.Separator:
1132
- return /* @__PURE__ */ n(yt, { ...o.content });
1132
+ return /* @__PURE__ */ n(yt, { ...r.content });
1133
1133
  case w.ItemList:
1134
- return /* @__PURE__ */ n(dt, { ...o.content, dispatch: e });
1134
+ return /* @__PURE__ */ n(dt, { ...r.content, dispatch: e });
1135
1135
  case w.LinkList:
1136
- return /* @__PURE__ */ n(ht, { ...o.content, dispatch: e });
1136
+ return /* @__PURE__ */ n(ht, { ...r.content, dispatch: e });
1137
1137
  case w.ButtonList:
1138
- return /* @__PURE__ */ n(ot, { ...o.content, dispatch: e });
1138
+ return /* @__PURE__ */ n(rt, { ...r.content, dispatch: e });
1139
1139
  case w.VideoRequest:
1140
- return /* @__PURE__ */ n(vt, { ...o.content, dispatch: e });
1140
+ return /* @__PURE__ */ n(vt, { ...r.content, dispatch: e });
1141
1141
  default:
1142
- return /* @__PURE__ */ n(it, { type: o.type, content: o.content });
1142
+ return /* @__PURE__ */ n(it, { type: r.type, content: r.content });
1143
1143
  }
1144
1144
  }
1145
1145
  }
1146
1146
  );
1147
1147
  }, St = i(le)`
1148
- ${ze}
1148
+ ${Le}
1149
1149
 
1150
1150
  > li {
1151
1151
  margin: 0;
1152
1152
  }
1153
1153
  `, Ct = ee(
1154
- ({ className: t, timestamp: e, sender: r, type: s, content: a }, o) => {
1154
+ ({ className: t, timestamp: e, sender: o, type: s, content: a }, r) => {
1155
1155
  const d = ue(
1156
1156
  (c) => {
1157
1157
  let g = "first";
@@ -1159,25 +1159,25 @@ const Oe = ({ className: t }) => {
1159
1159
  },
1160
1160
  [a]
1161
1161
  ), { userLabel: u = "" } = S(), l = () => /* @__PURE__ */ n(N, { children: a.map((c) => {
1162
- const { key: g, body: p, title: $, form: z, actions: v } = c, O = !!p && !$ && !z && !v;
1162
+ const { key: g, body: p, title: $, form: L, actions: v } = c, O = !!p && !$ && !L && !v;
1163
1163
  return /* @__PURE__ */ n(
1164
1164
  Qe,
1165
1165
  {
1166
1166
  className: t,
1167
1167
  discrete: O,
1168
- ref: o,
1168
+ ref: r,
1169
1169
  timestamp: e,
1170
- fullWidth: !!z || !!v,
1170
+ fullWidth: !!L || !!v,
1171
1171
  children: O && p ? /* @__PURE__ */ n(Q, { html: p }) : /* @__PURE__ */ n(V, { isSystem: !0, content: c })
1172
1172
  },
1173
1173
  g
1174
1174
  );
1175
1175
  }) }), m = () => /* @__PURE__ */ h(N, { children: [
1176
- /* @__PURE__ */ n(re, { className: "humany-sr-only", children: /* @__PURE__ */ n(M, { name: r == null ? void 0 : r.name, timestamp: e }) }),
1176
+ /* @__PURE__ */ n(oe, { className: "humany-sr-only", children: /* @__PURE__ */ n(M, { name: o == null ? void 0 : o.name, timestamp: e }) }),
1177
1177
  /* @__PURE__ */ n(
1178
1178
  fe,
1179
1179
  {
1180
- sender: r,
1180
+ sender: o,
1181
1181
  timestamp: e,
1182
1182
  className: t,
1183
1183
  children: /* @__PURE__ */ n(F, { className: "humany-message-content-bundle", children: a.map((c, g) => /* @__PURE__ */ n(
@@ -1185,7 +1185,7 @@ const Oe = ({ className: t }) => {
1185
1185
  {
1186
1186
  className: "humany-message-container",
1187
1187
  left: !0,
1188
- ref: o,
1188
+ ref: r,
1189
1189
  children: /* @__PURE__ */ n(
1190
1190
  V,
1191
1191
  {
@@ -1199,13 +1199,13 @@ const Oe = ({ className: t }) => {
1199
1199
  }
1200
1200
  )
1201
1201
  ] }), y = () => /* @__PURE__ */ h(N, { children: [
1202
- /* @__PURE__ */ n(re, { className: "humany-sr-only", children: /* @__PURE__ */ n(M, { name: u, timestamp: e }) }),
1202
+ /* @__PURE__ */ n(oe, { className: "humany-sr-only", children: /* @__PURE__ */ n(M, { name: u, timestamp: e }) }),
1203
1203
  /* @__PURE__ */ n(tt, { timestamp: e, className: t, children: /* @__PURE__ */ n(F, { className: "humany-message-content-bundle", children: a.map((c, g) => /* @__PURE__ */ n(
1204
1204
  Y,
1205
1205
  {
1206
1206
  className: "humany-message-container",
1207
1207
  right: !0,
1208
- ref: o,
1208
+ ref: r,
1209
1209
  children: /* @__PURE__ */ n(
1210
1210
  V,
1211
1211
  {
@@ -1232,10 +1232,10 @@ const Oe = ({ className: t }) => {
1232
1232
  ), V = ({
1233
1233
  content: t,
1234
1234
  isUser: e,
1235
- isSystem: r,
1235
+ isSystem: o,
1236
1236
  stacked: s
1237
1237
  }) => {
1238
- const a = G(), { title: o, body: d, actions: u, form: l, items: m } = t;
1238
+ const a = G(), { title: r, body: d, actions: u, form: l, items: m } = t;
1239
1239
  return m ? /* @__PURE__ */ n(
1240
1240
  X,
1241
1241
  {
@@ -1248,12 +1248,12 @@ const Oe = ({ className: t }) => {
1248
1248
  X,
1249
1249
  {
1250
1250
  className: "humany-message-content",
1251
- padded: !r,
1251
+ padded: !o,
1252
1252
  user: !!e,
1253
1253
  stacked: s,
1254
1254
  fullWidth: !!l || !!u,
1255
1255
  children: [
1256
- o && /* @__PURE__ */ n(E, { children: /* @__PURE__ */ n(qe, { variant: "h2", children: o }) }),
1256
+ r && /* @__PURE__ */ n(E, { children: /* @__PURE__ */ n(qe, { variant: "h2", children: r }) }),
1257
1257
  d && /* @__PURE__ */ n(E, { children: /* @__PURE__ */ n(Fe, { html: d }) }),
1258
1258
  l && /* @__PURE__ */ n(E, { children: /* @__PURE__ */ n(
1259
1259
  _e,
@@ -1286,7 +1286,7 @@ const Oe = ({ className: t }) => {
1286
1286
  ]
1287
1287
  }
1288
1288
  );
1289
- }, re = i.div`
1289
+ }, oe = i.div`
1290
1290
  position: absolute !important;
1291
1291
  height: 1px;
1292
1292
  width: 1px;
@@ -1295,8 +1295,8 @@ const Oe = ({ className: t }) => {
1295
1295
  clip: rect(1px, 1px, 1px, 1px);
1296
1296
  left: -10000000px;
1297
1297
  top: auto;
1298
- `, zt = () => {
1299
- const { skipToLatestMessageLabel: t = "Skip to latest message" } = S(), e = A(), r = () => {
1298
+ `, Lt = () => {
1299
+ const { skipToLatestMessageLabel: t = "Skip to latest message" } = S(), e = I(), o = () => {
1300
1300
  const s = e.get("widgetDOMElement");
1301
1301
  if (s) {
1302
1302
  const a = s.querySelectorAll(
@@ -1306,17 +1306,17 @@ const Oe = ({ className: t }) => {
1306
1306
  }
1307
1307
  };
1308
1308
  return /* @__PURE__ */ n(
1309
- Lt,
1309
+ zt,
1310
1310
  {
1311
1311
  className: "humany-skip-to-latest-message",
1312
1312
  onKeyDown: (s) => {
1313
- (s.key === "Enter" || s.keyCode === 13) && r();
1313
+ (s.key === "Enter" || s.keyCode === 13) && o();
1314
1314
  },
1315
- onClick: r,
1315
+ onClick: o,
1316
1316
  children: t
1317
1317
  }
1318
1318
  );
1319
- }, Lt = i.button`
1319
+ }, zt = i.button`
1320
1320
  position: absolute;
1321
1321
  bottom: 60px;
1322
1322
  text-align: center;
@@ -1337,16 +1337,16 @@ const Oe = ({ className: t }) => {
1337
1337
  ${b};
1338
1338
  }
1339
1339
  `, ye = () => {
1340
- const t = A(), e = ue((m) => {
1340
+ const t = I(), e = ue((m) => {
1341
1341
  m && setTimeout(() => {
1342
1342
  m.scrollIntoView({
1343
1343
  block: "start",
1344
1344
  behavior: "smooth"
1345
1345
  });
1346
1346
  }, 250);
1347
- }, []), [r, s] = ie(!0), {
1347
+ }, []), [o, s] = ie(!0), {
1348
1348
  messages: a,
1349
- loading: o,
1349
+ loading: r,
1350
1350
  typingActors: d = []
1351
1351
  } = S(), u = () => d && d.length ? d.map((m, y) => /* @__PURE__ */ n(
1352
1352
  _,
@@ -1371,7 +1371,7 @@ const Oe = ({ className: t }) => {
1371
1371
  y.length && y.length > l.current && (l.current = y.length, y[y.length - 1].focus());
1372
1372
  }
1373
1373
  }), /* @__PURE__ */ h(N, { children: [
1374
- /* @__PURE__ */ h(Nt, { tabIndex: 0, scrollableCss: r, ref: s, children: [
1374
+ /* @__PURE__ */ h(Nt, { tabIndex: 0, scrollableCss: o, ref: s, children: [
1375
1375
  a && a.length ? a.map((m, y) => {
1376
1376
  const { type: c, timestamp: g, sender: p, content: $ } = m;
1377
1377
  return /* @__PURE__ */ n(
@@ -1385,10 +1385,10 @@ const Oe = ({ className: t }) => {
1385
1385
  );
1386
1386
  }) : null,
1387
1387
  u(),
1388
- o && /* @__PURE__ */ n(_, { children: /* @__PURE__ */ n(ne, { ref: e }) })
1388
+ r && /* @__PURE__ */ n(_, { children: /* @__PURE__ */ n(ne, { ref: e }) })
1389
1389
  ] }),
1390
1390
  /* @__PURE__ */ n(Oe, {}),
1391
- /* @__PURE__ */ n(zt, {})
1391
+ /* @__PURE__ */ n(Lt, {})
1392
1392
  ] });
1393
1393
  }, Nt = i.div`
1394
1394
  display: flex;
@@ -1461,12 +1461,12 @@ const Oe = ({ className: t }) => {
1461
1461
  ref: e
1462
1462
  }
1463
1463
  );
1464
- }, It = ({
1464
+ }, At = ({
1465
1465
  dispatch: t,
1466
1466
  header: e,
1467
- buttonLabel: r
1467
+ buttonLabel: o
1468
1468
  }) => /* @__PURE__ */ h(
1469
- At,
1469
+ It,
1470
1470
  {
1471
1471
  portalId: "humany-conversation-portal",
1472
1472
  className: "humany-conversation-outlet",
@@ -1476,8 +1476,8 @@ const Oe = ({ className: t }) => {
1476
1476
  Ot,
1477
1477
  {
1478
1478
  className: "humany-conversation-outlet-head-button",
1479
- "aria-label": r,
1480
- title: r,
1479
+ "aria-label": o,
1480
+ title: o,
1481
1481
  onClick: () => t("hide-overlay-conversation"),
1482
1482
  children: /* @__PURE__ */ n(
1483
1483
  k,
@@ -1503,7 +1503,7 @@ const Oe = ({ className: t }) => {
1503
1503
  /* @__PURE__ */ n(ye, {})
1504
1504
  ]
1505
1505
  }
1506
- ), At = i(ce)`
1506
+ ), It = i(ce)`
1507
1507
  z-index: 11;
1508
1508
  top: auto;
1509
1509
  height: 65%;
@@ -1542,7 +1542,7 @@ const Oe = ({ className: t }) => {
1542
1542
  return (e = t.theme.colors) == null ? void 0 : e.text;
1543
1543
  }};
1544
1544
  margin: 0;
1545
- `, Ot = i(I)`
1545
+ `, Ot = i(A)`
1546
1546
  display: flex;
1547
1547
  align-items: center;
1548
1548
  justify-content: center;
@@ -1567,15 +1567,15 @@ const Oe = ({ className: t }) => {
1567
1567
  }
1568
1568
  `, Ft = ({ className: t, ...e }) => {
1569
1569
  const {
1570
- overlay: r,
1570
+ overlay: o,
1571
1571
  overlayConversationHeader: s,
1572
1572
  overlayConversationCloseLabel: a,
1573
- conversationControllerId: o
1574
- } = S(), d = G(), l = A().get("$settings");
1573
+ conversationControllerId: r
1574
+ } = S(), d = G(), l = I().get("$settings");
1575
1575
  return /* @__PURE__ */ n(
1576
- Le.Provider,
1576
+ ze.Provider,
1577
1577
  {
1578
- value: o ? { id: o } : null,
1578
+ value: r ? { id: r } : null,
1579
1579
  children: /* @__PURE__ */ h(ge.Provider, { value: l == null ? void 0 : l.language, children: [
1580
1580
  /* @__PURE__ */ n(
1581
1581
  Et,
@@ -1589,10 +1589,10 @@ const Oe = ({ className: t }) => {
1589
1589
  children: /* @__PURE__ */ n(ye, {})
1590
1590
  }
1591
1591
  ),
1592
- r && /* @__PURE__ */ h(N, { children: [
1592
+ o && /* @__PURE__ */ h(N, { children: [
1593
1593
  /* @__PURE__ */ n(Mt, { dispatch: d }),
1594
- r.conversation && /* @__PURE__ */ n(
1595
- It,
1594
+ o.conversation && /* @__PURE__ */ n(
1595
+ At,
1596
1596
  {
1597
1597
  dispatch: d,
1598
1598
  header: s,
@@ -247,7 +247,7 @@
247
247
  line-height: 1.5em;
248
248
  grid-area: info;
249
249
  color: ${t=>{var e;return(e=t.theme.colors)==null?void 0:e.text}};
250
- `,q=(t,e)=>new Date(t).toLocaleTimeString(e||[],{hour:"numeric",minute:"2-digit"}),L=({className:t,name:e,timestamp:o,ariaHidden:a=!1})=>{const i=g.useContext(W);if(!e&&!o)return null;let r="";return e?o?r=`${e}: ${q(o,i)}`:r=e:o&&(r=q(o,i)),s.jsx(ge,{"aria-hidden":a,children:r})},U=({className:t,children:e,sender:o,timestamp:a})=>{const{avatar:i,name:r}=o,{avatarSize:u}=n.useProperties();return s.jsxs(ye,{hasAvatar:!!i,className:S.appendClassNames(t,"humany-conversation-agent-message"),children:[i&&s.jsx(re,{className:"humany-agent-avatar",avatarSize:u,children:typeof i=="string"?s.jsx("img",{src:i}):s.jsx(n.SymbolBadge,{symbol:i})}),e,s.jsx(L,{name:r,timestamp:a,ariaHidden:!0})]})},ye=l.div`
250
+ `,q=(t,e)=>new Date(t).toLocaleTimeString(e||[],{hour:"numeric",minute:"2-digit"}),L=({className:t,name:e,timestamp:o,ariaHidden:a=!1})=>{const i=g.useContext(W);if(!e&&!o)return null;let r="";return e?o?r=`${e}: ${q(o,i)}`:r=e:o&&(r=q(o,i)),s.jsx(ge,{"aria-hidden":a,children:r})},U=({className:t,children:e,sender:o,timestamp:a})=>{const{avatar:i,name:r}=o,{avatarSize:u,avatarLabel:h="Avatar"}=n.useProperties();return s.jsxs(ye,{hasAvatar:!!i,className:S.appendClassNames(t,"humany-conversation-agent-message"),children:[i&&s.jsx(re,{className:"humany-agent-avatar",avatarSize:u,children:typeof i=="string"?s.jsx("img",{src:i,alt:h}):s.jsx(n.SymbolBadge,{symbol:i})}),e,s.jsx(L,{name:r,timestamp:a,ariaHidden:!0})]})},ye=l.div`
251
251
  display: grid;
252
252
  margin-right: 10%;
253
253
  width: 90%;
package/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";var _=Object.defineProperty;var q=(o,e,t)=>e in o?_(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var h=(o,e,t)=>(q(o,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("@telia-ace/widget-core"),p=require("@telia-ace/widget-services"),E=require("@telia-ace/widget-utilities"),L=require("@telia-ace/widget-forms"),M=require("@telia-ace/widget-plugins"),N=require("@telia-ace/widget-ui"),z=require("react");class U{constructor(e){h(this,"cache",new Map);h(this,"subscriptions",[]);this.controller=e;const{events:t}=e.container.get("$widget"),s=t.subscribe("data-client:fetched",(r,n)=>{n.type==="contact-method"&&this.cache.set(n.response.id,n.response)});this.subscriptions.push(s)}getConversationLogs(){return this.controller.messages.reduce((t,s)=>{const r=k(s),{key:n,content:a,type:i,sender:c,timestamp:d}=r.content,u=this.parseEntry(a,i,c,d);return u&&t.push(u),t},[])}parseEntry(e,t,s,r){const n=d=>{let u=[],l=[],m;if(Array.isArray(d)){const[g,f]=d;m=f}else m=d;return this.createMessageContent(m).length&&(l=[...l,this.createMessageContent(m)]),u=[...u,...this.createMessageOptions(m)],{messagesAsList:l,options:u}};let a=[],i=[];if(Array.isArray(e.items)){const{items:d}=e;d.forEach(u=>{const l=n(u);a=[...a,...l.options],i=[...i,...l.messagesAsList]})}else{const d=n(e);a=[...a,...d.options],i=[...i,...d.messagesAsList]}return{options:a,message:i.length?i.join(`
2
2
  `):void 0,source:this.createMessageSource(t),alias:this.createAlias(t,s),timestamp:r}}createMessageSource(e){return e}createAlias(e,t){return e===y.System?"system":(t==null?void 0:t.name)||"Me"}handleContactMethod(e){if(!this.cache.has(e))return;const t=this.cache.get(e);let s="";return s=this.appendText(s,`${t.clientName}:`),s=this.appendText(s,t.title),t.description&&(s=this.appendText(s,t.title)),s}getDetails(e,t=!0){if(!e)return"";const{header:s,title:r,label:n,description:a,text:i,html:c,body:d,contactMethodId:u}=e;let l="";if(u){const m=this.handleContactMethod(u.toString());m&&(l=this.appendText(l,m,t))}return s&&(l=this.appendText(l,s,t)),r&&(l=this.appendText(l,r,t)),a&&(l=this.appendText(l,a,t)),i&&(l=this.appendText(l,i,t)),n&&(l=this.appendText(l,n,t)),c&&(l=this.appendText(l,c,t)),d&&typeof d=="string"&&(l=this.appendText(l,d,t)),l}createMessageContent(e){let t="";return t=this.getDetails(e),t}createMessageOptions(e){let t=[],s=[];return Array.isArray(e==null?void 0:e.actions)?s=e.actions:typeof(e==null?void 0:e.actions)=="object"&&(s=Object.entries(e.actions).map(([r,n])=>({actionKey:r,label:n}))),s.length&&(t=s.map(r=>this.getDetails(r,!1))),t}appendText(e,t,s=!0){return s&&e.length?`${e}
3
- ${t}`:e.length?`${e} ${t}`:t}dispose(){this.subscriptions.forEach(e=>{e()})}}class P{constructor(e,t){h(this,"id");h(this,"name");h(this,"avatar");h(this,"print",(e,t,s=null)=>{var i,c,d;const r={name:this.name,avatar:this.avatar,id:this.id},n=k(e,t);s=s??n.timestamp;const a=(c=(i=this.provider)==null?void 0:i.controller)==null?void 0:c.container.get("$widget");return(d=a==null?void 0:a.events)==null||d.dispatch("tracking:conversation-message",{sender:"agent"}),this.provider.createEntry(n.key,n.content,y.Agent,r,s)});h(this,"typing",()=>this.provider.setTypingState({name:this.name,avatar:this.avatar}));this.provider=e,this.id=t.id||E.uuid(),this.name=t.name,this.avatar=t.avatar}update(e){var r;const{name:t,avatar:s}=e;s===null?this.avatar=void 0:s&&(this.avatar=s),t===null?this.name=void 0:t&&(this.name=t),(r=this.provider.controller)==null||r.events.dispatch("conversation:agent-updated",{agent:this})}}class A{constructor(e,t,s){h(this,"subscriptions",[]);h(this,"options");h(this,"user");this.name=e,this.container=t,this.controller=s,this.user=s==null?void 0:s.user,this.options={silent:!1}}static create(e,t,s){return new A(e,t,s)}createAgent(e={}){var t;if(this.controller){const s=this.controller.getAgentById(e.id),r=s?new P(this,{...s,...e}):new P(this,e);return s||(t=this.controller)==null||t.events.dispatch("conversation:agent-created",{agent:r}),r}}print(e){var t;return(t=this.controller)==null?void 0:t.print(e)}setTypingState(e,t){var s;return(s=this.controller)==null?void 0:s.setTypingState(e,t)}loading(){return this.controller?this.controller.loader():()=>()=>{}}createEntry(e,t,s,r,n){var a;return(a=this.controller)==null?void 0:a.createEntry(e,t,s,r,n)}dispose(){var e;process.env.NODE_ENV!=="production"&&console.log(`conversation-provider: dispose (${this.name})`),(e=this.controller)==null||e.disposeProvider(this),this.controller=null,this.subscriptions.forEach(t=>t())}isRehydrated(){var e;return((e=this.controller)==null?void 0:e.isRehydrated())||Promise.resolve(!1)}getHistory(){var e;return((e=this.controller)==null?void 0:e.getHistory())||[]}complete(){var e;(e=this.controller)==null||e.onCompleteProvider()}setOptions(e={silent:!1}){this.options=e}onUnreadMessage(e){var t;if(this.controller){const s=(t=this.controller)==null?void 0:t.onUnreadMessage(e);return this.subscriptions.push(s),()=>{s()}}}onMounted(e){var t;if(this.controller){const s=(t=this.controller)==null?void 0:t.events.subscribe("conversation:component-mount-changed",e);return this.subscriptions.push(s),e({},this.controller.getComponentMountedState()),()=>{s()}}}}const O=o=>`conversation-${o}`;class K{constructor(){h(this,"_locking",Promise.resolve());h(this,"_locks",0)}isLocked(){return this._locks>0}lock(){this._locks+=1;let e;const t=new Promise(r=>e=()=>{this._locks-=1,r()}),s=this._locking.then(()=>e);return this._locking=this._locking.then(()=>t),s}}class Q{constructor(e,t,s){h(this,"sessionStorageKey");h(this,"locker",new K);h(this,"initialStoredAgents",[]);this.container=e,this.conversation=t,this.enabled=s,this.sessionStorageKey=O(t.id),t.onStarted(async()=>{if(t.messages.length>0)return;const{agents:r}=await this.read(),n=[];r&&r.forEach(i=>{const c=t.providerIndex(i.providerName),d=c>-1?t.registeredProviders[c]:t.createProvider(i.providerName),u=new P(d,{name:i.name,avatar:i.avatar,id:i.id});n.push(u)});const{messages:a}=await this.read();a.forEach(i=>{switch(i.type){case"agent":{const c=n.find(d=>{var u;return d.id===((u=i.sender)==null?void 0:u.id)});c&&c.print(i.content.items||i.content,{key:i.key},i.timestamp);return}case"user":{t.user.print(i.content.items||i.content,{key:i.key},i.timestamp);return}case"system":default:t.print(i.content.items||i.content,i.timestamp)}})}),t.onMessageCreated(async(r,n)=>{this.write(n.message,"messages")}),t.events.subscribe("conversation:agent-created",async(r,n)=>{const a={id:n.agent.id,name:n.agent.name,avatar:n.agent.avatar,providerName:n.agent.provider.name};await this.write(a,"agents")}),t.events.subscribe("conversation:agent-updated",async(r,n)=>{const{agents:a}=await this.read();await this.write([...a.map(i=>i.id===n.agent.id?{...i,name:n.agent.name,avatar:n.agent.avatar}:i)],"agents","update")})}setInitialData(e){this.initialStoredAgents=e.agents}async isRehydrated(){const{messages:e}=await this.read();return e.length>0}getStoredAgent(e){if(this.enabled)return this.initialStoredAgents.find(t=>t.id===e)}async write(e,t,s="add"){if(!this.enabled)return;const r=await this.locker.lock();return p.createStorageWriter(this.container,this.sessionStorageKey,p.StorageCategory.Necessary).then(async n=>{if(s==="add"){const a=await this.read();if(t==="messages"&&a.messages.findIndex(c=>c.key===e.key)>-1){r();return}const i={...a};return t==="messages"?i.messages=[...i.messages,e]:t==="agents"&&(i.agents=[...i.agents,e]),n({...a,...i}).then(()=>{r()})}if(s==="update"&&t==="agents"){const a=await this.read();return n({...a,agents:e}).then(()=>{r()})}return n(e).then(()=>{r()})})}async read(){return p.readStorage(this.container,this.sessionStorageKey).then(e=>e||{messages:[],agents:[]})}}class j{constructor(e){h(this,"print",(e,t,s=null)=>{var a,i;const r=k(e,t);return s=s??r.timestamp,(i=((a=this.controller)==null?void 0:a.container.get("$widget")).events)==null||i.dispatch("tracking:conversation-message",{sender:"user"}),this.controller.createEntry(r.key,r.content,y.User,void 0,s)});this.controller=e}}const x=async(o,e,t)=>{const s=await o.getAsync("conversation"),r=await o.getAsync("components"),n=s.controllers.find(a=>a.conversation.id===e);if(n){const a=[...n.conversation.providers];a.forEach(c=>{n.conversation.setProviderOptions(c,{silent:!0})}),n.conversation.queueProviders(a),n.conversation.setProviders([t]);const i=r.components().ofType("conversation");r.write({key:"setConversationProvider",attributes:{properties:{providers:[t]}},target:i,provider:"localStorage"})}};class ${constructor(e){this.writer=e}update(e){const t=this.getNormalizedSettings(e);this.writer(t)}remove(){this.writer(null)}getNormalizedSettings(e){return typeof e=="string"?{body:e}:e.length>-1&&typeof e=="object"?{items:e}:e}}var y=(o=>(o.User="user",o.Agent="agent",o.System="system",o))(y||{});const k=(o,e)=>{let t,s=(e==null?void 0:e.key)||E.uuid(),r=Date.now();if(Array.isArray(o)&&o.length>-1)typeof o[0]=="string"?t={items:[o]}:t={items:o};else if(typeof o=="string")t={body:o};else if(o=o||{},o.type)t={...o};else{if(t={body:o.body,actions:o.actions,title:o.title},o.key&&(s=o.key),o.timestamp&&(r=o.timestamp),typeof o.form=="function"){const n=L.FormBuilder.create(s);o.form(n);const a=n.get();t.form=a}o.timestamp===null&&(r=null)}return{content:t,key:s,timestamp:r}},W=(o,e)=>{if(!e)return;const t=JSON.stringify(e),s=o.findIndex(r=>t===JSON.stringify(r));if(s>-1)return o.splice(s,1)};class H{constructor(e,t,s){h(this,"formHandlers",{});h(this,"user",new j(this));h(this,"events");h(this,"providers",[]);h(this,"active",!1);h(this,"queuedProviders",[]);h(this,"registeredProviders",[]);h(this,"loaders",0);h(this,"componentMounted",!1);h(this,"store");h(this,"messages",[]);h(this,"typingActors",[]);h(this,"conversationHistory");h(this,"print",(e,t=null)=>{const s=k(e);t=t??s.timestamp;const r=this.container.get("$widget");return r==null||r.events.dispatch("tracking:conversation-message",{sender:"system"}),this.createEntry(s.key,s.content,"system",void 0,t)});this.container=e,this.id=t;const r=e.get("$widget");this.events=r.events.createChild(this),this.store=new Q(e,this,s.rehydrate),this.conversationHistory=new U(this)}setInitialStorage(e){this.store.setInitialData(e)}setProviders(e){const t=[],s=[];this.providers.reduce((r,n)=>(e.indexOf(n)===-1&&r.push(n),r),[]).forEach(r=>{const n=this.providers.indexOf(r);n>-1&&(t.push(r),this.providers.splice(n,1))}),e.forEach(r=>{this.providers.indexOf(r)===-1&&(s.push(r),this.providers.push(r))}),(s.length||t.length)&&this.events.dispatch("conversation:providers-changed",{added:s,removed:t})}createProvider(e){const t=this.providerIndex(e);if(t>-1)return this.registeredProviders[t];const s=A.create(e,this.container,this);return this.registeredProviders.push(s),s}providerIndex(e){return this.registeredProviders.findIndex(t=>t.name===e)}getAgentById(e){if(e)return this.store.getStoredAgent(e)}dispose(){this.conversationHistory.dispose(),this.registeredProviders.forEach(e=>e.dispose()),this.messages=[],this.events.dispatch("conversation:controller-disposed",this),this.active=!1}onDispose(e){return this.events.subscribe("conversation:controller-disposed",e)}onStarted(e){return this.events.subscribe("conversation:started",e)}onMessageCreated(e){return this.events.subscribe("conversation:message-created",e)}isRehydrated(){return this.store.isRehydrated()}disposeProvider(e){const t=this.providerIndex(e.name);t>-1&&this.registeredProviders.splice(t,1),this.events.dispatch("conversation:providers-changed",{removed:[e.name]}),this.registeredProviders.length||this.dispose()}onProvidersChange(e){return this.events.subscribe("conversation:providers-changed",e)}setComponentMountedState(e){this.componentMounted!==e&&(this.componentMounted=e,e&&(this.events.dispatch("conversation:unread-message",!1),this.events.dispatch("conversation:started",!0),this.active=!0),this.events.dispatch("conversation:component-mount-changed",e))}setProviderOptions(e,t){const s=this.providerIndex(e);s>-1&&this.registeredProviders[s].setOptions(t)}changeProvider(e){this.registeredProviders.find(s=>s.name===e)&&x(this.container,this.id,e)}queueProviders(e){this.queuedProviders=e}onCompleteProvider(){const e=this.queuedProviders.pop();e&&x(this.container,this.id,e)}getComponentMountedState(){return this.componentMounted}onUnreadMessage(e){return this.events.subscribe("conversation:unread-message",e)}createEntry(e,t,s,r,n){const a={key:e,content:t,type:s,sender:r||null,timestamp:n||n===null?n:Date.now()};this.messages.push(a),a.type==="agent"&&W(this.typingActors,r);const i=new $(c=>{if(c!==null){const{timestamp:d=void 0,...u}=c;a.content=u,d&&(a.timestamp=d)}else{const d=this.messages.indexOf(a);a.content=null,d>-1&&this.messages.splice(d,1)}this.events.dispatch("conversation:message-updated",{message:a}),this.update()});return this.events.dispatch("conversation:message-created",{message:a}),this.update(),this.componentMounted||this.events.dispatch("conversation:unread-message",!0),i}update(){this.events.dispatch("conversation:updated",{messages:this.messages,loading:this.loaders>0,typingActors:this.typingActors})}getMessageStream(){return{messages:this.messages,loading:this.loaders>0,typingActors:this.typingActors}}setTypingState(e,t){return this.typingActors.indexOf(e)===-1&&(this.typingActors.push(e),this.update()),()=>{W(this.typingActors,e),this.update()}}loader(){this.loaders=this.loaders+1;let e=!1;return this.loaders===1&&this.update(),()=>{e||(e=!0,this.loaders=this.loaders-1,this.loaders===0&&this.update())}}submitForm(e,t){this.formHandlers[e]={...this.formHandlers[e],submit:t}}validateForm(e,t){this.formHandlers[e]={...this.formHandlers[e],validate:t}}getHistory(){return this.conversationHistory.getConversationLogs()}}const F=(o,e)=>{const t=o.split("_contact");return e.widgets.get(t[0])},I=o=>{const e=o.get("$widget"),{name:t,implementation:s}=o.get("$widget"),r=t.indexOf("_contact")>-1?F(t,s):e,{data:n}=o.get("$settings"),{trigger:a}=r.container.get("$settings"),i=`${t.replace("_contact-method","").replace("_contact","")}_contact-method`,c=s.widgets.get(i);return c&&!a?{chatWidget:c,mainWidget:r,data:n}:{mainWidget:r,data:n}},G=o=>{const{chatWidget:e}=I(o);return!!e},R=(o,e,t)=>{const{mainWidget:s,data:r,chatWidget:n}=I(o);return n?n.state==="activated"?n.invoke("open").then(()=>{n.container.getAsync("conversation").then(a=>{a.navigateToConversationIfActive(e.id).then(()=>M.closeAllModals(o))})}):n.activate().then(()=>{const{trigger:a}=n.container.get("$settings");return a.action="hide",n.invoke("setSettings",()=>({data:r,trigger:a,activate:!0})).then(()=>n.container.getAsync("components").then(i=>{const c=i.components().ofType("contact-method");i.write({key:"setContactMethodId",attributes:{properties:{id:e.id,guideId:e.guideId}},target:c,provider:"localStorage"});const d=i.components().ofType("conversation");i.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:d,provider:"localStorage"})}))}).then(()=>n.invoke("attach",{key:"contact-method",triggerDOMElement:t,withRenderState:"open"})).then(()=>(p.createStorageWriter(n.container,"activeStickyWidget",p.StorageCategory.Necessary,{medium:p.StorageMedium.Local,scope:p.StorageScope.Implementation}).then(a=>a(n.name)),n.container.getAsync("conversation").then(a=>{a.setConversationEndedBehavior(S.Deactivate)}).then(()=>M.closeAllModals(o)).then(()=>!1))):(s.container.getAsync("conversation").then(a=>a.navigateToConversationIfActive(e.id).then(()=>a.setConversationEndedBehavior(S.Navigate))),!n)},J=(o,e,t="conversation")=>{const{mainWidget:s,chatWidget:r}=I(o);return r?r.container.getAsync("router").then(n=>{n.navigate(t,{id:e.id})}):s.container.getAsync("conversation").then(n=>{var a;(a=n.setConversationEndedBehavior(S.Navigate))==null||a.then(()=>{s.container.getAsync("router").then(i=>{s.container.getAsync("components").then(c=>{const d=c.components().ofType("conversation");c.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:d,provider:"localStorage"})}).then(()=>{i.navigate(t,{id:e.id})})})})})},b="conversations";var S=(o=>(o.Deactivate="deactivate",o.Navigate="navigate",o.None="none",o))(S||{});class w{constructor(e,t){h(this,"events");h(this,"controllers",[]);h(this,"providers",[]);h(this,"disposeProviders",{});h(this,"subscriptions",[]);h(this,"storageWriter",null);h(this,"router",null);h(this,"buttonQuery",null);h(this,"sessionInfo",null);this.container=e,this.components=t;const s=e.get("$widget");this.events=s.events.createChild(this)}initialize(){p.createStorageWriter(this.container,b,p.StorageCategory.Necessary,{medium:p.StorageMedium.Local}).then(e=>this.storageWriter=e),p.readStorage(this.container,b,p.StorageMedium.Local).then(e=>{this.buttonQuery=this.components.components().ofType("conversation-return-button"),e&&(this.sessionInfo=e,e.id&&e.route&&this.writeToComponents({active:!0,alert:{show:!1}}))}),this.container.getAsync("router").then(e=>this.router=e),this.events.subscribe("conversation:ended",(e,t)=>{var s,r,n;switch((s=this.sessionInfo)==null?void 0:s.conversationEndedBehavior){case"deactivate":this.container.get("$widget").deactivate();break;case"navigate":const i=(r=this.router)==null?void 0:r.getInitialRoute();i&&((n=this.router)==null||n.navigate(i.name));break}this.writeToComponents({active:!1}),this.sessionInfo=null,this.storageWriter&&this.storageWriter()})}addSubscription(e){this.subscriptions.push(e)}static getInstance(e,t="conversation"){return E.lock(e)(()=>e.getAsync(t).then(s=>{let r=s;return r||D.ComponentPlatform.getInstance(e).then(n=>(r=new w(e,n),r.initialize(),e.registerAsync(t,()=>r),r))}))}navigateToConversationIfActive(e){return p.readStorage(this.container,b,p.StorageMedium.Local).then(t=>{var s;if(t&&t.id===e&&t.route){const{name:r,params:n}=t.route;(s=this.router)==null||s.navigate(r,n)}})}setConversationEndedBehavior(e){return p.readStorage(this.container,b,p.StorageMedium.Local).then(t=>{let s=t;return s?s.conversationEndedBehavior=e:s={conversationEndedBehavior:e},this.sessionInfo=s,this.storageWriter&&this.storageWriter(this.sessionInfo)||Promise.resolve()})}async createController(e,t){const s=O(e),{agents:r}=await p.readStorage(this.container,s)||{agents:[]},n=this.controllers.findIndex(i=>i.conversation.id===e);let a;return n>-1?a=this.controllers[n].conversation:a=new H(this.container,e,t),a.setInitialStorage({agents:r||[]}),a}registerProvider(e,t){const s={name:e,handler:t};this.providers.push(s),this.controllers.filter(r=>r.conversation.providers.indexOf(e)>-1).forEach(r=>{this.invokeHandler(s,r)})}registerController(e,t){const s=this.controllers.findIndex(n=>n.conversation.id===e.id);let r;if(s<0){r={conversation:e,component:t},this.controllers.push(r);const n=a=>{a&&this.providers.filter(i=>a.indexOf(i.name)>-1).forEach(i=>{this.invokeHandler(i,r)})};return this.subscriptions.push(e.onDispose((a,i)=>{const c=this.controllers.findIndex(d=>d.conversation===i);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})})),this.subscriptions.push(e.onProvidersChange((a,i)=>{const{added:c,removed:d=[]}=i;d.forEach(u=>{(this.disposeProviders[u]||[]).forEach(l=>{l()})}),n(c)})),this.subscriptions.push(e.onStarted((a,i)=>{var d,u;const c={id:e.id,route:(d=this.router)==null?void 0:d.getRouteData(),conversationEndedBehavior:(u=this.sessionInfo)==null?void 0:u.conversationEndedBehavior};this.sessionInfo=c,this.storageWriter&&this.storageWriter(c),this.writeToComponents({active:i})})),this.subscriptions.push(e.onUnreadMessage((a,i)=>{this.events.dispatch("conversation:unread-message",i),this.writeToComponents({alert:{show:i}})})),n(e.providers),!0}return r=this.controllers[s],!1}writeToComponents(e,t="conversationReturnButtonState"){this.buttonQuery&&this.components.write({key:"conversationReturnButtonState",attributes:{properties:e},target:this.buttonQuery,provider:"localStorage"})}invokeHandler(e,t){const s=e.handler(t.conversation.createProvider(e.name),t.component);s&&(this.disposeProviders[e.name]||(this.disposeProviders[e.name]=[]),this.disposeProviders[e.name].push(s))}getComponentRoute(){return p.readStorage(this.container,b,p.StorageMedium.Local).then(e=>e==null?void 0:e.route)}dispose(){Object.keys(this.disposeProviders).forEach(e=>{this.disposeProviders[e].forEach(t=>{t()})}),this.subscriptions.forEach(e=>{e()}),this.controllers=[],this.providers=[]}static async handleContactMethodClick(e,t,s,r){if(G(t)){e.preventDefault();let n=document.getElementById("humany-dynamic-anchor");n||(n=document.createElement("a"),n.setAttribute("href","#"),n.id="humany-dynamic-anchor",document.body.appendChild(n)),R(t,s,n)}R(t,s)}static async handleContactMethodSubmit(e,t){var s,r;return(r=(s=t==null?void 0:t.body.form.meta)==null?void 0:s.conversation)!=null&&r.id?x(e,t.body.form.meta.conversation.id,t.clientName):J(e,t)}}const V=(o,e)=>o.reduce((t,s,r)=>{var a,i;const n={...s,content:[{...s.content,key:s.key}]};if(t.length>0&&s.type!==y.System){const c=t[t.length-1];if((!e&&e!==0||Math.abs(c.timestamp-s.timestamp)<e)&&((a=c.sender)==null?void 0:a.name)===((i=s.sender)==null?void 0:i.name)&&c.type===s.type)return c.timestamp=s.timestamp,c.content.push({...s.content,key:s.key}),t}return t.push(n),t},[]),Y=o=>Promise.all([w.getInstance(o),o.getAsync("router")]).then(([e,t])=>N.createReactComponent(o,"conversation",Promise.resolve().then(()=>require("./conversation-083be7f1.js")),async s=>{const{rehydrate:r=!1}=s.properties(),a=t.getRouteData().params.id||s.node.name||"component",i=await e.createController(a,{rehydrate:r}),c=e.registerController(i,s),d=3*60*1e3,u=v=>{const{providers:g=[]}=v;if(g){const f=Array.isArray(g)?g:[g];return i.setProviders(f),f}};u(s.properties(u)),i.setComponentMountedState(!0);const l=v=>{const{loading:g,typingActors:f,messages:C}=v;s.writeProperties({loading:g,typingActors:f,messages:V(C,d)})};l(i.getMessageStream()),c&&(s.writeProperties({conversationControllerId:i.id}),s.actions.create("user-submit",(v,g)=>{if(g){const{preventDefault:f,validationPromise:C}=g;if(f){C&&C().then(T=>{T&&i.user.print(T)});return}}i.user.print(v.text)}),s.actions.create("user-typing",(v,g)=>{}),s.actions.create("form",(v,g)=>{}),s.actions.create("action",(v,g)=>{}),s.actions.create("overlay-mounted",(v,g)=>{}),s.actions.create("show-overlay",(v,g)=>{s.writeProperties({overlay:{conversation:!1,secondary:!1}})}),s.actions.create("hide-overlay",(v,g)=>{s.writeProperties({overlay:null})}),s.actions.create("show-overlay-conversation",(v,g)=>{s.writeProperties({overlay:{conversation:!0,secondary:!1}})}),s.actions.create("hide-overlay-conversation",(v,g)=>{s.writeProperties({overlay:{conversation:!1,secondary:!1}})}));const m=i.events.subscribe("conversation:updated",(v,g)=>{l(g)});return()=>{i.setComponentMountedState(!1),m(),i.active||l({messages:[],typingActors:[],loading:!1})}},{reuseController:!0})),X=o=>Promise.all([D.ComponentPlatform.getInstance(o),w.getInstance(o),o.getAsync("router")]).then(([e,t,s])=>N.createReactComponent(o,"conversation-return-button",Promise.resolve().then(()=>require("./return-button-f1f43984.js")),r=>{r.actions.create("toggle",(n={})=>{var a;(a=t.getComponentRoute())==null||a.then(i=>{i&&s.navigate(i.name,i.params)})})}));var B=(o=>(o.LinkList="link-list",o.Separator="separator",o.ButtonList="button-list",o.ItemList="item-list",o.Text="text",o.HTML="html",o.VideoRequest="video-request",o))(B||{});const Z=(o,e,t)=>o.getAsync("componentResolver").then(async s=>{(await w.getInstance(o)).addSubscription(s.registerComponent(e,z.lazy(()=>t)))});exports.Agent=P;exports.ConversationComponent=Y;exports.ConversationController=H;exports.ConversationEndedBehavior=S;exports.ConversationEntry=$;exports.ConversationMessageListItemType=B;exports.ConversationMessageType=y;exports.ConversationPlatform=w;exports.ConversationProvider=A;exports.ConversationReturnButtonComponent=X;exports.registerCustomMessageComponent=Z;
3
+ ${t}`:e.length?`${e} ${t}`:t}dispose(){this.subscriptions.forEach(e=>{e()})}}class P{constructor(e,t){h(this,"id");h(this,"name");h(this,"avatar");h(this,"print",(e,t,s=null)=>{var i,c,d;const r={name:this.name,avatar:this.avatar,id:this.id},n=k(e,t);s=s??n.timestamp;const a=(c=(i=this.provider)==null?void 0:i.controller)==null?void 0:c.container.get("$widget");return(d=a==null?void 0:a.events)==null||d.dispatch("tracking:conversation-message",{sender:"agent"}),this.provider.createEntry(n.key,n.content,y.Agent,r,s)});h(this,"typing",()=>this.provider.setTypingState({name:this.name,avatar:this.avatar}));this.provider=e,this.id=t.id||E.uuid(),this.name=t.name,this.avatar=t.avatar}update(e){var r;const{name:t,avatar:s}=e;s===null?this.avatar=void 0:s&&(this.avatar=s),t===null?this.name=void 0:t&&(this.name=t),(r=this.provider.controller)==null||r.events.dispatch("conversation:agent-updated",{agent:this})}}class A{constructor(e,t,s){h(this,"subscriptions",[]);h(this,"options");h(this,"user");this.name=e,this.container=t,this.controller=s,this.user=s==null?void 0:s.user,this.options={silent:!1}}static create(e,t,s){return new A(e,t,s)}createAgent(e={}){var t;if(this.controller){const s=this.controller.getAgentById(e.id),r=s?new P(this,{...s,...e}):new P(this,e);return s||(t=this.controller)==null||t.events.dispatch("conversation:agent-created",{agent:r}),r}}print(e){var t;return(t=this.controller)==null?void 0:t.print(e)}setTypingState(e,t){var s;return(s=this.controller)==null?void 0:s.setTypingState(e,t)}loading(){return this.controller?this.controller.loader():()=>()=>{}}createEntry(e,t,s,r,n){var a;return(a=this.controller)==null?void 0:a.createEntry(e,t,s,r,n)}dispose(){var e;process.env.NODE_ENV!=="production"&&console.log(`conversation-provider: dispose (${this.name})`),(e=this.controller)==null||e.disposeProvider(this),this.controller=null,this.subscriptions.forEach(t=>t())}isRehydrated(){var e;return((e=this.controller)==null?void 0:e.isRehydrated())||Promise.resolve(!1)}getHistory(){var e;return((e=this.controller)==null?void 0:e.getHistory())||[]}complete(){var e;(e=this.controller)==null||e.onCompleteProvider()}setOptions(e={silent:!1}){this.options=e}onUnreadMessage(e){var t;if(this.controller){const s=(t=this.controller)==null?void 0:t.onUnreadMessage(e);return this.subscriptions.push(s),()=>{s()}}}onMounted(e){var t;if(this.controller){const s=(t=this.controller)==null?void 0:t.events.subscribe("conversation:component-mount-changed",e);return this.subscriptions.push(s),e({},this.controller.getComponentMountedState()),()=>{s()}}}}const O=o=>`conversation-${o}`;class K{constructor(){h(this,"_locking",Promise.resolve());h(this,"_locks",0)}isLocked(){return this._locks>0}lock(){this._locks+=1;let e;const t=new Promise(r=>e=()=>{this._locks-=1,r()}),s=this._locking.then(()=>e);return this._locking=this._locking.then(()=>t),s}}class Q{constructor(e,t,s){h(this,"sessionStorageKey");h(this,"locker",new K);h(this,"initialStoredAgents",[]);this.container=e,this.conversation=t,this.enabled=s,this.sessionStorageKey=O(t.id),t.onStarted(async()=>{if(t.messages.length>0)return;const{agents:r}=await this.read(),n=[];r&&r.forEach(i=>{const c=t.providerIndex(i.providerName),d=c>-1?t.registeredProviders[c]:t.createProvider(i.providerName),u=new P(d,{name:i.name,avatar:i.avatar,id:i.id});n.push(u)});const{messages:a}=await this.read();a.forEach(i=>{switch(i.type){case"agent":{const c=n.find(d=>{var u;return d.id===((u=i.sender)==null?void 0:u.id)});c&&c.print(i.content.items||i.content,{key:i.key},i.timestamp);return}case"user":{t.user.print(i.content.items||i.content,{key:i.key},i.timestamp);return}case"system":default:t.print(i.content.items||i.content,i.timestamp)}})}),t.onMessageCreated(async(r,n)=>{this.write(n.message,"messages")}),t.events.subscribe("conversation:agent-created",async(r,n)=>{const a={id:n.agent.id,name:n.agent.name,avatar:n.agent.avatar,providerName:n.agent.provider.name};await this.write(a,"agents")}),t.events.subscribe("conversation:agent-updated",async(r,n)=>{const{agents:a}=await this.read();await this.write([...a.map(i=>i.id===n.agent.id?{...i,name:n.agent.name,avatar:n.agent.avatar}:i)],"agents","update")})}setInitialData(e){this.initialStoredAgents=e.agents}async isRehydrated(){const{messages:e}=await this.read();return e.length>0}getStoredAgent(e){if(this.enabled)return this.initialStoredAgents.find(t=>t.id===e)}async write(e,t,s="add"){if(!this.enabled)return;const r=await this.locker.lock();return p.createStorageWriter(this.container,this.sessionStorageKey,p.StorageCategory.Necessary).then(async n=>{if(s==="add"){const a=await this.read();if(t==="messages"&&a.messages.findIndex(c=>c.key===e.key)>-1){r();return}const i={...a};return t==="messages"?i.messages=[...i.messages,e]:t==="agents"&&(i.agents=[...i.agents,e]),n({...a,...i}).then(()=>{r()})}if(s==="update"&&t==="agents"){const a=await this.read();return n({...a,agents:e}).then(()=>{r()})}return n(e).then(()=>{r()})})}async read(){return p.readStorage(this.container,this.sessionStorageKey).then(e=>e||{messages:[],agents:[]})}}class j{constructor(e){h(this,"print",(e,t,s=null)=>{var a,i;const r=k(e,t);return s=s??r.timestamp,(i=((a=this.controller)==null?void 0:a.container.get("$widget")).events)==null||i.dispatch("tracking:conversation-message",{sender:"user"}),this.controller.createEntry(r.key,r.content,y.User,void 0,s)});this.controller=e}}const x=async(o,e,t)=>{const s=await o.getAsync("conversation"),r=await o.getAsync("components"),n=s.controllers.find(a=>a.conversation.id===e);if(n){const a=[...n.conversation.providers];a.forEach(c=>{n.conversation.setProviderOptions(c,{silent:!0})}),n.conversation.queueProviders(a),n.conversation.setProviders([t]);const i=r.components().ofType("conversation");r.write({key:"setConversationProvider",attributes:{properties:{providers:[t]}},target:i,provider:"localStorage"})}};class ${constructor(e){this.writer=e}update(e){const t=this.getNormalizedSettings(e);this.writer(t)}remove(){this.writer(null)}getNormalizedSettings(e){return typeof e=="string"?{body:e}:e.length>-1&&typeof e=="object"?{items:e}:e}}var y=(o=>(o.User="user",o.Agent="agent",o.System="system",o))(y||{});const k=(o,e)=>{let t,s=(e==null?void 0:e.key)||E.uuid(),r=Date.now();if(Array.isArray(o)&&o.length>-1)typeof o[0]=="string"?t={items:[o]}:t={items:o};else if(typeof o=="string")t={body:o};else if(o=o||{},o.type)t={...o};else{if(t={body:o.body,actions:o.actions,title:o.title},o.key&&(s=o.key),o.timestamp&&(r=o.timestamp),typeof o.form=="function"){const n=L.FormBuilder.create(s);o.form(n);const a=n.get();t.form=a}o.timestamp===null&&(r=null)}return{content:t,key:s,timestamp:r}},W=(o,e)=>{if(!e)return;const t=JSON.stringify(e),s=o.findIndex(r=>t===JSON.stringify(r));if(s>-1)return o.splice(s,1)};class H{constructor(e,t,s){h(this,"formHandlers",{});h(this,"user",new j(this));h(this,"events");h(this,"providers",[]);h(this,"active",!1);h(this,"queuedProviders",[]);h(this,"registeredProviders",[]);h(this,"loaders",0);h(this,"componentMounted",!1);h(this,"store");h(this,"messages",[]);h(this,"typingActors",[]);h(this,"conversationHistory");h(this,"print",(e,t=null)=>{const s=k(e);t=t??s.timestamp;const r=this.container.get("$widget");return r==null||r.events.dispatch("tracking:conversation-message",{sender:"system"}),this.createEntry(s.key,s.content,"system",void 0,t)});this.container=e,this.id=t;const r=e.get("$widget");this.events=r.events.createChild(this),this.store=new Q(e,this,s.rehydrate),this.conversationHistory=new U(this)}setInitialStorage(e){this.store.setInitialData(e)}setProviders(e){const t=[],s=[];this.providers.reduce((r,n)=>(e.indexOf(n)===-1&&r.push(n),r),[]).forEach(r=>{const n=this.providers.indexOf(r);n>-1&&(t.push(r),this.providers.splice(n,1))}),e.forEach(r=>{this.providers.indexOf(r)===-1&&(s.push(r),this.providers.push(r))}),(s.length||t.length)&&this.events.dispatch("conversation:providers-changed",{added:s,removed:t})}createProvider(e){const t=this.providerIndex(e);if(t>-1)return this.registeredProviders[t];const s=A.create(e,this.container,this);return this.registeredProviders.push(s),s}providerIndex(e){return this.registeredProviders.findIndex(t=>t.name===e)}getAgentById(e){if(e)return this.store.getStoredAgent(e)}dispose(){this.conversationHistory.dispose(),this.registeredProviders.forEach(e=>e.dispose()),this.messages=[],this.events.dispatch("conversation:controller-disposed",this),this.active=!1}onDispose(e){return this.events.subscribe("conversation:controller-disposed",e)}onStarted(e){return this.events.subscribe("conversation:started",e)}onMessageCreated(e){return this.events.subscribe("conversation:message-created",e)}isRehydrated(){return this.store.isRehydrated()}disposeProvider(e){const t=this.providerIndex(e.name);t>-1&&this.registeredProviders.splice(t,1),this.events.dispatch("conversation:providers-changed",{removed:[e.name]}),this.registeredProviders.length||this.dispose()}onProvidersChange(e){return this.events.subscribe("conversation:providers-changed",e)}setComponentMountedState(e){this.componentMounted!==e&&(this.componentMounted=e,e&&(this.events.dispatch("conversation:unread-message",!1),this.events.dispatch("conversation:started",!0),this.active=!0),this.events.dispatch("conversation:component-mount-changed",e))}setProviderOptions(e,t){const s=this.providerIndex(e);s>-1&&this.registeredProviders[s].setOptions(t)}changeProvider(e){this.registeredProviders.find(s=>s.name===e)&&x(this.container,this.id,e)}queueProviders(e){this.queuedProviders=e}onCompleteProvider(){const e=this.queuedProviders.pop();e&&x(this.container,this.id,e)}getComponentMountedState(){return this.componentMounted}onUnreadMessage(e){return this.events.subscribe("conversation:unread-message",e)}createEntry(e,t,s,r,n){const a={key:e,content:t,type:s,sender:r||null,timestamp:n||n===null?n:Date.now()};this.messages.push(a),a.type==="agent"&&W(this.typingActors,r);const i=new $(c=>{if(c!==null){const{timestamp:d=void 0,...u}=c;a.content=u,d&&(a.timestamp=d)}else{const d=this.messages.indexOf(a);a.content=null,d>-1&&this.messages.splice(d,1)}this.events.dispatch("conversation:message-updated",{message:a}),this.update()});return this.events.dispatch("conversation:message-created",{message:a}),this.update(),this.componentMounted||this.events.dispatch("conversation:unread-message",!0),i}update(){this.events.dispatch("conversation:updated",{messages:this.messages,loading:this.loaders>0,typingActors:this.typingActors})}getMessageStream(){return{messages:this.messages,loading:this.loaders>0,typingActors:this.typingActors}}setTypingState(e,t){return this.typingActors.indexOf(e)===-1&&(this.typingActors.push(e),this.update()),()=>{W(this.typingActors,e),this.update()}}loader(){this.loaders=this.loaders+1;let e=!1;return this.loaders===1&&this.update(),()=>{e||(e=!0,this.loaders=this.loaders-1,this.loaders===0&&this.update())}}submitForm(e,t){this.formHandlers[e]={...this.formHandlers[e],submit:t}}validateForm(e,t){this.formHandlers[e]={...this.formHandlers[e],validate:t}}getHistory(){return this.conversationHistory.getConversationLogs()}}const F=(o,e)=>{const t=o.split("_contact");return e.widgets.get(t[0])},I=o=>{const e=o.get("$widget"),{name:t,implementation:s}=o.get("$widget"),r=t.indexOf("_contact")>-1?F(t,s):e,{data:n}=o.get("$settings"),{trigger:a}=r.container.get("$settings"),i=`${t.replace("_contact-method","").replace("_contact","")}_contact-method`,c=s.widgets.get(i);return c&&!a?{chatWidget:c,mainWidget:r,data:n}:{mainWidget:r,data:n}},G=o=>{const{chatWidget:e}=I(o);return!!e},R=(o,e,t)=>{const{mainWidget:s,data:r,chatWidget:n}=I(o);return n?n.state==="activated"?n.invoke("open").then(()=>{n.container.getAsync("conversation").then(a=>{a.navigateToConversationIfActive(e.id).then(()=>M.closeAllModals(o))})}):n.activate().then(()=>{const{trigger:a}=n.container.get("$settings");return a.action="hide",n.invoke("setSettings",()=>({data:r,trigger:a,activate:!0})).then(()=>n.container.getAsync("components").then(i=>{const c=i.components().ofType("contact-method");i.write({key:"setContactMethodId",attributes:{properties:{id:e.id,guideId:e.guideId}},target:c,provider:"localStorage"});const d=i.components().ofType("conversation");i.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:d,provider:"localStorage"})}))}).then(()=>n.invoke("attach",{key:"contact-method",triggerDOMElement:t,withRenderState:"open"})).then(()=>(p.createStorageWriter(n.container,"activeStickyWidget",p.StorageCategory.Necessary,{medium:p.StorageMedium.Local,scope:p.StorageScope.Implementation}).then(a=>a(n.name)),n.container.getAsync("conversation").then(a=>{a.setConversationEndedBehavior(S.Deactivate)}).then(()=>M.closeAllModals(o)).then(()=>!1))):(s.container.getAsync("conversation").then(a=>a.navigateToConversationIfActive(e.id).then(()=>a.setConversationEndedBehavior(S.Navigate))),!n)},J=(o,e,t="conversation")=>{const{mainWidget:s,chatWidget:r}=I(o);return r?r.container.getAsync("router").then(n=>{n.navigate(t,{id:e.id})}):s.container.getAsync("conversation").then(n=>{var a;(a=n.setConversationEndedBehavior(S.Navigate))==null||a.then(()=>{s.container.getAsync("router").then(i=>{s.container.getAsync("components").then(c=>{const d=c.components().ofType("conversation");c.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:d,provider:"localStorage"})}).then(()=>{i.navigate(t,{id:e.id})})})})})},b="conversations";var S=(o=>(o.Deactivate="deactivate",o.Navigate="navigate",o.None="none",o))(S||{});class w{constructor(e,t){h(this,"events");h(this,"controllers",[]);h(this,"providers",[]);h(this,"disposeProviders",{});h(this,"subscriptions",[]);h(this,"storageWriter",null);h(this,"router",null);h(this,"buttonQuery",null);h(this,"sessionInfo",null);this.container=e,this.components=t;const s=e.get("$widget");this.events=s.events.createChild(this)}initialize(){p.createStorageWriter(this.container,b,p.StorageCategory.Necessary,{medium:p.StorageMedium.Local}).then(e=>this.storageWriter=e),p.readStorage(this.container,b,p.StorageMedium.Local).then(e=>{this.buttonQuery=this.components.components().ofType("conversation-return-button"),e&&(this.sessionInfo=e,e.id&&e.route&&this.writeToComponents({active:!0,alert:{show:!1}}))}),this.container.getAsync("router").then(e=>this.router=e),this.events.subscribe("conversation:ended",(e,t)=>{var s,r,n;switch((s=this.sessionInfo)==null?void 0:s.conversationEndedBehavior){case"deactivate":this.container.get("$widget").deactivate();break;case"navigate":const i=(r=this.router)==null?void 0:r.getInitialRoute();i&&((n=this.router)==null||n.navigate(i.name));break}this.writeToComponents({active:!1}),this.sessionInfo=null,this.storageWriter&&this.storageWriter()})}addSubscription(e){this.subscriptions.push(e)}static getInstance(e,t="conversation"){return E.lock(e)(()=>e.getAsync(t).then(s=>{let r=s;return r||D.ComponentPlatform.getInstance(e).then(n=>(r=new w(e,n),r.initialize(),e.registerAsync(t,()=>r),r))}))}navigateToConversationIfActive(e){return p.readStorage(this.container,b,p.StorageMedium.Local).then(t=>{var s;if(t&&t.id===e&&t.route){const{name:r,params:n}=t.route;(s=this.router)==null||s.navigate(r,n)}})}setConversationEndedBehavior(e){return p.readStorage(this.container,b,p.StorageMedium.Local).then(t=>{let s=t;return s?s.conversationEndedBehavior=e:s={conversationEndedBehavior:e},this.sessionInfo=s,this.storageWriter&&this.storageWriter(this.sessionInfo)||Promise.resolve()})}async createController(e,t){const s=O(e),{agents:r}=await p.readStorage(this.container,s)||{agents:[]},n=this.controllers.findIndex(i=>i.conversation.id===e);let a;return n>-1?a=this.controllers[n].conversation:a=new H(this.container,e,t),a.setInitialStorage({agents:r||[]}),a}registerProvider(e,t){const s={name:e,handler:t};this.providers.push(s),this.controllers.filter(r=>r.conversation.providers.indexOf(e)>-1).forEach(r=>{this.invokeHandler(s,r)})}registerController(e,t){const s=this.controllers.findIndex(n=>n.conversation.id===e.id);let r;if(s<0){r={conversation:e,component:t},this.controllers.push(r);const n=a=>{a&&this.providers.filter(i=>a.indexOf(i.name)>-1).forEach(i=>{this.invokeHandler(i,r)})};return this.subscriptions.push(e.onDispose((a,i)=>{const c=this.controllers.findIndex(d=>d.conversation===i);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})})),this.subscriptions.push(e.onProvidersChange((a,i)=>{const{added:c,removed:d=[]}=i;d.forEach(u=>{(this.disposeProviders[u]||[]).forEach(l=>{l()})}),n(c)})),this.subscriptions.push(e.onStarted((a,i)=>{var d,u;const c={id:e.id,route:(d=this.router)==null?void 0:d.getRouteData(),conversationEndedBehavior:(u=this.sessionInfo)==null?void 0:u.conversationEndedBehavior};this.sessionInfo=c,this.storageWriter&&this.storageWriter(c),this.writeToComponents({active:i})})),this.subscriptions.push(e.onUnreadMessage((a,i)=>{this.events.dispatch("conversation:unread-message",i),this.writeToComponents({alert:{show:i}})})),n(e.providers),!0}return r=this.controllers[s],!1}writeToComponents(e,t="conversationReturnButtonState"){this.buttonQuery&&this.components.write({key:"conversationReturnButtonState",attributes:{properties:e},target:this.buttonQuery,provider:"localStorage"})}invokeHandler(e,t){const s=e.handler(t.conversation.createProvider(e.name),t.component);s&&(this.disposeProviders[e.name]||(this.disposeProviders[e.name]=[]),this.disposeProviders[e.name].push(s))}getComponentRoute(){return p.readStorage(this.container,b,p.StorageMedium.Local).then(e=>e==null?void 0:e.route)}dispose(){Object.keys(this.disposeProviders).forEach(e=>{this.disposeProviders[e].forEach(t=>{t()})}),this.subscriptions.forEach(e=>{e()}),this.controllers=[],this.providers=[]}static async handleContactMethodClick(e,t,s,r){if(G(t)){e.preventDefault();let n=document.getElementById("humany-dynamic-anchor");n||(n=document.createElement("a"),n.setAttribute("href","#"),n.id="humany-dynamic-anchor",document.body.appendChild(n)),R(t,s,n)}R(t,s)}static async handleContactMethodSubmit(e,t){var s,r;return(r=(s=t==null?void 0:t.body.form.meta)==null?void 0:s.conversation)!=null&&r.id?x(e,t.body.form.meta.conversation.id,t.clientName):J(e,t)}}const V=(o,e)=>o.reduce((t,s,r)=>{var a,i;const n={...s,content:[{...s.content,key:s.key}]};if(t.length>0&&s.type!==y.System){const c=t[t.length-1];if((!e&&e!==0||Math.abs(c.timestamp-s.timestamp)<e)&&((a=c.sender)==null?void 0:a.name)===((i=s.sender)==null?void 0:i.name)&&c.type===s.type)return c.timestamp=s.timestamp,c.content.push({...s.content,key:s.key}),t}return t.push(n),t},[]),Y=o=>Promise.all([w.getInstance(o),o.getAsync("router")]).then(([e,t])=>N.createReactComponent(o,"conversation",Promise.resolve().then(()=>require("./conversation-dae76c70.js")),async s=>{const{rehydrate:r=!1}=s.properties(),a=t.getRouteData().params.id||s.node.name||"component",i=await e.createController(a,{rehydrate:r}),c=e.registerController(i,s),d=3*60*1e3,u=v=>{const{providers:g=[]}=v;if(g){const f=Array.isArray(g)?g:[g];return i.setProviders(f),f}};u(s.properties(u)),i.setComponentMountedState(!0);const l=v=>{const{loading:g,typingActors:f,messages:C}=v;s.writeProperties({loading:g,typingActors:f,messages:V(C,d)})};l(i.getMessageStream()),c&&(s.writeProperties({conversationControllerId:i.id}),s.actions.create("user-submit",(v,g)=>{if(g){const{preventDefault:f,validationPromise:C}=g;if(f){C&&C().then(T=>{T&&i.user.print(T)});return}}i.user.print(v.text)}),s.actions.create("user-typing",(v,g)=>{}),s.actions.create("form",(v,g)=>{}),s.actions.create("action",(v,g)=>{}),s.actions.create("overlay-mounted",(v,g)=>{}),s.actions.create("show-overlay",(v,g)=>{s.writeProperties({overlay:{conversation:!1,secondary:!1}})}),s.actions.create("hide-overlay",(v,g)=>{s.writeProperties({overlay:null})}),s.actions.create("show-overlay-conversation",(v,g)=>{s.writeProperties({overlay:{conversation:!0,secondary:!1}})}),s.actions.create("hide-overlay-conversation",(v,g)=>{s.writeProperties({overlay:{conversation:!1,secondary:!1}})}));const m=i.events.subscribe("conversation:updated",(v,g)=>{l(g)});return()=>{i.setComponentMountedState(!1),m(),i.active||l({messages:[],typingActors:[],loading:!1})}},{reuseController:!0})),X=o=>Promise.all([D.ComponentPlatform.getInstance(o),w.getInstance(o),o.getAsync("router")]).then(([e,t,s])=>N.createReactComponent(o,"conversation-return-button",Promise.resolve().then(()=>require("./return-button-f1f43984.js")),r=>{r.actions.create("toggle",(n={})=>{var a;(a=t.getComponentRoute())==null||a.then(i=>{i&&s.navigate(i.name,i.params)})})}));var B=(o=>(o.LinkList="link-list",o.Separator="separator",o.ButtonList="button-list",o.ItemList="item-list",o.Text="text",o.HTML="html",o.VideoRequest="video-request",o))(B||{});const Z=(o,e,t)=>o.getAsync("componentResolver").then(async s=>{(await w.getInstance(o)).addSubscription(s.registerComponent(e,z.lazy(()=>t)))});exports.Agent=P;exports.ConversationComponent=Y;exports.ConversationController=H;exports.ConversationEndedBehavior=S;exports.ConversationEntry=$;exports.ConversationMessageListItemType=B;exports.ConversationMessageType=y;exports.ConversationPlatform=w;exports.ConversationProvider=A;exports.ConversationReturnButtonComponent=X;exports.registerCustomMessageComponent=Z;
package/index.mjs CHANGED
@@ -953,7 +953,7 @@ const ee = (o, e) => o.reduce((t, s, r) => {
953
953
  ]).then(([e, t]) => H(
954
954
  o,
955
955
  "conversation",
956
- import("./conversation-d6ec6d94.mjs"),
956
+ import("./conversation-43344a01.mjs"),
957
957
  async (s) => {
958
958
  const { rehydrate: r = !1 } = s.properties(), a = t.getRouteData().params.id || s.node.name || "component", i = await e.createController(a, {
959
959
  rehydrate: r
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/widget-conversation",
3
- "version": "1.3.0-rc.9",
3
+ "version": "1.3.0",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
@@ -10,13 +10,13 @@
10
10
  }
11
11
  },
12
12
  "dependencies": {
13
- "@telia-ace/widget-core": "^1.3.0-rc.9",
14
- "@telia-ace/widget-forms": "^1.3.0-rc.9",
15
- "@telia-ace/widget-plugins": "^1.3.0-rc.9",
16
- "@telia-ace/widget-routing": "^1.3.0-rc.9",
17
- "@telia-ace/widget-services": "^1.3.0-rc.9",
18
- "@telia-ace/widget-ui": "^1.3.0-rc.9",
19
- "@telia-ace/widget-utilities": "^1.3.0-rc.9",
13
+ "@telia-ace/widget-core": "^1.3.0",
14
+ "@telia-ace/widget-forms": "^1.3.0",
15
+ "@telia-ace/widget-plugins": "^1.3.0",
16
+ "@telia-ace/widget-routing": "^1.3.0",
17
+ "@telia-ace/widget-services": "^1.3.0",
18
+ "@telia-ace/widget-ui": "^1.3.0",
19
+ "@telia-ace/widget-utilities": "^1.3.0",
20
20
  "@webprovisions/platform": "^1.1.4"
21
21
  },
22
22
  "peerDependencies": {