@telia-ace/widget-conversation 1.1.2-rc.10 → 1.1.2-rc.11

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.
@@ -3,6 +3,7 @@ type Props = {
3
3
  className?: string;
4
4
  name?: string;
5
5
  timestamp?: number | null;
6
+ ariaHidden?: boolean;
6
7
  };
7
8
  declare const Timestamp: React.FC<Props>;
8
9
  export default Timestamp;
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),i=require("@emotion/styled"),n=require("@telia-ace/widget-ui"),L=require("@telia-ace/widget-utilities"),b=require("@emotion/react"),y=require("react"),Q=require("@telia-ace/widget-forms"),$=require("./index.js");require("@telia-ace/widget-core");require("@telia-ace/widget-services");require("@telia-ace/widget-plugins");const Z=({className:t})=>{const[e,r]=y.useState(""),[o,a]=y.useState(0),[l,d]=y.useState(0),u=n.useIsTabbing(),h=n.useDispatch(),f=n.useContainer(),{inputPlaceholder:p="Type your message",inputHidden:c=!1,inputDisabled:g=!1,sendButtonLabel:j="Send message",inputMultiline:k=!0,secondaryAction:x,skipToLatestMessageLabel:z="Skip to latest message"}=n.useProperties(),[T,v]=n.useScroll(!0);y.useEffect(()=>{if(v.current){const{lineHeight:m,maxHeight:S}=getComputedStyle(v.current);if(m&&m.indexOf("px")>-1){const C=m.split("px"),G=parseInt(C[0],10);a(G);const J=S.split("px");d(parseInt(J[0],10))}}},[v.current]);const I=m=>{!m.shiftKey||!k?(m.preventDefault(),e&&e.length>0&&(h("user-submit",{text:e}),r(""),B(""))):e.length<1&&m.preventDefault()},Y=m=>{x&&(m.preventDefault(),h("action",{actionKey:x.action,...x}))},X=m=>{if(k&&v.current){const S=v.current.scrollHeight;if(S>o){v.current.style.height="auto";let C=S;m.length<1&&(C=o),v.current.style.height=`${C}px`,C>=l?v.current.style.overflowY="scroll":v.current.style.overflowY="hidden"}}},B=m=>{X(m),r(m),m&&m.length>0&&h("user-typing",{textLength:m.length})},K=()=>{const m=f.get("widgetDOMElement");if(m){const S=m.querySelectorAll(".humany-conversation-entry");S.length&&S[S.length-1].focus()}};return c?null:s.jsxs(re,{grow:k,className:L.appendClassNames("humany-conversation-input",t),scrollableCss:T,isTabbing:u,children:[x&&s.jsx(ne,{disabled:g,onClick:Y,title:x.label,"aria-label":x.label,children:s.jsx(n.SymbolBadge,{size:24,symbol:{type:"Svg",content:x.icon||"browse"}})}),k?s.jsx(te,{value:e,onChange:B,onEnter:I,disabled:g,"aria-label":p,placeholder:p,type:"textarea",rows:1,ref:v}):s.jsx(se,{value:e,onChange:B,onEnter:I,disabled:g,"aria-label":p,placeholder:p}),s.jsx(W,{disabled:!1,onClick:I,title:j,"aria-label":j,children:s.jsx(oe,{size:22,symbol:{type:"Svg",content:"send"},hasContent:!!e&&!!e.length})}),s.jsx(ee,{className:"humany-skip-to-latest-message",onKeyDown:m=>{(m.key==="Enter"||m.keyCode===13)&&K()},onClick:K,children:z})]})},ee=i.button`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),i=require("@emotion/styled"),n=require("@telia-ace/widget-ui"),z=require("@telia-ace/widget-utilities"),f=require("@emotion/react"),y=require("react"),Q=require("@telia-ace/widget-forms"),$=require("./index.js");require("@telia-ace/widget-core");require("@telia-ace/widget-services");require("@telia-ace/widget-plugins");const Z=({className:t})=>{const[e,r]=y.useState(""),[o,a]=y.useState(0),[l,d]=y.useState(0),u=n.useIsTabbing(),h=n.useDispatch(),b=n.useContainer(),{inputPlaceholder:p="Type your message",inputHidden:c=!1,inputDisabled:g=!1,sendButtonLabel:j="Send message",inputMultiline:k=!0,secondaryAction:x,skipToLatestMessageLabel:T="Skip to latest message"}=n.useProperties(),[N,v]=n.useScroll(!0);y.useEffect(()=>{if(v.current){const{lineHeight:m,maxHeight:S}=getComputedStyle(v.current);if(m&&m.indexOf("px")>-1){const C=m.split("px"),G=parseInt(C[0],10);a(G);const J=S.split("px");d(parseInt(J[0],10))}}},[v.current]);const I=m=>{!m.shiftKey||!k?(m.preventDefault(),e&&e.length>0&&(h("user-submit",{text:e}),r(""),B(""))):e.length<1&&m.preventDefault()},Y=m=>{x&&(m.preventDefault(),h("action",{actionKey:x.action,...x}))},X=m=>{if(k&&v.current){const S=v.current.scrollHeight;if(S>o){v.current.style.height="auto";let C=S;m.length<1&&(C=o),v.current.style.height=`${C}px`,C>=l?v.current.style.overflowY="scroll":v.current.style.overflowY="hidden"}}},B=m=>{X(m),r(m),m&&m.length>0&&h("user-typing",{textLength:m.length})},K=()=>{const m=b.get("widgetDOMElement");if(m){const S=m.querySelectorAll(".humany-conversation-entry");S.length&&S[S.length-1].focus()}};return c?null:s.jsxs(re,{grow:k,className:z.appendClassNames("humany-conversation-input",t),scrollableCss:N,isTabbing:u,children:[x&&s.jsx(ne,{disabled:g,onClick:Y,title:x.label,"aria-label":x.label,children:s.jsx(n.SymbolBadge,{size:24,symbol:{type:"Svg",content:x.icon||"browse"}})}),k?s.jsx(te,{value:e,onChange:B,onEnter:I,disabled:g,"aria-label":p,placeholder:p,type:"textarea",rows:1,ref:v}):s.jsx(se,{value:e,onChange:B,onEnter:I,disabled:g,"aria-label":p,placeholder:p}),s.jsx(W,{disabled:!1,onClick:I,title:j,"aria-label":j,children:s.jsx(oe,{size:22,symbol:{type:"Svg",content:"send"},hasContent:!!e&&!!e.length})}),s.jsx(ee,{className:"humany-skip-to-latest-message",onKeyDown:m=>{(m.key==="Enter"||m.keyCode===13)&&K()},onClick:K,children:T})]})},ee=i.button`
2
2
  position: absolute;
3
3
  bottom: 112px;
4
4
  text-align: center;
@@ -60,10 +60,10 @@
60
60
  border-right: ${t=>t.theme.border};
61
61
  margin: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.normal}} 0;
62
62
  `,re=i.div`
63
- ${t=>t.grow?b.css`
63
+ ${t=>t.grow?f.css`
64
64
  min-height: 50px;
65
65
  max-height: 150px;
66
- `:b.css`
66
+ `:f.css`
67
67
  height: 50px;
68
68
  `}
69
69
  flex: 0 0 auto;
@@ -116,7 +116,7 @@
116
116
  stroke: ${t=>{var e;return(e=t.theme.colors)==null?void 0:e.text}};
117
117
  }
118
118
  }
119
- `,ie=b.keyframes`
119
+ `,ie=f.keyframes`
120
120
  0% {
121
121
  opacity: 0;
122
122
  }
@@ -172,11 +172,11 @@
172
172
  }
173
173
  max-width: 100%;
174
174
  ${t=>t.fullWidth&&"width: 100%;"}
175
- `,de=(t,e)=>{var o,a;const r=b.css`
175
+ `,de=(t,e)=>{var o,a;const r=f.css`
176
176
  background-color: ${(o=e.colors)==null?void 0:o.accent};
177
177
  color: ${(a=e.colors)==null?void 0:a.text};
178
178
  ${e.border&&`border: ${e.border};`};
179
- `;return e.borderRadius?b.css`
179
+ `;return e.borderRadius?f.css`
180
180
  ${r}
181
181
 
182
182
  border-top-right-radius: ${e.borderRadius};
@@ -189,10 +189,10 @@
189
189
  ${t==="last"&&`
190
190
  border-bottom-left-radius: ${e.borderRadius};
191
191
  `}
192
- `:r},me=(t,e)=>{var o,a;const r=b.css`
192
+ `:r},me=(t,e)=>{var o,a;const r=f.css`
193
193
  background-color: ${(o=e.colors)==null?void 0:o.primary};
194
194
  color: ${(a=e.colors)==null?void 0:a.accent};
195
- `;return e.borderRadius?b.css`
195
+ `;return e.borderRadius?f.css`
196
196
  ${r}
197
197
 
198
198
  border-top-left-radius: ${e.borderRadius};
@@ -205,12 +205,12 @@
205
205
  ${t==="last"&&`
206
206
  border-bottom-right-radius: ${e.borderRadius};
207
207
  `}
208
- `:r},N=i.div`
208
+ `:r},M=i.div`
209
209
  margin-bottom: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.normal}};
210
210
  &:last-child {
211
211
  margin-bottom: 0;
212
212
  }
213
- `,w=t=>{var e,r;return b.css`
213
+ `,w=t=>{var e,r;return f.css`
214
214
  margin: ${(e=t.theme.sizes)==null?void 0:e.medium} 0;
215
215
  padding: 0 ${(r=t.theme.sizes)==null?void 0:r.medium};
216
216
  `},ue=i(Q.FormComponent)`
@@ -252,7 +252,7 @@
252
252
  ${n.borderTabStyle}
253
253
  background-color: transparent;
254
254
  }
255
- `,q=y.forwardRef(({boxed:t,className:e,agentData:r},o)=>s.jsx(O,{ref:o,children:s.jsx(R,{left:t,center:!t,children:s.jsx(E,{padded:!!t,stacked:t?"first":void 0,children:s.jsxs(le,{children:[s.jsx("div",{}),s.jsx("div",{}),s.jsx("div",{})]})})})})),U=y.createContext(null),be=i.p`
255
+ `,q=y.forwardRef(({boxed:t,className:e,agentData:r},o)=>s.jsx(O,{ref:o,children:s.jsx(R,{left:t,center:!t,children:s.jsx(E,{padded:!!t,stacked:t?"first":void 0,children:s.jsxs(le,{children:[s.jsx("div",{}),s.jsx("div",{}),s.jsx("div",{})]})})})})),U=y.createContext(null),fe=i.p`
256
256
  && {
257
257
  font-size: ${t=>{var e;return(e=t.theme.fonts)==null?void 0:e.small}};
258
258
  font-weight: 300;
@@ -261,24 +261,24 @@
261
261
  line-height: 1.5em;
262
262
  grid-area: info;
263
263
  color: ${t=>{var e;return(e=t.theme.colors)==null?void 0:e.text}};
264
- `,P=(t,e)=>new Date(t).toLocaleTimeString(e||[],{hour:"numeric",minute:"2-digit"}),M=({className:t,name:e,timestamp:r})=>{const o=y.useContext(U);if(!e&&!r)return null;let a="";return e?r?a=`${e}: ${P(r,o)}`:a=e:r&&(a=P(r,o)),s.jsx(be,{children:a})},V=({className:t,children:e,sender:r,timestamp:o})=>{const{avatar:a,name:l}=r,{avatarSize:d}=n.useProperties();return s.jsxs(fe,{hasAvatar:!!a,className:L.appendClassNames(t,"humany-conversation-agent-message"),children:[a&&s.jsx(ae,{avatarSize:d,children:typeof a=="string"?s.jsx("img",{src:a}):s.jsx(n.SymbolBadge,{symbol:a})}),e,s.jsx(M,{name:l,timestamp:o})]})},fe=i.div`
264
+ `,P=(t,e)=>new Date(t).toLocaleTimeString(e||[],{hour:"numeric",minute:"2-digit"}),L=({className:t,name:e,timestamp:r,ariaHidden:o=!1})=>{const a=y.useContext(U);if(!e&&!r)return null;let l="";return e?r?l=`${e}: ${P(r,a)}`:l=e:r&&(l=P(r,a)),s.jsx(fe,{"aria-hidden":o,children:l})},V=({className:t,children:e,sender:r,timestamp:o})=>{const{avatar:a,name:l}=r,{avatarSize:d}=n.useProperties();return s.jsxs(be,{hasAvatar:!!a,className:z.appendClassNames(t,"humany-conversation-agent-message"),children:[a&&s.jsx(ae,{avatarSize:d,children:typeof a=="string"?s.jsx("img",{src:a}):s.jsx(n.SymbolBadge,{symbol:a})}),e,s.jsx(L,{name:l,timestamp:o,ariaHidden:!0})]})},be=i.div`
265
265
  display: grid;
266
266
  margin-right: 10%;
267
267
  width: 90%;
268
- ${t=>t.hasAvatar?b.css`
268
+ ${t=>t.hasAvatar?f.css`
269
269
  grid-template-columns: auto 1fr;
270
270
  grid-template-rows: 1fr auto;
271
271
  grid-template-areas:
272
272
  'avatar content'
273
273
  '. info';
274
- `:b.css`
274
+ `:f.css`
275
275
  grid-template-columns: 1fr;
276
276
  grid-template-rows: 1fr auto;
277
277
  grid-template-areas:
278
278
  'content'
279
279
  'info';
280
280
  `};
281
- `,pe=y.forwardRef(({className:t,children:e,timestamp:r,discrete:o,fullWidth:a},l)=>s.jsx(xe,{ref:l,className:L.appendClassNames(t,"humany-conversation-system-message"),fullWidth:a,children:o?s.jsxs(ve,{className:"humany-conversation-discrete-message",children:[e,s.jsx(M,{timestamp:r})]}):s.jsxs(s.Fragment,{children:[e,s.jsx(M,{timestamp:r})]})})),xe=i.div`
281
+ `,pe=y.forwardRef(({className:t,children:e,timestamp:r,discrete:o,fullWidth:a},l)=>s.jsx(xe,{ref:l,className:z.appendClassNames(t,"humany-conversation-system-message"),fullWidth:a,children:o?s.jsxs(ve,{className:"humany-conversation-discrete-message",children:[e,s.jsx(L,{timestamp:r})]}):s.jsxs(s.Fragment,{children:[e,s.jsx(L,{timestamp:r})]})})),xe=i.div`
282
282
  ${t=>t.fullWidth&&"width: 100%"};
283
283
  padding: 0 ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.large}};
284
284
  overflow: auto;
@@ -290,7 +290,7 @@
290
290
  > p {
291
291
  margin: 0;
292
292
  }
293
- `,$e=({className:t,children:e,timestamp:r})=>{const{userLabel:o=""}=n.useProperties();return s.jsxs(je,{className:L.appendClassNames(t,"humany-conversation-user-message"),children:[e,s.jsx(M,{name:o,timestamp:r})]})},je=i.div`
293
+ `,$e=({className:t,children:e,timestamp:r})=>{const{userLabel:o=""}=n.useProperties();return s.jsxs(je,{className:z.appendClassNames(t,"humany-conversation-user-message"),children:[e,s.jsx(L,{name:o,timestamp:r,ariaHidden:!0})]})},je=i.div`
294
294
  margin-left: 10%;
295
295
  width: 90%;
296
296
  display: flex;
@@ -368,7 +368,7 @@
368
368
  }
369
369
  }
370
370
 
371
- ${t=>n.headingElement(t)("h1",b.css`
371
+ ${t=>n.headingElement(t)("h1",f.css`
372
372
  white-space: normal;
373
373
  `)}
374
374
 
@@ -425,11 +425,11 @@
425
425
  }
426
426
  }
427
427
  }
428
- `,Be=({header:t,actions:e,dispatch:r})=>{const o=n.usePrevious(e),a=y.useRef(),l=n.useIsTabbing();return y.useEffect(()=>{if(o&&Array.isArray(e)&&Array.isArray(o)&&o.length<e.length&&a.current){const d=a.current.querySelectorAll(".humany-conversation-link-list > ul > li"),u=d[o.length];if(d.length===e.length&&o.length){const h=d[o.length-1];if(h){const f=h.querySelector(".humany-button");f&&f.focus()}}else u&&new MutationObserver((f,p)=>{f.forEach(c=>{if(c.addedNodes){const g=Array.from(c.addedNodes).find(j=>j.tagName==="BUTTON");g&&L.htmlParentContains(a.current,document.activeElement)&&(l&&g.focus(),p.disconnect())}})}).observe(u,{attributes:!1,characterData:!1,childList:!0,subtree:!0,attributeOldValue:!1,characterDataOldValue:!1})}}),s.jsx(Ae,{ref:a,className:"humany-conversation-link-list",header:t,items:D(e),renderItem:d=>s.jsx("li",{children:s.jsxs(He,{help:d.actionKey==="help",onClick:()=>{r("action",d)},"aria-label":d.label,title:d.label,children:[d.label,d.actionKey==="help"&&s.jsx(n.SymbolBadge,{size:14,symbol:{type:"Svg",content:"caret-down"}})]})},d.actionKey)})},Ae=i(n.ItemList)`
428
+ `,Be=({header:t,actions:e,dispatch:r})=>{const o=n.usePrevious(e),a=y.useRef(),l=n.useIsTabbing();return y.useEffect(()=>{if(o&&Array.isArray(e)&&Array.isArray(o)&&o.length<e.length&&a.current){const d=a.current.querySelectorAll(".humany-conversation-link-list > ul > li"),u=d[o.length];if(d.length===e.length&&o.length){const h=d[o.length-1];if(h){const b=h.querySelector(".humany-button");b&&b.focus()}}else u&&new MutationObserver((b,p)=>{b.forEach(c=>{if(c.addedNodes){const g=Array.from(c.addedNodes).find(j=>j.tagName==="BUTTON");g&&z.htmlParentContains(a.current,document.activeElement)&&(l&&g.focus(),p.disconnect())}})}).observe(u,{attributes:!1,characterData:!1,childList:!0,subtree:!0,attributeOldValue:!1,characterDataOldValue:!1})}}),s.jsx(He,{ref:a,className:"humany-conversation-link-list",header:t,items:D(e),renderItem:d=>s.jsx("li",{children:s.jsxs(Ae,{help:d.actionKey==="help",onClick:()=>{r("action",d)},"aria-label":d.label,title:d.label,children:[d.label,d.actionKey==="help"&&s.jsx(n.SymbolBadge,{size:14,symbol:{type:"Svg",content:"caret-down"}})]})},d.actionKey)})},He=i(n.ItemList)`
429
429
  ${n.itemList}
430
430
  ${w}
431
431
 
432
- ${t=>n.headingElement(t)("h1",b.css`
432
+ ${t=>n.headingElement(t)("h1",f.css`
433
433
  white-space: normal;
434
434
  `)}
435
435
 
@@ -441,7 +441,7 @@
441
441
  margin: 0;
442
442
  }
443
443
  }
444
- `,He=i(n.Button)`
444
+ `,Ae=i(n.Button)`
445
445
  display: block;
446
446
  text-align: left;
447
447
  font-weight: 300;
@@ -450,7 +450,7 @@
450
450
  text-overflow: ellipsis;
451
451
  overflow: hidden;
452
452
 
453
- ${t=>{var e,r;return t.help&&b.css`
453
+ ${t=>{var e,r;return t.help&&f.css`
454
454
  color: ${(e=t.theme.colors)==null?void 0:e.text};
455
455
  text-decoration: underline;
456
456
 
@@ -523,14 +523,14 @@
523
523
  > li {
524
524
  margin: 0;
525
525
  }
526
- `,Ve=y.forwardRef(({className:t,timestamp:e,sender:r,type:o,content:a},l)=>{const d=y.useCallback(c=>{let g="first";return a.length>1&&(g=c===0?"first":c+1===a.length?"last":"middle"),g},[a]),{userLabel:u=""}=n.useProperties(),h=()=>s.jsx(s.Fragment,{children:a.map(c=>{const{key:g,body:j,title:k,form:x,actions:z}=c,T=!!j&&!k&&!x&&!z;return s.jsx(pe,{className:t,discrete:T,ref:l,timestamp:e,fullWidth:!!x||!!z,children:T&&j?s.jsx(n.Html,{html:j}):s.jsx(A,{isSystem:!0,content:c})},g)})}),f=()=>s.jsxs(s.Fragment,{children:[s.jsxs(F,{className:"humany-sr-only",children:[r==null?void 0:r.name,":"]}),s.jsx(V,{sender:r,timestamp:e,className:t,children:s.jsx(O,{className:"humany-message-content-bundle",children:a.map((c,g)=>s.jsx(R,{className:"humany-message-container",left:!0,ref:l,children:s.jsx(A,{content:c,stacked:d(g)})},c.key))})})]}),p=()=>s.jsxs(s.Fragment,{children:[s.jsxs(F,{className:"humany-sr-only",children:[u,":"]}),s.jsx($e,{timestamp:e,className:t,children:s.jsx(O,{className:"humany-message-content-bundle",children:a.map((c,g)=>s.jsx(R,{className:"humany-message-container",right:!0,ref:l,children:s.jsx(A,{isUser:!0,content:c,stacked:d(g)})},c.key))})})]});switch(o){case $.ConversationMessageType.System:return h();case $.ConversationMessageType.Agent:return f();case $.ConversationMessageType.User:return p();default:return null}}),A=({content:t,isUser:e,isSystem:r,stacked:o})=>{const a=n.useDispatch(),{title:l,body:d,actions:u,form:h,items:f}=t;return f?s.jsx(E,{className:"humany-message-content",user:!!e,stacked:o,children:s.jsx(We,{items:f,dispatch:a})}):s.jsxs(E,{className:"humany-message-content",padded:!r,user:!!e,stacked:o,fullWidth:!!h||!!u,children:[l&&s.jsx(N,{children:s.jsx(ce,{variant:"h2",children:l})}),d&&s.jsx(N,{children:s.jsx(he,{html:d})}),h&&s.jsx(N,{children:s.jsx(ue,{...h,onChange:(c,g)=>{a("form",{data:g,formKey:h.schema.id,actionKey:c})}})}),u&&s.jsx(N,{children:s.jsx(ge,{items:Object.keys(u).map(c=>({label:u[c],actionKey:c})),renderItem:c=>s.jsx("li",{children:s.jsx(ye,{onClick:()=>{a("action",c.actionKey)},children:c.label})},c.actionKey)})})]})},F=i.div`
526
+ `,Ve=y.forwardRef(({className:t,timestamp:e,sender:r,type:o,content:a},l)=>{const d=y.useCallback(c=>{let g="first";return a.length>1&&(g=c===0?"first":c+1===a.length?"last":"middle"),g},[a]),{userLabel:u=""}=n.useProperties(),h=()=>s.jsx(s.Fragment,{children:a.map(c=>{const{key:g,body:j,title:k,form:x,actions:T}=c,N=!!j&&!k&&!x&&!T;return s.jsx(pe,{className:t,discrete:N,ref:l,timestamp:e,fullWidth:!!x||!!T,children:N&&j?s.jsx(n.Html,{html:j}):s.jsx(H,{isSystem:!0,content:c})},g)})}),b=()=>s.jsxs(s.Fragment,{children:[s.jsx(F,{className:"humany-sr-only",children:s.jsx(L,{name:r==null?void 0:r.name,timestamp:e})}),s.jsx(V,{sender:r,timestamp:e,className:t,children:s.jsx(O,{className:"humany-message-content-bundle",children:a.map((c,g)=>s.jsx(R,{className:"humany-message-container",left:!0,ref:l,children:s.jsx(H,{content:c,stacked:d(g)})},c.key))})})]}),p=()=>s.jsxs(s.Fragment,{children:[s.jsx(F,{className:"humany-sr-only",children:s.jsx(L,{name:u,timestamp:e})}),s.jsx($e,{timestamp:e,className:t,children:s.jsx(O,{className:"humany-message-content-bundle",children:a.map((c,g)=>s.jsx(R,{className:"humany-message-container",right:!0,ref:l,children:s.jsx(H,{isUser:!0,content:c,stacked:d(g)})},c.key))})})]});switch(o){case $.ConversationMessageType.System:return h();case $.ConversationMessageType.Agent:return b();case $.ConversationMessageType.User:return p();default:return null}}),H=({content:t,isUser:e,isSystem:r,stacked:o})=>{const a=n.useDispatch(),{title:l,body:d,actions:u,form:h,items:b}=t;return b?s.jsx(E,{className:"humany-message-content",user:!!e,stacked:o,children:s.jsx(We,{items:b,dispatch:a})}):s.jsxs(E,{className:"humany-message-content",padded:!r,user:!!e,stacked:o,fullWidth:!!h||!!u,children:[l&&s.jsx(M,{children:s.jsx(ce,{variant:"h2",children:l})}),d&&s.jsx(M,{children:s.jsx(he,{html:d})}),h&&s.jsx(M,{children:s.jsx(ue,{...h,onChange:(c,g)=>{a("form",{data:g,formKey:h.schema.id,actionKey:c})}})}),u&&s.jsx(M,{children:s.jsx(ge,{items:Object.keys(u).map(c=>({label:u[c],actionKey:c})),renderItem:c=>s.jsx("li",{children:s.jsx(ye,{onClick:()=>{a("action",c.actionKey)},children:c.label})},c.actionKey)})})]})},F=i.div`
527
527
  position: absolute;
528
528
  left: -10000px;
529
529
  top: auto;
530
530
  width: 1px;
531
531
  height: 1px;
532
532
  overflow: hidden;
533
- `,_=()=>{const t=y.useCallback(u=>{u&&setTimeout(()=>{u.scrollIntoView({block:"start",behavior:"smooth"})},250)},[]),[e,r]=n.useScroll(!0),{messages:o,loading:a,typingActors:l=[]}=n.useProperties(),d=()=>l&&l.length?l.map((u,h)=>s.jsx(H,{id:`typing_${u.name}`,children:s.jsx(V,{timestamp:Date.now(),sender:u,children:s.jsx(q,{boxed:!0,ref:t})})},`typing_${u.name}`)):null;return s.jsxs(s.Fragment,{children:[s.jsxs(_e,{tabIndex:0,scrollableCss:e,ref:r,children:[o&&o.length?o.map((u,h)=>{const{type:f,timestamp:p,sender:c,content:g}=u;return s.jsx(H,{className:"humany-conversation-entry",tabIndex:-1,children:s.jsx(Ve,{...u,ref:t})},`${f}_${c==null?void 0:c.name}_${p}_${g[0].key}`)}):null,d(),a&&s.jsx(H,{children:s.jsx(q,{ref:t})})]}),s.jsx(Z,{})]})},_e=i.div`
533
+ `,_=()=>{const t=y.useCallback(u=>{u&&setTimeout(()=>{u.scrollIntoView({block:"start",behavior:"smooth"})},250)},[]),[e,r]=n.useScroll(!0),{messages:o,loading:a,typingActors:l=[]}=n.useProperties(),d=()=>l&&l.length?l.map((u,h)=>s.jsx(A,{id:`typing_${u.name}`,children:s.jsx(V,{timestamp:Date.now(),sender:u,children:s.jsx(q,{boxed:!0,ref:t})})},`typing_${u.name}`)):null;return s.jsxs(s.Fragment,{children:[s.jsxs(_e,{tabIndex:0,scrollableCss:e,ref:r,children:[o&&o.length?o.map((u,h)=>{const{type:b,timestamp:p,sender:c,content:g}=u;return s.jsx(A,{className:"humany-conversation-entry",tabIndex:-1,children:s.jsx(Ve,{...u,ref:t})},`${b}_${c==null?void 0:c.name}_${p}_${g[0].key}`)}):null,d(),a&&s.jsx(A,{children:s.jsx(q,{ref:t})})]}),s.jsx(Z,{})]})},_e=i.div`
534
534
  display: flex;
535
535
  flex-direction: column;
536
536
  align-items: stretch;
@@ -540,7 +540,7 @@
540
540
  &:focus-visible {
541
541
  ${t=>n.borderTabStyle(t)};
542
542
  }
543
- `,H=i.div`
543
+ `,A=i.div`
544
544
  margin: 0;
545
545
  margin-bottom: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.medium}};
546
546
 
@@ -568,7 +568,7 @@
568
568
  ${n.borderTabStyle}
569
569
  border-radius: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.small}};
570
570
  }
571
- ${t=>n.headingElement(t)("h1",b.css`
571
+ ${t=>n.headingElement(t)("h1",f.css`
572
572
  font-weight: normal;
573
573
  `)}
574
574
  `,Ye=({dispatch:t})=>{const e=y.useRef(null);return y.useEffect(()=>{e.current&&e.current.parentNode&&t("overlay-mounted",e.current)},[e]),s.jsx(n.WidgetOverlayOutlet,{portalId:"humany-conversation-overlay-portal",className:"humany-conversation-overlay-outlet",ref:e})},Xe=({dispatch:t,header:e,buttonLabel:r})=>s.jsxs(Ge,{portalId:"humany-conversation-portal",className:"humany-conversation-outlet",children:[s.jsxs(Je,{className:"humany-conversation-outlet-head",children:[s.jsx(Ze,{className:"humany-conversation-outlet-head-button","aria-label":r,title:r,onClick:()=>t("hide-overlay-conversation"),children:s.jsx(n.SymbolBadge,{symbol:{type:"Svg",content:"caret-down"},size:20})}),e&&s.jsx(Qe,{className:"humany-conversation-outlet-header",variant:"h1",children:e})]}),s.jsx(_,{})]}),Ge=i(n.WidgetOverlayOutlet)`
@@ -606,7 +606,7 @@
606
606
  svg line {
607
607
  stroke: ${t=>{var e;return(e=t.theme.colors)==null?void 0:e.text}};
608
608
  }
609
- `,et=({className:t,...e})=>{const{overlay:r,overlayConversationHeader:o,overlayConversationCloseLabel:a,conversationControllerId:l}=n.useProperties(),d=n.useDispatch(),h=n.useContainer().get("$settings");return s.jsx(n.ConversationContext.Provider,{value:l?{id:l}:null,children:s.jsxs(U.Provider,{value:h==null?void 0:h.language,children:[s.jsx(tt,{"aria-live":"assertive",...e,className:L.appendClassNames(t,"humany-conversation-component"),children:s.jsx(_,{})}),r&&s.jsxs(s.Fragment,{children:[s.jsx(Ye,{dispatch:d}),r.conversation&&s.jsx(Xe,{dispatch:d,header:o,buttonLabel:a})]})]})})},tt=i.div`
609
+ `,et=({className:t,...e})=>{const{overlay:r,overlayConversationHeader:o,overlayConversationCloseLabel:a,conversationControllerId:l}=n.useProperties(),d=n.useDispatch(),h=n.useContainer().get("$settings");return s.jsx(n.ConversationContext.Provider,{value:l?{id:l}:null,children:s.jsxs(U.Provider,{value:h==null?void 0:h.language,children:[s.jsx(tt,{"aria-live":"assertive",...e,className:z.appendClassNames(t,"humany-conversation-component"),children:s.jsx(_,{})}),r&&s.jsxs(s.Fragment,{children:[s.jsx(Ye,{dispatch:d}),r.conversation&&s.jsx(Xe,{dispatch:d,header:o,buttonLabel:a})]})]})})},tt=i.div`
610
610
  position: absolute;
611
611
  right: 0;
612
612
  left: 0;
@@ -1,16 +1,16 @@
1
- import { jsx as n, jsxs as u, Fragment as N } from "react/jsx-runtime";
1
+ import { jsx as n, jsxs as h, Fragment as N } from "react/jsx-runtime";
2
2
  import a from "@emotion/styled";
3
- import { borderTabStyle as f, Input as se, Button as M, SymbolBadge as x, useIsTabbing as ae, useDispatch as Y, useContainer as ie, useProperties as I, useScroll as le, Typography as X, invertedHoverButton as xe, Html as G, List as ce, buttonCss as B, ItemList as K, itemList as E, Link as we, useComponent as ke, genericHtml as Ce, headingElement as J, usePrevious as Se, list as ze, WidgetOverlayOutlet as de, ConversationContext as Le } from "@telia-ace/widget-ui";
3
+ import { borderTabStyle as f, Input as se, Button as I, SymbolBadge as x, useIsTabbing as ae, useDispatch as Y, useContainer as ie, useProperties as H, useScroll as le, Typography as X, invertedHoverButton as xe, Html as G, List as ce, buttonCss as B, ItemList as K, itemList as E, Link as we, useComponent as ke, genericHtml as Ce, headingElement as J, usePrevious as Se, list as ze, WidgetOverlayOutlet as de, ConversationContext as Le } from "@telia-ace/widget-ui";
4
4
  import { appendClassNames as T, htmlParentContains as Ne } from "@telia-ace/widget-utilities";
5
5
  import { css as p, keyframes as Me } from "@emotion/react";
6
- import Ie, { useState as P, useEffect as Q, forwardRef as Z, useContext as Te, Suspense as Ae, useRef as me, useMemo as He, useCallback as ue } from "react";
6
+ import Ie, { useState as P, useEffect as Q, forwardRef as Z, useContext as He, Suspense as Te, useRef as me, useMemo as Ae, useCallback as ue } from "react";
7
7
  import { FormComponent as Oe } from "@telia-ace/widget-forms";
8
8
  import { ConversationMessageListItemType as C, ConversationMessageType as W } 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 Re = ({ className: t }) => {
13
- const [e, r] = P(""), [o, s] = P(0), [i, c] = P(0), m = ae(), h = Y(), y = ie(), {
13
+ const [e, r] = P(""), [o, s] = P(0), [i, c] = P(0), m = ae(), u = Y(), y = ie(), {
14
14
  inputPlaceholder: b = "Type your message",
15
15
  inputHidden: l = !1,
16
16
  inputDisabled: g = !1,
@@ -18,7 +18,7 @@ const Re = ({ className: t }) => {
18
18
  inputMultiline: z = !0,
19
19
  secondaryAction: $,
20
20
  skipToLatestMessageLabel: A = "Skip to latest message"
21
- } = I(), [H, v] = le(!0);
21
+ } = H(), [O, v] = le(!0);
22
22
  Q(() => {
23
23
  if (v.current) {
24
24
  const { lineHeight: d, maxHeight: k } = getComputedStyle(v.current);
@@ -31,9 +31,9 @@ const Re = ({ className: t }) => {
31
31
  }
32
32
  }, [v.current]);
33
33
  const D = (d) => {
34
- !d.shiftKey || !z ? (d.preventDefault(), e && e.length > 0 && (h("user-submit", { text: e }), r(""), j(""))) : e.length < 1 && d.preventDefault();
34
+ !d.shiftKey || !z ? (d.preventDefault(), e && e.length > 0 && (u("user-submit", { text: e }), r(""), j(""))) : e.length < 1 && d.preventDefault();
35
35
  }, pe = (d) => {
36
- $ && (d.preventDefault(), h("action", {
36
+ $ && (d.preventDefault(), u("action", {
37
37
  actionKey: $.action,
38
38
  ...$
39
39
  }));
@@ -47,7 +47,7 @@ const Re = ({ className: t }) => {
47
47
  }
48
48
  }
49
49
  }, j = (d) => {
50
- be(d), r(d), d && d.length > 0 && h("user-typing", { textLength: d.length });
50
+ be(d), r(d), d && d.length > 0 && u("user-typing", { textLength: d.length });
51
51
  }, te = () => {
52
52
  const d = y.get("widgetDOMElement");
53
53
  if (d) {
@@ -57,12 +57,12 @@ const Re = ({ className: t }) => {
57
57
  k.length && k[k.length - 1].focus();
58
58
  }
59
59
  };
60
- return l ? null : /* @__PURE__ */ u(
60
+ return l ? null : /* @__PURE__ */ h(
61
61
  je,
62
62
  {
63
63
  grow: z,
64
64
  className: T("humany-conversation-input", t),
65
- scrollableCss: H,
65
+ scrollableCss: O,
66
66
  isTabbing: m,
67
67
  children: [
68
68
  $ && /* @__PURE__ */ n(
@@ -206,7 +206,7 @@ const Re = ({ className: t }) => {
206
206
  }};
207
207
  font-style: italic;
208
208
  }
209
- `, he = a(M)`
209
+ `, he = a(I)`
210
210
  flex: 0 0 50px;
211
211
  align-self: stretch;
212
212
  background-color: transparent;
@@ -416,7 +416,7 @@ const Re = ({ className: t }) => {
416
416
  border-bottom-right-radius: ${e.borderRadius};
417
417
  `}
418
418
  ` : r;
419
- }, O = a.div`
419
+ }, R = a.div`
420
420
  margin-bottom: ${(t) => {
421
421
  var e;
422
422
  return (e = t.theme.sizes) == null ? void 0 : e.normal;
@@ -501,7 +501,7 @@ const Re = ({ className: t }) => {
501
501
  {
502
502
  padded: !!t,
503
503
  stacked: t ? "first" : void 0,
504
- children: /* @__PURE__ */ u(Ue, { children: [
504
+ children: /* @__PURE__ */ h(Ue, { children: [
505
505
  /* @__PURE__ */ n("div", {}),
506
506
  /* @__PURE__ */ n("div", {}),
507
507
  /* @__PURE__ */ n("div", {})
@@ -526,20 +526,25 @@ const Re = ({ className: t }) => {
526
526
  `, re = (t, e) => new Date(t).toLocaleTimeString(e || [], {
527
527
  hour: "numeric",
528
528
  minute: "2-digit"
529
- }), R = ({ className: t, name: e, timestamp: r }) => {
530
- const o = Te(ge);
529
+ }), M = ({
530
+ className: t,
531
+ name: e,
532
+ timestamp: r,
533
+ ariaHidden: o = !1
534
+ }) => {
535
+ const s = He(ge);
531
536
  if (!e && !r)
532
537
  return null;
533
- let s = "";
534
- return e ? r ? s = `${e}: ${re(r, o)}` : s = e : r && (s = re(r, o)), /* @__PURE__ */ n(Qe, { children: s });
538
+ let i = "";
539
+ return e ? r ? i = `${e}: ${re(r, s)}` : i = e : r && (i = re(r, s)), /* @__PURE__ */ n(Qe, { "aria-hidden": o, children: i });
535
540
  }, fe = ({
536
541
  className: t,
537
542
  children: e,
538
543
  sender: r,
539
544
  timestamp: o
540
545
  }) => {
541
- const { avatar: s, name: i } = r, { avatarSize: c } = I();
542
- return /* @__PURE__ */ u(
546
+ const { avatar: s, name: i } = r, { avatarSize: c } = H();
547
+ return /* @__PURE__ */ h(
543
548
  Ze,
544
549
  {
545
550
  hasAvatar: !!s,
@@ -553,7 +558,14 @@ const Re = ({ className: t }) => {
553
558
  /* @__PURE__ */ n("img", { src: s })
554
559
  ) : /* @__PURE__ */ n(x, { symbol: s }) }),
555
560
  e,
556
- /* @__PURE__ */ n(R, { name: i, timestamp: o })
561
+ /* @__PURE__ */ n(
562
+ M,
563
+ {
564
+ name: i,
565
+ timestamp: o,
566
+ ariaHidden: !0
567
+ }
568
+ )
557
569
  ]
558
570
  }
559
571
  );
@@ -584,12 +596,12 @@ const Re = ({ className: t }) => {
584
596
  "humany-conversation-system-message"
585
597
  ),
586
598
  fullWidth: s,
587
- children: o ? /* @__PURE__ */ u(nt, { className: "humany-conversation-discrete-message", children: [
599
+ children: o ? /* @__PURE__ */ h(nt, { className: "humany-conversation-discrete-message", children: [
588
600
  e,
589
- /* @__PURE__ */ n(R, { timestamp: r })
590
- ] }) : /* @__PURE__ */ u(N, { children: [
601
+ /* @__PURE__ */ n(M, { timestamp: r })
602
+ ] }) : /* @__PURE__ */ h(N, { children: [
591
603
  e,
592
- /* @__PURE__ */ n(R, { timestamp: r })
604
+ /* @__PURE__ */ n(M, { timestamp: r })
593
605
  ] })
594
606
  }
595
607
  )
@@ -615,8 +627,8 @@ const Re = ({ className: t }) => {
615
627
  margin: 0;
616
628
  }
617
629
  `, rt = ({ className: t, children: e, timestamp: r }) => {
618
- const { userLabel: o = "" } = I();
619
- return /* @__PURE__ */ u(
630
+ const { userLabel: o = "" } = H();
631
+ return /* @__PURE__ */ h(
620
632
  ot,
621
633
  {
622
634
  className: T(
@@ -625,7 +637,14 @@ const Re = ({ className: t }) => {
625
637
  ),
626
638
  children: [
627
639
  e,
628
- /* @__PURE__ */ n(R, { name: o, timestamp: r })
640
+ /* @__PURE__ */ n(
641
+ M,
642
+ {
643
+ name: o,
644
+ timestamp: r,
645
+ ariaHidden: !0
646
+ }
647
+ )
629
648
  ]
630
649
  }
631
650
  );
@@ -647,7 +666,7 @@ const Re = ({ className: t }) => {
647
666
  renderItem: (o) => {
648
667
  var i;
649
668
  const s = !!((i = o == null ? void 0 : o.data) != null && i.href);
650
- return /* @__PURE__ */ n("li", { children: s ? /* @__PURE__ */ u(
669
+ return /* @__PURE__ */ n("li", { children: s ? /* @__PURE__ */ h(
651
670
  it,
652
671
  {
653
672
  onClick: () => {
@@ -662,7 +681,7 @@ const Re = ({ className: t }) => {
662
681
  o.label
663
682
  ]
664
683
  }
665
- ) : /* @__PURE__ */ u(
684
+ ) : /* @__PURE__ */ h(
666
685
  lt,
667
686
  {
668
687
  onClick: () => {
@@ -720,7 +739,7 @@ const Re = ({ className: t }) => {
720
739
  return (e = t.theme.sizes) == null ? void 0 : e.small;
721
740
  }};
722
741
  }
723
- `, lt = a(M)`
742
+ `, lt = a(I)`
724
743
  ${B};
725
744
 
726
745
  display: block;
@@ -750,7 +769,7 @@ const Re = ({ className: t }) => {
750
769
  }
751
770
  `, ct = ({ type: t, content: e = {} }) => {
752
771
  const r = ke(t);
753
- return !r || !t ? null : /* @__PURE__ */ n(Ae, { fallback: null, children: /* @__PURE__ */ n(r, { ...e }) });
772
+ return !r || !t ? null : /* @__PURE__ */ n(Te, { fallback: null, children: /* @__PURE__ */ n(r, { ...e }) });
754
773
  }, dt = ({ body: t }) => /* @__PURE__ */ n(mt, { html: t }), mt = a(G)`
755
774
  ${Ce}
756
775
  color: inherit;
@@ -770,7 +789,7 @@ const Re = ({ className: t }) => {
770
789
  items: ee(e),
771
790
  renderItem: (o) => {
772
791
  var s;
773
- return /* @__PURE__ */ n("li", { children: /* @__PURE__ */ u(gt, { children: [
792
+ return /* @__PURE__ */ n("li", { children: /* @__PURE__ */ h(gt, { children: [
774
793
  ((s = o.symbol) == null ? void 0 : s.content) && /* @__PURE__ */ n("div", { className: "item-icon", children: /* @__PURE__ */ n(
775
794
  x,
776
795
  {
@@ -781,9 +800,9 @@ const Re = ({ className: t }) => {
781
800
  }
782
801
  }
783
802
  ) }),
784
- /* @__PURE__ */ u("div", { className: "item-body", children: [
803
+ /* @__PURE__ */ h("div", { className: "item-body", children: [
785
804
  /* @__PURE__ */ n(
786
- M,
805
+ I,
787
806
  {
788
807
  onClick: () => {
789
808
  r("action", o);
@@ -893,9 +912,9 @@ const Re = ({ className: t }) => {
893
912
  ".humany-conversation-link-list > ul > li"
894
913
  ), m = c[o.length];
895
914
  if (c.length === e.length && o.length) {
896
- const h = c[o.length - 1];
897
- if (h) {
898
- const y = h.querySelector(
915
+ const u = c[o.length - 1];
916
+ if (u) {
917
+ const y = u.querySelector(
899
918
  ".humany-button"
900
919
  );
901
920
  y && y.focus();
@@ -926,7 +945,7 @@ const Re = ({ className: t }) => {
926
945
  className: "humany-conversation-link-list",
927
946
  header: t,
928
947
  items: ee(e),
929
- renderItem: (c) => /* @__PURE__ */ n("li", { children: /* @__PURE__ */ u(
948
+ renderItem: (c) => /* @__PURE__ */ n("li", { children: /* @__PURE__ */ h(
930
949
  pt,
931
950
  {
932
951
  help: c.actionKey === "help",
@@ -974,7 +993,7 @@ const Re = ({ className: t }) => {
974
993
  margin: 0;
975
994
  }
976
995
  }
977
- `, pt = a(M)`
996
+ `, pt = a(I)`
978
997
  display: block;
979
998
  text-align: left;
980
999
  font-weight: 300;
@@ -1020,7 +1039,7 @@ const Re = ({ className: t }) => {
1020
1039
  declineLabel: r = "Decline",
1021
1040
  dispatch: o
1022
1041
  }) => {
1023
- const s = He(() => [
1042
+ const s = Ae(() => [
1024
1043
  {
1025
1044
  label: e,
1026
1045
  actionKey: "accept-video-call",
@@ -1075,7 +1094,7 @@ const Re = ({ className: t }) => {
1075
1094
  }
1076
1095
  }
1077
1096
  ${(t) => S(t)}
1078
- `, Ct = a(M)`
1097
+ `, Ct = a(I)`
1079
1098
  ${B};
1080
1099
 
1081
1100
  background-color: ${(t) => t.bgColor};
@@ -1157,25 +1176,22 @@ const Re = ({ className: t }) => {
1157
1176
  return s.length > 1 && (g = l === 0 ? "first" : l + 1 === s.length ? "last" : "middle"), g;
1158
1177
  },
1159
1178
  [s]
1160
- ), { userLabel: m = "" } = I(), h = () => /* @__PURE__ */ n(N, { children: s.map((l) => {
1161
- const { key: g, body: w, title: z, form: $, actions: A } = l, H = !!w && !z && !$ && !A;
1179
+ ), { userLabel: m = "" } = H(), u = () => /* @__PURE__ */ n(N, { children: s.map((l) => {
1180
+ const { key: g, body: w, title: z, form: $, actions: A } = l, O = !!w && !z && !$ && !A;
1162
1181
  return /* @__PURE__ */ n(
1163
1182
  et,
1164
1183
  {
1165
1184
  className: t,
1166
- discrete: H,
1185
+ discrete: O,
1167
1186
  ref: i,
1168
1187
  timestamp: e,
1169
1188
  fullWidth: !!$ || !!A,
1170
- children: H && w ? /* @__PURE__ */ n(G, { html: w }) : /* @__PURE__ */ n(q, { isSystem: !0, content: l })
1189
+ children: O && w ? /* @__PURE__ */ n(G, { html: w }) : /* @__PURE__ */ n(q, { isSystem: !0, content: l })
1171
1190
  },
1172
1191
  g
1173
1192
  );
1174
- }) }), y = () => /* @__PURE__ */ u(N, { children: [
1175
- /* @__PURE__ */ u(oe, { className: "humany-sr-only", children: [
1176
- r == null ? void 0 : r.name,
1177
- ":"
1178
- ] }),
1193
+ }) }), y = () => /* @__PURE__ */ h(N, { children: [
1194
+ /* @__PURE__ */ n(oe, { className: "humany-sr-only", children: /* @__PURE__ */ n(M, { name: r == null ? void 0 : r.name, timestamp: e }) }),
1179
1195
  /* @__PURE__ */ n(
1180
1196
  fe,
1181
1197
  {
@@ -1200,11 +1216,8 @@ const Re = ({ className: t }) => {
1200
1216
  )) })
1201
1217
  }
1202
1218
  )
1203
- ] }), b = () => /* @__PURE__ */ u(N, { children: [
1204
- /* @__PURE__ */ u(oe, { className: "humany-sr-only", children: [
1205
- m,
1206
- ":"
1207
- ] }),
1219
+ ] }), b = () => /* @__PURE__ */ h(N, { children: [
1220
+ /* @__PURE__ */ n(oe, { className: "humany-sr-only", children: /* @__PURE__ */ n(M, { name: m, timestamp: e }) }),
1208
1221
  /* @__PURE__ */ n(rt, { timestamp: e, className: t, children: /* @__PURE__ */ n(V, { className: "humany-message-content-bundle", children: s.map((l, g) => /* @__PURE__ */ n(
1209
1222
  _,
1210
1223
  {
@@ -1225,7 +1238,7 @@ const Re = ({ className: t }) => {
1225
1238
  ] });
1226
1239
  switch (o) {
1227
1240
  case W.System:
1228
- return h();
1241
+ return u();
1229
1242
  case W.Agent:
1230
1243
  return y();
1231
1244
  case W.User:
@@ -1240,7 +1253,7 @@ const Re = ({ className: t }) => {
1240
1253
  isSystem: r,
1241
1254
  stacked: o
1242
1255
  }) => {
1243
- const s = Y(), { title: i, body: c, actions: m, form: h, items: y } = t;
1256
+ const s = Y(), { title: i, body: c, actions: m, form: u, items: y } = t;
1244
1257
  return y ? /* @__PURE__ */ n(
1245
1258
  F,
1246
1259
  {
@@ -1249,31 +1262,31 @@ const Re = ({ className: t }) => {
1249
1262
  stacked: o,
1250
1263
  children: /* @__PURE__ */ n(zt, { items: y, dispatch: s })
1251
1264
  }
1252
- ) : /* @__PURE__ */ u(
1265
+ ) : /* @__PURE__ */ h(
1253
1266
  F,
1254
1267
  {
1255
1268
  className: "humany-message-content",
1256
1269
  padded: !r,
1257
1270
  user: !!e,
1258
1271
  stacked: o,
1259
- fullWidth: !!h || !!m,
1272
+ fullWidth: !!u || !!m,
1260
1273
  children: [
1261
- i && /* @__PURE__ */ n(O, { children: /* @__PURE__ */ n(Ve, { variant: "h2", children: i }) }),
1262
- c && /* @__PURE__ */ n(O, { children: /* @__PURE__ */ n(Xe, { html: c }) }),
1263
- h && /* @__PURE__ */ n(O, { children: /* @__PURE__ */ n(
1274
+ i && /* @__PURE__ */ n(R, { children: /* @__PURE__ */ n(Ve, { variant: "h2", children: i }) }),
1275
+ c && /* @__PURE__ */ n(R, { children: /* @__PURE__ */ n(Xe, { html: c }) }),
1276
+ u && /* @__PURE__ */ n(R, { children: /* @__PURE__ */ n(
1264
1277
  Ye,
1265
1278
  {
1266
- ...h,
1279
+ ...u,
1267
1280
  onChange: (l, g) => {
1268
1281
  s("form", {
1269
1282
  data: g,
1270
- formKey: h.schema.id,
1283
+ formKey: u.schema.id,
1271
1284
  actionKey: l
1272
1285
  });
1273
1286
  }
1274
1287
  }
1275
1288
  ) }),
1276
- m && /* @__PURE__ */ n(O, { children: /* @__PURE__ */ n(
1289
+ m && /* @__PURE__ */ n(R, { children: /* @__PURE__ */ n(
1277
1290
  Ge,
1278
1291
  {
1279
1292
  items: Object.keys(m).map((l) => ({ label: m[l], actionKey: l })),
@@ -1310,7 +1323,7 @@ const Re = ({ className: t }) => {
1310
1323
  messages: o,
1311
1324
  loading: s,
1312
1325
  typingActors: i = []
1313
- } = I(), c = () => i && i.length ? i.map((m, h) => /* @__PURE__ */ n(
1326
+ } = H(), c = () => i && i.length ? i.map((m, u) => /* @__PURE__ */ n(
1314
1327
  U,
1315
1328
  {
1316
1329
  id: `typing_${m.name}`,
@@ -1324,9 +1337,9 @@ const Re = ({ className: t }) => {
1324
1337
  },
1325
1338
  `typing_${m.name}`
1326
1339
  )) : null;
1327
- return /* @__PURE__ */ u(N, { children: [
1328
- /* @__PURE__ */ u(Mt, { tabIndex: 0, scrollableCss: e, ref: r, children: [
1329
- o && o.length ? o.map((m, h) => {
1340
+ return /* @__PURE__ */ h(N, { children: [
1341
+ /* @__PURE__ */ h(Mt, { tabIndex: 0, scrollableCss: e, ref: r, children: [
1342
+ o && o.length ? o.map((m, u) => {
1330
1343
  const { type: y, timestamp: b, sender: l, content: g } = m;
1331
1344
  return /* @__PURE__ */ n(
1332
1345
  U,
@@ -1414,17 +1427,17 @@ const Re = ({ className: t }) => {
1414
1427
  ref: e
1415
1428
  }
1416
1429
  );
1417
- }, Tt = ({
1430
+ }, Ht = ({
1418
1431
  dispatch: t,
1419
1432
  header: e,
1420
1433
  buttonLabel: r
1421
- }) => /* @__PURE__ */ u(
1422
- At,
1434
+ }) => /* @__PURE__ */ h(
1435
+ Tt,
1423
1436
  {
1424
1437
  portalId: "humany-conversation-portal",
1425
1438
  className: "humany-conversation-outlet",
1426
1439
  children: [
1427
- /* @__PURE__ */ u(Ht, { className: "humany-conversation-outlet-head", children: [
1440
+ /* @__PURE__ */ h(At, { className: "humany-conversation-outlet-head", children: [
1428
1441
  /* @__PURE__ */ n(
1429
1442
  Rt,
1430
1443
  {
@@ -1456,7 +1469,7 @@ const Re = ({ className: t }) => {
1456
1469
  /* @__PURE__ */ n(ye, {})
1457
1470
  ]
1458
1471
  }
1459
- ), At = a(de)`
1472
+ ), Tt = a(de)`
1460
1473
  z-index: 11;
1461
1474
  top: auto;
1462
1475
  height: 65%;
@@ -1471,7 +1484,7 @@ const Re = ({ className: t }) => {
1471
1484
  var e;
1472
1485
  return (e = t.theme.sizes) == null ? void 0 : e.large;
1473
1486
  }};
1474
- `, Ht = a.div`
1487
+ `, At = a.div`
1475
1488
  display: flex;
1476
1489
  flex-direction: column;
1477
1490
  justify-content: center;
@@ -1495,7 +1508,7 @@ const Re = ({ className: t }) => {
1495
1508
  return (e = t.theme.colors) == null ? void 0 : e.text;
1496
1509
  }};
1497
1510
  margin: 0;
1498
- `, Rt = a(M)`
1511
+ `, Rt = a(I)`
1499
1512
  display: flex;
1500
1513
  align-items: center;
1501
1514
  justify-content: center;
@@ -1524,12 +1537,12 @@ const Re = ({ className: t }) => {
1524
1537
  overlayConversationHeader: o,
1525
1538
  overlayConversationCloseLabel: s,
1526
1539
  conversationControllerId: i
1527
- } = I(), c = Y(), h = ie().get("$settings");
1540
+ } = H(), c = Y(), u = ie().get("$settings");
1528
1541
  return /* @__PURE__ */ n(
1529
1542
  Le.Provider,
1530
1543
  {
1531
1544
  value: i ? { id: i } : null,
1532
- children: /* @__PURE__ */ u(ge.Provider, { value: h == null ? void 0 : h.language, children: [
1545
+ children: /* @__PURE__ */ h(ge.Provider, { value: u == null ? void 0 : u.language, children: [
1533
1546
  /* @__PURE__ */ n(
1534
1547
  Bt,
1535
1548
  {
@@ -1542,10 +1555,10 @@ const Re = ({ className: t }) => {
1542
1555
  children: /* @__PURE__ */ n(ye, {})
1543
1556
  }
1544
1557
  ),
1545
- r && /* @__PURE__ */ u(N, { children: [
1558
+ r && /* @__PURE__ */ h(N, { children: [
1546
1559
  /* @__PURE__ */ n(It, { dispatch: c }),
1547
1560
  r.conversation && /* @__PURE__ */ n(
1548
- Tt,
1561
+ Ht,
1549
1562
  {
1550
1563
  dispatch: c,
1551
1564
  header: o,
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 d=(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){d(this,"cache",new Map);d(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:h}=r.content,u=this.parseEntry(a,i,c,h);return u&&t.push(u),t},[])}parseEntry(e,t,s,r){const n=h=>{let u=[],l=[],m;if(Array.isArray(h)){const[g,f]=h;m=f}else m=h;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:h}=e;h.forEach(u=>{const l=n(u);a=[...a,...l.options],i=[...i,...l.messagesAsList]})}else{const h=n(e);a=[...a,...h.options],i=[...i,...h.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:h,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)),h&&typeof h=="string"&&(l=this.appendText(l,h,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){d(this,"id");d(this,"name");d(this,"avatar");d(this,"print",(e,t,s=null)=>{const r={name:this.name,avatar:this.avatar,id:this.id},n=k(e,t);return s=s??n.timestamp,this.provider.createEntry(n.key,n.content,y.Agent,r,s)});d(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){d(this,"subscriptions",[]);d(this,"options");d(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(){d(this,"_locking",Promise.resolve());d(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){d(this,"sessionStorageKey");d(this,"locker",new K);d(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),h=c>-1?t.registeredProviders[c]:t.createProvider(i.providerName),u=new P(h,{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(h=>{var u;return h.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){d(this,"print",(e,t,s=null)=>{const r=k(e,t);return s=s??r.timestamp,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 H{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 B{constructor(e,t,s){d(this,"formHandlers",{});d(this,"user",new j(this));d(this,"events");d(this,"providers",[]);d(this,"active",!1);d(this,"queuedProviders",[]);d(this,"registeredProviders",[]);d(this,"loaders",0);d(this,"componentMounted",!1);d(this,"store");d(this,"messages",[]);d(this,"typingActors",[]);d(this,"conversationHistory");d(this,"print",(e,t=null)=>{const s=k(e);return t=t??s.timestamp,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 H(c=>{if(c!==null){const{timestamp:h=void 0,...u}=c;a.content=u,h&&(a.timestamp=h)}else{const h=this.messages.indexOf(a);a.content=null,h>-1&&this.messages.splice(h,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 h=i.components().ofType("conversation");i.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:h,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 h=c.components().ofType("conversation");c.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:h,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){d(this,"events");d(this,"controllers",[]);d(this,"providers",[]);d(this,"disposeProviders",{});d(this,"subscriptions",[]);d(this,"storageWriter",null);d(this,"router",null);d(this,"buttonQuery",null);d(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 B(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(h=>h.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:h=[]}=i;h.forEach(u=>{(this.disposeProviders[u]||[]).forEach(l=>{l()})}),n(c)})),this.subscriptions.push(e.onStarted((a,i)=>{var h,u;const c={id:e.id,route:(h=this.router)==null?void 0:h.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-aa155357.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),h=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,h)})};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 _=(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))(_||{});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=B;exports.ConversationEndedBehavior=S;exports.ConversationEntry=H;exports.ConversationMessageListItemType=_;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){d(this,"id");d(this,"name");d(this,"avatar");d(this,"print",(e,t,s=null)=>{const r={name:this.name,avatar:this.avatar,id:this.id},n=k(e,t);return s=s??n.timestamp,this.provider.createEntry(n.key,n.content,y.Agent,r,s)});d(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){d(this,"subscriptions",[]);d(this,"options");d(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(){d(this,"_locking",Promise.resolve());d(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){d(this,"sessionStorageKey");d(this,"locker",new K);d(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),h=c>-1?t.registeredProviders[c]:t.createProvider(i.providerName),u=new P(h,{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(h=>{var u;return h.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){d(this,"print",(e,t,s=null)=>{const r=k(e,t);return s=s??r.timestamp,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 H{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 B{constructor(e,t,s){d(this,"formHandlers",{});d(this,"user",new j(this));d(this,"events");d(this,"providers",[]);d(this,"active",!1);d(this,"queuedProviders",[]);d(this,"registeredProviders",[]);d(this,"loaders",0);d(this,"componentMounted",!1);d(this,"store");d(this,"messages",[]);d(this,"typingActors",[]);d(this,"conversationHistory");d(this,"print",(e,t=null)=>{const s=k(e);return t=t??s.timestamp,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 H(c=>{if(c!==null){const{timestamp:h=void 0,...u}=c;a.content=u,h&&(a.timestamp=h)}else{const h=this.messages.indexOf(a);a.content=null,h>-1&&this.messages.splice(h,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 h=i.components().ofType("conversation");i.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:h,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 h=c.components().ofType("conversation");c.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:h,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){d(this,"events");d(this,"controllers",[]);d(this,"providers",[]);d(this,"disposeProviders",{});d(this,"subscriptions",[]);d(this,"storageWriter",null);d(this,"router",null);d(this,"buttonQuery",null);d(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 B(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(h=>h.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:h=[]}=i;h.forEach(u=>{(this.disposeProviders[u]||[]).forEach(l=>{l()})}),n(c)})),this.subscriptions.push(e.onStarted((a,i)=>{var h,u;const c={id:e.id,route:(h=this.router)==null?void 0:h.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-40b46299.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),h=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,h)})};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 _=(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))(_||{});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=B;exports.ConversationEndedBehavior=S;exports.ConversationEntry=H;exports.ConversationMessageListItemType=_;exports.ConversationMessageType=y;exports.ConversationPlatform=w;exports.ConversationProvider=A;exports.ConversationReturnButtonComponent=X;exports.registerCustomMessageComponent=Z;
package/index.mjs CHANGED
@@ -939,7 +939,7 @@ const ee = (o, e) => o.reduce((t, s, r) => {
939
939
  ]).then(([e, t]) => _(
940
940
  o,
941
941
  "conversation",
942
- import("./conversation-c78cdab6.mjs"),
942
+ import("./conversation-d0c4d18c.mjs"),
943
943
  async (s) => {
944
944
  const { rehydrate: r = !1 } = s.properties(), a = t.getRouteData().params.id || s.node.name || "component", i = await e.createController(a, {
945
945
  rehydrate: r
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/widget-conversation",
3
- "version": "1.1.2-rc.10",
3
+ "version": "1.1.2-rc.11",
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.1.2-rc.10",
14
- "@telia-ace/widget-forms": "^1.1.2-rc.10",
15
- "@telia-ace/widget-plugins": "^1.1.2-rc.10",
16
- "@telia-ace/widget-routing": "^1.1.2-rc.10",
17
- "@telia-ace/widget-services": "^1.1.2-rc.10",
18
- "@telia-ace/widget-ui": "^1.1.2-rc.10",
19
- "@telia-ace/widget-utilities": "^1.1.2-rc.10",
13
+ "@telia-ace/widget-core": "^1.1.2-rc.11",
14
+ "@telia-ace/widget-forms": "^1.1.2-rc.11",
15
+ "@telia-ace/widget-plugins": "^1.1.2-rc.11",
16
+ "@telia-ace/widget-routing": "^1.1.2-rc.11",
17
+ "@telia-ace/widget-services": "^1.1.2-rc.11",
18
+ "@telia-ace/widget-ui": "^1.1.2-rc.11",
19
+ "@telia-ace/widget-utilities": "^1.1.2-rc.11",
20
20
  "@webprovisions/platform": "^1.1.4"
21
21
  },
22
22
  "peerDependencies": {